[libcxx-commits] [libcxx] [libcxx] Use generic builtins for popcount, clz and ctz (PR #86563)

Nick Desaulniers via libcxx-commits libcxx-commits at lists.llvm.org
Fri Mar 29 10:53:59 PDT 2024


================
@@ -40,12 +40,11 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_ct
 
 template <class _Tp>
 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int __countr_zero(_Tp __t) _NOEXCEPT {
-  if (__t == 0)
-    return numeric_limits<_Tp>::digits;
-
-#if __has_builtin(__builtin_ctzg)
+#if __has_builtin(__builtin_ctzg, numeric_limits<_Tp>::digits)
   return __builtin_ctzg(__t);
----------------
nickdesaulniers wrote:

Sorry, I may have gotten that wrong in my suggestion, but the optional second argument goes to the invocation of the builtin, not `__has_builtin`.

You compiled this locally, right? :wink: 

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


More information about the libcxx-commits mailing list