1 #ifndef SIMDJSON_GENERIC_JSONCHARUTILS_H
3 #ifndef SIMDJSON_CONDITIONAL_INCLUDE
4 #define SIMDJSON_GENERIC_JSONCHARUTILS_H
5 #include "simdjson/generic/base.h"
6 #include "simdjson/internal/jsoncharutils_tables.h"
7 #include "simdjson/internal/numberparsing_tables.h"
11 namespace SIMDJSON_IMPLEMENTATION {
13 namespace jsoncharutils {
17 simdjson_inline uint32_t is_not_structural_or_whitespace(uint8_t c) {
18 return internal::structural_or_whitespace_negated[c];
21 simdjson_inline uint32_t is_structural_or_whitespace(uint8_t c) {
22 return internal::structural_or_whitespace[c];
31 static inline uint32_t hex_to_u32_nocheck(
33 uint32_t v1 = internal::digit_to_val32[630 + src[0]];
34 uint32_t v2 = internal::digit_to_val32[420 + src[1]];
35 uint32_t v3 = internal::digit_to_val32[210 + src[2]];
36 uint32_t v4 = internal::digit_to_val32[0 + src[3]];
37 return v1 | v2 | v3 | v4;
52 simdjson_inline
size_t codepoint_to_utf8(uint32_t cp, uint8_t *c) {
58 c[0] = uint8_t((cp >> 6) + 192);
59 c[1] = uint8_t((cp & 63) + 128);
64 }
else if (cp <= 0xFFFF) {
65 c[0] = uint8_t((cp >> 12) + 224);
66 c[1] = uint8_t(((cp >> 6) & 63) + 128);
67 c[2] = uint8_t((cp & 63) + 128);
69 }
else if (cp <= 0x10FFFF) {
71 c[0] = uint8_t((cp >> 18) + 240);
72 c[1] = uint8_t(((cp >> 12) & 63) + 128);
73 c[2] = uint8_t(((cp >> 6) & 63) + 128);
74 c[3] = uint8_t((cp & 63) + 128);
81 #if SIMDJSON_IS_32BITS
84 static simdjson_inline uint64_t __emulu(uint32_t x, uint32_t y) {
85 return x * (uint64_t)y;
87 static simdjson_inline uint64_t _umul128(uint64_t ab, uint64_t cd, uint64_t *hi) {
88 uint64_t ad = __emulu((uint32_t)(ab >> 32), (uint32_t)cd);
89 uint64_t bd = __emulu((uint32_t)ab, (uint32_t)cd);
90 uint64_t adbc = ad + __emulu((uint32_t)ab, (uint32_t)(cd >> 32));
91 uint64_t adbc_carry = !!(adbc < ad);
92 uint64_t lo = bd + (adbc << 32);
93 *hi = __emulu((uint32_t)(ab >> 32), (uint32_t)(cd >> 32)) + (adbc >> 32) +
94 (adbc_carry << 32) + !!(lo < bd);
The top level simdjson namespace, containing everything the library provides.