Fix old-style C-Casts
This commit is contained in:
parent
ff22e75f95
commit
b521719b6f
|
@ -88,5 +88,3 @@ private:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -51,9 +51,9 @@ stat_t simdjson_computestats(const std::string_view &p) {
|
||||||
if (!answer.valid) {
|
if (!answer.valid) {
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
answer.backslash_count = count_backslash((const uint8_t *)p.data(), p.size());
|
answer.backslash_count = count_backslash(reinterpret_cast<const uint8_t *>(p.data()), p.size());
|
||||||
answer.nonasciibyte_count =
|
answer.nonasciibyte_count =
|
||||||
count_nonasciibytes((const uint8_t *)p.data(), p.size());
|
count_nonasciibytes(reinterpret_cast<const uint8_t *>(p.data()), p.size());
|
||||||
answer.byte_count = p.size();
|
answer.byte_count = p.size();
|
||||||
answer.integer_count = 0;
|
answer.integer_count = 0;
|
||||||
answer.float_count = 0;
|
answer.float_count = 0;
|
||||||
|
|
|
@ -81,7 +81,7 @@ static inline void print_with_escapes(const unsigned char *src, std::ostream &os
|
||||||
default:
|
default:
|
||||||
if (*src <= 0x1F) {
|
if (*src <= 0x1F) {
|
||||||
std::ios::fmtflags f(os.flags());
|
std::ios::fmtflags f(os.flags());
|
||||||
os << std::hex << std::setw(4) << std::setfill('0') << (int) *src;
|
os << std::hex << std::setw(4) << std::setfill('0') << static_cast<int>(*src);
|
||||||
os.flags(f);
|
os.flags(f);
|
||||||
} else {
|
} else {
|
||||||
os << *src;
|
os << *src;
|
||||||
|
@ -92,7 +92,7 @@ static inline void print_with_escapes(const unsigned char *src, std::ostream &os
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void print_with_escapes(const char *src, std::ostream &os) {
|
static inline void print_with_escapes(const char *src, std::ostream &os) {
|
||||||
print_with_escapes((const unsigned char *)src, os);
|
print_with_escapes(reinterpret_cast<const unsigned char *>(src), os);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -11,7 +11,7 @@ size_t jsonminify(const uint8_t *buf, size_t len, uint8_t *out);
|
||||||
|
|
||||||
|
|
||||||
static inline size_t jsonminify(const char *buf, size_t len, char *out) {
|
static inline size_t jsonminify(const char *buf, size_t len, char *out) {
|
||||||
return jsonminify((const uint8_t *)buf, len, (uint8_t *)out);
|
return jsonminify(reinterpret_cast<const uint8_t *>(buf), len, reinterpret_cast<uint8_t *>(out));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ bool json_parse(const uint8_t *buf, size_t len, ParsedJson &pj, bool reallocifne
|
||||||
// all bytes at and after buf + len are ignored (can be garbage).
|
// all bytes at and after buf + len are ignored (can be garbage).
|
||||||
WARN_UNUSED
|
WARN_UNUSED
|
||||||
inline bool json_parse(const char * buf, size_t len, ParsedJson &pj, bool reallocifneeded = true) {
|
inline bool json_parse(const char * buf, size_t len, ParsedJson &pj, bool reallocifneeded = true) {
|
||||||
return json_parse((const uint8_t *) buf, len, pj, reallocifneeded);
|
return json_parse(reinterpret_cast<const uint8_t *>(buf), len, pj, reallocifneeded);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse a document found in buf, need to preallocate ParsedJson.
|
// Parse a document found in buf, need to preallocate ParsedJson.
|
||||||
|
@ -66,7 +66,7 @@ WARN_UNUSED
|
||||||
// The input buf should be readable up to buf + len + SIMDJSON_PADDING if reallocifneeded is false,
|
// The input buf should be readable up to buf + len + SIMDJSON_PADDING if reallocifneeded is false,
|
||||||
// all bytes at and after buf + len are ignored (can be garbage).
|
// all bytes at and after buf + len are ignored (can be garbage).
|
||||||
inline ParsedJson build_parsed_json(const char * buf, size_t len, bool reallocifneeded = true) {
|
inline ParsedJson build_parsed_json(const char * buf, size_t len, bool reallocifneeded = true) {
|
||||||
return build_parsed_json((const uint8_t *) buf, len, reallocifneeded);
|
return build_parsed_json(reinterpret_cast<const uint8_t *>(buf), len, reallocifneeded);
|
||||||
}
|
}
|
||||||
|
|
||||||
// convenience function
|
// convenience function
|
||||||
|
|
|
@ -141,7 +141,7 @@ static inline uint32_t parse_eight_digits_unrolled(const char *chars) {
|
||||||
const __m128i mul_1_100 = _mm_setr_epi16(100, 1, 100, 1, 100, 1, 100, 1);
|
const __m128i mul_1_100 = _mm_setr_epi16(100, 1, 100, 1, 100, 1, 100, 1);
|
||||||
const __m128i mul_1_10000 =
|
const __m128i mul_1_10000 =
|
||||||
_mm_setr_epi16(10000, 1, 10000, 1, 10000, 1, 10000, 1);
|
_mm_setr_epi16(10000, 1, 10000, 1, 10000, 1, 10000, 1);
|
||||||
const __m128i input = _mm_sub_epi8(_mm_loadu_si128((const __m128i *)chars), ascii0);
|
const __m128i input = _mm_sub_epi8(_mm_loadu_si128(reinterpret_cast<const __m128i *>(chars)), ascii0);
|
||||||
const __m128i t1 = _mm_maddubs_epi16(input, mul_1_10);
|
const __m128i t1 = _mm_maddubs_epi16(input, mul_1_10);
|
||||||
const __m128i t2 = _mm_madd_epi16(t1, mul_1_100);
|
const __m128i t2 = _mm_madd_epi16(t1, mul_1_100);
|
||||||
const __m128i t3 = _mm_packus_epi32(t2, t2);
|
const __m128i t3 = _mm_packus_epi32(t2, t2);
|
||||||
|
@ -166,7 +166,7 @@ static never_inline bool
|
||||||
parse_float(const uint8_t *const buf,
|
parse_float(const uint8_t *const buf,
|
||||||
ParsedJson &pj, const uint32_t offset,
|
ParsedJson &pj, const uint32_t offset,
|
||||||
bool found_minus) {
|
bool found_minus) {
|
||||||
const char *p = (const char *)(buf + offset);
|
const char *p = reinterpret_cast<const char *>(buf + offset);
|
||||||
bool negative = false;
|
bool negative = false;
|
||||||
if (found_minus) {
|
if (found_minus) {
|
||||||
++p;
|
++p;
|
||||||
|
@ -280,7 +280,7 @@ static never_inline bool parse_large_integer(const uint8_t *const buf,
|
||||||
ParsedJson &pj,
|
ParsedJson &pj,
|
||||||
const uint32_t offset,
|
const uint32_t offset,
|
||||||
bool found_minus) {
|
bool found_minus) {
|
||||||
const char *p = (const char *)(buf + offset);
|
const char *p = reinterpret_cast<const char *>(buf + offset);
|
||||||
|
|
||||||
bool negative = false;
|
bool negative = false;
|
||||||
if (found_minus) {
|
if (found_minus) {
|
||||||
|
@ -352,7 +352,7 @@ static really_inline bool parse_number(const uint8_t *const buf,
|
||||||
pj.write_tape_s64(0); // always write zero
|
pj.write_tape_s64(0); // always write zero
|
||||||
return true; // always succeeds
|
return true; // always succeeds
|
||||||
#else
|
#else
|
||||||
const char *p = (const char *)(buf + offset);
|
const char *p = reinterpret_cast<const char *>(buf + offset);
|
||||||
bool negative = false;
|
bool negative = false;
|
||||||
if (found_minus) {
|
if (found_minus) {
|
||||||
++p;
|
++p;
|
||||||
|
|
|
@ -68,12 +68,12 @@ public:
|
||||||
|
|
||||||
// this should be considered a private function
|
// this should be considered a private function
|
||||||
really_inline void write_tape(uint64_t val, uint8_t c) {
|
really_inline void write_tape(uint64_t val, uint8_t c) {
|
||||||
tape[current_loc++] = val | (((uint64_t)c) << 56);
|
tape[current_loc++] = val | ((static_cast<uint64_t>(c)) << 56);
|
||||||
}
|
}
|
||||||
|
|
||||||
really_inline void write_tape_s64(int64_t i) {
|
really_inline void write_tape_s64(int64_t i) {
|
||||||
write_tape(0, 'l');
|
write_tape(0, 'l');
|
||||||
tape[current_loc++] = *((uint64_t *)&i);
|
tape[current_loc++] = *(reinterpret_cast<uint64_t *>(&i));
|
||||||
}
|
}
|
||||||
|
|
||||||
really_inline void write_tape_double(double d) {
|
really_inline void write_tape_double(double d) {
|
||||||
|
@ -238,14 +238,14 @@ private :
|
||||||
// dump bits low to high
|
// dump bits low to high
|
||||||
inline void dumpbits_always(uint64_t v, const std::string &msg) {
|
inline void dumpbits_always(uint64_t v, const std::string &msg) {
|
||||||
for (uint32_t i = 0; i < 64; i++) {
|
for (uint32_t i = 0; i < 64; i++) {
|
||||||
std::cout << (((v >> (uint64_t)i) & 0x1ULL) != 0u ? "1" : "_");
|
std::cout << (((v >> static_cast<uint64_t>(i)) & 0x1ULL) != 0u ? "1" : "_");
|
||||||
}
|
}
|
||||||
std::cout << " " << msg.c_str() << "\n";
|
std::cout << " " << msg.c_str() << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void dumpbits32_always(uint32_t v, const std::string &msg) {
|
inline void dumpbits32_always(uint32_t v, const std::string &msg) {
|
||||||
for (uint32_t i = 0; i < 32; i++) {
|
for (uint32_t i = 0; i < 32; i++) {
|
||||||
std::cout << (((v >> (uint32_t)i) & 0x1ULL) != 0u ? "1" : "_");
|
std::cout << (((v >> i) & 0x1ULL) != 0u ? "1" : "_");
|
||||||
}
|
}
|
||||||
std::cout << " " << msg.c_str() << "\n";
|
std::cout << " " << msg.c_str() << "\n";
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,10 +46,10 @@ static inline int hamming(uint64_t input_num) {
|
||||||
#include <x86intrin.h>
|
#include <x86intrin.h>
|
||||||
|
|
||||||
static inline bool add_overflow(uint64_t value1, uint64_t value2, uint64_t *result) {
|
static inline bool add_overflow(uint64_t value1, uint64_t value2, uint64_t *result) {
|
||||||
return __builtin_uaddll_overflow(value1, value2, (unsigned long long*)result);
|
return __builtin_uaddll_overflow(value1, value2, static_cast<unsigned long long*>(result));
|
||||||
}
|
}
|
||||||
static inline bool mul_overflow(uint64_t value1, uint64_t value2, uint64_t *result) {
|
static inline bool mul_overflow(uint64_t value1, uint64_t value2, uint64_t *result) {
|
||||||
return __builtin_umulll_overflow(value1, value2, (unsigned long long *)result);
|
return __builtin_umulll_overflow(value1, value2, static_cast<unsigned long long *>(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* result might be undefined when input_num is zero */
|
/* result might be undefined when input_num is zero */
|
||||||
|
|
|
@ -9,7 +9,7 @@ bool find_structural_bits(const uint8_t *buf, size_t len, ParsedJson &pj);
|
||||||
|
|
||||||
WARN_UNUSED
|
WARN_UNUSED
|
||||||
static inline bool find_structural_bits(const char *buf, size_t len, ParsedJson &pj) {
|
static inline bool find_structural_bits(const char *buf, size_t len, ParsedJson &pj) {
|
||||||
return find_structural_bits((const uint8_t *)buf, len, pj);
|
return find_structural_bits(reinterpret_cast<const uint8_t *>(buf), len, pj);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -12,7 +12,7 @@ bool unified_machine(const uint8_t *buf, size_t len, ParsedJson &pj);
|
||||||
|
|
||||||
WARN_UNUSED
|
WARN_UNUSED
|
||||||
static inline bool unified_machine(const char *buf, size_t len, ParsedJson &pj) {
|
static inline bool unified_machine(const char *buf, size_t len, ParsedJson &pj) {
|
||||||
return unified_machine((const uint8_t *)buf,len,pj);
|
return unified_machine(reinterpret_cast<const uint8_t *>(buf),len,pj);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -72,11 +72,11 @@ really_inline bool parse_string(const uint8_t *buf, UNUSED size_t len,
|
||||||
uint8_t *const start_of_string = dst;
|
uint8_t *const start_of_string = dst;
|
||||||
#endif
|
#endif
|
||||||
while (1) {
|
while (1) {
|
||||||
__m256i v = _mm256_loadu_si256((const __m256i *)(src));
|
__m256i v = _mm256_loadu_si256(reinterpret_cast<const __m256i *>(src));
|
||||||
auto bs_bits =
|
auto bs_bits =
|
||||||
(uint32_t)_mm256_movemask_epi8(_mm256_cmpeq_epi8(v, _mm256_set1_epi8('\\')));
|
static_cast<uint32_t>(_mm256_movemask_epi8(_mm256_cmpeq_epi8(v, _mm256_set1_epi8('\\'))));
|
||||||
auto quote_bits =
|
auto quote_bits =
|
||||||
(uint32_t)_mm256_movemask_epi8(_mm256_cmpeq_epi8(v, _mm256_set1_epi8('"')));
|
static_cast<uint32_t>(_mm256_movemask_epi8(_mm256_cmpeq_epi8(v, _mm256_set1_epi8('"'))));
|
||||||
#define CHECKUNESCAPED
|
#define CHECKUNESCAPED
|
||||||
// All Unicode characters may be placed within the
|
// All Unicode characters may be placed within the
|
||||||
// quotation marks, except for the characters that MUST be escaped:
|
// quotation marks, except for the characters that MUST be escaped:
|
||||||
|
@ -92,7 +92,7 @@ really_inline bool parse_string(const uint8_t *buf, UNUSED size_t len,
|
||||||
uint32_t bs_dist = trailingzeroes(bs_bits);
|
uint32_t bs_dist = trailingzeroes(bs_bits);
|
||||||
// store to dest unconditionally - we can overwrite the bits we don't like
|
// store to dest unconditionally - we can overwrite the bits we don't like
|
||||||
// later
|
// later
|
||||||
_mm256_storeu_si256((__m256i *)(dst), v);
|
_mm256_storeu_si256(reinterpret_cast<__m256i *>(dst), v);
|
||||||
if (quote_dist < bs_dist) {
|
if (quote_dist < bs_dist) {
|
||||||
// we encountered quotes first. Move dst to point to quotes and exit
|
// we encountered quotes first. Move dst to point to quotes and exit
|
||||||
dst[quote_dist] = 0; // null terminate and get out
|
dst[quote_dist] = 0; // null terminate and get out
|
||||||
|
@ -102,7 +102,7 @@ really_inline bool parse_string(const uint8_t *buf, UNUSED size_t len,
|
||||||
pj.current_string_buf_loc = dst + quote_dist + 1; // the +1 is due to the 0 value
|
pj.current_string_buf_loc = dst + quote_dist + 1; // the +1 is due to the 0 value
|
||||||
#ifdef CHECKUNESCAPED
|
#ifdef CHECKUNESCAPED
|
||||||
// check that there is no unescaped char before the quote
|
// check that there is no unescaped char before the quote
|
||||||
auto unescaped_bits = (uint32_t)_mm256_movemask_epi8(unescaped_vec);
|
auto unescaped_bits = static_cast<uint32_t>(_mm256_movemask_epi8(unescaped_vec));
|
||||||
bool is_ok = ((quote_bits - 1) & (~ quote_bits) & unescaped_bits) == 0;
|
bool is_ok = ((quote_bits - 1) & (~ quote_bits) & unescaped_bits) == 0;
|
||||||
#ifdef JSON_TEST_STRINGS // for unit testing
|
#ifdef JSON_TEST_STRINGS // for unit testing
|
||||||
if(is_ok) foundString(buf + offset,start_of_string,pj.current_string_buf_loc - 1);
|
if(is_ok) foundString(buf + offset,start_of_string,pj.current_string_buf_loc - 1);
|
||||||
|
@ -119,7 +119,7 @@ really_inline bool parse_string(const uint8_t *buf, UNUSED size_t len,
|
||||||
uint8_t escape_char = src[bs_dist + 1];
|
uint8_t escape_char = src[bs_dist + 1];
|
||||||
#ifdef CHECKUNESCAPED
|
#ifdef CHECKUNESCAPED
|
||||||
// we are going to need the unescaped_bits to check for unescaped chars
|
// we are going to need the unescaped_bits to check for unescaped chars
|
||||||
auto unescaped_bits = (uint32_t)_mm256_movemask_epi8(unescaped_vec);
|
auto unescaped_bits = static_cast<uint32_t>(_mm256_movemask_epi8(unescaped_vec));
|
||||||
if(((bs_bits - 1) & (~ bs_bits) & unescaped_bits) != 0) {
|
if(((bs_bits - 1) & (~ bs_bits) & unescaped_bits) != 0) {
|
||||||
#ifdef JSON_TEST_STRINGS // for unit testing
|
#ifdef JSON_TEST_STRINGS // for unit testing
|
||||||
foundBadString(buf + offset);
|
foundBadString(buf + offset);
|
||||||
|
|
|
@ -13,7 +13,7 @@ char * allocate_padded_buffer(size_t length) {
|
||||||
#elif defined(__MINGW32__) || defined(__MINGW64__)
|
#elif defined(__MINGW32__) || defined(__MINGW64__)
|
||||||
padded_buffer = __mingw_aligned_malloc(totalpaddedlength, 64);
|
padded_buffer = __mingw_aligned_malloc(totalpaddedlength, 64);
|
||||||
#else
|
#else
|
||||||
if (posix_memalign((void **)&padded_buffer, 64, totalpaddedlength) != 0) { return nullptr;
|
if (posix_memalign(reinterpret_cast<void **>(&padded_buffer), 64, totalpaddedlength) != 0) { return nullptr;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return padded_buffer;
|
return padded_buffer;
|
||||||
|
|
|
@ -66,7 +66,7 @@ size_t jsonminify(const unsigned char *bytes, size_t howmany,
|
||||||
static uint64_t cmp_mask_against_input_mini(__m256i input_lo, __m256i input_hi,
|
static uint64_t cmp_mask_against_input_mini(__m256i input_lo, __m256i input_hi,
|
||||||
__m256i mask) {
|
__m256i mask) {
|
||||||
__m256i cmp_res_0 = _mm256_cmpeq_epi8(input_lo, mask);
|
__m256i cmp_res_0 = _mm256_cmpeq_epi8(input_lo, mask);
|
||||||
uint64_t res_0 = (uint32_t)_mm256_movemask_epi8(cmp_res_0);
|
uint64_t res_0 = static_cast<uint32_t>(_mm256_movemask_epi8(cmp_res_0));
|
||||||
__m256i cmp_res_1 = _mm256_cmpeq_epi8(input_hi, mask);
|
__m256i cmp_res_1 = _mm256_cmpeq_epi8(input_hi, mask);
|
||||||
uint64_t res_1 = _mm256_movemask_epi8(cmp_res_1);
|
uint64_t res_1 = _mm256_movemask_epi8(cmp_res_1);
|
||||||
return res_0 | (res_1 << 32);
|
return res_0 | (res_1 << 32);
|
||||||
|
@ -87,8 +87,8 @@ size_t jsonminify(const uint8_t *buf, size_t len, uint8_t *out) {
|
||||||
size_t avxlen = len - 63;
|
size_t avxlen = len - 63;
|
||||||
|
|
||||||
for (; idx < avxlen; idx += 64) {
|
for (; idx < avxlen; idx += 64) {
|
||||||
__m256i input_lo = _mm256_loadu_si256((const __m256i *)(buf + idx + 0));
|
__m256i input_lo = _mm256_loadu_si256(reinterpret_cast<const __m256i *>(buf + idx + 0));
|
||||||
__m256i input_hi = _mm256_loadu_si256((const __m256i *)(buf + idx + 32));
|
__m256i input_hi = _mm256_loadu_si256(reinterpret_cast<const __m256i *>(buf + idx + 32));
|
||||||
uint64_t bs_bits = cmp_mask_against_input_mini(input_lo, input_hi,
|
uint64_t bs_bits = cmp_mask_against_input_mini(input_lo, input_hi,
|
||||||
_mm256_set1_epi8('\\'));
|
_mm256_set1_epi8('\\'));
|
||||||
uint64_t start_edges = bs_bits & ~(bs_bits << 1);
|
uint64_t start_edges = bs_bits & ~(bs_bits << 1);
|
||||||
|
@ -112,7 +112,7 @@ size_t jsonminify(const uint8_t *buf, size_t len, uint8_t *out) {
|
||||||
uint64_t quote_mask = _mm_cvtsi128_si64(_mm_clmulepi64_si128(
|
uint64_t quote_mask = _mm_cvtsi128_si64(_mm_clmulepi64_si128(
|
||||||
_mm_set_epi64x(0ULL, quote_bits), _mm_set1_epi8(0xFF), 0));
|
_mm_set_epi64x(0ULL, quote_bits), _mm_set1_epi8(0xFF), 0));
|
||||||
quote_mask ^= prev_iter_inside_quote;
|
quote_mask ^= prev_iter_inside_quote;
|
||||||
prev_iter_inside_quote = (uint64_t)((int64_t)quote_mask >> 63);// might be undefined behavior, should be fully defined in C++20, ok according to John Regher from Utah University
|
prev_iter_inside_quote = static_cast<uint64_t>(static_cast<int64_t>(quote_mask) >> 63);// might be undefined behavior, should be fully defined in C++20, ok according to John Regher from Utah University
|
||||||
const __m256i low_nibble_mask = _mm256_setr_epi8(
|
const __m256i low_nibble_mask = _mm256_setr_epi8(
|
||||||
// 0 9 a b c d
|
// 0 9 a b c d
|
||||||
16, 0, 0, 0, 0, 0, 0, 0, 0, 8, 12, 1, 2, 9, 0, 0, 16, 0, 0, 0, 0, 0,
|
16, 0, 0, 0, 0, 0, 0, 0, 0, 8, 12, 1, 2, 9, 0, 0, 16, 0, 0, 0, 0, 0,
|
||||||
|
@ -138,7 +138,7 @@ size_t jsonminify(const uint8_t *buf, size_t len, uint8_t *out) {
|
||||||
__m256i tmp_ws_hi = _mm256_cmpeq_epi8(
|
__m256i tmp_ws_hi = _mm256_cmpeq_epi8(
|
||||||
_mm256_and_si256(v_hi, whitespace_shufti_mask), _mm256_set1_epi8(0));
|
_mm256_and_si256(v_hi, whitespace_shufti_mask), _mm256_set1_epi8(0));
|
||||||
|
|
||||||
uint64_t ws_res_0 = (uint32_t)_mm256_movemask_epi8(tmp_ws_lo);
|
uint64_t ws_res_0 = static_cast<uint32_t>(_mm256_movemask_epi8(tmp_ws_lo));
|
||||||
uint64_t ws_res_1 = _mm256_movemask_epi8(tmp_ws_hi);
|
uint64_t ws_res_1 = _mm256_movemask_epi8(tmp_ws_hi);
|
||||||
uint64_t whitespace = ~(ws_res_0 | (ws_res_1 << 32));
|
uint64_t whitespace = ~(ws_res_0 | (ws_res_1 << 32));
|
||||||
whitespace &= ~quote_mask;
|
whitespace &= ~quote_mask;
|
||||||
|
@ -151,15 +151,15 @@ size_t jsonminify(const uint8_t *buf, size_t len, uint8_t *out) {
|
||||||
int pop3 = hamming((~whitespace) & UINT64_C(0xFFFFFFFFFFFF));
|
int pop3 = hamming((~whitespace) & UINT64_C(0xFFFFFFFFFFFF));
|
||||||
int pop4 = hamming((~whitespace));
|
int pop4 = hamming((~whitespace));
|
||||||
__m256i vmask1 =
|
__m256i vmask1 =
|
||||||
_mm256_loadu2_m128i((const __m128i *)mask128_epi8 + (mask2 & 0x7FFF),
|
_mm256_loadu2_m128i(reinterpret_cast<const __m128i *>(mask128_epi8) + (mask2 & 0x7FFF),
|
||||||
(const __m128i *)mask128_epi8 + (mask1 & 0x7FFF));
|
reinterpret_cast<const __m128i *>(mask128_epi8) + (mask1 & 0x7FFF));
|
||||||
__m256i vmask2 =
|
__m256i vmask2 =
|
||||||
_mm256_loadu2_m128i((const __m128i *)mask128_epi8 + (mask4 & 0x7FFF),
|
_mm256_loadu2_m128i(reinterpret_cast<const __m128i *>(mask128_epi8) + (mask4 & 0x7FFF),
|
||||||
(const __m128i *)mask128_epi8 + (mask3 & 0x7FFF));
|
reinterpret_cast<const __m128i *>(mask128_epi8) + (mask3 & 0x7FFF));
|
||||||
__m256i result1 = _mm256_shuffle_epi8(input_lo, vmask1);
|
__m256i result1 = _mm256_shuffle_epi8(input_lo, vmask1);
|
||||||
__m256i result2 = _mm256_shuffle_epi8(input_hi, vmask2);
|
__m256i result2 = _mm256_shuffle_epi8(input_hi, vmask2);
|
||||||
_mm256_storeu2_m128i((__m128i *)(out + pop1), (__m128i *)out, result1);
|
_mm256_storeu2_m128i(reinterpret_cast<__m128i *>(out + pop1), reinterpret_cast<__m128i *>(out), result1);
|
||||||
_mm256_storeu2_m128i((__m128i *)(out + pop3), (__m128i *)(out + pop2),
|
_mm256_storeu2_m128i(reinterpret_cast<__m128i *>(out + pop3), reinterpret_cast<__m128i *>(out + pop2),
|
||||||
result2);
|
result2);
|
||||||
out += pop4;
|
out += pop4;
|
||||||
}
|
}
|
||||||
|
@ -170,8 +170,8 @@ size_t jsonminify(const uint8_t *buf, size_t len, uint8_t *out) {
|
||||||
uint8_t buffer[64];
|
uint8_t buffer[64];
|
||||||
memset(buffer, 0, 64);
|
memset(buffer, 0, 64);
|
||||||
memcpy(buffer, buf + idx, len - idx);
|
memcpy(buffer, buf + idx, len - idx);
|
||||||
__m256i input_lo = _mm256_loadu_si256((const __m256i *)(buffer));
|
__m256i input_lo = _mm256_loadu_si256(reinterpret_cast<const __m256i *>(buffer));
|
||||||
__m256i input_hi = _mm256_loadu_si256((const __m256i *)(buffer + 32));
|
__m256i input_hi = _mm256_loadu_si256(reinterpret_cast<const __m256i *>(buffer + 32));
|
||||||
uint64_t bs_bits =
|
uint64_t bs_bits =
|
||||||
cmp_mask_against_input_mini(input_lo, input_hi, _mm256_set1_epi8('\\'));
|
cmp_mask_against_input_mini(input_lo, input_hi, _mm256_set1_epi8('\\'));
|
||||||
uint64_t start_edges = bs_bits & ~(bs_bits << 1);
|
uint64_t start_edges = bs_bits & ~(bs_bits << 1);
|
||||||
|
@ -213,7 +213,7 @@ size_t jsonminify(const uint8_t *buf, size_t len, uint8_t *out) {
|
||||||
__m256i tmp_ws_hi = _mm256_or_si256(
|
__m256i tmp_ws_hi = _mm256_or_si256(
|
||||||
_mm256_cmpeq_epi8(mask_20, input_hi),
|
_mm256_cmpeq_epi8(mask_20, input_hi),
|
||||||
_mm256_shuffle_epi8(lut_cntrl, _mm256_adds_epu8(mask_70, input_hi)));
|
_mm256_shuffle_epi8(lut_cntrl, _mm256_adds_epu8(mask_70, input_hi)));
|
||||||
uint64_t ws_res_0 = (uint32_t)_mm256_movemask_epi8(tmp_ws_lo);
|
uint64_t ws_res_0 = static_cast<uint32_t>(_mm256_movemask_epi8(tmp_ws_lo));
|
||||||
uint64_t ws_res_1 = _mm256_movemask_epi8(tmp_ws_hi);
|
uint64_t ws_res_1 = _mm256_movemask_epi8(tmp_ws_hi);
|
||||||
uint64_t whitespace = (ws_res_0 | (ws_res_1 << 32));
|
uint64_t whitespace = (ws_res_0 | (ws_res_1 << 32));
|
||||||
whitespace &= ~quote_mask;
|
whitespace &= ~quote_mask;
|
||||||
|
@ -230,16 +230,16 @@ size_t jsonminify(const uint8_t *buf, size_t len, uint8_t *out) {
|
||||||
int pop3 = hamming((~whitespace) & UINT64_C(0xFFFFFFFFFFFF));
|
int pop3 = hamming((~whitespace) & UINT64_C(0xFFFFFFFFFFFF));
|
||||||
int pop4 = hamming((~whitespace));
|
int pop4 = hamming((~whitespace));
|
||||||
__m256i vmask1 =
|
__m256i vmask1 =
|
||||||
_mm256_loadu2_m128i((const __m128i *)mask128_epi8 + (mask2 & 0x7FFF),
|
_mm256_loadu2_m128i(reinterpret_cast<const __m128i *>(mask128_epi8) + (mask2 & 0x7FFF),
|
||||||
(const __m128i *)mask128_epi8 + (mask1 & 0x7FFF));
|
reinterpret_cast<const __m128i *>(mask128_epi8) + (mask1 & 0x7FFF));
|
||||||
__m256i vmask2 =
|
__m256i vmask2 =
|
||||||
_mm256_loadu2_m128i((const __m128i *)mask128_epi8 + (mask4 & 0x7FFF),
|
_mm256_loadu2_m128i(reinterpret_cast<const __m128i *>(mask128_epi8) + (mask4 & 0x7FFF),
|
||||||
(const __m128i *)mask128_epi8 + (mask3 & 0x7FFF));
|
reinterpret_cast<const __m128i *>(mask128_epi8) + (mask3 & 0x7FFF));
|
||||||
__m256i result1 = _mm256_shuffle_epi8(input_lo, vmask1);
|
__m256i result1 = _mm256_shuffle_epi8(input_lo, vmask1);
|
||||||
__m256i result2 = _mm256_shuffle_epi8(input_hi, vmask2);
|
__m256i result2 = _mm256_shuffle_epi8(input_hi, vmask2);
|
||||||
_mm256_storeu2_m128i((__m128i *)(buffer + pop1), (__m128i *)buffer,
|
_mm256_storeu2_m128i(reinterpret_cast<__m128i *>(buffer + pop1), reinterpret_cast<__m128i *>(buffer),
|
||||||
result1);
|
result1);
|
||||||
_mm256_storeu2_m128i((__m128i *)(buffer + pop3), (__m128i *)(buffer + pop2),
|
_mm256_storeu2_m128i(reinterpret_cast<__m128i *>(buffer + pop3), reinterpret_cast<__m128i *>(buffer + pop2),
|
||||||
result2);
|
result2);
|
||||||
memcpy(out, buffer, pop4);
|
memcpy(out, buffer, pop4);
|
||||||
out += pop4;
|
out += pop4;
|
||||||
|
|
|
@ -33,7 +33,7 @@ bool json_parse(const uint8_t *buf, size_t len, ParsedJson &pj, bool reallocifne
|
||||||
#endif
|
#endif
|
||||||
if ( (reinterpret_cast<uintptr_t>(buf + len - 1) % pagesize ) < SIMDJSON_PADDING ) {
|
if ( (reinterpret_cast<uintptr_t>(buf + len - 1) % pagesize ) < SIMDJSON_PADDING ) {
|
||||||
const uint8_t *tmpbuf = buf;
|
const uint8_t *tmpbuf = buf;
|
||||||
buf = (uint8_t *) allocate_padded_buffer(len);
|
buf = reinterpret_cast<uint8_t *>(allocate_padded_buffer(len));
|
||||||
if(buf == nullptr) { return false;
|
if(buf == nullptr) { return false;
|
||||||
}
|
}
|
||||||
memcpy((void*)buf,tmpbuf,len);
|
memcpy((void*)buf,tmpbuf,len);
|
||||||
|
|
|
@ -164,7 +164,7 @@ bool ParsedJson::printjson(std::ostream &os) {
|
||||||
if (tapeidx + 1 >= howmany) {
|
if (tapeidx + 1 >= howmany) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
os << (int64_t)tape[++tapeidx];
|
os << static_cast<int64_t>(tape[++tapeidx]);
|
||||||
break;
|
break;
|
||||||
case 'd': // we have a double
|
case 'd': // we have a double
|
||||||
if (tapeidx + 1 >= howmany) {
|
if (tapeidx + 1 >= howmany) {
|
||||||
|
@ -254,7 +254,7 @@ bool ParsedJson::dump_raw_tape(std::ostream &os) {
|
||||||
if (tapeidx + 1 >= howmany) {
|
if (tapeidx + 1 >= howmany) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
os << "integer " << (int64_t)tape[++tapeidx] << "\n";
|
os << "integer " << static_cast<int64_t>(tape[++tapeidx]) << "\n";
|
||||||
break;
|
break;
|
||||||
case 'd': // we have a double
|
case 'd': // we have a double
|
||||||
os << "float ";
|
os << "float ";
|
||||||
|
|
|
@ -109,7 +109,7 @@ uint8_t ParsedJson::iterator::get_type() const {
|
||||||
int64_t ParsedJson::iterator::get_integer() const {
|
int64_t ParsedJson::iterator::get_integer() const {
|
||||||
if(location + 1 >= tape_length) { return 0;// default value in case of error
|
if(location + 1 >= tape_length) { return 0;// default value in case of error
|
||||||
}
|
}
|
||||||
return (int64_t) pj.tape[location + 1];
|
return static_cast<int64_t>(pj.tape[location + 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
double ParsedJson::iterator::get_double() const {
|
double ParsedJson::iterator::get_double() const {
|
||||||
|
@ -121,7 +121,7 @@ double ParsedJson::iterator::get_double() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * ParsedJson::iterator::get_string() const {
|
const char * ParsedJson::iterator::get_string() const {
|
||||||
return (const char *)(pj.string_buf + (current_val & JSONVALUEMASK)) ;
|
return reinterpret_cast<const char *>(pj.string_buf + (current_val & JSONVALUEMASK)) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -292,7 +292,7 @@ bool ParsedJson::iterator::print(std::ostream &os, bool escape_strings) const {
|
||||||
case '}': // we end an object
|
case '}': // we end an object
|
||||||
case '[': // we start an array
|
case '[': // we start an array
|
||||||
case ']': // we end an array
|
case ']': // we end an array
|
||||||
os << (char) current_type;
|
os << static_cast<char>(current_type);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -21,7 +21,7 @@ using namespace std;
|
||||||
really_inline uint64_t cmp_mask_against_input(__m256i input_lo, __m256i input_hi,
|
really_inline uint64_t cmp_mask_against_input(__m256i input_lo, __m256i input_hi,
|
||||||
__m256i mask) {
|
__m256i mask) {
|
||||||
__m256i cmp_res_0 = _mm256_cmpeq_epi8(input_lo, mask);
|
__m256i cmp_res_0 = _mm256_cmpeq_epi8(input_lo, mask);
|
||||||
uint64_t res_0 = (uint32_t)_mm256_movemask_epi8(cmp_res_0);
|
uint64_t res_0 = static_cast<uint32_t>(_mm256_movemask_epi8(cmp_res_0));
|
||||||
__m256i cmp_res_1 = _mm256_cmpeq_epi8(input_hi, mask);
|
__m256i cmp_res_1 = _mm256_cmpeq_epi8(input_hi, mask);
|
||||||
uint64_t res_1 = _mm256_movemask_epi8(cmp_res_1);
|
uint64_t res_1 = _mm256_movemask_epi8(cmp_res_1);
|
||||||
return res_0 | (res_1 << 32);
|
return res_0 | (res_1 << 32);
|
||||||
|
@ -66,8 +66,8 @@ WARN_UNUSED
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
__builtin_prefetch(buf + idx + 128);
|
__builtin_prefetch(buf + idx + 128);
|
||||||
#endif
|
#endif
|
||||||
__m256i input_lo = _mm256_loadu_si256((const __m256i *)(buf + idx + 0));
|
__m256i input_lo = _mm256_loadu_si256(reinterpret_cast<const __m256i *>(buf + idx + 0));
|
||||||
__m256i input_hi = _mm256_loadu_si256((const __m256i *)(buf + idx + 32));
|
__m256i input_hi = _mm256_loadu_si256(reinterpret_cast<const __m256i *>(buf + idx + 32));
|
||||||
#ifdef SIMDJSON_UTF8VALIDATE
|
#ifdef SIMDJSON_UTF8VALIDATE
|
||||||
__m256i highbit = _mm256_set1_epi8(0x80);
|
__m256i highbit = _mm256_set1_epi8(0x80);
|
||||||
if((_mm256_testz_si256(_mm256_or_si256(input_lo, input_hi),highbit)) == 1) {
|
if((_mm256_testz_si256(_mm256_or_si256(input_lo, input_hi),highbit)) == 1) {
|
||||||
|
@ -131,28 +131,28 @@ WARN_UNUSED
|
||||||
uint32_t cnt = hamming(structurals);
|
uint32_t cnt = hamming(structurals);
|
||||||
uint32_t next_base = base + cnt;
|
uint32_t next_base = base + cnt;
|
||||||
while (structurals != 0u) {
|
while (structurals != 0u) {
|
||||||
base_ptr[base + 0] = (uint32_t)idx - 64 + trailingzeroes(structurals);
|
base_ptr[base + 0] = static_cast<uint32_t>(idx) - 64 + trailingzeroes(structurals);
|
||||||
structurals = structurals & (structurals - 1);
|
structurals = structurals & (structurals - 1);
|
||||||
base_ptr[base + 1] = (uint32_t)idx - 64 + trailingzeroes(structurals);
|
base_ptr[base + 1] = static_cast<uint32_t>(idx) - 64 + trailingzeroes(structurals);
|
||||||
structurals = structurals & (structurals - 1);
|
structurals = structurals & (structurals - 1);
|
||||||
base_ptr[base + 2] = (uint32_t)idx - 64 + trailingzeroes(structurals);
|
base_ptr[base + 2] = static_cast<uint32_t>(idx) - 64 + trailingzeroes(structurals);
|
||||||
structurals = structurals & (structurals - 1);
|
structurals = structurals & (structurals - 1);
|
||||||
base_ptr[base + 3] = (uint32_t)idx - 64 + trailingzeroes(structurals);
|
base_ptr[base + 3] = static_cast<uint32_t>(idx) - 64 + trailingzeroes(structurals);
|
||||||
structurals = structurals & (structurals - 1);
|
structurals = structurals & (structurals - 1);
|
||||||
base_ptr[base + 4] = (uint32_t)idx - 64 + trailingzeroes(structurals);
|
base_ptr[base + 4] = static_cast<uint32_t>(idx) - 64 + trailingzeroes(structurals);
|
||||||
structurals = structurals & (structurals - 1);
|
structurals = structurals & (structurals - 1);
|
||||||
base_ptr[base + 5] = (uint32_t)idx - 64 + trailingzeroes(structurals);
|
base_ptr[base + 5] = static_cast<uint32_t>(idx) - 64 + trailingzeroes(structurals);
|
||||||
structurals = structurals & (structurals - 1);
|
structurals = structurals & (structurals - 1);
|
||||||
base_ptr[base + 6] = (uint32_t)idx - 64 + trailingzeroes(structurals);
|
base_ptr[base + 6] = static_cast<uint32_t>(idx) - 64 + trailingzeroes(structurals);
|
||||||
structurals = structurals & (structurals - 1);
|
structurals = structurals & (structurals - 1);
|
||||||
base_ptr[base + 7] = (uint32_t)idx - 64 + trailingzeroes(structurals);
|
base_ptr[base + 7] = static_cast<uint32_t>(idx) - 64 + trailingzeroes(structurals);
|
||||||
structurals = structurals & (structurals - 1);
|
structurals = structurals & (structurals - 1);
|
||||||
base += 8;
|
base += 8;
|
||||||
}
|
}
|
||||||
base = next_base;
|
base = next_base;
|
||||||
|
|
||||||
quote_mask ^= prev_iter_inside_quote;
|
quote_mask ^= prev_iter_inside_quote;
|
||||||
prev_iter_inside_quote = (uint64_t)((int64_t)quote_mask >> 63); // right shift of a signed value expected to be well-defined and standard compliant as of C++20, John Regher from Utah U. says this is fine code
|
prev_iter_inside_quote = static_cast<uint64_t>(static_cast<int64_t>(quote_mask) >> 63); // right shift of a signed value expected to be well-defined and standard compliant as of C++20, John Regher from Utah U. says this is fine code
|
||||||
|
|
||||||
// How do we build up a user traversable data structure
|
// How do we build up a user traversable data structure
|
||||||
// first, do a 'shufti' to detect structural JSON characters
|
// first, do a 'shufti' to detect structural JSON characters
|
||||||
|
@ -190,7 +190,7 @@ WARN_UNUSED
|
||||||
__m256i tmp_hi = _mm256_cmpeq_epi8(
|
__m256i tmp_hi = _mm256_cmpeq_epi8(
|
||||||
_mm256_and_si256(v_hi, structural_shufti_mask), _mm256_set1_epi8(0));
|
_mm256_and_si256(v_hi, structural_shufti_mask), _mm256_set1_epi8(0));
|
||||||
|
|
||||||
uint64_t structural_res_0 = (uint32_t)_mm256_movemask_epi8(tmp_lo);
|
uint64_t structural_res_0 = static_cast<uint32_t>(_mm256_movemask_epi8(tmp_lo));
|
||||||
uint64_t structural_res_1 = _mm256_movemask_epi8(tmp_hi);
|
uint64_t structural_res_1 = _mm256_movemask_epi8(tmp_hi);
|
||||||
structurals = ~(structural_res_0 | (structural_res_1 << 32));
|
structurals = ~(structural_res_0 | (structural_res_1 << 32));
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ WARN_UNUSED
|
||||||
__m256i tmp_ws_hi = _mm256_cmpeq_epi8(
|
__m256i tmp_ws_hi = _mm256_cmpeq_epi8(
|
||||||
_mm256_and_si256(v_hi, whitespace_shufti_mask), _mm256_set1_epi8(0));
|
_mm256_and_si256(v_hi, whitespace_shufti_mask), _mm256_set1_epi8(0));
|
||||||
|
|
||||||
uint64_t ws_res_0 = (uint32_t)_mm256_movemask_epi8(tmp_ws_lo);
|
uint64_t ws_res_0 = static_cast<uint32_t>(_mm256_movemask_epi8(tmp_ws_lo));
|
||||||
uint64_t ws_res_1 = _mm256_movemask_epi8(tmp_ws_hi);
|
uint64_t ws_res_1 = _mm256_movemask_epi8(tmp_ws_hi);
|
||||||
uint64_t whitespace = ~(ws_res_0 | (ws_res_1 << 32));
|
uint64_t whitespace = ~(ws_res_0 | (ws_res_1 << 32));
|
||||||
// mask off anything inside quotes
|
// mask off anything inside quotes
|
||||||
|
@ -244,8 +244,8 @@ WARN_UNUSED
|
||||||
uint8_t tmpbuf[64];
|
uint8_t tmpbuf[64];
|
||||||
memset(tmpbuf,0x20,64);
|
memset(tmpbuf,0x20,64);
|
||||||
memcpy(tmpbuf,buf+idx,len - idx);
|
memcpy(tmpbuf,buf+idx,len - idx);
|
||||||
__m256i input_lo = _mm256_loadu_si256((const __m256i *)(tmpbuf + 0));
|
__m256i input_lo = _mm256_loadu_si256(reinterpret_cast<const __m256i *>(tmpbuf + 0));
|
||||||
__m256i input_hi = _mm256_loadu_si256((const __m256i *)(tmpbuf + 32));
|
__m256i input_hi = _mm256_loadu_si256(reinterpret_cast<const __m256i *>(tmpbuf + 32));
|
||||||
#ifdef SIMDJSON_UTF8VALIDATE
|
#ifdef SIMDJSON_UTF8VALIDATE
|
||||||
__m256i highbit = _mm256_set1_epi8(0x80);
|
__m256i highbit = _mm256_set1_epi8(0x80);
|
||||||
if((_mm256_testz_si256(_mm256_or_si256(input_lo, input_hi),highbit)) == 1) {
|
if((_mm256_testz_si256(_mm256_or_si256(input_lo, input_hi),highbit)) == 1) {
|
||||||
|
@ -309,21 +309,21 @@ WARN_UNUSED
|
||||||
uint32_t cnt = hamming(structurals);
|
uint32_t cnt = hamming(structurals);
|
||||||
uint32_t next_base = base + cnt;
|
uint32_t next_base = base + cnt;
|
||||||
while (structurals != 0u) {
|
while (structurals != 0u) {
|
||||||
base_ptr[base + 0] = (uint32_t)idx - 64 + trailingzeroes(structurals);
|
base_ptr[base + 0] = static_cast<uint32_t>(idx) - 64 + trailingzeroes(structurals);
|
||||||
structurals = structurals & (structurals - 1);
|
structurals = structurals & (structurals - 1);
|
||||||
base_ptr[base + 1] = (uint32_t)idx - 64 + trailingzeroes(structurals);
|
base_ptr[base + 1] = static_cast<uint32_t>(idx) - 64 + trailingzeroes(structurals);
|
||||||
structurals = structurals & (structurals - 1);
|
structurals = structurals & (structurals - 1);
|
||||||
base_ptr[base + 2] = (uint32_t)idx - 64 + trailingzeroes(structurals);
|
base_ptr[base + 2] = static_cast<uint32_t>(idx) - 64 + trailingzeroes(structurals);
|
||||||
structurals = structurals & (structurals - 1);
|
structurals = structurals & (structurals - 1);
|
||||||
base_ptr[base + 3] = (uint32_t)idx - 64 + trailingzeroes(structurals);
|
base_ptr[base + 3] = static_cast<uint32_t>(idx) - 64 + trailingzeroes(structurals);
|
||||||
structurals = structurals & (structurals - 1);
|
structurals = structurals & (structurals - 1);
|
||||||
base_ptr[base + 4] = (uint32_t)idx - 64 + trailingzeroes(structurals);
|
base_ptr[base + 4] = static_cast<uint32_t>(idx) - 64 + trailingzeroes(structurals);
|
||||||
structurals = structurals & (structurals - 1);
|
structurals = structurals & (structurals - 1);
|
||||||
base_ptr[base + 5] = (uint32_t)idx - 64 + trailingzeroes(structurals);
|
base_ptr[base + 5] = static_cast<uint32_t>(idx) - 64 + trailingzeroes(structurals);
|
||||||
structurals = structurals & (structurals - 1);
|
structurals = structurals & (structurals - 1);
|
||||||
base_ptr[base + 6] = (uint32_t)idx - 64 + trailingzeroes(structurals);
|
base_ptr[base + 6] = static_cast<uint32_t>(idx) - 64 + trailingzeroes(structurals);
|
||||||
structurals = structurals & (structurals - 1);
|
structurals = structurals & (structurals - 1);
|
||||||
base_ptr[base + 7] = (uint32_t)idx - 64 + trailingzeroes(structurals);
|
base_ptr[base + 7] = static_cast<uint32_t>(idx) - 64 + trailingzeroes(structurals);
|
||||||
structurals = structurals & (structurals - 1);
|
structurals = structurals & (structurals - 1);
|
||||||
base += 8;
|
base += 8;
|
||||||
}
|
}
|
||||||
|
@ -364,7 +364,7 @@ WARN_UNUSED
|
||||||
__m256i tmp_hi = _mm256_cmpeq_epi8(
|
__m256i tmp_hi = _mm256_cmpeq_epi8(
|
||||||
_mm256_and_si256(v_hi, structural_shufti_mask), _mm256_set1_epi8(0));
|
_mm256_and_si256(v_hi, structural_shufti_mask), _mm256_set1_epi8(0));
|
||||||
|
|
||||||
uint64_t structural_res_0 = (uint32_t)_mm256_movemask_epi8(tmp_lo);
|
uint64_t structural_res_0 = static_cast<uint32_t>(_mm256_movemask_epi8(tmp_lo));
|
||||||
uint64_t structural_res_1 = _mm256_movemask_epi8(tmp_hi);
|
uint64_t structural_res_1 = _mm256_movemask_epi8(tmp_hi);
|
||||||
structurals = ~(structural_res_0 | (structural_res_1 << 32));
|
structurals = ~(structural_res_0 | (structural_res_1 << 32));
|
||||||
|
|
||||||
|
@ -375,7 +375,7 @@ WARN_UNUSED
|
||||||
__m256i tmp_ws_hi = _mm256_cmpeq_epi8(
|
__m256i tmp_ws_hi = _mm256_cmpeq_epi8(
|
||||||
_mm256_and_si256(v_hi, whitespace_shufti_mask), _mm256_set1_epi8(0));
|
_mm256_and_si256(v_hi, whitespace_shufti_mask), _mm256_set1_epi8(0));
|
||||||
|
|
||||||
uint64_t ws_res_0 = (uint32_t)_mm256_movemask_epi8(tmp_ws_lo);
|
uint64_t ws_res_0 = static_cast<uint32_t>(_mm256_movemask_epi8(tmp_ws_lo));
|
||||||
uint64_t ws_res_1 = _mm256_movemask_epi8(tmp_ws_hi);
|
uint64_t ws_res_1 = _mm256_movemask_epi8(tmp_ws_hi);
|
||||||
uint64_t whitespace = ~(ws_res_0 | (ws_res_1 << 32));
|
uint64_t whitespace = ~(ws_res_0 | (ws_res_1 << 32));
|
||||||
|
|
||||||
|
@ -413,21 +413,21 @@ WARN_UNUSED
|
||||||
uint32_t cnt = hamming(structurals);
|
uint32_t cnt = hamming(structurals);
|
||||||
uint32_t next_base = base + cnt;
|
uint32_t next_base = base + cnt;
|
||||||
while (structurals != 0u) {
|
while (structurals != 0u) {
|
||||||
base_ptr[base + 0] = (uint32_t)idx - 64 + trailingzeroes(structurals);
|
base_ptr[base + 0] = static_cast<uint32_t>(idx) - 64 + trailingzeroes(structurals);
|
||||||
structurals = structurals & (structurals - 1);
|
structurals = structurals & (structurals - 1);
|
||||||
base_ptr[base + 1] = (uint32_t)idx - 64 + trailingzeroes(structurals);
|
base_ptr[base + 1] = static_cast<uint32_t>(idx) - 64 + trailingzeroes(structurals);
|
||||||
structurals = structurals & (structurals - 1);
|
structurals = structurals & (structurals - 1);
|
||||||
base_ptr[base + 2] = (uint32_t)idx - 64 + trailingzeroes(structurals);
|
base_ptr[base + 2] = static_cast<uint32_t>(idx) - 64 + trailingzeroes(structurals);
|
||||||
structurals = structurals & (structurals - 1);
|
structurals = structurals & (structurals - 1);
|
||||||
base_ptr[base + 3] = (uint32_t)idx - 64 + trailingzeroes(structurals);
|
base_ptr[base + 3] = static_cast<uint32_t>(idx) - 64 + trailingzeroes(structurals);
|
||||||
structurals = structurals & (structurals - 1);
|
structurals = structurals & (structurals - 1);
|
||||||
base_ptr[base + 4] = (uint32_t)idx - 64 + trailingzeroes(structurals);
|
base_ptr[base + 4] = static_cast<uint32_t>(idx) - 64 + trailingzeroes(structurals);
|
||||||
structurals = structurals & (structurals - 1);
|
structurals = structurals & (structurals - 1);
|
||||||
base_ptr[base + 5] = (uint32_t)idx - 64 + trailingzeroes(structurals);
|
base_ptr[base + 5] = static_cast<uint32_t>(idx) - 64 + trailingzeroes(structurals);
|
||||||
structurals = structurals & (structurals - 1);
|
structurals = structurals & (structurals - 1);
|
||||||
base_ptr[base + 6] = (uint32_t)idx - 64 + trailingzeroes(structurals);
|
base_ptr[base + 6] = static_cast<uint32_t>(idx) - 64 + trailingzeroes(structurals);
|
||||||
structurals = structurals & (structurals - 1);
|
structurals = structurals & (structurals - 1);
|
||||||
base_ptr[base + 7] = (uint32_t)idx - 64 + trailingzeroes(structurals);
|
base_ptr[base + 7] = static_cast<uint32_t>(idx) - 64 + trailingzeroes(structurals);
|
||||||
structurals = structurals & (structurals - 1);
|
structurals = structurals & (structurals - 1);
|
||||||
base += 8;
|
base += 8;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ using namespace std;
|
||||||
|
|
||||||
WARN_UNUSED
|
WARN_UNUSED
|
||||||
really_inline bool is_valid_true_atom(const uint8_t *loc) {
|
really_inline bool is_valid_true_atom(const uint8_t *loc) {
|
||||||
uint64_t tv = *(const uint64_t *)"true ";
|
uint64_t tv = *reinterpret_cast<const uint64_t *>("true ");
|
||||||
uint64_t mask4 = 0x00000000ffffffff;
|
uint64_t mask4 = 0x00000000ffffffff;
|
||||||
uint32_t error = 0;
|
uint32_t error = 0;
|
||||||
uint64_t locval; // we want to avoid unaligned 64-bit loads (undefined in C/C++)
|
uint64_t locval; // we want to avoid unaligned 64-bit loads (undefined in C/C++)
|
||||||
|
@ -34,7 +34,7 @@ really_inline bool is_valid_true_atom(const uint8_t *loc) {
|
||||||
|
|
||||||
WARN_UNUSED
|
WARN_UNUSED
|
||||||
really_inline bool is_valid_false_atom(const uint8_t *loc) {
|
really_inline bool is_valid_false_atom(const uint8_t *loc) {
|
||||||
uint64_t fv = *(const uint64_t *)"false ";
|
uint64_t fv = *reinterpret_cast<const uint64_t *>("false ");
|
||||||
uint64_t mask5 = 0x000000ffffffffff;
|
uint64_t mask5 = 0x000000ffffffffff;
|
||||||
uint32_t error = 0;
|
uint32_t error = 0;
|
||||||
uint64_t locval; // we want to avoid unaligned 64-bit loads (undefined in C/C++)
|
uint64_t locval; // we want to avoid unaligned 64-bit loads (undefined in C/C++)
|
||||||
|
@ -46,7 +46,7 @@ really_inline bool is_valid_false_atom(const uint8_t *loc) {
|
||||||
|
|
||||||
WARN_UNUSED
|
WARN_UNUSED
|
||||||
really_inline bool is_valid_null_atom(const uint8_t *loc) {
|
really_inline bool is_valid_null_atom(const uint8_t *loc) {
|
||||||
uint64_t nv = *(const uint64_t *)"null ";
|
uint64_t nv = *reinterpret_cast<const uint64_t *>("null ");
|
||||||
uint64_t mask4 = 0x00000000ffffffff;
|
uint64_t mask4 = 0x00000000ffffffff;
|
||||||
uint32_t error = 0;
|
uint32_t error = 0;
|
||||||
uint64_t locval; // we want to avoid unaligned 64-bit loads (undefined in C/C++)
|
uint64_t locval; // we want to avoid unaligned 64-bit loads (undefined in C/C++)
|
||||||
|
@ -141,12 +141,12 @@ bool unified_machine(const uint8_t *buf, size_t len, ParsedJson &pj) {
|
||||||
// we need to make a copy to make sure that the string is NULL terminated.
|
// we need to make a copy to make sure that the string is NULL terminated.
|
||||||
// this only applies to the JSON document made solely of the true value.
|
// this only applies to the JSON document made solely of the true value.
|
||||||
// this will almost never be called in practice
|
// this will almost never be called in practice
|
||||||
char * copy = (char *) malloc(len + SIMDJSON_PADDING);
|
char * copy = static_cast<char *>(malloc(len + SIMDJSON_PADDING));
|
||||||
if(copy == nullptr) { goto fail;
|
if(copy == nullptr) { goto fail;
|
||||||
}
|
}
|
||||||
memcpy(copy, buf, len);
|
memcpy(copy, buf, len);
|
||||||
copy[len] = '\0';
|
copy[len] = '\0';
|
||||||
if (!is_valid_true_atom((const uint8_t *)copy + idx)) {
|
if (!is_valid_true_atom(reinterpret_cast<const uint8_t *>(copy) + idx)) {
|
||||||
free(copy);
|
free(copy);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -158,12 +158,12 @@ bool unified_machine(const uint8_t *buf, size_t len, ParsedJson &pj) {
|
||||||
// we need to make a copy to make sure that the string is NULL terminated.
|
// we need to make a copy to make sure that the string is NULL terminated.
|
||||||
// this only applies to the JSON document made solely of the false value.
|
// this only applies to the JSON document made solely of the false value.
|
||||||
// this will almost never be called in practice
|
// this will almost never be called in practice
|
||||||
char * copy = (char *) malloc(len + SIMDJSON_PADDING);
|
char * copy = static_cast<char *>(malloc(len + SIMDJSON_PADDING));
|
||||||
if(copy == nullptr) { goto fail;
|
if(copy == nullptr) { goto fail;
|
||||||
}
|
}
|
||||||
memcpy(copy, buf, len);
|
memcpy(copy, buf, len);
|
||||||
copy[len] = '\0';
|
copy[len] = '\0';
|
||||||
if (!is_valid_false_atom((const uint8_t *)copy + idx)) {
|
if (!is_valid_false_atom(reinterpret_cast<const uint8_t *>(copy) + idx)) {
|
||||||
free(copy);
|
free(copy);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -175,12 +175,12 @@ bool unified_machine(const uint8_t *buf, size_t len, ParsedJson &pj) {
|
||||||
// we need to make a copy to make sure that the string is NULL terminated.
|
// we need to make a copy to make sure that the string is NULL terminated.
|
||||||
// this only applies to the JSON document made solely of the null value.
|
// this only applies to the JSON document made solely of the null value.
|
||||||
// this will almost never be called in practice
|
// this will almost never be called in practice
|
||||||
char * copy = (char *) malloc(len + SIMDJSON_PADDING);
|
char * copy = static_cast<char *>(malloc(len + SIMDJSON_PADDING));
|
||||||
if(copy == nullptr) { goto fail;
|
if(copy == nullptr) { goto fail;
|
||||||
}
|
}
|
||||||
memcpy(copy, buf, len);
|
memcpy(copy, buf, len);
|
||||||
copy[len] = '\0';
|
copy[len] = '\0';
|
||||||
if (!is_valid_null_atom((const uint8_t *)copy + idx)) {
|
if (!is_valid_null_atom(reinterpret_cast<const uint8_t *>(copy) + idx)) {
|
||||||
free(copy);
|
free(copy);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -201,12 +201,12 @@ bool unified_machine(const uint8_t *buf, size_t len, ParsedJson &pj) {
|
||||||
// we need to make a copy to make sure that the string is NULL terminated.
|
// we need to make a copy to make sure that the string is NULL terminated.
|
||||||
// this is done only for JSON documents made of a sole number
|
// this is done only for JSON documents made of a sole number
|
||||||
// this will almost never be called in practice
|
// this will almost never be called in practice
|
||||||
char * copy = (char *) malloc(len + SIMDJSON_PADDING);
|
char * copy = static_cast<char *>(malloc(len + SIMDJSON_PADDING));
|
||||||
if(copy == nullptr) { goto fail;
|
if(copy == nullptr) { goto fail;
|
||||||
}
|
}
|
||||||
memcpy(copy, buf, len);
|
memcpy(copy, buf, len);
|
||||||
copy[len] = '\0';
|
copy[len] = '\0';
|
||||||
if (!parse_number((const uint8_t *)copy, pj, idx, false)) {
|
if (!parse_number(reinterpret_cast<const uint8_t *>(copy), pj, idx, false)) {
|
||||||
free(copy);
|
free(copy);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -217,12 +217,12 @@ bool unified_machine(const uint8_t *buf, size_t len, ParsedJson &pj) {
|
||||||
// we need to make a copy to make sure that the string is NULL terminated.
|
// we need to make a copy to make sure that the string is NULL terminated.
|
||||||
// this is done only for JSON documents made of a sole number
|
// this is done only for JSON documents made of a sole number
|
||||||
// this will almost never be called in practice
|
// this will almost never be called in practice
|
||||||
char * copy = (char *) malloc(len + SIMDJSON_PADDING);
|
char * copy = static_cast<char *>(malloc(len + SIMDJSON_PADDING));
|
||||||
if(copy == nullptr) { goto fail;
|
if(copy == nullptr) { goto fail;
|
||||||
}
|
}
|
||||||
memcpy(copy, buf, len);
|
memcpy(copy, buf, len);
|
||||||
copy[len] = '\0';
|
copy[len] = '\0';
|
||||||
if (!parse_number((const uint8_t *)copy, pj, idx, true)) {
|
if (!parse_number(reinterpret_cast<const uint8_t *>(copy), pj, idx, true)) {
|
||||||
free(copy);
|
free(copy);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ bool validate(const char *dirname) {
|
||||||
printf("validating: file %s ", name);
|
printf("validating: file %s ", name);
|
||||||
fflush(nullptr);
|
fflush(nullptr);
|
||||||
size_t filelen = strlen(name);
|
size_t filelen = strlen(name);
|
||||||
char *fullpath = (char *)malloc(dirlen + filelen + 1 + 1);
|
char *fullpath = static_cast<char *>(malloc(dirlen + filelen + 1 + 1));
|
||||||
strcpy(fullpath, dirname);
|
strcpy(fullpath, dirname);
|
||||||
if (needsep) {
|
if (needsep) {
|
||||||
fullpath[dirlen] = '/';
|
fullpath[dirlen] = '/';
|
||||||
|
|
|
@ -50,8 +50,8 @@ stat_t simdjson_computestats(const std::string_view &p) {
|
||||||
if (!answer.valid) {
|
if (!answer.valid) {
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
answer.backslash_count = count_backslash((const uint8_t*)p.data(), p.size());
|
answer.backslash_count = count_backslash(reinterpret_cast<const uint8_t*>(p.data()), p.size());
|
||||||
answer.nonasciibyte_count = count_nonasciibytes((const uint8_t*)p.data(), p.size());
|
answer.nonasciibyte_count = count_nonasciibytes(reinterpret_cast<const uint8_t*>(p.data()), p.size());
|
||||||
answer.byte_count = p.size();
|
answer.byte_count = p.size();
|
||||||
answer.integer_count = 0;
|
answer.integer_count = 0;
|
||||||
answer.float_count = 0;
|
answer.float_count = 0;
|
||||||
|
|
|
@ -16,7 +16,7 @@ int main(int argc, char *argv[]) {
|
||||||
std::cout << "Could not load the file " << filename << std::endl;
|
std::cout << "Could not load the file " << filename << std::endl;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
jsonminify(p, (char *)p.data());
|
jsonminify(p, const_cast<char *>(p.data()));
|
||||||
printf("%s",p.data());
|
printf("%s",p.data());
|
||||||
aligned_free((void*)p.data());
|
aligned_free((void*)p.data());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue