simdjson 4.2.4
Ridiculously Fast JSON
Loading...
Searching...
No Matches
stringparsing_defs.h
1#ifndef SIMDJSON_PPC64_STRINGPARSING_DEFS_H
2#define SIMDJSON_PPC64_STRINGPARSING_DEFS_H
3
4#ifndef SIMDJSON_CONDITIONAL_INCLUDE
5#include "simdjson/ppc64/base.h"
6#include "simdjson/ppc64/bitmanipulation.h"
7#include "simdjson/ppc64/simd.h"
8#endif // SIMDJSON_CONDITIONAL_INCLUDE
9
10namespace simdjson {
11namespace ppc64 {
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
21 copy_and_find(const uint8_t *src, uint8_t *dst);
22
23 simdjson_inline bool has_quote_first() {
24 return ((bs_bits - 1) & quote_bits) != 0;
25 }
26 simdjson_inline bool has_backslash() { return bs_bits != 0; }
27 simdjson_inline int quote_index() {
28 return trailing_zeroes(quote_bits);
29 }
30 simdjson_inline int backslash_index() {
31 return trailing_zeroes(bs_bits);
32 }
33
34 uint32_t bs_bits;
35 uint32_t quote_bits;
36}; // struct backslash_and_quote
37
38simdjson_inline backslash_and_quote
39backslash_and_quote::copy_and_find(const uint8_t *src, uint8_t *dst) {
40 // this can read up to 31 bytes beyond the buffer size, but we require
41 // SIMDJSON_PADDING of padding
42 static_assert(SIMDJSON_PADDING >= (BYTES_PROCESSED - 1),
43 "backslash and quote finder must process fewer than "
44 "SIMDJSON_PADDING bytes");
45 simd8<uint8_t> v0(src);
46 simd8<uint8_t> v1(src + sizeof(v0));
47 v0.store(dst);
48 v1.store(dst + sizeof(v0));
49
50 // Getting a 64-bit bitmask is much cheaper than multiple 16-bit bitmasks on
51 // PPC; therefore, we smash them together into a 64-byte mask and get the
52 // bitmask from there.
53 uint64_t bs_and_quote =
54 simd8x64<bool>(v0 == '\\', v1 == '\\', v0 == '"', v1 == '"').to_bitmask();
55 return {
56 uint32_t(bs_and_quote), // bs_bits
57 uint32_t(bs_and_quote >> 32) // quote_bits
58 };
59}
60
61
62struct escaping {
63 static constexpr uint32_t BYTES_PROCESSED = 16;
64 simdjson_inline static escaping copy_and_find(const uint8_t *src, uint8_t *dst);
65
66 simdjson_inline bool has_escape() { return escape_bits != 0; }
67 simdjson_inline int escape_index() { return trailing_zeroes(escape_bits); }
68
69 uint64_t escape_bits;
70}; // struct escaping
71
72
73
74simdjson_inline escaping escaping::copy_and_find(const uint8_t *src, uint8_t *dst) {
75 static_assert(SIMDJSON_PADDING >= (BYTES_PROCESSED - 1), "escaping finder must process fewer than SIMDJSON_PADDING bytes");
76 simd8<uint8_t> v(src);
77 v.store(dst);
78 simd8<bool> is_quote = (v == '"');
79 simd8<bool> is_backslash = (v == '\\');
80 simd8<bool> is_control = (v < 32);
81 return {
82 // We store it as a 64-bit bitmask even though we only need 16 bits.
83 uint64_t((is_backslash | is_quote | is_control).to_bitmask())
84 };
85}
86
87} // unnamed namespace
88} // namespace ppc64
89} // namespace simdjson
90
91#endif // SIMDJSON_PPC64_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