summaryrefslogtreecommitdiff
path: root/src/ast/bits.h
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2017-08-01 08:06:04 -0700
committerGitHub <noreply@github.com>2017-08-01 08:06:04 -0700
commit5a07a930ad51003411b2bc827ea9bf08728ecc5a (patch)
tree7a599caa2977464e4b056c59457d17c4d7e1bd91 /src/ast/bits.h
parent76751bf1f9df4eb2ee6c216744af9ed1e097132e (diff)
parent44154e3d0895e2f5688861f0bc8d62af71ee6b6d (diff)
downloadbinaryen-5a07a930ad51003411b2bc827ea9bf08728ecc5a.tar.gz
binaryen-5a07a930ad51003411b2bc827ea9bf08728ecc5a.tar.bz2
binaryen-5a07a930ad51003411b2bc827ea9bf08728ecc5a.zip
Merge pull request #1116 from WebAssembly/fuzz
Fuzz fixes
Diffstat (limited to 'src/ast/bits.h')
-rw-r--r--src/ast/bits.h20
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