diff options
author | Alon Zakai <alonzakai@gmail.com> | 2017-10-20 11:11:30 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-20 11:11:30 -0700 |
commit | 74d026b9afb7b11bf01639e900a382b32bacfb33 (patch) | |
tree | 89fa8acb6b69250fc30e01c2c76a6c6f3d0e6e0f /src/ast/bits.h | |
parent | 939706d9c4d7584a2a1c2627986f977512490058 (diff) | |
download | binaryen-74d026b9afb7b11bf01639e900a382b32bacfb33.tar.gz binaryen-74d026b9afb7b11bf01639e900a382b32bacfb33.tar.bz2 binaryen-74d026b9afb7b11bf01639e900a382b32bacfb33.zip |
Atomics support in interpreter + optimizer + fuzz fixes for that (#1227)
Diffstat (limited to 'src/ast/bits.h')
-rw-r--r-- | src/ast/bits.h | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/ast/bits.h b/src/ast/bits.h index 0aee50ffe..7a86e70f4 100644 --- a/src/ast/bits.h +++ b/src/ast/bits.h @@ -18,6 +18,8 @@ #define wasm_ast_bits_h #include "support/bits.h" +#include "wasm-builder.h" +#include "ast/literal-utils.h" namespace wasm { @@ -60,6 +62,43 @@ struct Bits { } WASM_UNREACHABLE(); } + + static Expression* makeSignExt(Expression* value, Index bytes, Module& wasm) { + if (value->type == i32) { + if (bytes == 1 || bytes == 2) { + auto shifts = bytes == 1 ? 24 : 16; + Builder builder(wasm); + return builder.makeBinary( + ShrSInt32, + builder.makeBinary( + ShlInt32, + value, + LiteralUtils::makeFromInt32(shifts, i32, wasm) + ), + LiteralUtils::makeFromInt32(shifts, i32, wasm) + ); + } + assert(bytes == 4); + return value; // nothing to do + } else { + assert(value->type == i64); + if (bytes == 1 || bytes == 2 || bytes == 4) { + auto shifts = bytes == 1 ? 56 : (bytes == 2 ? 48 : 32); + Builder builder(wasm); + return builder.makeBinary( + ShrSInt64, + builder.makeBinary( + ShlInt64, + value, + LiteralUtils::makeFromInt32(shifts, i64, wasm) + ), + LiteralUtils::makeFromInt32(shifts, i64, wasm) + ); + } + assert(bytes == 8); + return value; // nothing to do + } + } }; } // namespace wasm |