simdjson  3.11.0
Ridiculously Fast JSON
bitmanipulation.h
1 #ifndef SIMDJSON_LASX_BITMANIPULATION_H
2 #define SIMDJSON_LASX_BITMANIPULATION_H
3 
4 #ifndef SIMDJSON_CONDITIONAL_INCLUDE
5 #include "simdjson/lasx/base.h"
6 #include "simdjson/lasx/intrinsics.h"
7 #include "simdjson/lasx/bitmask.h"
8 #endif // SIMDJSON_CONDITIONAL_INCLUDE
9 
10 namespace simdjson {
11 namespace lasx {
12 namespace {
13 
14 // We sometimes call trailing_zero on inputs that are zero,
15 // but the algorithms do not end up using the returned value.
16 // Sadly, sanitizers are not smart enough to figure it out.
17 SIMDJSON_NO_SANITIZE_UNDEFINED
18 // This function can be used safely even if not all bytes have been
19 // initialized.
20 // See issue https://github.com/simdjson/simdjson/issues/1965
21 SIMDJSON_NO_SANITIZE_MEMORY
22 simdjson_inline int trailing_zeroes(uint64_t input_num) {
23  return __builtin_ctzll(input_num);
24 }
25 
26 /* result might be undefined when input_num is zero */
27 simdjson_inline uint64_t clear_lowest_bit(uint64_t input_num) {
28  return input_num & (input_num-1);
29 }
30 
31 /* result might be undefined when input_num is zero */
32 simdjson_inline int leading_zeroes(uint64_t input_num) {
33  return __builtin_clzll(input_num);
34 }
35 
36 /* result might be undefined when input_num is zero */
37 simdjson_inline int count_ones(uint64_t input_num) {
38  return __lasx_xvpickve2gr_w(__lasx_xvpcnt_d(__m256i(v4u64{input_num, 0, 0, 0})), 0);
39 }
40 
41 simdjson_inline bool add_overflow(uint64_t value1, uint64_t value2, uint64_t *result) {
42  return __builtin_uaddll_overflow(value1, value2,
43  reinterpret_cast<unsigned long long *>(result));
44 }
45 
46 } // unnamed namespace
47 } // namespace lasx
48 } // namespace simdjson
49 
50 #endif // SIMDJSON_LASX_BITMANIPULATION_H
The top level simdjson namespace, containing everything the library provides.
Definition: base.h:8