[libc-commits] [libc] [libc][stdbit] implement	stdc_first_leading_zero (C23) (PR #81340)
    Nick Desaulniers via libc-commits 
    libc-commits at lists.llvm.org
       
    Fri Feb  9 16:04:06 PST 2024
    
    
  
================
@@ -238,6 +238,13 @@ LIBC_INLINE constexpr To bit_or_static_cast(const From &from) {
   }
 }
 
+template <typename T, typename = cpp::enable_if_t<cpp::is_unsigned_v<T>>>
+[[nodiscard]] LIBC_INLINE constexpr int first_leading_zero(T value) {
+  return value == cpp::numeric_limits<T>::max()
+             ? 0
+             : countl_zero(static_cast<T>(~value)) + 1;
----------------
nickdesaulniers wrote:
@gchatelet perhaps I should do something akin to `ADD_SPECIALIZATION`?
```c++
return value == cpp::numeric_limits<T>::max() ? 0 : BUILTIN(static_cast<T>(~value) + 1;
```
https://github.com/llvm/llvm-project/pull/81340
    
    
More information about the libc-commits
mailing list