summaryrefslogtreecommitdiff
path: root/src/support/bits.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/support/bits.h')
-rw-r--r--src/support/bits.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/support/bits.h b/src/support/bits.h
index bbafb29d4..6c9fbad94 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,20 @@ 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));
+}
+
+
} // namespace wasm
#endif // wasm_support_bits_h