/src/simdutf/src/generic/utf16.h
Line | Count | Source |
1 | | namespace simdutf { |
2 | | namespace SIMDUTF_IMPLEMENTATION { |
3 | | namespace { |
4 | | namespace utf16 { |
5 | | |
6 | | template <endianness big_endian> |
7 | | simdutf_really_inline size_t count_code_points(const char16_t *in, |
8 | 0 | size_t size) { |
9 | 0 | size_t pos = 0; |
10 | 0 | size_t count = 0; |
11 | 0 | for (; pos < size / 32 * 32; pos += 32) { |
12 | 0 | simd16x32<uint16_t> input(reinterpret_cast<const uint16_t *>(in + pos)); |
13 | 0 | if constexpr (!match_system(big_endian)) { |
14 | 0 | input.swap_bytes(); |
15 | 0 | } |
16 | 0 | uint64_t not_pair = input.not_in_range(0xDC00, 0xDFFF); |
17 | 0 | count += count_ones(not_pair) / 2; |
18 | 0 | } |
19 | 0 | return count + |
20 | 0 | scalar::utf16::count_code_points<big_endian>(in + pos, size - pos); |
21 | 0 | } Unexecuted instantiation: simdutf.cpp:unsigned long simdutf::haswell::(anonymous namespace)::utf16::count_code_points<(simdutf::endianness)0>(char16_t const*, unsigned long) Unexecuted instantiation: simdutf.cpp:unsigned long simdutf::haswell::(anonymous namespace)::utf16::count_code_points<(simdutf::endianness)1>(char16_t const*, unsigned long) Unexecuted instantiation: simdutf.cpp:unsigned long simdutf::westmere::(anonymous namespace)::utf16::count_code_points<(simdutf::endianness)0>(char16_t const*, unsigned long) Unexecuted instantiation: simdutf.cpp:unsigned long simdutf::westmere::(anonymous namespace)::utf16::count_code_points<(simdutf::endianness)1>(char16_t const*, unsigned long) |
22 | | |
23 | | template <endianness big_endian> |
24 | | simdutf_really_inline size_t utf8_length_from_utf16(const char16_t *in, |
25 | | size_t size) { |
26 | | size_t pos = 0; |
27 | | size_t count = 0; |
28 | | // This algorithm could no doubt be improved! |
29 | | for (; pos < size / 32 * 32; pos += 32) { |
30 | | simd16x32<uint16_t> input(reinterpret_cast<const uint16_t *>(in + pos)); |
31 | | if constexpr (!match_system(big_endian)) { |
32 | | input.swap_bytes(); |
33 | | } |
34 | | uint64_t ascii_mask = input.lteq(0x7F); |
35 | | uint64_t twobyte_mask = input.lteq(0x7FF); |
36 | | uint64_t not_pair_mask = input.not_in_range(0xD800, 0xDFFF); |
37 | | |
38 | | size_t ascii_count = count_ones(ascii_mask) / 2; |
39 | | size_t twobyte_count = count_ones(twobyte_mask & ~ascii_mask) / 2; |
40 | | size_t threebyte_count = count_ones(not_pair_mask & ~twobyte_mask) / 2; |
41 | | size_t fourbyte_count = 32 - count_ones(not_pair_mask) / 2; |
42 | | count += 2 * fourbyte_count + 3 * threebyte_count + 2 * twobyte_count + |
43 | | ascii_count; |
44 | | } |
45 | | return count + scalar::utf16::utf8_length_from_utf16<big_endian>(in + pos, |
46 | | size - pos); |
47 | | } |
48 | | |
49 | | template <endianness big_endian> |
50 | | simdutf_really_inline size_t utf32_length_from_utf16(const char16_t *in, |
51 | 0 | size_t size) { |
52 | 0 | return count_code_points<big_endian>(in, size); |
53 | 0 | } Unexecuted instantiation: simdutf.cpp:unsigned long simdutf::haswell::(anonymous namespace)::utf16::utf32_length_from_utf16<(simdutf::endianness)0>(char16_t const*, unsigned long) Unexecuted instantiation: simdutf.cpp:unsigned long simdutf::haswell::(anonymous namespace)::utf16::utf32_length_from_utf16<(simdutf::endianness)1>(char16_t const*, unsigned long) Unexecuted instantiation: simdutf.cpp:unsigned long simdutf::westmere::(anonymous namespace)::utf16::utf32_length_from_utf16<(simdutf::endianness)0>(char16_t const*, unsigned long) Unexecuted instantiation: simdutf.cpp:unsigned long simdutf::westmere::(anonymous namespace)::utf16::utf32_length_from_utf16<(simdutf::endianness)1>(char16_t const*, unsigned long) |
54 | | |
55 | | simdutf_really_inline void |
56 | 0 | change_endianness_utf16(const char16_t *in, size_t size, char16_t *output) { |
57 | 0 | size_t pos = 0; |
58 | |
|
59 | 0 | while (pos < size / 32 * 32) { |
60 | 0 | simd16x32<uint16_t> input(reinterpret_cast<const uint16_t *>(in + pos)); |
61 | 0 | input.swap_bytes(); |
62 | 0 | input.store(reinterpret_cast<uint16_t *>(output)); |
63 | 0 | pos += 32; |
64 | 0 | output += 32; |
65 | 0 | } |
66 | |
|
67 | 0 | scalar::utf16::change_endianness_utf16(in + pos, size - pos, output); |
68 | 0 | } Unexecuted instantiation: simdutf.cpp:simdutf::haswell::(anonymous namespace)::utf16::change_endianness_utf16(char16_t const*, unsigned long, char16_t*) Unexecuted instantiation: simdutf.cpp:simdutf::westmere::(anonymous namespace)::utf16::change_endianness_utf16(char16_t const*, unsigned long, char16_t*) |
69 | | |
70 | | } // namespace utf16 |
71 | | } // unnamed namespace |
72 | | } // namespace SIMDUTF_IMPLEMENTATION |
73 | | } // namespace simdutf |