content/base/src/nsTextFragmentSSE2.cpp

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 // This file should only be compiled if you're on x86 or x86_64. Additionally,
michael@0 6 // you'll need to compile this file with -msse2 if you're using gcc.
michael@0 7
michael@0 8 #include <emmintrin.h>
michael@0 9 #include "nscore.h"
michael@0 10 #include "nsAlgorithm.h"
michael@0 11 #include "nsTextFragmentImpl.h"
michael@0 12 #include <algorithm>
michael@0 13
michael@0 14 namespace mozilla {
michael@0 15 namespace SSE2 {
michael@0 16
michael@0 17 static inline bool
michael@0 18 is_zero (__m128i x)
michael@0 19 {
michael@0 20 return
michael@0 21 _mm_movemask_epi8(_mm_cmpeq_epi8(x, _mm_setzero_si128())) == 0xffff;
michael@0 22 }
michael@0 23
michael@0 24 int32_t
michael@0 25 FirstNon8Bit(const char16_t *str, const char16_t *end)
michael@0 26 {
michael@0 27 const uint32_t numUnicharsPerVector = 8;
michael@0 28 typedef Non8BitParameters<sizeof(size_t)> p;
michael@0 29 const size_t mask = p::mask();
michael@0 30 const uint32_t numUnicharsPerWord = p::numUnicharsPerWord();
michael@0 31 const int32_t len = end - str;
michael@0 32 int32_t i = 0;
michael@0 33
michael@0 34 // Align ourselves to a 16-byte boundary, as required by _mm_load_si128
michael@0 35 // (i.e. MOVDQA).
michael@0 36 int32_t alignLen =
michael@0 37 std::min(len, int32_t(((-NS_PTR_TO_INT32(str)) & 0xf) / sizeof(char16_t)));
michael@0 38 for (; i < alignLen; i++) {
michael@0 39 if (str[i] > 255)
michael@0 40 return i;
michael@0 41 }
michael@0 42
michael@0 43 // Check one XMM register (16 bytes) at a time.
michael@0 44 const int32_t vectWalkEnd = ((len - i) / numUnicharsPerVector) * numUnicharsPerVector;
michael@0 45 const uint16_t shortMask = 0xff00;
michael@0 46 __m128i vectmask = _mm_set1_epi16(static_cast<int16_t>(shortMask));
michael@0 47 for(; i < vectWalkEnd; i += numUnicharsPerVector) {
michael@0 48 const __m128i vect = *reinterpret_cast<const __m128i*>(str + i);
michael@0 49 if (!is_zero(_mm_and_si128(vect, vectmask)))
michael@0 50 return i;
michael@0 51 }
michael@0 52
michael@0 53 // Check one word at a time.
michael@0 54 const int32_t wordWalkEnd = ((len - i) / numUnicharsPerWord) * numUnicharsPerWord;
michael@0 55 for(; i < wordWalkEnd; i += numUnicharsPerWord) {
michael@0 56 const size_t word = *reinterpret_cast<const size_t*>(str + i);
michael@0 57 if (word & mask)
michael@0 58 return i;
michael@0 59 }
michael@0 60
michael@0 61 // Take care of the remainder one character at a time.
michael@0 62 for (; i < len; i++) {
michael@0 63 if (str[i] > 255) {
michael@0 64 return i;
michael@0 65 }
michael@0 66 }
michael@0 67
michael@0 68 return -1;
michael@0 69 }
michael@0 70
michael@0 71 } // namespace SSE2
michael@0 72 } // namespace mozilla

mercurial