summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/support/bits.h15
-rw-r--r--src/wasm.h21
2 files changed, 19 insertions, 17 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
diff --git a/src/wasm.h b/src/wasm.h
index 26b5e18e1..4bcb4bc87 100644
--- a/src/wasm.h
+++ b/src/wasm.h
@@ -45,7 +45,6 @@
#include <cassert>
#include <cmath>
-#include <climits>
#include <cstddef>
#include <cstdint>
#include <cstring>
@@ -504,29 +503,17 @@ public:
default: WASM_UNREACHABLE();
}
}
- template <typename T>
- static T rol(T val, T count) {
- T mask = sizeof(T) * CHAR_BIT - 1;
- count &= mask;
- return (val << count) | (val >> (-count & mask));
- }
Literal rotL(const Literal& other) const {
switch (type) {
- case WasmType::i32: return Literal(rol(uint32_t(i32), uint32_t(other.i32)));
- case WasmType::i64: return Literal(rol(uint64_t(i64), uint64_t(other.i64)));
+ case WasmType::i32: return Literal(RotateLeft(uint32_t(i32), uint32_t(other.i32)));
+ case WasmType::i64: return Literal(RotateLeft(uint64_t(i64), uint64_t(other.i64)));
default: WASM_UNREACHABLE();
}
}
- template <typename T>
- static T ror (T val, T count) {
- T mask = sizeof(T) * CHAR_BIT - 1;
- count &= mask;
- return (val >> count) | (val << (-count & mask));
- }
Literal rotR(const Literal& other) const {
switch (type) {
- case WasmType::i32: return Literal(ror(uint32_t(i32), uint32_t(other.i32)));
- case WasmType::i64: return Literal(ror(uint64_t(i64), uint64_t(other.i64)));
+ case WasmType::i32: return Literal(RotateRight(uint32_t(i32), uint32_t(other.i32)));
+ case WasmType::i64: return Literal(RotateRight(uint64_t(i64), uint64_t(other.i64)));
default: WASM_UNREACHABLE();
}
}