diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-11-05 20:09:52 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-11-05 20:09:52 -0800 |
commit | 194d152e26edca924dd272ee578c493d92154298 (patch) | |
tree | 621f43b1350cf73510576ee3eabbfd46f799c33b /src | |
parent | a7aef882a766e12847d021981b2f445c310aaf5e (diff) | |
download | binaryen-194d152e26edca924dd272ee578c493d92154298.tar.gz binaryen-194d152e26edca924dd272ee578c493d92154298.tar.bz2 binaryen-194d152e26edca924dd272ee578c493d92154298.zip |
clz and ctz corner cases
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm-interpreter.h | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 9cf3adf24..23ffb76d2 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -311,8 +311,14 @@ public: if (value.type == i32) { int32_t v = value.geti32(); switch (curr->op) { - case Clz: return Literal((int32_t)__builtin_clz(v)); - case Ctz: return Literal((int32_t)__builtin_ctz(v)); + case Clz: { + if (v == 0) return Literal(32); + return Literal((int32_t)__builtin_clz(v)); + } + case Ctz: { + if (v == 0) return Literal(32); + return Literal((int32_t)__builtin_ctz(v)); + } case Popcnt: return Literal((int32_t)__builtin_popcount(v)); default: abort(); } @@ -320,8 +326,14 @@ public: if (value.type == i64) { int64_t v = value.geti64(); switch (curr->op) { - case Clz: return Literal((int64_t)__builtin_clz(v)); - case Ctz: return Literal((int64_t)__builtin_ctz(v)); + case Clz: { + if (v == 0) return Literal(32); + return Literal((int64_t)__builtin_clz(v)); + } + case Ctz: { + if (v == 0) return Literal(32); + return Literal((int64_t)__builtin_ctz(v)); + } case Popcnt: return Literal((int64_t)__builtin_popcount(v)); default: abort(); } |