@@ -22,46 +22,35 @@ _LIBCPP_BEGIN_NAMESPACE_STD
22
22
// Writing two full functions for rotl and rotr makes it easier for the compiler
23
23
// to optimize the code. On x86 this function becomes the ROL instruction and
24
24
// the rotr function becomes the ROR instruction.
25
- template <class _Tp >
26
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp __rotl (_Tp __x, int __s) _NOEXCEPT {
27
- static_assert (__is_unsigned_integer_v<_Tp>, " __rotl requires an unsigned integer type" );
25
+
26
+ #if _LIBCPP_STD_VER >= 20
27
+
28
+ template <__unsigned_integer _Tp>
29
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp rotl (_Tp __t , int __cnt) noexcept {
28
30
const int __n = numeric_limits<_Tp>::digits;
29
- int __r = __s % __n;
31
+ int __r = __cnt % __n;
30
32
31
33
if (__r == 0 )
32
- return __x ;
34
+ return __t ;
33
35
34
36
if (__r > 0 )
35
- return (__x << __r) | (__x >> (__n - __r));
37
+ return (__t << __r) | (__t >> (__n - __r));
36
38
37
- return (__x >> -__r) | (__x << (__n + __r));
39
+ return (__t >> -__r) | (__t << (__n + __r));
38
40
}
39
41
40
- template <class _Tp >
41
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp __rotr (_Tp __x, int __s) _NOEXCEPT {
42
- static_assert (__is_unsigned_integer_v<_Tp>, " __rotr requires an unsigned integer type" );
42
+ template <__unsigned_integer _Tp>
43
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp rotr (_Tp __t , int __cnt) noexcept {
43
44
const int __n = numeric_limits<_Tp>::digits;
44
- int __r = __s % __n;
45
+ int __r = __cnt % __n;
45
46
46
47
if (__r == 0 )
47
- return __x ;
48
+ return __t ;
48
49
49
50
if (__r > 0 )
50
- return (__x >> __r) | (__x << (__n - __r));
51
-
52
- return (__x << -__r) | (__x >> (__n + __r));
53
- }
51
+ return (__t >> __r) | (__t << (__n - __r));
54
52
55
- #if _LIBCPP_STD_VER >= 20
56
-
57
- template <__unsigned_integer _Tp>
58
- [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp rotl (_Tp __t , int __cnt) noexcept {
59
- return std::__rotl (__t , __cnt);
60
- }
61
-
62
- template <__unsigned_integer _Tp>
63
- [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp rotr (_Tp __t , int __cnt) noexcept {
64
- return std::__rotr (__t , __cnt);
53
+ return (__t << -__r) | (__t >> (__n + __r));
65
54
}
66
55
67
56
#endif // _LIBCPP_STD_VER >= 20
0 commit comments