simdjson  3.11.0
Ridiculously Fast JSON
numberparsing_defs.h
1 #ifndef SIMDJSON_ARM64_NUMBERPARSING_DEFS_H
2 #define SIMDJSON_ARM64_NUMBERPARSING_DEFS_H
3 
4 #ifndef SIMDJSON_CONDITIONAL_INCLUDE
5 #include "simdjson/arm64/base.h"
6 #include "simdjson/arm64/intrinsics.h"
7 #include "simdjson/internal/numberparsing_tables.h"
8 #endif // SIMDJSON_CONDITIONAL_INCLUDE
9 
10 #include <cstring>
11 
12 #if SIMDJSON_REGULAR_VISUAL_STUDIO && SIMDJSON_IS_ARM64
13 // __umulh requires intrin.h
14 #include <intrin.h>
15 #endif // SIMDJSON_REGULAR_VISUAL_STUDIO && SIMDJSON_IS_ARM64
16 
17 namespace simdjson {
18 namespace arm64 {
19 namespace numberparsing {
20 
21 // we don't have SSE, so let us use a scalar function
22 // credit: https://johnnylee-sde.github.io/Fast-numeric-string-to-int/
24 static simdjson_inline uint32_t parse_eight_digits_unrolled(const uint8_t *chars) {
25  uint64_t val;
26  std::memcpy(&val, chars, sizeof(uint64_t));
27  val = (val & 0x0F0F0F0F0F0F0F0F) * 2561 >> 8;
28  val = (val & 0x00FF00FF00FF00FF) * 6553601 >> 16;
29  return uint32_t((val & 0x0000FFFF0000FFFF) * 42949672960001 >> 32);
30 }
31 
32 simdjson_inline internal::value128 full_multiplication(uint64_t value1, uint64_t value2) {
33  internal::value128 answer;
34 #if SIMDJSON_REGULAR_VISUAL_STUDIO || SIMDJSON_IS_32BITS
35 #if SIMDJSON_IS_ARM64
36  // ARM64 has native support for 64-bit multiplications, no need to emultate
37  answer.high = __umulh(value1, value2);
38  answer.low = value1 * value2;
39 #else
40  answer.low = _umul128(value1, value2, &answer.high); // _umul128 not available on ARM64
41 #endif // SIMDJSON_IS_ARM64
42 #else // SIMDJSON_REGULAR_VISUAL_STUDIO || SIMDJSON_IS_32BITS
43  __uint128_t r = (static_cast<__uint128_t>(value1)) * value2;
44  answer.low = uint64_t(r);
45  answer.high = uint64_t(r >> 64);
46 #endif
47  return answer;
48 }
49 
50 } // namespace numberparsing
51 } // namespace arm64
52 } // namespace simdjson
53 
54 #ifndef SIMDJSON_SWAR_NUMBER_PARSING
55 #if SIMDJSON_IS_BIG_ENDIAN
56 #define SIMDJSON_SWAR_NUMBER_PARSING 0
57 #else
58 #define SIMDJSON_SWAR_NUMBER_PARSING 1
59 #endif
60 #endif
61 
62 #endif // SIMDJSON_ARM64_NUMBERPARSING_DEFS_H
The top level simdjson namespace, containing everything the library provides.
Definition: base.h:8