Mostly tiny changes, with one optimization to fallback for number parsing. (#1265)

* Mostly tiny changes, with one optimization to fallback for number parsing.

* Missed an update.
This commit is contained in:
Daniel Lemire 2020-10-29 11:18:11 -04:00 committed by GitHub
parent ed21875083
commit b1444b4dfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 11 deletions

View File

@ -9,7 +9,7 @@ namespace {
// credit: https://johnnylee-sde.github.io/Fast-numeric-string-to-int/
static simdjson_really_inline uint32_t parse_eight_digits_unrolled(const uint8_t *chars) {
uint64_t val;
memcpy(&val, chars, sizeof(uint64_t));
std::memcpy(&val, chars, sizeof(uint64_t));
val = (val & 0x0F0F0F0F0F0F0F0F) * 2561 >> 8;
val = (val & 0x00FF00FF00FF00FF) * 6553601 >> 16;
return uint32_t((val & 0x0000FFFF0000FFFF) * 42949672960001 >> 32);

View File

@ -11,12 +11,13 @@ void found_float(double result, const uint8_t *buf);
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) {
uint32_t result = 0;
for (int i=0;i<8;i++) {
result = result*10 + (chars[i] - '0');
}
return result;
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);

View File

@ -31,7 +31,7 @@ simdjson_really_inline double to_double(uint64_t mantissa, uint64_t real_exponen
mantissa &= ~(1ULL << 52);
mantissa |= real_exponent << 52;
mantissa |= (((uint64_t)negative) << 63);
memcpy(&d, &mantissa, sizeof(d));
std::memcpy(&d, &mantissa, sizeof(d));
return d;
}
}
@ -307,7 +307,7 @@ simdjson_really_inline bool is_made_of_eight_digits_fast(const uint8_t *chars) {
// this can read up to 7 bytes beyond the buffer size, but we require
// SIMDJSON_PADDING of padding
static_assert(7 <= SIMDJSON_PADDING, "SIMDJSON_PADDING must be bigger than 7");
memcpy(&val, chars, 8);
std::memcpy(&val, chars, 8);
// a branchy method might be faster:
// return (( val & 0xF0F0F0F0F0F0F0F0 ) == 0x3030303030303030)
// && (( (val + 0x0606060606060606) & 0xF0F0F0F0F0F0F0F0 ) ==

View File

@ -204,7 +204,7 @@ simdjson_warn_unused simdjson_really_inline bool json_iterator::copy_to_buffer(c
}
// Copy to the buffer.
memcpy(tmpbuf, json, len);
std::memcpy(tmpbuf, json, len);
tmpbuf[len] = ' ';
return true;
}

View File

@ -7,12 +7,12 @@ namespace simdjson {
namespace SIMDJSON_IMPLEMENTATION {
namespace {
// we don't have appropriate, so let us use a scalar function
// we don't have appropriate instructions, so let us use a scalar function
// credit: https://johnnylee-sde.github.io/Fast-numeric-string-to-int/
static simdjson_really_inline uint32_t
parse_eight_digits_unrolled(const uint8_t *chars) {
uint64_t val;
memcpy(&val, chars, sizeof(uint64_t));
std::memcpy(&val, chars, sizeof(uint64_t));
#ifdef __BIG_ENDIAN__
val = bswap_64(val);
#endif