Skip to content

Commit 61c90b8

Browse files
committed
Do cleanup and remove non-feasible usages
1 parent e2fa6fe commit 61c90b8

File tree

6 files changed

+17
-44
lines changed

6 files changed

+17
-44
lines changed

libcxx/include/__bit/countl.h

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
// ToDo: __builtin_clzg 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_clzg.
11+
912
#ifndef _LIBCPP___BIT_COUNTL_H
1013
#define _LIBCPP___BIT_COUNTL_H
1114

@@ -25,31 +28,22 @@ _LIBCPP_PUSH_MACROS
2528
_LIBCPP_BEGIN_NAMESPACE_STD
2629

2730
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(unsigned __x) _NOEXCEPT {
28-
#if __has_builtin(__builtin_clzg)
29-
return __builtin_clzg(__x);
30-
#else
3131
return __builtin_clz(__x);
32-
#endif
3332
}
3433

3534
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(unsigned long __x) _NOEXCEPT {
36-
#if __has_builtin(__builtin_clzg)
37-
return __builtin_clzg(__x);
38-
#else
3935
return __builtin_clzl(__x);
40-
#endif
4136
}
4237

4338
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(unsigned long long __x) _NOEXCEPT {
44-
#if __has_builtin(__builtin_clzg)
45-
return __builtin_clzg(__x);
46-
#else
4739
return __builtin_clzll(__x);
48-
#endif
4940
}
5041

5142
#ifndef _LIBCPP_HAS_NO_INT128
5243
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(__uint128_t __x) _NOEXCEPT {
44+
# if __has_builtin(__builtin_clzg)
45+
return __builtin_clzg(__x);
46+
# else
5347
// The function is written in this form due to C++ constexpr limitations.
5448
// The algorithm:
5549
// - Test whether any bit in the high 64-bits is set
@@ -59,9 +53,6 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(__uint128_t __x)
5953
// - Any bits set:
6054
// - The number of leading zeros of the input is the number of leading
6155
// zeros in the high 64-bits.
62-
# if __has_builtin(__builtin_clzg)
63-
return __builtin_clzg(__x);
64-
# else
6556
return ((__x >> 64) == 0) ? (64 + __builtin_clzll(static_cast<unsigned long long>(__x)))
6657
: __builtin_clzll(static_cast<unsigned long long>(__x >> 64));
6758
# endif
@@ -76,7 +67,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int __countl_zero(_Tp __t) _
7667
if (__t == 0)
7768
return numeric_limits<_Tp>::digits;
7869

79-
return __builtin_clzg(__t) - (numeric_limits<unsigned>::digits - numeric_limits<_Tp>::digits);
70+
return __builtin_clzg(__t);
8071
}
8172

8273
#else // __has_builtin(__builtin_clzg)

libcxx/include/__bit/countr.h

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
// ToDo: __builtin_ctzg 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_ctzg.
11+
912
#ifndef _LIBCPP___BIT_COUNTR_H
1013
#define _LIBCPP___BIT_COUNTR_H
1114

@@ -24,27 +27,15 @@ _LIBCPP_PUSH_MACROS
2427
_LIBCPP_BEGIN_NAMESPACE_STD
2528

2629
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_ctz(unsigned __x) _NOEXCEPT {
27-
#if __has_builtin(__builtin_ctzg)
28-
return __builtin_ctzg(__x);
29-
#else
3030
return __builtin_ctz(__x);
31-
#endif
3231
}
3332

3433
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_ctz(unsigned long __x) _NOEXCEPT {
35-
#if __has_builtin(__builtin_ctzg)
36-
return __builtin_ctzg(__x);
37-
#else
3834
return __builtin_ctzl(__x);
39-
#endif
4035
}
4136

4237
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_ctz(unsigned long long __x) _NOEXCEPT {
43-
#if __has_builtin(__builtin_ctzg)
44-
return __builtin_ctzg(__x);
45-
#else
4638
return __builtin_ctzll(__x);
47-
#endif
4839
}
4940

5041
#if __has_builtin(__builtin_ctzg)

libcxx/include/__bit/popcount.h

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
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+
912
#ifndef _LIBCPP___BIT_POPCOUNT_H
1013
#define _LIBCPP___BIT_POPCOUNT_H
1114

@@ -24,27 +27,15 @@ _LIBCPP_PUSH_MACROS
2427
_LIBCPP_BEGIN_NAMESPACE_STD
2528

2629
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_popcount(unsigned __x) _NOEXCEPT {
27-
#if __has_builtin(__builtin_popcountg)
28-
return __builtin_popcountg(__x);
29-
#else
3030
return __builtin_popcount(__x);
31-
#endif
3231
}
3332

3433
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_popcount(unsigned long __x) _NOEXCEPT {
35-
#if __has_builtin(__builtin_popcountg)
36-
return __builtin_popcountg(__x);
37-
#else
3834
return __builtin_popcountl(__x);
39-
#endif
4035
}
4136

4237
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_popcount(unsigned long long __x) _NOEXCEPT {
43-
#if __has_builtin(__builtin_popcountg)
44-
return __builtin_popcountg(__x);
45-
#else
4638
return __builtin_popcountll(__x);
47-
#endif
4839
}
4940

5041
#if _LIBCPP_STD_VER >= 20

libcxx/src/include/ryu/d2s_intrinsics.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
249249
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline bool __multipleOfPowerOf2(const uint64_t __value, const uint32_t __p) {
250250
_LIBCPP_ASSERT_INTERNAL(__value != 0, "");
251251
_LIBCPP_ASSERT_INTERNAL(__p < 64, "");
252-
// __builtin_ctzll/__builtin_ctzg doesn't appear to be faster here.
252+
// __builtin_ctzll doesn't appear to be faster here.
253253
return (__value & ((1ull << __p) - 1)) == 0;
254254
}
255255

libcxx/src/include/ryu/ryu.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ _LIBCPP_HIDE_FROM_ABI inline unsigned char _BitScanForward64(unsigned long* __in
7373
if (__mask == 0) {
7474
return false;
7575
}
76-
*__index = __libcpp_ctz(__mask);
76+
*__index = __builtin_ctzll(__mask);
7777
return true;
7878
}
7979

8080
_LIBCPP_HIDE_FROM_ABI inline unsigned char _BitScanForward(unsigned long* __index, unsigned int __mask) {
8181
if (__mask == 0) {
8282
return false;
8383
}
84-
*__index = __libcpp_ctz(__mask);
84+
*__index = __builtin_ctz(__mask);
8585
return true;
8686
}
8787
#endif // !_MSC_VER

libcxx/src/ryu/f2s.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ inline constexpr uint64_t __FLOAT_POW5_SPLIT[47] = {
107107
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline bool __multipleOfPowerOf2(const uint32_t __value, const uint32_t __p) {
108108
_LIBCPP_ASSERT_INTERNAL(__value != 0, "");
109109
_LIBCPP_ASSERT_INTERNAL(__p < 32, "");
110-
// __builtin_ctz/__builtin_ctzg doesn't appear to be faster here.
110+
// __builtin_ctz doesn't appear to be faster here.
111111
return (__value & ((1u << __p) - 1)) == 0;
112112
}
113113

0 commit comments

Comments
 (0)