simdjson  3.11.0
Ridiculously Fast JSON
bitmanipulation.h
1 #ifndef SIMDJSON_FALLBACK_BITMANIPULATION_H
2 #define SIMDJSON_FALLBACK_BITMANIPULATION_H
3 
4 #ifndef SIMDJSON_CONDITIONAL_INCLUDE
5 #include "simdjson/fallback/base.h"
6 #endif // SIMDJSON_CONDITIONAL_INCLUDE
7 
8 namespace simdjson {
9 namespace fallback {
10 namespace {
11 
12 #if defined(_MSC_VER) && !defined(_M_ARM64) && !defined(_M_X64)
13 static inline unsigned char _BitScanForward64(unsigned long* ret, uint64_t x) {
14  unsigned long x0 = (unsigned long)x, top, bottom;
15  _BitScanForward(&top, (unsigned long)(x >> 32));
16  _BitScanForward(&bottom, x0);
17  *ret = x0 ? bottom : 32 + top;
18  return x != 0;
19 }
20 static unsigned char _BitScanReverse64(unsigned long* ret, uint64_t x) {
21  unsigned long x1 = (unsigned long)(x >> 32), top, bottom;
22  _BitScanReverse(&top, x1);
23  _BitScanReverse(&bottom, (unsigned long)x);
24  *ret = x1 ? top + 32 : bottom;
25  return x != 0;
26 }
27 #endif
28 
29 /* result might be undefined when input_num is zero */
30 simdjson_inline int leading_zeroes(uint64_t input_num) {
31 #ifdef _MSC_VER
32  unsigned long leading_zero = 0;
33  // Search the mask data from most significant bit (MSB)
34  // to least significant bit (LSB) for a set bit (1).
35  if (_BitScanReverse64(&leading_zero, input_num))
36  return (int)(63 - leading_zero);
37  else
38  return 64;
39 #else
40  return __builtin_clzll(input_num);
41 #endif// _MSC_VER
42 }
43 
44 } // unnamed namespace
45 } // namespace fallback
46 } // namespace simdjson
47 
48 #endif // SIMDJSON_FALLBACK_BITMANIPULATION_H
The top level simdjson namespace, containing everything the library provides.
Definition: base.h:8