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