| 1 | #include <cassert> |
| 2 | #include <cstring> |
| 3 | #include <iostream> |
| 4 | |
| 5 | #include "simdjson/portability.h" |
| 6 | #include "simdjson/common_defs.h" |
| 7 | #include "jsoncharutils.h" |
| 8 | |
| 9 | using namespace simdjson; |
| 10 | |
| 11 | WARN_UNUSED |
| 12 | really_inline bool is_valid_true_atom(const uint8_t *loc) { |
| 13 | uint64_t tv = *reinterpret_cast<const uint64_t *>("true " ); |
| 14 | uint64_t mask4 = 0x00000000ffffffff; |
| 15 | uint32_t error = 0; |
| 16 | uint64_t |
| 17 | locval; // we want to avoid unaligned 64-bit loads (undefined in C/C++) |
| 18 | // this can read up to 7 bytes beyond the buffer size, but we require |
| 19 | // SIMDJSON_PADDING of padding |
| 20 | static_assert(sizeof(uint64_t) - 1 <= SIMDJSON_PADDING); |
| 21 | std::memcpy(&locval, loc, sizeof(uint64_t)); |
| 22 | error = (locval & mask4) ^ tv; |
| 23 | error |= is_not_structural_or_whitespace(loc[4]); |
| 24 | return error == 0; |
| 25 | } |
| 26 | |
| 27 | WARN_UNUSED |
| 28 | really_inline bool is_valid_false_atom(const uint8_t *loc) { |
| 29 | // We have to use an integer constant because the space in the cast |
| 30 | // below would lead to values illegally being qualified |
| 31 | // uint64_t fv = *reinterpret_cast<const uint64_t *>("false "); |
| 32 | // using this constant (that is the same false) but nulls out the |
| 33 | // unused bits solves that |
| 34 | uint64_t fv = 0x00000065736c6166; // takes into account endianness |
| 35 | uint64_t mask5 = 0x000000ffffffffff; |
| 36 | // we can't use the 32 bit value for checking for errors otherwise |
| 37 | // the last character of false (it being 5 byte long!) would be |
| 38 | // ignored |
| 39 | uint64_t error = 0; |
| 40 | uint64_t |
| 41 | locval; // we want to avoid unaligned 64-bit loads (undefined in C/C++) |
| 42 | // this can read up to 7 bytes beyond the buffer size, but we require |
| 43 | // SIMDJSON_PADDING of padding |
| 44 | static_assert(sizeof(uint64_t) - 1 <= SIMDJSON_PADDING); |
| 45 | std::memcpy(&locval, loc, sizeof(uint64_t)); |
| 46 | error = (locval & mask5) ^ fv; |
| 47 | error |= is_not_structural_or_whitespace(loc[5]); |
| 48 | return error == 0; |
| 49 | } |
| 50 | |
| 51 | WARN_UNUSED |
| 52 | really_inline bool is_valid_null_atom(const uint8_t *loc) { |
| 53 | uint64_t nv = *reinterpret_cast<const uint64_t *>("null " ); |
| 54 | uint64_t mask4 = 0x00000000ffffffff; |
| 55 | uint32_t error = 0; |
| 56 | uint64_t |
| 57 | locval; // we want to avoid unaligned 64-bit loads (undefined in C/C++) |
| 58 | // this can read up to 7 bytes beyond the buffer size, but we require |
| 59 | // SIMDJSON_PADDING of padding |
| 60 | static_assert(sizeof(uint64_t) - 1 <= SIMDJSON_PADDING); |
| 61 | std::memcpy(&locval, loc, sizeof(uint64_t)); |
| 62 | error = (locval & mask4) ^ nv; |
| 63 | error |= is_not_structural_or_whitespace(loc[4]); |
| 64 | return error == 0; |
| 65 | } |
| 66 | |
| 67 | #ifdef JSON_TEST_STRINGS |
| 68 | void found_string(const uint8_t *buf, const uint8_t *parsed_begin, |
| 69 | const uint8_t *parsed_end); |
| 70 | void found_bad_string(const uint8_t *buf); |
| 71 | #endif |
| 72 | |
| 73 | #include "arm64/stage2_build_tape.h" |
| 74 | #include "haswell/stage2_build_tape.h" |
| 75 | #include "westmere/stage2_build_tape.h" |
| 76 | |