diff options
Diffstat (limited to 'src/support/bits.h')
-rw-r--r-- | src/support/bits.h | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/src/support/bits.h b/src/support/bits.h index f1dc4364f..f2241bea8 100644 --- a/src/support/bits.h +++ b/src/support/bits.h @@ -56,31 +56,23 @@ extern template int CountLeadingZeroes(uint64_t); // Convenience signed -> unsigned. It usually doesn't make much sense to use bit // functions on signed types. -template<typename T> -int PopCount(T v) { +template<typename T> int PopCount(T v) { return PopCount(typename std::make_unsigned<T>::type(v)); } -template<typename T> -int CountTrailingZeroes(T v) { +template<typename T> int CountTrailingZeroes(T v) { return CountTrailingZeroes(typename std::make_unsigned<T>::type(v)); } -template<typename T> -int CountLeadingZeroes(T v) { +template<typename T> int CountLeadingZeroes(T v) { return CountLeadingZeroes(typename std::make_unsigned<T>::type(v)); } -template<typename T> -bool IsPowerOf2(T v) { - return v != 0 && PopCount(v) == 1; -} +template<typename T> bool IsPowerOf2(T v) { return v != 0 && PopCount(v) == 1; } -template<typename T, typename U> -inline static T RotateLeft(T val, U count) { +template<typename T, typename U> inline static T RotateLeft(T val, U count) { T mask = sizeof(T) * CHAR_BIT - 1; count &= mask; return (val << count) | (val >> (-count & mask)); } -template<typename T, typename U> -inline static T RotateRight(T val, U count) { +template<typename T, typename U> inline static T RotateRight(T val, U count) { T mask = sizeof(T) * CHAR_BIT - 1; count &= mask; return (val >> count) | (val << (-count & mask)); @@ -89,6 +81,6 @@ inline static T RotateRight(T val, U count) { extern uint32_t Log2(uint32_t v); extern uint32_t Pow2(uint32_t v); -} // namespace wasm +} // namespace wasm -#endif // wasm_support_bits_h +#endif // wasm_support_bits_h |