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