summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-03-28 14:30:39 -0700
committerAlon Zakai <alonzakai@gmail.com>2016-04-01 15:46:41 -0700
commitbca89bde3e532e0632dd08c478cf5ca14645b2ed (patch)
tree01a2c5ab89301986836eb6d62846fb0bbdd9a4e7
parentb22f29a4ee0858721278df7d9cea1a487bc7b543 (diff)
downloadbinaryen-bca89bde3e532e0632dd08c478cf5ca14645b2ed.tar.gz
binaryen-bca89bde3e532e0632dd08c478cf5ca14645b2ed.tar.bz2
binaryen-bca89bde3e532e0632dd08c478cf5ca14645b2ed.zip
add a test for bitcast patterns in asm2wasm
-rw-r--r--test/unit.asm.js19
-rw-r--r--test/unit.fromasm37
-rw-r--r--test/unit.fromasm.imprecise37
3 files changed, 92 insertions, 1 deletions
diff --git a/test/unit.asm.js b/test/unit.asm.js
index 5bb84bdcd..cd432da5c 100644
--- a/test/unit.asm.js
+++ b/test/unit.asm.js
@@ -1,4 +1,4 @@
-function asm() {
+function asm(global, env, buffer) {
"use asm";
var t = global.NaN, u = global.Infinity;
@@ -7,11 +7,21 @@ function asm() {
var Math_fround = global.Math.fround;
var Math_abs = global.Math.abs;
var Math_ceil = global.Math.ceil;
+ var tempDoublePtr = env.tempDoublePtr | 0;
var abort = env.abort;
var print = env.print;
var h = env.h;
+ var HEAP8 = new global.Int8Array(buffer);
+ var HEAP16 = new global.Int16Array(buffer);
+ var HEAP32 = new global.Int32Array(buffer);
+ var HEAPU8 = new global.Uint8Array(buffer);
+ var HEAPU16 = new global.Uint16Array(buffer);
+ var HEAPU32 = new global.Uint32Array(buffer);
+ var HEAPF32 = new global.Float32Array(buffer);
+ var HEAPF64 = new global.Float64Array(buffer);
+
function big_negative() {
var temp = 0.0;
temp = +-2147483648;
@@ -190,6 +200,13 @@ function asm() {
print(2);
}
}
+ function bitcasts(i, f) {
+ i = i | 0;
+ f = Math_fround(f);
+ (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
+ }
function z() {
}
diff --git a/test/unit.fromasm b/test/unit.fromasm
index 3db25c78b..dc1db8abe 100644
--- a/test/unit.fromasm
+++ b/test/unit.fromasm
@@ -516,6 +516,43 @@
(br $while-in$1)
)
)
+ (func $bitcasts (param $i i32) (param $f f32)
+ (i32.store
+ (i32.load
+ (i32.const 40)
+ )
+ (get_local $i)
+ )
+ (f32.load
+ (i32.load
+ (i32.const 40)
+ )
+ )
+ (i32.store
+ (i32.load
+ (i32.const 40)
+ )
+ (get_local $i)
+ )
+ (f64.promote/f32
+ (f32.load
+ (i32.load
+ (i32.const 40)
+ )
+ )
+ )
+ (f32.store
+ (i32.load
+ (i32.const 40)
+ )
+ (get_local $f)
+ )
+ (i32.load
+ (i32.load
+ (i32.const 40)
+ )
+ )
+ )
(func $z
(nop)
)
diff --git a/test/unit.fromasm.imprecise b/test/unit.fromasm.imprecise
index ef9ccaa5d..96e22fc37 100644
--- a/test/unit.fromasm.imprecise
+++ b/test/unit.fromasm.imprecise
@@ -512,6 +512,43 @@
(br $while-in$1)
)
)
+ (func $bitcasts (param $i i32) (param $f f32)
+ (i32.store
+ (i32.load
+ (i32.const 40)
+ )
+ (get_local $i)
+ )
+ (f32.load
+ (i32.load
+ (i32.const 40)
+ )
+ )
+ (i32.store
+ (i32.load
+ (i32.const 40)
+ )
+ (get_local $i)
+ )
+ (f64.promote/f32
+ (f32.load
+ (i32.load
+ (i32.const 40)
+ )
+ )
+ )
+ (f32.store
+ (i32.load
+ (i32.const 40)
+ )
+ (get_local $f)
+ )
+ (i32.load
+ (i32.load
+ (i32.const 40)
+ )
+ )
+ )
(func $z
(nop)
)