simdjson 4.1.0
Ridiculously Fast JSON
Loading...
Searching...
No Matches
stringparsing_defs.h
1#ifndef SIMDJSON_ARM64_STRINGPARSING_DEFS_H
2#define SIMDJSON_ARM64_STRINGPARSING_DEFS_H
3
4#ifndef SIMDJSON_CONDITIONAL_INCLUDE
5#include "simdjson/arm64/base.h"
6#include "simdjson/arm64/simd.h"
7#include "simdjson/arm64/bitmanipulation.h"
8#endif // SIMDJSON_CONDITIONAL_INCLUDE
9
10namespace simdjson {
11namespace arm64 {
12namespace {
13
14using namespace simd;
15
16// Holds backslashes and quotes locations.
17struct backslash_and_quote {
18public:
19 static constexpr uint32_t BYTES_PROCESSED = 32;
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 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
31simdjson_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> v0(src);
36 simd8<uint8_t> v1(src + sizeof(v0));
37 v0.store(dst);
38 v1.store(dst + sizeof(v0));
39
40 // Getting a 64-bit bitmask is much cheaper than multiple 16-bit bitmasks on ARM; therefore, we
41 // smash them together into a 64-byte mask and get the bitmask from there.
42 uint64_t bs_and_quote = simd8x64<bool>(v0 == '\\', v1 == '\\', v0 == '"', v1 == '"').to_bitmask();
43 return {
44 uint32_t(bs_and_quote), // bs_bits
45 uint32_t(bs_and_quote >> 32) // quote_bits
46 };
47}
48
49struct escaping {
50 static constexpr uint32_t BYTES_PROCESSED = 16;
51 simdjson_inline static escaping copy_and_find(const uint8_t *src, uint8_t *dst);
52
53 simdjson_inline bool has_escape() { return escape_bits != 0; }
54 simdjson_inline int escape_index() { return trailing_zeroes(escape_bits) / 4; }
55
56 uint64_t escape_bits;
57}; // struct escaping
58
59
60
61simdjson_inline escaping escaping::copy_and_find(const uint8_t *src, uint8_t *dst) {
62 static_assert(SIMDJSON_PADDING >= (BYTES_PROCESSED - 1), "escaping finder must process fewer than SIMDJSON_PADDING bytes");
63 simd8<uint8_t> v(src);
64 v.store(dst);
65 simd8<bool> is_quote = (v == '"');
66 simd8<bool> is_backslash = (v == '\\');
67 simd8<bool> is_control = (v < 32);
68 return {
69 (is_backslash | is_quote | is_control).to_bitmask64()
70 };
71}
72
73
74
75} // unnamed namespace
76} // namespace arm64
77} // namespace simdjson
78
79#endif // SIMDJSON_ARM64_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