simdjson  3.1.6
Ridiculously Fast JSON
stringparsing.h
1 #ifndef SIMDJSON_PPC64_STRINGPARSING_H
2 #define SIMDJSON_PPC64_STRINGPARSING_H
3 
4 #include "simdjson/base.h"
5 #include "simdjson/ppc64/bitmanipulation.h"
6 #include "simdjson/ppc64/simd.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
19  copy_and_find(const uint8_t *src, uint8_t *dst);
20 
21  simdjson_inline bool has_quote_first() {
22  return ((bs_bits - 1) & quote_bits) != 0;
23  }
24  simdjson_inline bool has_backslash() { return bs_bits != 0; }
25  simdjson_inline int quote_index() {
26  return trailing_zeroes(quote_bits);
27  }
28  simdjson_inline int backslash_index() {
29  return trailing_zeroes(bs_bits);
30  }
31 
32  uint32_t bs_bits;
33  uint32_t quote_bits;
34 }; // struct backslash_and_quote
35 
36 simdjson_inline backslash_and_quote
37 backslash_and_quote::copy_and_find(const uint8_t *src, uint8_t *dst) {
38  // this can read up to 31 bytes beyond the buffer size, but we require
39  // SIMDJSON_PADDING of padding
40  static_assert(SIMDJSON_PADDING >= (BYTES_PROCESSED - 1),
41  "backslash and quote finder must process fewer than "
42  "SIMDJSON_PADDING bytes");
43  simd8<uint8_t> v0(src);
44  simd8<uint8_t> v1(src + sizeof(v0));
45  v0.store(dst);
46  v1.store(dst + sizeof(v0));
47 
48  // Getting a 64-bit bitmask is much cheaper than multiple 16-bit bitmasks on
49  // PPC; therefore, we smash them together into a 64-byte mask and get the
50  // bitmask from there.
51  uint64_t bs_and_quote =
52  simd8x64<bool>(v0 == '\\', v1 == '\\', v0 == '"', v1 == '"').to_bitmask();
53  return {
54  uint32_t(bs_and_quote), // bs_bits
55  uint32_t(bs_and_quote >> 32) // quote_bits
56  };
57 }
58 
59 } // unnamed namespace
60 } // namespace SIMDJSON_IMPLEMENTATION
61 } // namespace simdjson
62 
63 #endif // SIMDJSON_PPC64_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