simdjson 4.2.3
Ridiculously Fast JSON
Loading...
Searching...
No Matches
stringparsing_defs.h
1#ifndef SIMDJSON_ICELAKE_STRINGPARSING_DEFS_H
2#define SIMDJSON_ICELAKE_STRINGPARSING_DEFS_H
3
4#ifndef SIMDJSON_CONDITIONAL_INCLUDE
5#include "simdjson/icelake/base.h"
6#include "simdjson/icelake/simd.h"
7#include "simdjson/icelake/bitmanipulation.h"
8#endif // SIMDJSON_CONDITIONAL_INCLUDE
9
10namespace simdjson {
11namespace icelake {
12namespace {
13
14using namespace simd;
15
16// Holds backslashes and quotes locations.
17struct backslash_and_quote {
18public:
19 static constexpr uint32_t BYTES_PROCESSED = 64;
20 simdjson_inline 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 ((quote_bits - 1) & 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 uint64_t bs_bits;
28 uint64_t quote_bits;
29}; // struct backslash_and_quote
30
31simdjson_inline backslash_and_quote backslash_and_quote::copy_and_find(const uint8_t *src, uint8_t *dst) {
32 // this can read up to 15 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 // store to dest unconditionally - we can overwrite the bits we don't like later
37 v.store(dst);
38 return {
39 static_cast<uint64_t>(v == '\\'), // bs_bits
40 static_cast<uint64_t>(v == '"'), // quote_bits
41 };
42}
43
44
45
46struct escaping {
47 static constexpr uint32_t BYTES_PROCESSED = 64;
48 simdjson_inline static escaping copy_and_find(const uint8_t *src, uint8_t *dst);
49
50 simdjson_inline bool has_escape() { return escape_bits != 0; }
51 simdjson_inline int escape_index() { return trailing_zeroes(uint64_t(escape_bits)); }
52
53 __mmask64 escape_bits;
54}; // struct escaping
55
56
57
58simdjson_inline escaping escaping::copy_and_find(const uint8_t *src, uint8_t *dst) {
59 static_assert(SIMDJSON_PADDING >= (BYTES_PROCESSED - 1), "escaping finder must process fewer than SIMDJSON_PADDING bytes");
60 simd8<uint8_t> v(src);
61 v.store(dst);
62 __mmask64 is_quote = _mm512_cmpeq_epi8_mask(v, _mm512_set1_epi8('"'));
63 __mmask64 is_backslash = _mm512_cmpeq_epi8_mask(v, _mm512_set1_epi8('\\'));
64 __mmask64 is_control = _mm512_cmplt_epi8_mask(v, _mm512_set1_epi8(32));
65 return {
66 (is_backslash | is_quote | is_control)
67 };
68}
69
70
71
72
73} // unnamed namespace
74} // namespace icelake
75} // namespace simdjson
76
77#endif // SIMDJSON_ICELAKE_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:33