diff options
Diffstat (limited to 'src/support/bits.h')
-rw-r--r-- | src/support/bits.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/support/bits.h b/src/support/bits.h index bbafb29d4..5d3502b81 100644 --- a/src/support/bits.h +++ b/src/support/bits.h @@ -17,6 +17,7 @@ #ifndef wasm_support_bits_h #define wasm_support_bits_h +#include <climits> #include <cstdint> #include <type_traits> @@ -65,6 +66,22 @@ int CountLeadingZeroes(T v) { return CountLeadingZeroes(typename std::make_unsigned<T>::type(v)); } +template <typename T> +inline static T RotateLeft(T val, T count) { + T mask = sizeof(T) * CHAR_BIT - 1; + count &= mask; + return (val << count) | (val >> (-count & mask)); +} +template <typename T> +inline static T RotateRight(T val, T count) { + T mask = sizeof(T) * CHAR_BIT - 1; + count &= mask; + return (val >> count) | (val << (-count & mask)); +} + +extern uint32_t Log2(uint32_t v); +extern uint32_t Pow2(uint32_t v); + } // namespace wasm #endif // wasm_support_bits_h |