diff --git a/bitwise.hpp b/bitwise.hpp index d77a8287..6be6c2d7 100644 --- a/bitwise.hpp +++ b/bitwise.hpp @@ -30,6 +30,7 @@ const uint8_t BITMASK_6BITS = 0x3F; const uint8_t BITMASK_7BITS = 0x7F; const uint8_t BITMASK_8BITS = 0xFF; +/////////////////////////////////////////////////////////////////////////////// #define MODT(x) ((x) % (sizeof (T) * 8)) template @@ -49,6 +50,8 @@ rotater (const T &value, size_t magnitude) { #undef MODT + +/////////////////////////////////////////////////////////////////////////////// // TODO: make constexpr for C++14 template T @@ -66,5 +69,14 @@ reverse (T value) { return out; } + +/////////////////////////////////////////////////////////////////////////////// +template +constexpr T +popcount (std::enable_if_t::value,T> t) +{ + return __builtin_popcount (t); +} + #endif