Skip to content

Commit 0078bed

Browse files
committed
Ignore HAVE_CLZ macro when building with MSVC
`__builtin_clz*` intrinsics are not available for MSVC.
1 parent 1c77291 commit 0078bed

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/int_utils.h

+11-11
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,7 @@ constexpr inline I Mask() { return ((I((I(-1)) << (std::numeric_limits<I>::digit
129129
/** Compute the smallest power of two that is larger than val. */
130130
template<typename I>
131131
static inline int CountBits(I val, int max) {
132-
#ifdef HAVE_CLZ
133-
(void)max;
134-
if (val == 0) return 0;
135-
if (std::numeric_limits<unsigned>::digits >= std::numeric_limits<I>::digits) {
136-
return std::numeric_limits<unsigned>::digits - __builtin_clz(val);
137-
} else if (std::numeric_limits<unsigned long>::digits >= std::numeric_limits<I>::digits) {
138-
return std::numeric_limits<unsigned long>::digits - __builtin_clzl(val);
139-
} else {
140-
return std::numeric_limits<unsigned long long>::digits - __builtin_clzll(val);
141-
}
142-
#elif _MSC_VER
132+
#ifdef _MSC_VER
143133
(void)max;
144134
unsigned long index;
145135
unsigned char ret;
@@ -150,6 +140,16 @@ static inline int CountBits(I val, int max) {
150140
}
151141
if (!ret) return 0;
152142
return index + 1;
143+
#elif HAVE_CLZ
144+
(void)max;
145+
if (val == 0) return 0;
146+
if (std::numeric_limits<unsigned>::digits >= std::numeric_limits<I>::digits) {
147+
return std::numeric_limits<unsigned>::digits - __builtin_clz(val);
148+
} else if (std::numeric_limits<unsigned long>::digits >= std::numeric_limits<I>::digits) {
149+
return std::numeric_limits<unsigned long>::digits - __builtin_clzl(val);
150+
} else {
151+
return std::numeric_limits<unsigned long long>::digits - __builtin_clzll(val);
152+
}
153153
#else
154154
while (max && (val >> (max - 1) == 0)) --max;
155155
return max;

0 commit comments

Comments
 (0)