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