Skip to content

Commit

Permalink
Do cleanup and remove non-feasible usages
Browse files Browse the repository at this point in the history
  • Loading branch information
marcauberer committed Mar 26, 2024
1 parent e2fa6fe commit 61c90b8
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 44 deletions.
23 changes: 7 additions & 16 deletions libcxx/include/__bit/countl.h
Expand Up @@ -6,6 +6,9 @@
//
//===----------------------------------------------------------------------===//

// ToDo: __builtin_clzg is available since Clang 19 and GCC 14. When support for older versions is dropped, we can
// refactor this code to exclusively use __builtin_clzg.

#ifndef _LIBCPP___BIT_COUNTL_H
#define _LIBCPP___BIT_COUNTL_H

Expand All @@ -25,31 +28,22 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD

_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(unsigned __x) _NOEXCEPT {
#if __has_builtin(__builtin_clzg)
return __builtin_clzg(__x);
#else
return __builtin_clz(__x);
#endif
}

_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(unsigned long __x) _NOEXCEPT {
#if __has_builtin(__builtin_clzg)
return __builtin_clzg(__x);
#else
return __builtin_clzl(__x);
#endif
}

_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(unsigned long long __x) _NOEXCEPT {
#if __has_builtin(__builtin_clzg)
return __builtin_clzg(__x);
#else
return __builtin_clzll(__x);
#endif
}

#ifndef _LIBCPP_HAS_NO_INT128
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(__uint128_t __x) _NOEXCEPT {
# if __has_builtin(__builtin_clzg)
return __builtin_clzg(__x);
# else
// The function is written in this form due to C++ constexpr limitations.
// The algorithm:
// - Test whether any bit in the high 64-bits is set
Expand All @@ -59,9 +53,6 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(__uint128_t __x)
// - Any bits set:
// - The number of leading zeros of the input is the number of leading
// zeros in the high 64-bits.
# if __has_builtin(__builtin_clzg)
return __builtin_clzg(__x);
# else
return ((__x >> 64) == 0) ? (64 + __builtin_clzll(static_cast<unsigned long long>(__x)))
: __builtin_clzll(static_cast<unsigned long long>(__x >> 64));
# endif
Expand All @@ -76,7 +67,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int __countl_zero(_Tp __t) _
if (__t == 0)
return numeric_limits<_Tp>::digits;

return __builtin_clzg(__t) - (numeric_limits<unsigned>::digits - numeric_limits<_Tp>::digits);
return __builtin_clzg(__t);
}

#else // __has_builtin(__builtin_clzg)
Expand Down
15 changes: 3 additions & 12 deletions libcxx/include/__bit/countr.h
Expand Up @@ -6,6 +6,9 @@
//
//===----------------------------------------------------------------------===//

// ToDo: __builtin_ctzg is available since Clang 19 and GCC 14. When support for older versions is dropped, we can
// refactor this code to exclusively use __builtin_ctzg.

#ifndef _LIBCPP___BIT_COUNTR_H
#define _LIBCPP___BIT_COUNTR_H

Expand All @@ -24,27 +27,15 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD

_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_ctz(unsigned __x) _NOEXCEPT {
#if __has_builtin(__builtin_ctzg)
return __builtin_ctzg(__x);
#else
return __builtin_ctz(__x);
#endif
}

_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_ctz(unsigned long __x) _NOEXCEPT {
#if __has_builtin(__builtin_ctzg)
return __builtin_ctzg(__x);
#else
return __builtin_ctzl(__x);
#endif
}

_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_ctz(unsigned long long __x) _NOEXCEPT {
#if __has_builtin(__builtin_ctzg)
return __builtin_ctzg(__x);
#else
return __builtin_ctzll(__x);
#endif
}

#if __has_builtin(__builtin_ctzg)
Expand Down
15 changes: 3 additions & 12 deletions libcxx/include/__bit/popcount.h
Expand Up @@ -6,6 +6,9 @@
//
//===----------------------------------------------------------------------===//

// ToDo: __builtin_popcountg is available since Clang 19 and GCC 14. When support for older versions is dropped, we can
// refactor this code to exclusively use __builtin_popcountg.

#ifndef _LIBCPP___BIT_POPCOUNT_H
#define _LIBCPP___BIT_POPCOUNT_H

Expand All @@ -24,27 +27,15 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD

inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_popcount(unsigned __x) _NOEXCEPT {
#if __has_builtin(__builtin_popcountg)
return __builtin_popcountg(__x);
#else
return __builtin_popcount(__x);
#endif
}

inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_popcount(unsigned long __x) _NOEXCEPT {
#if __has_builtin(__builtin_popcountg)
return __builtin_popcountg(__x);
#else
return __builtin_popcountl(__x);
#endif
}

inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_popcount(unsigned long long __x) _NOEXCEPT {
#if __has_builtin(__builtin_popcountg)
return __builtin_popcountg(__x);
#else
return __builtin_popcountll(__x);
#endif
}

#if _LIBCPP_STD_VER >= 20
Expand Down
2 changes: 1 addition & 1 deletion libcxx/src/include/ryu/d2s_intrinsics.h
Expand Up @@ -249,7 +249,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline bool __multipleOfPowerOf2(const uint64_t __value, const uint32_t __p) {
_LIBCPP_ASSERT_INTERNAL(__value != 0, "");
_LIBCPP_ASSERT_INTERNAL(__p < 64, "");
// __builtin_ctzll/__builtin_ctzg doesn't appear to be faster here.
// __builtin_ctzll doesn't appear to be faster here.
return (__value & ((1ull << __p) - 1)) == 0;
}

Expand Down
4 changes: 2 additions & 2 deletions libcxx/src/include/ryu/ryu.h
Expand Up @@ -73,15 +73,15 @@ _LIBCPP_HIDE_FROM_ABI inline unsigned char _BitScanForward64(unsigned long* __in
if (__mask == 0) {
return false;
}
*__index = __libcpp_ctz(__mask);
*__index = __builtin_ctzll(__mask);
return true;
}

_LIBCPP_HIDE_FROM_ABI inline unsigned char _BitScanForward(unsigned long* __index, unsigned int __mask) {
if (__mask == 0) {
return false;
}
*__index = __libcpp_ctz(__mask);
*__index = __builtin_ctz(__mask);
return true;
}
#endif // !_MSC_VER
Expand Down
2 changes: 1 addition & 1 deletion libcxx/src/ryu/f2s.cpp
Expand Up @@ -107,7 +107,7 @@ inline constexpr uint64_t __FLOAT_POW5_SPLIT[47] = {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline bool __multipleOfPowerOf2(const uint32_t __value, const uint32_t __p) {
_LIBCPP_ASSERT_INTERNAL(__value != 0, "");
_LIBCPP_ASSERT_INTERNAL(__p < 32, "");
// __builtin_ctz/__builtin_ctzg doesn't appear to be faster here.
// __builtin_ctz doesn't appear to be faster here.
return (__value & ((1u << __p) - 1)) == 0;
}

Expand Down

0 comments on commit 61c90b8

Please sign in to comment.