[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
Mon Mar 25 13:47:36 PDT 2024
================
@@ -47,8 +59,13 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(__uint128_t __x)
// - Any bits set:
// - The number of leading zeros of the input is the number of leading
// zeros in the high 64-bits.
+# if __has_builtin(__builtin_clzg)
+ return ((__x >> 64) == 0) ? (64 + __builtin_clzg(static_cast<unsigned long long>(__x)))
+ : __builtin_clzg(static_cast<unsigned long long>(__x >> 64));
----------------
nickdesaulniers wrote:
`__builtin_clzg` can handle `__uint128_t` I suspect. No need to do any of this.
https://github.com/llvm/llvm-project/pull/86563
More information about the libcxx-commits
mailing list