[llvm] [ADT] Define countr_zero in terms of popcount (NFC) (PR #158519)

Jakub Kuderski via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 15 06:03:18 PDT 2025


================
@@ -150,30 +150,31 @@ template <typename T, typename = std::enable_if_t<std::is_unsigned_v<T>>>
 
 /// Count the number of set bits in a value.
 /// Ex. popcount(0xF000F000) = 8
-/// Returns 0 if the word is zero.
-template <typename T, typename = std::enable_if_t<std::is_unsigned_v<T>>>
+/// Returns 0 if Value is zero.
+template <typename T>
 [[nodiscard]] inline int popcount(T Value) noexcept {
+  static_assert(std::is_unsigned_v<T>, "T must be an unsigned integer type");
----------------
kuhar wrote:

My suggestion was that we allow unsigned types and call make_unsigned as a part of the implementation. Would there be any issues with that?

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


More information about the llvm-commits mailing list