summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-04-28 12:55:21 -0700
committerAlon Zakai <alonzakai@gmail.com>2016-04-28 12:55:21 -0700
commit5c11c30dad7ac608acf9ee6bf473f6407547bca2 (patch)
tree12b7aac0b6c1dab399012aeb0dc8bffdd9dba525
parenteff3a393493f5ce4c906f50f4b360c3f9ecdf2eb (diff)
downloadbinaryen-5c11c30dad7ac608acf9ee6bf473f6407547bca2.tar.gz
binaryen-5c11c30dad7ac608acf9ee6bf473f6407547bca2.tar.bz2
binaryen-5c11c30dad7ac608acf9ee6bf473f6407547bca2.zip
fix asm2wasm f64->f32->i32 bitcast (#412)
-rw-r--r--src/asm2wasm.h4
-rw-r--r--test/unit.asm.js2
-rw-r--r--test/unit.fromasm6
-rw-r--r--test/unit.fromasm.imprecise6
4 files changed, 18 insertions, 0 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h
index f905d2047..974a06bf3 100644
--- a/src/asm2wasm.h
+++ b/src/asm2wasm.h
@@ -1579,6 +1579,10 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
auto conv = allocator.alloc<Unary>();
conv->op = ReinterpretFloat;
conv->value = process(writtenValue);
+ if (conv->value->type == f64) {
+ // this has an implicit f64->f32 in the write to memory
+ conv->value = builder.makeUnary(DemoteFloat64, conv->value, f32);
+ }
conv->type = WasmType::i32;
return conv;
}
diff --git a/test/unit.asm.js b/test/unit.asm.js
index df731148a..da4269873 100644
--- a/test/unit.asm.js
+++ b/test/unit.asm.js
@@ -207,9 +207,11 @@ function asm(global, env, buffer) {
function bitcasts(i, f) {
i = i | 0;
f = Math_fround(f);
+ var d = 0.0;
(HEAP32[tempDoublePtr >> 2] = i, Math_fround(HEAPF32[tempDoublePtr >> 2])); // i32->f32
(HEAP32[tempDoublePtr >> 2] = i, +HEAPF32[tempDoublePtr >> 2]); // i32->f32, no fround
(HEAPF32[tempDoublePtr >> 2] = f, HEAP32[tempDoublePtr >> 2] | 0); // f32->i32
+ (HEAPF32[tempDoublePtr >> 2] = d, HEAP32[tempDoublePtr >> 2] | 0); // f64 with implict f32 conversion, ->i32
}
function z() {
diff --git a/test/unit.fromasm b/test/unit.fromasm
index eda3ea485..41e1154b5 100644
--- a/test/unit.fromasm
+++ b/test/unit.fromasm
@@ -460,6 +460,7 @@
)
)
(func $bitcasts (param $i i32) (param $f f32)
+ (local $d f64)
(f32.reinterpret/i32
(get_local $i)
)
@@ -471,6 +472,11 @@
(i32.reinterpret/f32
(get_local $f)
)
+ (i32.reinterpret/f32
+ (f32.demote/f64
+ (get_local $d)
+ )
+ )
)
(func $z
(nop)
diff --git a/test/unit.fromasm.imprecise b/test/unit.fromasm.imprecise
index 2d7147edb..3c8a7d917 100644
--- a/test/unit.fromasm.imprecise
+++ b/test/unit.fromasm.imprecise
@@ -454,6 +454,7 @@
)
)
(func $bitcasts (param $i i32) (param $f f32)
+ (local $d f64)
(f32.reinterpret/i32
(get_local $i)
)
@@ -465,6 +466,11 @@
(i32.reinterpret/f32
(get_local $f)
)
+ (i32.reinterpret/f32
+ (f32.demote/f64
+ (get_local $d)
+ )
+ )
)
(func $z
(nop)