[libcxx-commits] [libcxx] [libc++][bit] Improves rotate functions. (PR #98032)
via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jul 9 03:09:26 PDT 2024
================
@@ -20,24 +20,37 @@
_LIBCPP_BEGIN_NAMESPACE_STD
+// Writing two full functions for rotl and rotr makes it easier for the compiler
+// to optimize the code. On x86 this function becomes the ROL instruction and
+// the rotr function becomes the ROR instruction.
template <class _Tp>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp __rotr(_Tp __t, int __cnt) _NOEXCEPT {
- static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__rotr requires an unsigned integer type");
- const unsigned int __dig = numeric_limits<_Tp>::digits;
----------------
mk-huawei wrote:
Given that `numeric_limits<_Tp>::digits` (cf. https://en.cppreference.com/w/cpp/types/numeric_limits/digits) already returns an `int` (signed). Wouldn't it be simpler to just do the following (no other changes required if I'm not mistaken)?
```
const int __dig = numeric_limits<_Tp>::digits;
```
https://github.com/llvm/llvm-project/pull/98032
More information about the libcxx-commits
mailing list