simdjson 4.2.1
Ridiculously Fast JSON
Loading...
Searching...
No Matches
numberparsing_defs.h
1#ifndef SIMDJSON_HASWELL_NUMBERPARSING_DEFS_H
2#define SIMDJSON_HASWELL_NUMBERPARSING_DEFS_H
3
4#ifndef SIMDJSON_CONDITIONAL_INCLUDE
5#include "simdjson/haswell/base.h"
6#include "simdjson/haswell/intrinsics.h"
7#endif // SIMDJSON_CONDITIONAL_INCLUDE
8
9#ifndef SIMDJSON_CONDITIONAL_INCLUDE
10#include "simdjson/internal/numberparsing_tables.h"
11#endif // SIMDJSON_CONDITIONAL_INCLUDE
12
13namespace simdjson {
14namespace haswell {
15namespace numberparsing {
16
18static simdjson_inline uint32_t parse_eight_digits_unrolled(const uint8_t *chars) {
19 // this actually computes *16* values so we are being wasteful.
20 const __m128i ascii0 = _mm_set1_epi8('0');
21 const __m128i mul_1_10 =
22 _mm_setr_epi8(10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1);
23 const __m128i mul_1_100 = _mm_setr_epi16(100, 1, 100, 1, 100, 1, 100, 1);
24 const __m128i mul_1_10000 =
25 _mm_setr_epi16(10000, 1, 10000, 1, 10000, 1, 10000, 1);
26 const __m128i input = _mm_sub_epi8(
27 _mm_loadu_si128(reinterpret_cast<const __m128i *>(chars)), ascii0);
28 const __m128i t1 = _mm_maddubs_epi16(input, mul_1_10);
29 const __m128i t2 = _mm_madd_epi16(t1, mul_1_100);
30 const __m128i t3 = _mm_packus_epi32(t2, t2);
31 const __m128i t4 = _mm_madd_epi16(t3, mul_1_10000);
32 return _mm_cvtsi128_si32(
33 t4); // only captures the sum of the first 8 digits, drop the rest
34}
35
37simdjson_inline internal::value128 full_multiplication(uint64_t value1, uint64_t value2) {
38 internal::value128 answer;
39#if SIMDJSON_REGULAR_VISUAL_STUDIO || SIMDJSON_IS_32BITS
40#if SIMDJSON_IS_ARM64
41 // ARM64 has native support for 64-bit multiplications, no need to emultate
42 answer.high = __umulh(value1, value2);
43 answer.low = value1 * value2;
44#else
45 answer.low = _umul128(value1, value2, &answer.high); // _umul128 not available on ARM64
46#endif // SIMDJSON_IS_ARM64
47#else // SIMDJSON_REGULAR_VISUAL_STUDIO || SIMDJSON_IS_32BITS
48 __uint128_t r = (static_cast<__uint128_t>(value1)) * value2;
49 answer.low = uint64_t(r);
50 answer.high = uint64_t(r >> 64);
51#endif
52 return answer;
53}
54
55} // namespace numberparsing
56} // namespace haswell
57} // namespace simdjson
58
59#define SIMDJSON_SWAR_NUMBER_PARSING 1
60
61#endif // SIMDJSON_HASWELL_NUMBERPARSING_DEFS_H
The top level simdjson namespace, containing everything the library provides.
Definition base.h:8