summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/asm2wasm.h10
-rw-r--r--test/unit.asm.js3
-rw-r--r--test/unit.fromasm8
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)