1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef nsTextFragmentGeneric_h__
8 #define nsTextFragmentGeneric_h__
10 #include "nsTextFragmentGenericFwd.h"
13 #include "nsTextFragmentImpl.h"
19 int32_t FirstNon8Bit(const char16_t
* str
, const char16_t
* end
) {
20 const uint32_t numUnicharsPerVector
= xsimd::batch
<int16_t, Arch
>::size
;
21 using p
= Non8BitParameters
<sizeof(size_t)>;
22 const size_t mask
= p::mask();
23 const uint32_t numUnicharsPerWord
= p::numUnicharsPerWord();
24 const int32_t len
= end
- str
;
27 // Align ourselves to the Arch boundary
28 int32_t alignLen
= std::min(
29 len
, int32_t(((-NS_PTR_TO_INT32(str
)) & (Arch::alignment() - 1)) /
31 for (; i
< alignLen
; i
++) {
32 if (str
[i
] > 255) return i
;
35 // Check one batch at a time.
36 const int32_t vectWalkEnd
=
37 ((len
- i
) / numUnicharsPerVector
) * numUnicharsPerVector
;
38 const uint16_t shortMask
= 0xff00;
39 xsimd::batch
<int16_t, Arch
> vectmask(static_cast<int16_t>(shortMask
));
40 for (; i
< vectWalkEnd
; i
+= numUnicharsPerVector
) {
41 const auto vect
= xsimd::batch
<int16_t, Arch
>::load_aligned(str
+ i
);
42 if (xsimd::any((vect
& vectmask
) != 0)) return i
;
45 // Check one word at a time.
46 const int32_t wordWalkEnd
=
47 ((len
- i
) / numUnicharsPerWord
) * numUnicharsPerWord
;
48 for (; i
< wordWalkEnd
; i
+= numUnicharsPerWord
) {
49 const size_t word
= *reinterpret_cast<const size_t*>(str
+ i
);
50 if (word
& mask
) return i
;
53 // Take care of the remainder one character at a time.
54 for (; i
< len
; i
++) {
63 } // namespace mozilla