[libc-commits] [libc] [libc][stdbit] implement stdc_first_leading_one (C23) (PR #81502)
via libc-commits
libc-commits at lists.llvm.org
Tue Feb 13 14:38:37 PST 2024
================
@@ -268,6 +268,11 @@ SPECIALIZE_FLZ(first_leading_zero, unsigned long long, __builtin_clzll)
#undef SPECIALIZE_FLZ
+template <typename T, typename = cpp::enable_if_t<cpp::is_unsigned_v<T>>>
+[[nodiscard]] LIBC_INLINE constexpr int first_leading_one(T value) {
+ return !value ? 0 : countl_zero<T>(static_cast<T>(value)) + 1;
----------------
michaelrj-google wrote:
would it be better to define `first_leading_one` as `first_leading_zero(~value)`?
https://github.com/llvm/llvm-project/pull/81502
More information about the libc-commits
mailing list