From db51c2efa3a9c2da064db199792b3bf0de4e850f Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 28 Jul 2017 15:45:27 -0700 Subject: refactor effective shift size computation --- src/ast/bits.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/ast/bits.h') diff --git a/src/ast/bits.h b/src/ast/bits.h index d88cb5edb..c7d2ea4f0 100644 --- a/src/ast/bits.h +++ b/src/ast/bits.h @@ -39,6 +39,17 @@ struct Bits { // this is indeed a mask return 32 - CountLeadingZeroes(mask); } + + // gets the number of effective shifts a shift operation does. In + // wasm, only 5 bits matter for 32-bit shifts, and 6 for 64. + static uint32_t getEffectiveShifts(Const* amount) { + if (amount->type == i32) { + return amount->value.geti32() & 31; + } else if (amount->type == i64) { + return amount->value.geti64() & 63; + } + WASM_UNREACHABLE(); + } }; } // namespace wasm -- cgit v1.2.3