Skip to content

Commit 154e022

Browse files
committed
backport-bit-log2
1 parent b2bb2e9 commit 154e022

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

libcxx/include/__algorithm/radix_sort.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include <__algorithm/for_each.h>
3131
#include <__algorithm/move.h>
32+
#include <__bit/bit_log2.h>
3233
#include <__bit/countl.h>
3334
#include <__config>
3435
#include <__functional/identity.h>
@@ -65,13 +66,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD
6566

6667
#if _LIBCPP_STD_VER >= 14
6768

68-
template <class _UnsignedInteger>
69-
_LIBCPP_HIDE_FROM_ABI constexpr _UnsignedInteger __intlog2(_UnsignedInteger __n) {
70-
static_assert(is_unsigned<_UnsignedInteger>::value, "Must be unsigned integral");
71-
72-
return numeric_limits<_UnsignedInteger>::digits - 1 - std::__countl_zero(__n);
73-
}
74-
7569
template <class _InputIterator, class _OutputIterator>
7670
_LIBCPP_HIDE_FROM_ABI pair<_OutputIterator, __iter_value_type<_InputIterator>>
7771
__partial_sum_max(_InputIterator __first, _InputIterator __last, _OutputIterator __result) {
@@ -101,7 +95,7 @@ struct __radix_sort_traits {
10195
static_assert(is_integral<__radix_type>::value, "");
10296

10397
constexpr static auto __radix_value_range = numeric_limits<__radix_type>::max() + 1;
104-
constexpr static auto __radix_size = std::__intlog2<uint64_t>(__radix_value_range);
98+
constexpr static auto __radix_size = std::__bit_log2<uint64_t>(__radix_value_range);
10599
constexpr static auto __radix_count = sizeof(__image_type) * CHAR_BIT / __radix_size;
106100
};
107101

@@ -111,7 +105,7 @@ struct __counting_sort_traits {
111105
static_assert(is_unsigned<__image_type>::value, "");
112106

113107
constexpr static const auto __value_range = numeric_limits<__image_type>::max() + 1;
114-
constexpr static auto __radix_size = std::__intlog2<uint64_t>(__value_range);
108+
constexpr static auto __radix_size = std::__bit_log2<uint64_t>(__value_range);
115109
};
116110

117111
template <class _Radix, class _Integer>

libcxx/include/__bit/bit_log2.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#define _LIBCPP___BIT_BIT_LOG2_H
1111

1212
#include <__bit/countl.h>
13-
#include <__concepts/arithmetic.h>
1413
#include <__config>
14+
#include <__type_traits/is_unsigned.h>
1515
#include <limits>
1616

1717
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -20,14 +20,15 @@
2020

2121
_LIBCPP_BEGIN_NAMESPACE_STD
2222

23-
#if _LIBCPP_STD_VER >= 20
23+
#if _LIBCPP_STD_VER >= 14
2424

25-
template <__libcpp_unsigned_integer _Tp>
25+
template <class _Tp>
2626
_LIBCPP_HIDE_FROM_ABI constexpr _Tp __bit_log2(_Tp __t) noexcept {
27+
static_assert(is_unsigned<_Tp>::value, "__bit_log2 requires an unsigned integer type");
2728
return numeric_limits<_Tp>::digits - 1 - std::countl_zero(__t);
2829
}
2930

30-
#endif // _LIBCPP_STD_VER >= 20
31+
#endif // _LIBCPP_STD_VER >= 14
3132

3233
_LIBCPP_END_NAMESPACE_STD
3334

0 commit comments

Comments
 (0)