diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-03-05 19:06:32 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-03-05 19:06:32 -0800 |
commit | c1823df9feea7ea90e3886cb18fedee56df48156 (patch) | |
tree | f1301cdab0c35aec1b8daac51b89d305366e579b | |
parent | 49b8031ecf4695850d060ef11926caddf4bd3352 (diff) | |
download | binaryen-c1823df9feea7ea90e3886cb18fedee56df48156.tar.gz binaryen-c1823df9feea7ea90e3886cb18fedee56df48156.tar.bz2 binaryen-c1823df9feea7ea90e3886cb18fedee56df48156.zip |
cast f32 to f64 before calling f64-to-int in asm2wasm
-rw-r--r-- | src/asm2wasm.h | 10 | ||||
-rw-r--r-- | test/unit.asm.js | 3 | ||||
-rw-r--r-- | test/unit.fromasm | 8 |
3 files changed, 19 insertions, 2 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h index 1aca26e88..06960a114 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -1018,7 +1018,15 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) { // WebAssembly traps on float-to-int overflows, but asm.js wouldn't, so we must emulate that CallImport *ret = allocator.alloc<CallImport>(); ret->target = F64_TO_INT; - ret->operands.push_back(process(ast[2][2])); + auto input = process(ast[2][2]); + if (input->type == f32) { + auto conv = allocator.alloc<Unary>(); + conv->op = PromoteFloat32; + conv->value = input; + conv->type = WasmType::f64; + input = conv; + } + ret->operands.push_back(input); ret->type = i32; static bool addedImport = false; if (!addedImport) { diff --git a/test/unit.asm.js b/test/unit.asm.js index b9c878613..e5673146d 100644 --- a/test/unit.asm.js +++ b/test/unit.asm.js @@ -41,8 +41,9 @@ function asm() { return !x; } function conversions() { - var i = 0, d = 0.0; + var i = 0, d = 0.0, f = Math_fround(0); i = ~~d; + i = ~~f; d = +(i | 0); d = +(i >>> 0); } diff --git a/test/unit.fromasm b/test/unit.fromasm index 67cf23f11..be62737b9 100644 --- a/test/unit.fromasm +++ b/test/unit.fromasm @@ -135,11 +135,19 @@ (func $conversions (local $i i32) (local $d f64) + (local $f f32) (set_local $i (call_import $f64-to-int (get_local $d) ) ) + (set_local $i + (call_import $f64-to-int + (f64.promote/f32 + (get_local $f) + ) + ) + ) (set_local $d (f64.convert_s/i32 (get_local $i) |