File tree Expand file tree Collapse file tree 6 files changed +45
-4
lines changed Expand file tree Collapse file tree 6 files changed +45
-4
lines changed Original file line number Diff line number Diff line change @@ -25,15 +25,27 @@ _LIBCPP_PUSH_MACROS
25
25
_LIBCPP_BEGIN_NAMESPACE_STD
26
26
27
27
_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
28
31
return __builtin_clz (__x);
32
+ #endif
29
33
}
30
34
31
35
_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
32
39
return __builtin_clzl (__x);
40
+ #endif
33
41
}
34
42
35
43
_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
36
47
return __builtin_clzll (__x);
48
+ #endif
37
49
}
38
50
39
51
#ifndef _LIBCPP_HAS_NO_INT128
@@ -47,8 +59,12 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(__uint128_t __x)
47
59
// - Any bits set:
48
60
// - The number of leading zeros of the input is the number of leading
49
61
// zeros in the high 64-bits.
62
+ # if __has_builtin(__builtin_clzg)
63
+ return __builtin_clzg (__x);
64
+ # else
50
65
return ((__x >> 64 ) == 0 ) ? (64 + __builtin_clzll (static_cast <unsigned long long >(__x)))
51
66
: __builtin_clzll (static_cast <unsigned long long >(__x >> 64 ));
67
+ # endif
52
68
}
53
69
#endif // _LIBCPP_HAS_NO_INT128
54
70
Original file line number Diff line number Diff line change @@ -24,15 +24,27 @@ _LIBCPP_PUSH_MACROS
24
24
_LIBCPP_BEGIN_NAMESPACE_STD
25
25
26
26
_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
27
30
return __builtin_ctz (__x);
31
+ #endif
28
32
}
29
33
30
34
_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
31
38
return __builtin_ctzl (__x);
39
+ #endif
32
40
}
33
41
34
42
_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
35
46
return __builtin_ctzll (__x);
47
+ #endif
36
48
}
37
49
38
50
template <class _Tp >
Original file line number Diff line number Diff line change @@ -24,15 +24,27 @@ _LIBCPP_PUSH_MACROS
24
24
_LIBCPP_BEGIN_NAMESPACE_STD
25
25
26
26
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
27
30
return __builtin_popcount (__x);
31
+ #endif
28
32
}
29
33
30
34
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
31
38
return __builtin_popcountl (__x);
39
+ #endif
32
40
}
33
41
34
42
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
35
46
return __builtin_popcountll (__x);
47
+ #endif
36
48
}
37
49
38
50
#if _LIBCPP_STD_VER >= 20
Original file line number Diff line number Diff line change @@ -249,7 +249,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
249
249
[[nodiscard ]] _LIBCPP_HIDE_FROM_ABI inline bool __multipleOfPowerOf2 (const uint64_t __value , const uint32_t __p ) {
250
250
_LIBCPP_ASSERT_INTERNAL (__value != 0 , "" );
251
251
_LIBCPP_ASSERT_INTERNAL (__p < 64 , "" );
252
- // __builtin_ctzll doesn't appear to be faster here.
252
+ // __builtin_ctzll/__builtin_ctzg doesn't appear to be faster here.
253
253
return (__value & ((1ull << __p ) - 1 )) == 0 ;
254
254
}
255
255
Original file line number Diff line number Diff line change 43
43
// Avoid formatting to keep the changes with the original code minimal.
44
44
// clang-format off
45
45
46
+ #include < __bit/countr.h>
46
47
#include < __charconv/chars_format.h>
47
48
#include < __charconv/to_chars_result.h>
48
49
#include < __config>
@@ -72,15 +73,15 @@ _LIBCPP_HIDE_FROM_ABI inline unsigned char _BitScanForward64(unsigned long* __in
72
73
if (__mask == 0 ) {
73
74
return false ;
74
75
}
75
- *__index = __builtin_ctzll (__mask);
76
+ *__index = __libcpp_ctz (__mask);
76
77
return true ;
77
78
}
78
79
79
80
_LIBCPP_HIDE_FROM_ABI inline unsigned char _BitScanForward (unsigned long * __index, unsigned int __mask) {
80
81
if (__mask == 0 ) {
81
82
return false ;
82
83
}
83
- *__index = __builtin_ctz (__mask);
84
+ *__index = __libcpp_ctz (__mask);
84
85
return true ;
85
86
}
86
87
#endif // !_MSC_VER
Original file line number Diff line number Diff line change @@ -107,7 +107,7 @@ inline constexpr uint64_t __FLOAT_POW5_SPLIT[47] = {
107
107
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline bool __multipleOfPowerOf2 (const uint32_t __value, const uint32_t __p) {
108
108
_LIBCPP_ASSERT_INTERNAL (__value != 0 , " " );
109
109
_LIBCPP_ASSERT_INTERNAL (__p < 32 , " " );
110
- // __builtin_ctz doesn't appear to be faster here.
110
+ // __builtin_ctz/__builtin_ctzg doesn't appear to be faster here.
111
111
return (__value & ((1u << __p) - 1 )) == 0 ;
112
112
}
113
113
You can’t perform that action at this time.
0 commit comments