Skip to content

Commit eb75b91

Browse files
committed
Replace __libcpp_popcount by __popcount
1 parent 5a41fc2 commit eb75b91

File tree

2 files changed

+1
-44
lines changed

2 files changed

+1
-44
lines changed

Diff for: libcxx/include/__bit/popcount.h

-43
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// TODO: __builtin_popcountg is available since Clang 19 and GCC 14. When support for older versions is dropped, we can
10-
// refactor this code to exclusively use __builtin_popcountg.
11-
129
#ifndef _LIBCPP___BIT_POPCOUNT_H
1310
#define _LIBCPP___BIT_POPCOUNT_H
1411

@@ -27,50 +24,10 @@ _LIBCPP_PUSH_MACROS
2724

2825
_LIBCPP_BEGIN_NAMESPACE_STD
2926

30-
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_popcount(unsigned __x) _NOEXCEPT {
31-
return __builtin_popcount(__x);
32-
}
33-
34-
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_popcount(unsigned long __x) _NOEXCEPT {
35-
return __builtin_popcountl(__x);
36-
}
37-
38-
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_popcount(unsigned long long __x) _NOEXCEPT {
39-
return __builtin_popcountll(__x);
40-
}
41-
42-
template <class _Tp>
43-
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __popcount_impl(_Tp __t) _NOEXCEPT {
44-
if _LIBCPP_CONSTEXPR (sizeof(_Tp) <= sizeof(unsigned int)) {
45-
return std::__libcpp_popcount(static_cast<unsigned int>(__t));
46-
} else if _LIBCPP_CONSTEXPR (sizeof(_Tp) <= sizeof(unsigned long)) {
47-
return std::__libcpp_popcount(static_cast<unsigned long>(__t));
48-
} else if _LIBCPP_CONSTEXPR (sizeof(_Tp) <= sizeof(unsigned long long)) {
49-
return std::__libcpp_popcount(static_cast<unsigned long long>(__t));
50-
} else {
51-
#if _LIBCPP_STD_VER == 11
52-
return __t != 0 ? std::__libcpp_popcount(static_cast<unsigned long long>(__t)) +
53-
std::__popcount_impl<_Tp>(__t >> numeric_limits<unsigned long long>::digits)
54-
: 0;
55-
#else
56-
int __ret = 0;
57-
while (__t != 0) {
58-
__ret += std::__libcpp_popcount(static_cast<unsigned long long>(__t));
59-
__t >>= std::numeric_limits<unsigned long long>::digits;
60-
}
61-
return __ret;
62-
#endif
63-
}
64-
}
65-
6627
template <class _Tp>
6728
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __popcount(_Tp __t) _NOEXCEPT {
6829
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.
7030
return __builtin_popcountg(__t);
71-
#else
72-
return std::__popcount_impl(__t);
73-
#endif
7431
}
7532

7633
#if _LIBCPP_STD_VER >= 20

Diff for: libcxx/include/__stop_token/atomic_unique_lock.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2828
// and LockedBit is the value of State when the lock bit is set, e.g 1 << 2
2929
template <class _State, _State _LockedBit>
3030
class _LIBCPP_AVAILABILITY_SYNC __atomic_unique_lock {
31-
static_assert(std::__libcpp_popcount(static_cast<unsigned long long>(_LockedBit)) == 1,
31+
static_assert(std::__popcount(static_cast<unsigned long long>(_LockedBit)) == 1,
3232
"LockedBit must be an integer where only one bit is set");
3333

3434
std::atomic<_State>& __state_;

0 commit comments

Comments
 (0)