diff options
Diffstat (limited to 'src/ast/bits.h')
-rw-r--r-- | src/ast/bits.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/ast/bits.h b/src/ast/bits.h index d88cb5edb..11cf7b06d 100644 --- a/src/ast/bits.h +++ b/src/ast/bits.h @@ -39,6 +39,26 @@ 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 Index getEffectiveShifts(Index amount, WasmType type) { + if (type == i32) { + return amount & 31; + } else if (type == i64) { + return amount & 63; + } + WASM_UNREACHABLE(); + } + + static Index getEffectiveShifts(Const* amount) { + if (amount->type == i32) { + return getEffectiveShifts(amount->value.geti32(), i32); + } else if (amount->type == i64) { + return getEffectiveShifts(amount->value.geti64(), i64); + } + WASM_UNREACHABLE(); + } }; } // namespace wasm |