simdjson  3.11.0
Ridiculously Fast JSON
stringparsing_defs.h
1 #ifndef SIMDJSON_LASX_STRINGPARSING_DEFS_H
2 #define SIMDJSON_LASX_STRINGPARSING_DEFS_H
3 
4 #ifndef SIMDJSON_CONDITIONAL_INCLUDE
5 #include "simdjson/lasx/base.h"
6 #include "simdjson/lasx/simd.h"
7 #include "simdjson/lasx/bitmanipulation.h"
8 #endif // SIMDJSON_CONDITIONAL_INCLUDE
9 
10 namespace simdjson {
11 namespace lasx {
12 namespace {
13 
14 using namespace simd;
15 
16 // Holds backslashes and quotes locations.
17 struct backslash_and_quote {
18 public:
19  static constexpr uint32_t BYTES_PROCESSED = 32;
20  simdjson_inline static backslash_and_quote copy_and_find(const uint8_t *src, uint8_t *dst);
21 
22  simdjson_inline bool has_quote_first() { return ((bs_bits - 1) & quote_bits) != 0; }
23  simdjson_inline bool has_backslash() { return bs_bits != 0; }
24  simdjson_inline int quote_index() { return trailing_zeroes(quote_bits); }
25  simdjson_inline int backslash_index() { return trailing_zeroes(bs_bits); }
26 
27  uint32_t bs_bits;
28  uint32_t quote_bits;
29 }; // struct backslash_and_quote
30 
31 simdjson_inline backslash_and_quote backslash_and_quote::copy_and_find(const uint8_t *src, uint8_t *dst) {
32  // this can read up to 31 bytes beyond the buffer size, but we require
33  // SIMDJSON_PADDING of padding
34  static_assert(SIMDJSON_PADDING >= (BYTES_PROCESSED - 1), "backslash and quote finder must process fewer than SIMDJSON_PADDING bytes");
35  simd8<uint8_t> v(src);
36  v.store(dst);
37  return {
38  static_cast<uint32_t>((v == '\\').to_bitmask()), // bs_bits
39  static_cast<uint32_t>((v == '"').to_bitmask()), // quote_bits
40  };
41 }
42 
43 } // unnamed namespace
44 } // namespace lasx
45 } // namespace simdjson
46 
47 #endif // SIMDJSON_LASX_STRINGPARSING_DEFS_H
The top level simdjson namespace, containing everything the library provides.
Definition: base.h:8
constexpr size_t SIMDJSON_PADDING
The amount of padding needed in a buffer to parse JSON.
Definition: base.h:32