15 #ifndef ABSL_BASE_INTERNAL_BITS_H_ 16 #define ABSL_BASE_INTERNAL_BITS_H_ 28 #pragma intrinsic(_BitScanReverse64) 29 #pragma intrinsic(_BitScanForward64) 31 #pragma intrinsic(_BitScanReverse) 32 #pragma intrinsic(_BitScanForward) 41 #define ABSL_BASE_INTERNAL_FORCEINLINE __forceinline 44 #define ABSL_BASE_INTERNAL_FORCEINLINE inline ABSL_ATTRIBUTE_ALWAYS_INLINE 49 namespace base_internal {
53 if (n >> 32) zeroes -= 32, n >>= 32;
54 if (n >> 16) zeroes -= 16, n >>= 16;
55 if (n >> 8) zeroes -= 8, n >>= 8;
56 if (n >> 4) zeroes -= 4, n >>= 4;
57 return "\4\3\2\2\1\1\1\1\0\0\0\0\0\0\0"[
n] + zeroes;
61 #if defined(_MSC_VER) && defined(_M_X64) 63 unsigned long result = 0;
64 if (_BitScanReverse64(&result, n)) {
68 #elif defined(_MSC_VER) 70 unsigned long result = 0;
71 if ((n >> 32) && _BitScanReverse(&result, n >> 32)) {
74 if (_BitScanReverse(&result, n)) {
78 #elif defined(__GNUC__) 83 static_assert(
sizeof(
unsigned long long) ==
sizeof(n),
84 "__builtin_clzll does not take 64-bit arg");
90 return __builtin_clzll(n);
98 if (n >> 16) zeroes -= 16, n >>= 16;
99 if (n >> 8) zeroes -= 8, n >>= 8;
100 if (n >> 4) zeroes -= 4, n >>= 4;
101 return "\4\3\2\2\1\1\1\1\0\0\0\0\0\0\0"[
n] + zeroes;
105 #if defined(_MSC_VER) 106 unsigned long result = 0;
107 if (_BitScanReverse(&result, n)) {
111 #elif defined(__GNUC__) 116 static_assert(
sizeof(
int) ==
sizeof(n),
117 "__builtin_clz does not take 32-bit arg");
123 return __builtin_clz(n);
132 if (n & 0x00000000FFFFFFFF) c -= 32;
133 if (n & 0x0000FFFF0000FFFF) c -= 16;
134 if (n & 0x00FF00FF00FF00FF) c -= 8;
135 if (n & 0x0F0F0F0F0F0F0F0F) c -= 4;
136 if (n & 0x3333333333333333) c -= 2;
137 if (n & 0x5555555555555555) c -= 1;
142 #if defined(_MSC_VER) && defined(_M_X64) 143 unsigned long result = 0;
144 _BitScanForward64(&result, n);
146 #elif defined(_MSC_VER) 147 unsigned long result = 0;
148 if (static_cast<uint32_t>(n) == 0) {
149 _BitScanForward(&result, n >> 32);
152 _BitScanForward(&result, n);
154 #elif defined(__GNUC__) 155 static_assert(
sizeof(
unsigned long long) ==
sizeof(n),
156 "__builtin_ctzll does not take 64-bit arg");
157 return __builtin_ctzll(n);
166 if (n & 0x0000FFFF) c -= 16;
167 if (n & 0x00FF00FF) c -= 8;
168 if (n & 0x0F0F0F0F) c -= 4;
169 if (n & 0x33333333) c -= 2;
170 if (n & 0x55555555) c -= 1;
175 #if defined(_MSC_VER) 176 unsigned long result = 0;
177 _BitScanForward(&result, n);
179 #elif defined(__GNUC__) 180 static_assert(
sizeof(
int) ==
sizeof(n),
181 "__builtin_ctz does not take 32-bit arg");
182 return __builtin_ctz(n);
188 #undef ABSL_BASE_INTERNAL_FORCEINLINE 193 #endif // ABSL_BASE_INTERNAL_BITS_H_
ABSL_BASE_INTERNAL_FORCEINLINE int CountLeadingZeros32(uint32_t n)
ABSL_BASE_INTERNAL_FORCEINLINE int CountLeadingZeros64Slow(uint64_t n)
ABSL_BASE_INTERNAL_FORCEINLINE int CountLeadingZeros64(uint64_t n)
ABSL_BASE_INTERNAL_FORCEINLINE int CountTrailingZerosNonZero32(uint32_t n)
#define ABSL_BASE_INTERNAL_FORCEINLINE
ABSL_BASE_INTERNAL_FORCEINLINE int CountLeadingZeros32Slow(uint64_t n)
ABSL_BASE_INTERNAL_FORCEINLINE int CountTrailingZerosNonZero64Slow(uint64_t n)
ABSL_BASE_INTERNAL_FORCEINLINE int CountTrailingZerosNonZero32Slow(uint32_t n)
ABSL_BASE_INTERNAL_FORCEINLINE int CountTrailingZerosNonZero64(uint64_t n)