| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011, 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011, 2012 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). | 3 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). |
| 4 * | 4 * |
| 5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
| 7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
| 8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
| 9 * | 9 * |
| 10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 inline void copyLCharsFromUCharSource(LChar* destination, | 109 inline void copyLCharsFromUCharSource(LChar* destination, |
| 110 const UChar* source, | 110 const UChar* source, |
| 111 size_t length) { | 111 size_t length) { |
| 112 #if OS(MACOSX) && (CPU(X86) || CPU(X86_64)) | 112 #if OS(MACOSX) && (CPU(X86) || CPU(X86_64)) |
| 113 const uintptr_t memoryAccessSize = | 113 const uintptr_t memoryAccessSize = |
| 114 16; // Memory accesses on 16 byte (128 bit) alignment | 114 16; // Memory accesses on 16 byte (128 bit) alignment |
| 115 const uintptr_t memoryAccessMask = memoryAccessSize - 1; | 115 const uintptr_t memoryAccessMask = memoryAccessSize - 1; |
| 116 | 116 |
| 117 size_t i = 0; | 117 size_t i = 0; |
| 118 for (; i < length && !isAlignedTo<memoryAccessMask>(&source[i]); ++i) { | 118 for (; i < length && !isAlignedTo<memoryAccessMask>(&source[i]); ++i) { |
| 119 ASSERT(!(source[i] & 0xff00)); | 119 DCHECK(!(source[i] & 0xff00)); |
| 120 destination[i] = static_cast<LChar>(source[i]); | 120 destination[i] = static_cast<LChar>(source[i]); |
| 121 } | 121 } |
| 122 | 122 |
| 123 const uintptr_t sourceLoadSize = | 123 const uintptr_t sourceLoadSize = |
| 124 32; // Process 32 bytes (16 UChars) each iteration | 124 32; // Process 32 bytes (16 UChars) each iteration |
| 125 const size_t ucharsPerLoop = sourceLoadSize / sizeof(UChar); | 125 const size_t ucharsPerLoop = sourceLoadSize / sizeof(UChar); |
| 126 if (length > ucharsPerLoop) { | 126 if (length > ucharsPerLoop) { |
| 127 const size_t endLength = length - ucharsPerLoop + 1; | 127 const size_t endLength = length - ucharsPerLoop + 1; |
| 128 for (; i < endLength; i += ucharsPerLoop) { | 128 for (; i < endLength; i += ucharsPerLoop) { |
| 129 #if ENABLE(ASSERT) | 129 #if DCHECK_IS_ON() |
| 130 for (unsigned checkIndex = 0; checkIndex < ucharsPerLoop; ++checkIndex) | 130 for (unsigned checkIndex = 0; checkIndex < ucharsPerLoop; ++checkIndex) |
| 131 ASSERT(!(source[i + checkIndex] & 0xff00)); | 131 DCHECK(!(source[i + checkIndex] & 0xff00)); |
| 132 #endif | 132 #endif |
| 133 __m128i first8UChars = | 133 __m128i first8UChars = |
| 134 _mm_load_si128(reinterpret_cast<const __m128i*>(&source[i])); | 134 _mm_load_si128(reinterpret_cast<const __m128i*>(&source[i])); |
| 135 __m128i second8UChars = | 135 __m128i second8UChars = |
| 136 _mm_load_si128(reinterpret_cast<const __m128i*>(&source[i + 8])); | 136 _mm_load_si128(reinterpret_cast<const __m128i*>(&source[i + 8])); |
| 137 __m128i packedChars = _mm_packus_epi16(first8UChars, second8UChars); | 137 __m128i packedChars = _mm_packus_epi16(first8UChars, second8UChars); |
| 138 _mm_storeu_si128(reinterpret_cast<__m128i*>(&destination[i]), | 138 _mm_storeu_si128(reinterpret_cast<__m128i*>(&destination[i]), |
| 139 packedChars); | 139 packedChars); |
| 140 } | 140 } |
| 141 } | 141 } |
| 142 | 142 |
| 143 for (; i < length; ++i) { | 143 for (; i < length; ++i) { |
| 144 ASSERT(!(source[i] & 0xff00)); | 144 DCHECK(!(source[i] & 0xff00)); |
| 145 destination[i] = static_cast<LChar>(source[i]); | 145 destination[i] = static_cast<LChar>(source[i]); |
| 146 } | 146 } |
| 147 #elif COMPILER(GCC) && CPU(ARM_NEON) && \ | 147 #elif COMPILER(GCC) && CPU(ARM_NEON) && \ |
| 148 !(CPU(BIG_ENDIAN) || CPU(MIDDLE_ENDIAN)) && defined(NDEBUG) | 148 !(CPU(BIG_ENDIAN) || CPU(MIDDLE_ENDIAN)) && defined(NDEBUG) |
| 149 const LChar* const end = destination + length; | 149 const LChar* const end = destination + length; |
| 150 const uintptr_t memoryAccessSize = 8; | 150 const uintptr_t memoryAccessSize = 8; |
| 151 | 151 |
| 152 if (length >= (2 * memoryAccessSize) - 1) { | 152 if (length >= (2 * memoryAccessSize) - 1) { |
| 153 // Prefix: align dst on 64 bits. | 153 // Prefix: align dst on 64 bits. |
| 154 const uintptr_t memoryAccessMask = memoryAccessSize - 1; | 154 const uintptr_t memoryAccessMask = memoryAccessSize - 1; |
| 155 while (!isAlignedTo<memoryAccessMask>(destination)) | 155 while (!isAlignedTo<memoryAccessMask>(destination)) |
| 156 *destination++ = static_cast<LChar>(*source++); | 156 *destination++ = static_cast<LChar>(*source++); |
| 157 | 157 |
| 158 // Vector interleaved unpack, we only store the lower 8 bits. | 158 // Vector interleaved unpack, we only store the lower 8 bits. |
| 159 const uintptr_t lengthLeft = end - destination; | 159 const uintptr_t lengthLeft = end - destination; |
| 160 const LChar* const simdEnd = end - (lengthLeft % memoryAccessSize); | 160 const LChar* const simdEnd = end - (lengthLeft % memoryAccessSize); |
| 161 do { | 161 do { |
| 162 asm("vld2.8 { d0-d1 }, [%[SOURCE]] !\n\t" | 162 asm("vld2.8 { d0-d1 }, [%[SOURCE]] !\n\t" |
| 163 "vst1.8 { d0 }, [%[DESTINATION],:64] !\n\t" | 163 "vst1.8 { d0 }, [%[DESTINATION],:64] !\n\t" |
| 164 : [SOURCE] "+r"(source), [DESTINATION] "+r"(destination) | 164 : [SOURCE] "+r"(source), [DESTINATION] "+r"(destination) |
| 165 : | 165 : |
| 166 : "memory", "d0", "d1"); | 166 : "memory", "d0", "d1"); |
| 167 } while (destination != simdEnd); | 167 } while (destination != simdEnd); |
| 168 } | 168 } |
| 169 | 169 |
| 170 while (destination != end) | 170 while (destination != end) |
| 171 *destination++ = static_cast<LChar>(*source++); | 171 *destination++ = static_cast<LChar>(*source++); |
| 172 #else | 172 #else |
| 173 for (size_t i = 0; i < length; ++i) { | 173 for (size_t i = 0; i < length; ++i) { |
| 174 ASSERT(!(source[i] & 0xff00)); | 174 DCHECK(!(source[i] & 0xff00)); |
| 175 destination[i] = static_cast<LChar>(source[i]); | 175 destination[i] = static_cast<LChar>(source[i]); |
| 176 } | 176 } |
| 177 #endif | 177 #endif |
| 178 } | 178 } |
| 179 | 179 |
| 180 } // namespace WTF | 180 } // namespace WTF |
| 181 | 181 |
| 182 #endif // ASCIIFastPath_h | 182 #endif // ASCIIFastPath_h |
| OLD | NEW |