|
21 | 21 | #include "unicode/uchar.h" |
22 | 22 | #endif |
23 | 23 |
|
| 24 | +#include "hwy/highway.h" |
24 | 25 | #include "third_party/simdutf/simdutf.h" |
25 | 26 |
|
26 | 27 | namespace unibrow { |
27 | 28 |
|
| 29 | +template <> |
| 30 | +size_t Utf8::WriteLeadingAscii<uint8_t>(const uint8_t* src, char* dest, |
| 31 | + size_t length) { |
| 32 | + namespace hw = hwy::HWY_NAMESPACE; |
| 33 | + const hw::ScalableTag<int8_t> d; |
| 34 | + const size_t N = hw::Lanes(d); |
| 35 | + // Don't bother with simd if the string isn't long enough. We're using 2 |
| 36 | + // registers, so don't enter the loop unless we can iterate 2 times through. |
| 37 | + if (length < 4 * N) { |
| 38 | + return 0; |
| 39 | + } |
| 40 | + // We're checking ascii by checking the sign bit so make the strings signed. |
| 41 | + const int8_t* src_s = reinterpret_cast<const int8_t*>(src); |
| 42 | + int8_t* dst_s = reinterpret_cast<int8_t*>(dest); |
| 43 | + size_t i = 0; |
| 44 | + DCHECK_GE(length, 2 * N); |
| 45 | + for (; i <= length - 2 * N; i += 2 * N) { |
| 46 | + const auto v0 = hw::LoadU(d, src_s + i); |
| 47 | + const auto v1 = hw::LoadU(d, src_s + i + N); |
| 48 | + const auto combined = hw::Or(v0, v1); |
| 49 | + bool is_ascii = hw::AllTrue(d, hw::Ge(combined, hw::Zero(d))); |
| 50 | + if (is_ascii) { |
| 51 | + hw::StoreU(v0, d, dst_s + i); |
| 52 | + hw::StoreU(v1, d, dst_s + i + N); |
| 53 | + } else { |
| 54 | + break; |
| 55 | + } |
| 56 | + } |
| 57 | + return i; |
| 58 | +} |
| 59 | + |
| 60 | +template <> |
| 61 | +size_t Utf8::WriteLeadingAscii<uint16_t>(const uint16_t* src, char* dest, |
| 62 | + size_t size) { |
| 63 | + // TODO(dcarney): this could be implemented similarly to the one byte variant |
| 64 | + return 0; |
| 65 | +} |
| 66 | + |
28 | 67 | #ifndef V8_INTL_SUPPORT |
29 | 68 | static const int kStartBit = (1 << 30); |
30 | 69 | static const int kChunkBits = (1 << 13); |
|
0 commit comments