/src/simdutf/src/generic/buf_block_reader.h
Line | Count | Source |
1 | | namespace simdutf { |
2 | | namespace SIMDUTF_IMPLEMENTATION { |
3 | | namespace { |
4 | | |
5 | | // Walks through a buffer in block-sized increments, loading the last part with |
6 | | // spaces |
7 | | template <size_t STEP_SIZE> struct buf_block_reader { |
8 | | public: |
9 | | simdutf_really_inline buf_block_reader(const uint8_t *_buf, size_t _len); |
10 | | simdutf_really_inline size_t block_index(); |
11 | | simdutf_really_inline bool has_full_block() const; |
12 | | simdutf_really_inline const uint8_t *full_block() const; |
13 | | /** |
14 | | * Get the last block, padded with spaces. |
15 | | * |
16 | | * There will always be a last block, with at least 1 byte, unless len == 0 |
17 | | * (in which case this function fills the buffer with spaces and returns 0. In |
18 | | * particular, if len == STEP_SIZE there will be 0 full_blocks and 1 remainder |
19 | | * block with STEP_SIZE bytes and no spaces for padding. |
20 | | * |
21 | | * @return the number of effective characters in the last block. |
22 | | */ |
23 | | simdutf_really_inline size_t get_remainder(uint8_t *dst) const; |
24 | | simdutf_really_inline void advance(); |
25 | | |
26 | | private: |
27 | | const uint8_t *buf; |
28 | | const size_t len; |
29 | | const size_t lenminusstep; |
30 | | size_t idx; |
31 | | }; |
32 | | |
33 | | // Routines to print masks and text for debugging bitmask operations |
34 | 0 | simdutf_unused static char *format_input_text_64(const uint8_t *text) { |
35 | 0 | static char *buf = |
36 | 0 | reinterpret_cast<char *>(malloc(sizeof(simd8x64<uint8_t>) + 1)); |
37 | 0 | for (size_t i = 0; i < sizeof(simd8x64<uint8_t>); i++) { |
38 | 0 | buf[i] = int8_t(text[i]) < ' ' ? '_' : int8_t(text[i]); |
39 | 0 | } |
40 | 0 | buf[sizeof(simd8x64<uint8_t>)] = '\0'; |
41 | 0 | return buf; |
42 | 0 | } Unexecuted instantiation: simdutf.cpp:simdutf::haswell::(anonymous namespace)::format_input_text_64(unsigned char const*) Unexecuted instantiation: simdutf.cpp:simdutf::westmere::(anonymous namespace)::format_input_text_64(unsigned char const*) |
43 | | |
44 | | // Routines to print masks and text for debugging bitmask operations |
45 | 0 | simdutf_unused static char *format_input_text(const simd8x64<uint8_t> &in) { |
46 | 0 | static char *buf = |
47 | 0 | reinterpret_cast<char *>(malloc(sizeof(simd8x64<uint8_t>) + 1)); |
48 | 0 | in.store(reinterpret_cast<uint8_t *>(buf)); |
49 | 0 | for (size_t i = 0; i < sizeof(simd8x64<uint8_t>); i++) { |
50 | 0 | if (buf[i] < ' ') { |
51 | 0 | buf[i] = '_'; |
52 | 0 | } |
53 | 0 | } |
54 | 0 | buf[sizeof(simd8x64<uint8_t>)] = '\0'; |
55 | 0 | return buf; |
56 | 0 | } Unexecuted instantiation: simdutf.cpp:simdutf::haswell::(anonymous namespace)::format_input_text(simdutf::haswell::(anonymous namespace)::simd::simd8x64<unsigned char> const&) Unexecuted instantiation: simdutf.cpp:simdutf::westmere::(anonymous namespace)::format_input_text(simdutf::westmere::(anonymous namespace)::simd::simd8x64<unsigned char> const&) |
57 | | |
58 | 0 | simdutf_unused static char *format_mask(uint64_t mask) { |
59 | 0 | static char *buf = reinterpret_cast<char *>(malloc(64 + 1)); |
60 | 0 | for (size_t i = 0; i < 64; i++) { |
61 | 0 | buf[i] = (mask & (size_t(1) << i)) ? 'X' : ' '; |
62 | 0 | } |
63 | 0 | buf[64] = '\0'; |
64 | 0 | return buf; |
65 | 0 | } Unexecuted instantiation: simdutf.cpp:simdutf::haswell::(anonymous namespace)::format_mask(unsigned long) Unexecuted instantiation: simdutf.cpp:simdutf::westmere::(anonymous namespace)::format_mask(unsigned long) |
66 | | |
67 | | template <size_t STEP_SIZE> |
68 | | simdutf_really_inline |
69 | | buf_block_reader<STEP_SIZE>::buf_block_reader(const uint8_t *_buf, size_t _len) |
70 | 3.56k | : buf{_buf}, len{_len}, lenminusstep{len < STEP_SIZE ? 0 : len - STEP_SIZE}, |
71 | 3.56k | idx{0} {}simdutf.cpp:simdutf::haswell::(anonymous namespace)::buf_block_reader<64ul>::buf_block_reader(unsigned char const*, unsigned long) Line | Count | Source | 70 | 1.78k | : buf{_buf}, len{_len}, lenminusstep{len < STEP_SIZE ? 0 : len - STEP_SIZE}, | 71 | 1.78k | idx{0} {} |
simdutf.cpp:simdutf::westmere::(anonymous namespace)::buf_block_reader<64ul>::buf_block_reader(unsigned char const*, unsigned long) Line | Count | Source | 70 | 1.78k | : buf{_buf}, len{_len}, lenminusstep{len < STEP_SIZE ? 0 : len - STEP_SIZE}, | 71 | 1.78k | idx{0} {} |
|
72 | | |
73 | | template <size_t STEP_SIZE> |
74 | 1.09k | simdutf_really_inline size_t buf_block_reader<STEP_SIZE>::block_index() { |
75 | 1.09k | return idx; |
76 | 1.09k | } simdutf.cpp:simdutf::haswell::(anonymous namespace)::buf_block_reader<64ul>::block_index() Line | Count | Source | 74 | 548 | simdutf_really_inline size_t buf_block_reader<STEP_SIZE>::block_index() { | 75 | 548 | return idx; | 76 | 548 | } |
simdutf.cpp:simdutf::westmere::(anonymous namespace)::buf_block_reader<64ul>::block_index() Line | Count | Source | 74 | 548 | simdutf_really_inline size_t buf_block_reader<STEP_SIZE>::block_index() { | 75 | 548 | return idx; | 76 | 548 | } |
|
77 | | |
78 | | template <size_t STEP_SIZE> |
79 | 1.55M | simdutf_really_inline bool buf_block_reader<STEP_SIZE>::has_full_block() const { |
80 | 1.55M | return idx < lenminusstep; |
81 | 1.55M | } simdutf.cpp:simdutf::haswell::(anonymous namespace)::buf_block_reader<64ul>::has_full_block() const Line | Count | Source | 79 | 779k | simdutf_really_inline bool buf_block_reader<STEP_SIZE>::has_full_block() const { | 80 | 779k | return idx < lenminusstep; | 81 | 779k | } |
simdutf.cpp:simdutf::westmere::(anonymous namespace)::buf_block_reader<64ul>::has_full_block() const Line | Count | Source | 79 | 779k | simdutf_really_inline bool buf_block_reader<STEP_SIZE>::has_full_block() const { | 80 | 779k | return idx < lenminusstep; | 81 | 779k | } |
|
82 | | |
83 | | template <size_t STEP_SIZE> |
84 | | simdutf_really_inline const uint8_t * |
85 | 1.55M | buf_block_reader<STEP_SIZE>::full_block() const { |
86 | 1.55M | return &buf[idx]; |
87 | 1.55M | } simdutf.cpp:simdutf::haswell::(anonymous namespace)::buf_block_reader<64ul>::full_block() const Line | Count | Source | 85 | 778k | buf_block_reader<STEP_SIZE>::full_block() const { | 86 | 778k | return &buf[idx]; | 87 | 778k | } |
simdutf.cpp:simdutf::westmere::(anonymous namespace)::buf_block_reader<64ul>::full_block() const Line | Count | Source | 85 | 778k | buf_block_reader<STEP_SIZE>::full_block() const { | 86 | 778k | return &buf[idx]; | 87 | 778k | } |
|
88 | | |
89 | | template <size_t STEP_SIZE> |
90 | | simdutf_really_inline size_t |
91 | 2.11k | buf_block_reader<STEP_SIZE>::get_remainder(uint8_t *dst) const { |
92 | 2.11k | if (len == idx) { |
93 | 8 | return 0; |
94 | 8 | } // memcpy(dst, null, 0) will trigger an error with some sanitizers |
95 | 2.10k | std::memset(dst, 0x20, |
96 | 2.10k | STEP_SIZE); // std::memset STEP_SIZE because it is more efficient |
97 | | // to write out 8 or 16 bytes at once. |
98 | 2.10k | std::memcpy(dst, buf + idx, len - idx); |
99 | 2.10k | return len - idx; |
100 | 2.11k | } simdutf.cpp:simdutf::haswell::(anonymous namespace)::buf_block_reader<64ul>::get_remainder(unsigned char*) const Line | Count | Source | 91 | 1.05k | buf_block_reader<STEP_SIZE>::get_remainder(uint8_t *dst) const { | 92 | 1.05k | if (len == idx) { | 93 | 4 | return 0; | 94 | 4 | } // memcpy(dst, null, 0) will trigger an error with some sanitizers | 95 | 1.05k | std::memset(dst, 0x20, | 96 | 1.05k | STEP_SIZE); // std::memset STEP_SIZE because it is more efficient | 97 | | // to write out 8 or 16 bytes at once. | 98 | 1.05k | std::memcpy(dst, buf + idx, len - idx); | 99 | 1.05k | return len - idx; | 100 | 1.05k | } |
simdutf.cpp:simdutf::westmere::(anonymous namespace)::buf_block_reader<64ul>::get_remainder(unsigned char*) const Line | Count | Source | 91 | 1.05k | buf_block_reader<STEP_SIZE>::get_remainder(uint8_t *dst) const { | 92 | 1.05k | if (len == idx) { | 93 | 4 | return 0; | 94 | 4 | } // memcpy(dst, null, 0) will trigger an error with some sanitizers | 95 | 1.05k | std::memset(dst, 0x20, | 96 | 1.05k | STEP_SIZE); // std::memset STEP_SIZE because it is more efficient | 97 | | // to write out 8 or 16 bytes at once. | 98 | 1.05k | std::memcpy(dst, buf + idx, len - idx); | 99 | 1.05k | return len - idx; | 100 | 1.05k | } |
|
101 | | |
102 | | template <size_t STEP_SIZE> |
103 | 1.55M | simdutf_really_inline void buf_block_reader<STEP_SIZE>::advance() { |
104 | 1.55M | idx += STEP_SIZE; |
105 | 1.55M | } simdutf.cpp:simdutf::haswell::(anonymous namespace)::buf_block_reader<64ul>::advance() Line | Count | Source | 103 | 779k | simdutf_really_inline void buf_block_reader<STEP_SIZE>::advance() { | 104 | 779k | idx += STEP_SIZE; | 105 | 779k | } |
simdutf.cpp:simdutf::westmere::(anonymous namespace)::buf_block_reader<64ul>::advance() Line | Count | Source | 103 | 779k | simdutf_really_inline void buf_block_reader<STEP_SIZE>::advance() { | 104 | 779k | idx += STEP_SIZE; | 105 | 779k | } |
|
106 | | |
107 | | } // unnamed namespace |
108 | | } // namespace SIMDUTF_IMPLEMENTATION |
109 | | } // namespace simdutf |