rot.hpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #ifndef BOOST_HASH2_DETAIL_ROT_HPP_INCLUDED
  2. #define BOOST_HASH2_DETAIL_ROT_HPP_INCLUDED
  3. // Copyright 2017, 2018, 2024 Peter Dimov
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // https://www.boost.org/LICENSE_1_0.txt
  6. #include <boost/config.hpp>
  7. #include <cstdint>
  8. namespace boost
  9. {
  10. namespace hash2
  11. {
  12. namespace detail
  13. {
  14. // k must not be 0
  15. BOOST_FORCEINLINE constexpr std::uint32_t rotl( std::uint32_t v, int k ) noexcept
  16. {
  17. return ( v << k ) | ( v >> ( 32 - k ) );
  18. }
  19. // k must not be 0
  20. BOOST_FORCEINLINE constexpr std::uint64_t rotl( std::uint64_t v, int k ) noexcept
  21. {
  22. return ( v << k ) | ( v >> ( 64 - k ) );
  23. }
  24. // k must not be 0
  25. BOOST_FORCEINLINE constexpr std::uint32_t rotr( std::uint32_t v, int k ) noexcept
  26. {
  27. return ( v >> k ) | ( v << ( 32 - k ) );
  28. }
  29. // k must not be 0
  30. BOOST_FORCEINLINE constexpr std::uint64_t rotr( std::uint64_t v, int k ) noexcept
  31. {
  32. return ( v >> k ) | ( v << ( 64 - k ) );
  33. }
  34. } // namespace detail
  35. } // namespace hash2
  36. } // namespace boost
  37. #endif // #ifndef BOOST_HASH2_DETAIL_ROT_HPP_INCLUDED