bitwise: add pure annotation to rotate functions

This commit is contained in:
Danny Robson 2016-06-20 17:59:21 +10:00
parent fa8933673f
commit b49d95eaf3

View File

@ -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