From ac9d61d45fec988640b57dc6b9de97e7d46c41f5 Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Wed, 9 Mar 2016 17:02:00 -0800 Subject: Move rol/ror to src/support/bits.h --- src/support/bits.h | 15 +++++++++++++++ src/wasm.h | 21 ++++----------------- 2 files changed, 19 insertions(+), 17 deletions(-) (limited to 'src') 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 #include #include @@ -65,6 +66,20 @@ int CountLeadingZeroes(T v) { return CountLeadingZeroes(typename std::make_unsigned::type(v)); } +template +inline static T RotateLeft(T val, T count) { + T mask = sizeof(T) * CHAR_BIT - 1; + count &= mask; + return (val << count) | (val >> (-count & mask)); +} +template +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 #include -#include #include #include #include @@ -504,29 +503,17 @@ public: default: WASM_UNREACHABLE(); } } - template - 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 - 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(); } } -- cgit v1.2.3