mirror of
https://github.com/simdjson/simdjson
synced 2026-06-08 17:27:07 +00:00
b1444b4dfb
* Mostly tiny changes, with one optimization to fallback for number parsing. * Missed an update.
34 lines
1.1 KiB
C++
34 lines
1.1 KiB
C++
#ifndef SIMDJSON_FALLBACK_NUMBERPARSING_H
|
|
#define SIMDJSON_FALLBACK_NUMBERPARSING_H
|
|
|
|
#ifdef JSON_TEST_NUMBERS // for unit testing
|
|
void found_invalid_number(const uint8_t *buf);
|
|
void found_integer(int64_t result, const uint8_t *buf);
|
|
void found_unsigned_integer(uint64_t result, const uint8_t *buf);
|
|
void found_float(double result, const uint8_t *buf);
|
|
#endif
|
|
|
|
namespace simdjson {
|
|
namespace SIMDJSON_IMPLEMENTATION {
|
|
namespace {
|
|
// credit: https://johnnylee-sde.github.io/Fast-numeric-string-to-int/
|
|
static simdjson_really_inline uint32_t parse_eight_digits_unrolled(const char *chars) {
|
|
uint64_t val;
|
|
memcpy(&val, chars, sizeof(uint64_t));
|
|
val = (val & 0x0F0F0F0F0F0F0F0F) * 2561 >> 8;
|
|
val = (val & 0x00FF00FF00FF00FF) * 6553601 >> 16;
|
|
return uint32_t((val & 0x0000FFFF0000FFFF) * 42949672960001 >> 32);
|
|
}
|
|
static simdjson_really_inline uint32_t parse_eight_digits_unrolled(const uint8_t *chars) {
|
|
return parse_eight_digits_unrolled((const char *)chars);
|
|
}
|
|
|
|
} // unnamed namespace
|
|
} // namespace SIMDJSON_IMPLEMENTATION
|
|
} // namespace simdjson
|
|
|
|
#define SWAR_NUMBER_PARSING
|
|
#include "simdjson/generic/numberparsing.h"
|
|
|
|
#endif // SIMDJSON_FALLBACK_NUMBERPARSING_H
|