@@ -22,46 +22,35 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2222// Writing two full functions for rotl and rotr makes it easier for the compiler
2323// to optimize the code. On x86 this function becomes the ROL instruction and
2424// 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 {
2830 const int __n = numeric_limits<_Tp>::digits;
29- int __r = __s % __n;
31+ int __r = __cnt % __n;
3032
3133 if (__r == 0 )
32- return __x ;
34+ return __t ;
3335
3436 if (__r > 0 )
35- return (__x << __r) | (__x >> (__n - __r));
37+ return (__t << __r) | (__t >> (__n - __r));
3638
37- return (__x >> -__r) | (__x << (__n + __r));
39+ return (__t >> -__r) | (__t << (__n + __r));
3840}
3941
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 {
4344 const int __n = numeric_limits<_Tp>::digits;
44- int __r = __s % __n;
45+ int __r = __cnt % __n;
4546
4647 if (__r == 0 )
47- return __x ;
48+ return __t ;
4849
4950 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));
5452
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));
6554}
6655
6756#endif // _LIBCPP_STD_VER >= 20
0 commit comments