1 #ifndef SIMDJSON_FALLBACK_BITMANIPULATION_H
2 #define SIMDJSON_FALLBACK_BITMANIPULATION_H
4 #include "simdjson/base.h"
8 namespace SIMDJSON_IMPLEMENTATION {
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;
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;
29 simdjson_inline
int leading_zeroes(uint64_t input_num) {
31 unsigned long leading_zero = 0;
34 if (_BitScanReverse64(&leading_zero, input_num))
35 return (
int)(63 - leading_zero);
39 return __builtin_clzll(input_num);
We want to support argument-dependent lookup (ADL).