// This file is part of the mcl project. // Copyright (c) 2022 merryhime // SPDX-License-Identifier: MIT #pragma once #include "mcl/bitsizeof.hpp" #include "mcl/concepts/bit_integral.hpp" #include "mcl/stdint.hpp" namespace mcl::bit { template constexpr T rotate_right(T x, size_t amount) { amount %= bitsizeof; if (amount == 0) { return x; } return static_cast((x >> amount) | (x << (bitsizeof - amount))); } template constexpr T rotate_left(T x, size_t amount) { amount %= bitsizeof; if (amount == 0) { return x; } return static_cast((x << amount) | (x >> (bitsizeof - amount))); } } // namespace mcl::bit