[libc-commits] [libc] [libc][support][bit] use new type generic builtins (PR #86746)

Nick Desaulniers via libc-commits libc-commits at lists.llvm.org
Fri Apr 5 10:02:00 PDT 2024


================
@@ -99,16 +107,25 @@ ADD_SPECIALIZATION(countr_zero, unsigned short, __builtin_ctzs)
 ADD_SPECIALIZATION(countr_zero, unsigned int, __builtin_ctz)
 ADD_SPECIALIZATION(countr_zero, unsigned long, __builtin_ctzl)
 ADD_SPECIALIZATION(countr_zero, unsigned long long, __builtin_ctzll)
+#endif // __has_builtin(__builtin_ctzg)
 
 /// Count number of 0's from the most significant bit to the least
 ///   stopping at the first 1.
 ///
 /// Only unsigned integral types are allowed.
 ///
 /// Returns cpp::numeric_limits<T>::digits on an input of 0.
+// clang-19+, gcc-14+
+#if __has_builtin(__builtin_clzg)
 template <typename T>
 [[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int>
 countl_zero(T value) {
+  return __builtin_clzg(value, cpp::numeric_limits<T>::digits);
+}
+#else
+template <typename T [[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<
----------------
nickdesaulniers wrote:

I guess the wacky formatting should have given this away (lines 127-128 below look awful to me).

https://github.com/llvm/llvm-project/pull/86746


More information about the libc-commits mailing list