bitwise: add pure annotation to rotate functions
This commit is contained in:
parent
fa8933673f
commit
b49d95eaf3
16
bitwise.hpp
16
bitwise.hpp
@ -31,25 +31,21 @@ const uint8_t BITMASK_7BITS = 0x7F;
|
||||
const uint8_t BITMASK_8BITS = 0xFF;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define MODT(x) ((x) % (sizeof (T) * 8))
|
||||
|
||||
template <typename T>
|
||||
constexpr T
|
||||
rotatel (const T &value, size_t magnitude) {
|
||||
return (value << MODT (magnitude)) |
|
||||
(value >> sizeof (value) * 8 - MODT (magnitude));
|
||||
rotatel [[gnu::pure]] (const T value, size_t magnitude)
|
||||
{
|
||||
return (value << magnitude) | (value >> sizeof (value) * 8 - magnitude);
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
constexpr T
|
||||
rotater (const T &value, size_t magnitude) {
|
||||
return (value >> MODT (magnitude)) |
|
||||
(value << sizeof (value) * 8 - MODT (magnitude));
|
||||
rotater [[gnu::pure]] (const T value, size_t magnitude)
|
||||
{
|
||||
return (value >> magnitude) | (value << sizeof (value) * 8 - magnitude);
|
||||
}
|
||||
|
||||
#undef MODT
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// TODO: make constexpr for C++14
|
||||
|
Loading…
Reference in New Issue
Block a user