[libcxx-commits] [PATCH] D157569: Fixed issue #64544 ([libc++] std::rotl and std::rotr have the wrong signature)

Danny via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Aug 9 21:20:19 PDT 2023


DKay7 added a comment.

In D157569#4575253 <https://reviews.llvm.org/D157569#4575253>, @philnik wrote:

> We might also want to fix __rotr, depending on where it is used. Generally, the underscore versions should have the same semantics as non-underscore versions.

I implemented the behavior for negative values in `__rotr` and thought that now `std::rotl` and `std::rotr` could be implemented as follows:

  template <__libcpp_unsigned_integer _Tp>
  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp rotl(_Tp __t, int __cnt) noexcept {
      return std::__rotr(__t, -__cnt);
  }
  
  template <__libcpp_unsigned_integer _Tp>
  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp rotr(_Tp __t, int __cnt) noexcept {
    return std::__rotr(__t, __cnt);
  }

This works for positive values, because `rotl` is the same as `rotr` with a negative value and vice versa. However, it doesn't seem very obvious and might be even confusing, so I wanted to find out if it's worth doing so. Thank you.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157569/new/

https://reviews.llvm.org/D157569



More information about the libcxx-commits mailing list