@@ -238,36 +238,11 @@ LIBC_INLINE constexpr To bit_or_static_cast(const From &from) {
238
238
}
239
239
}
240
240
241
- #define SPECIALIZE_FLZ (NAME, TYPE, BUILTIN ) \
242
- template <> [[nodiscard]] LIBC_INLINE constexpr int NAME<TYPE>(TYPE value) { \
243
- static_assert (cpp::is_unsigned_v<TYPE>); \
244
- return value == cpp::numeric_limits<TYPE>::max () \
245
- ? 0 \
246
- : BUILTIN (static_cast <TYPE>(~value)) + 1 ; \
247
- }
248
-
249
241
template <typename T, typename = cpp::enable_if_t <cpp::is_unsigned_v<T>>>
250
242
[[nodiscard]] LIBC_INLINE constexpr int first_leading_zero (T value) {
251
- return value == cpp::numeric_limits<T>::max ()
252
- ? 0
253
- : countl_zero (static_cast <T>(~value)) + 1 ;
243
+ return value == cpp::numeric_limits<T>::max () ? 0 : countl_one (value) + 1 ;
254
244
}
255
245
256
- #if LIBC_HAS_BUILTIN(__builtin_clzs)
257
- SPECIALIZE_FLZ (first_leading_zero, unsigned short , __builtin_clzs)
258
- #endif
259
- #if LIBC_HAS_BUILTIN(__builtin_clz)
260
- SPECIALIZE_FLZ (first_leading_zero, unsigned int , __builtin_clz)
261
- #endif
262
- #if LIBC_HAS_BUILTIN(__builtin_clzl)
263
- SPECIALIZE_FLZ (first_leading_zero, unsigned long , __builtin_clzl)
264
- #endif
265
- #if LIBC_HAS_BUILTIN(__builtin_clzll)
266
- SPECIALIZE_FLZ (first_leading_zero, unsigned long long , __builtin_clzll)
267
- #endif
268
-
269
- #undef SPECIALIZE_FLZ
270
-
271
246
} // namespace LIBC_NAMESPACE::cpp
272
247
273
248
#endif // LLVM_LIBC_SRC___SUPPORT_CPP_BIT_H
0 commit comments