simdjson  3.1.6
Ridiculously Fast JSON
stringparsing.h
1 #ifndef SIMDJSON_ARM64_STRINGPARSING_H
2 #define SIMDJSON_ARM64_STRINGPARSING_H
3 
4 #include "simdjson/base.h"
5 #include "simdjson/arm64/simd.h"
6 #include "simdjson/arm64/bitmanipulation.h"
7 
8 namespace simdjson {
9 namespace SIMDJSON_IMPLEMENTATION {
10 namespace {
11 
12 using namespace simd;
13 
14 // Holds backslashes and quotes locations.
15 struct backslash_and_quote {
16 public:
17  static constexpr uint32_t BYTES_PROCESSED = 32;
18  simdjson_inline static backslash_and_quote copy_and_find(const uint8_t *src, uint8_t *dst);
19 
20  simdjson_inline bool has_quote_first() { return ((bs_bits - 1) & quote_bits) != 0; }
21  simdjson_inline bool has_backslash() { return bs_bits != 0; }
22  simdjson_inline int quote_index() { return trailing_zeroes(quote_bits); }
23  simdjson_inline int backslash_index() { return trailing_zeroes(bs_bits); }
24 
25  uint32_t bs_bits;
26  uint32_t quote_bits;
27 }; // struct backslash_and_quote
28 
29 simdjson_inline backslash_and_quote backslash_and_quote::copy_and_find(const uint8_t *src, uint8_t *dst) {
30  // this can read up to 31 bytes beyond the buffer size, but we require
31  // SIMDJSON_PADDING of padding
32  static_assert(SIMDJSON_PADDING >= (BYTES_PROCESSED - 1), "backslash and quote finder must process fewer than SIMDJSON_PADDING bytes");
33  simd8<uint8_t> v0(src);
34  simd8<uint8_t> v1(src + sizeof(v0));
35  v0.store(dst);
36  v1.store(dst + sizeof(v0));
37 
38  // Getting a 64-bit bitmask is much cheaper than multiple 16-bit bitmasks on ARM; therefore, we
39  // smash them together into a 64-byte mask and get the bitmask from there.
40  uint64_t bs_and_quote = simd8x64<bool>(v0 == '\\', v1 == '\\', v0 == '"', v1 == '"').to_bitmask();
41  return {
42  uint32_t(bs_and_quote), // bs_bits
43  uint32_t(bs_and_quote >> 32) // quote_bits
44  };
45 }
46 
47 } // unnamed namespace
48 } // namespace SIMDJSON_IMPLEMENTATION
49 } // namespace simdjson
50 
51 #endif // SIMDJSON_ARM64_STRINGPARSING_H
We want to support argument-dependent lookup (ADL).
constexpr size_t SIMDJSON_PADDING
The amount of padding needed in a buffer to parse JSON.
Definition: common_defs.h:45