[libc-commits] [libc] [libc] Make `stdc_first_trailing_one` spec compliant (PR #116493)

Nick Desaulniers via libc-commits libc-commits at lists.llvm.org
Mon Nov 18 10:36:59 PST 2024


================
@@ -146,8 +146,7 @@ first_trailing_zero(T value) {
 template <typename T>
 [[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int>
 first_trailing_one(T value) {
-  return value == cpp::numeric_limits<T>::max() ? 0
-                                                : cpp::countr_zero(value) + 1;
+  return value == T(0) ? 0 : cpp::countr_zero(value) + 1;
----------------
nickdesaulniers wrote:

So for big int, you call `first_trailing_zero` with `value` negated. Why not do that here as well?

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


More information about the libc-commits mailing list