@@ -40,8 +40,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_popcount(unsigned lo
40
40
}
41
41
42
42
template <class _Tp >
43
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __popcount (_Tp __t ) _NOEXCEPT {
44
- static_assert (is_unsigned<_Tp>::value, " __popcount only works with unsigned types" );
43
+ [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __popcount_impl (_Tp __t ) _NOEXCEPT {
45
44
if _LIBCPP_CONSTEXPR (sizeof (_Tp) <= sizeof (unsigned int )) {
46
45
return std::__libcpp_popcount (static_cast <unsigned int >(__t ));
47
46
} else if _LIBCPP_CONSTEXPR (sizeof (_Tp) <= sizeof (unsigned long )) {
@@ -51,7 +50,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __popcount(_Tp __t) _NOEXCEPT {
51
50
} else {
52
51
#if _LIBCPP_STD_VER == 11
53
52
return __t != 0 ? std::__libcpp_popcount (static_cast <unsigned long long >(__t )) +
54
- std::__popcount <_Tp>(__t >> numeric_limits<unsigned long long >::digits)
53
+ std::__popcount_impl <_Tp>(__t >> numeric_limits<unsigned long long >::digits)
55
54
: 0 ;
56
55
#else
57
56
int __ret = 0 ;
@@ -64,15 +63,21 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __popcount(_Tp __t) _NOEXCEPT {
64
63
}
65
64
}
66
65
66
+ template <class _Tp >
67
+ [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __popcount (_Tp __t ) _NOEXCEPT {
68
+ static_assert (is_unsigned<_Tp>::value, " __popcount only works with unsigned types" );
69
+ #if __has_builtin(__builtin_popcountg) // TODO (LLVM 21): This can be dropped once we only support Clang >= 19.
70
+ return __builtin_popcountg (__t );
71
+ #else
72
+ return std::__popcount_impl (__t );
73
+ #endif
74
+ }
75
+
67
76
#if _LIBCPP_STD_VER >= 20
68
77
69
78
template <__libcpp_unsigned_integer _Tp>
70
79
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr int popcount (_Tp __t ) noexcept {
71
- # if __has_builtin(__builtin_popcountg) // TODO (LLVM 21): This can be dropped once we only support Clang >= 19.
72
- return __builtin_popcountg (__t );
73
- # else
74
80
return std::__popcount (__t );
75
- # endif
76
81
}
77
82
78
83
#endif
0 commit comments