summaryrefslogtreecommitdiff
path: root/test/wasm2asm/float-ops.2asm.js
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2018-05-16 18:40:45 -0500
committerAlon Zakai <alonzakai@gmail.com>2018-05-16 16:40:45 -0700
commit3c5a2de669542caebd7ef001db6678b70375f0b5 (patch)
treebbe25d21142627cc04041d7ecbea9d4d15f3a680 /test/wasm2asm/float-ops.2asm.js
parentd4aa0d30234ac9e553d743bd881a767d96554a4a (diff)
downloadbinaryen-3c5a2de669542caebd7ef001db6678b70375f0b5.tar.gz
binaryen-3c5a2de669542caebd7ef001db6678b70375f0b5.tar.bz2
binaryen-3c5a2de669542caebd7ef001db6678b70375f0b5.zip
wasm2asm: Implement float<->int conversions (#1550)
This commit lifts the same conversion strategy that `emcc` takes to convert between floats point numbers and integers, and it should implement all the various matrices of i32/u32/i64/u64 to f32/f64 Some refactoring was performed in the i64->i32 pass to allow for temporary variables to get allocated which have types other than i32, but otherwise this contains a pretty direct translation of `emcc`'s operations to `wasm2asm`.
Diffstat (limited to 'test/wasm2asm/float-ops.2asm.js')
-rw-r--r--test/wasm2asm/float-ops.2asm.js126
1 files changed, 125 insertions, 1 deletions
diff --git a/test/wasm2asm/float-ops.2asm.js b/test/wasm2asm/float-ops.2asm.js
index bad4bae9d..4d34766db 100644
--- a/test/wasm2asm/float-ops.2asm.js
+++ b/test/wasm2asm/float-ops.2asm.js
@@ -235,6 +235,114 @@ function asmFunc(global, env, buffer) {
return Math_fround((HEAP32[0] = (HEAPF32[0] = $0, HEAP32[0]) & 2147483647 | 0 | ((HEAPF32[0] = $1, HEAP32[0]) & 2147483648 | 0) | 0, HEAPF32[0]));
}
+ function $35($0) {
+ $0 = $0 | 0;
+ return Math_fround(Math_fround($0 | 0));
+ }
+
+ function $36($0) {
+ $0 = $0 | 0;
+ return +(+($0 | 0));
+ }
+
+ function $37($0) {
+ $0 = $0 | 0;
+ return Math_fround(Math_fround($0 >>> 0));
+ }
+
+ function $38($0) {
+ $0 = $0 | 0;
+ return +(+($0 >>> 0));
+ }
+
+ function $39($0) {
+ $0 = Math_fround($0);
+ return ~~$0 | 0;
+ }
+
+ function $40($0) {
+ $0 = +$0;
+ return ~~$0 | 0;
+ }
+
+ function $41($0) {
+ $0 = Math_fround($0);
+ return ~~$0 >>> 0 | 0;
+ }
+
+ function $42($0) {
+ $0 = +$0;
+ return ~~$0 >>> 0 | 0;
+ }
+
+ function $43($0, $0$hi) {
+ $0 = $0 | 0;
+ $0$hi = $0$hi | 0;
+ return Math_fround(Math_fround(+($0 >>> 0) + 4294967296.0 * +($0$hi | 0)));
+ }
+
+ function $44($0, $0$hi) {
+ $0 = $0 | 0;
+ $0$hi = $0$hi | 0;
+ return +(+($0 >>> 0) + 4294967296.0 * +($0$hi | 0));
+ }
+
+ function $45($0, $0$hi) {
+ $0 = $0 | 0;
+ $0$hi = $0$hi | 0;
+ return Math_fround(Math_fround(+($0 >>> 0) + 4294967296.0 * +($0$hi >>> 0)));
+ }
+
+ function $46($0, $0$hi) {
+ $0 = $0 | 0;
+ $0$hi = $0$hi | 0;
+ return +(+($0 >>> 0) + 4294967296.0 * +($0$hi >>> 0));
+ }
+
+ function $47($0) {
+ $0 = Math_fround($0);
+ var i64toi32_i32$0 = Math_fround(0), $2 = 0, $3 = 0;
+ i64toi32_i32$0 = $0;
+ if (Math_fround(Math_abs(i64toi32_i32$0)) >= Math_fround(1.0)) {
+ if (i64toi32_i32$0 > Math_fround(0.0)) $2 = ~~Math_fround(Math_min(Math_fround(Math_floor(Math_fround(i64toi32_i32$0 / Math_fround(4294967296.0)))), Math_fround(Math_fround(4294967296.0) - Math_fround(1.0)))) >>> 0; else $2 = ~~Math_fround(Math_ceil(Math_fround(Math_fround(i64toi32_i32$0 - Math_fround(~~i64toi32_i32$0 >>> 0 >>> 0)) / Math_fround(4294967296.0)))) >>> 0;
+ $3 = $2;
+ } else $3 = 0;
+ return (~~i64toi32_i32$0 >>> 0 | 0) == (0 | 0) & ($3 | 0) == (0 | 0) | 0 | 0;
+ }
+
+ function $48($0) {
+ $0 = +$0;
+ var i64toi32_i32$0 = 0.0, $2 = 0, $3 = 0;
+ i64toi32_i32$0 = $0;
+ if (Math_abs(i64toi32_i32$0) >= 1.0) {
+ if (i64toi32_i32$0 > 0.0) $2 = ~~Math_min(Math_floor(i64toi32_i32$0 / 4294967296.0), 4294967296.0 - 1.0) >>> 0; else $2 = ~~Math_ceil((i64toi32_i32$0 - +(~~i64toi32_i32$0 >>> 0 >>> 0)) / 4294967296.0) >>> 0;
+ $3 = $2;
+ } else $3 = 0;
+ return (~~i64toi32_i32$0 >>> 0 | 0) == (0 | 0) & ($3 | 0) == (0 | 0) | 0 | 0;
+ }
+
+ function $49($0) {
+ $0 = Math_fround($0);
+ var i64toi32_i32$0 = Math_fround(0), $2 = 0, $3 = 0;
+ i64toi32_i32$0 = $0;
+ if (Math_fround(Math_abs(i64toi32_i32$0)) >= Math_fround(1.0)) {
+ if (i64toi32_i32$0 > Math_fround(0.0)) $2 = ~~Math_fround(Math_min(Math_fround(Math_floor(Math_fround(i64toi32_i32$0 / Math_fround(4294967296.0)))), Math_fround(Math_fround(4294967296.0) - Math_fround(1.0)))) >>> 0; else $2 = ~~Math_fround(Math_ceil(Math_fround(Math_fround(i64toi32_i32$0 - Math_fround(~~i64toi32_i32$0 >>> 0 >>> 0)) / Math_fround(4294967296.0)))) >>> 0;
+ $3 = $2;
+ } else $3 = 0;
+ return (~~i64toi32_i32$0 >>> 0 | 0) == (0 | 0) & ($3 | 0) == (0 | 0) | 0 | 0;
+ }
+
+ function $50($0) {
+ $0 = +$0;
+ var i64toi32_i32$0 = 0.0, $2 = 0, $3 = 0;
+ i64toi32_i32$0 = $0;
+ if (Math_abs(i64toi32_i32$0) >= 1.0) {
+ if (i64toi32_i32$0 > 0.0) $2 = ~~Math_min(Math_floor(i64toi32_i32$0 / 4294967296.0), 4294967296.0 - 1.0) >>> 0; else $2 = ~~Math_ceil((i64toi32_i32$0 - +(~~i64toi32_i32$0 >>> 0 >>> 0)) / 4294967296.0) >>> 0;
+ $3 = $2;
+ } else $3 = 0;
+ return (~~i64toi32_i32$0 >>> 0 | 0) == (0 | 0) & ($3 | 0) == (0 | 0) | 0 | 0;
+ }
+
function __wasm_ctz_i32(x) {
x = x | 0;
var $1 = 0;
@@ -303,7 +411,23 @@ function asmFunc(global, env, buffer) {
f64_floor: $29,
f64_ceil: $30,
f32_sqrt: $31,
- f64_sqrt: $32
+ f64_sqrt: $32,
+ i32_to_f32: $35,
+ i32_to_f64: $36,
+ u32_to_f32: $37,
+ u32_to_f64: $38,
+ f32_to_i32: $39,
+ f64_to_i32: $40,
+ f32_to_u32: $41,
+ f64_to_u32: $42,
+ i64_to_f32: $43,
+ i64_to_f64: $44,
+ u64_to_f32: $45,
+ u64_to_f64: $46,
+ f32_to_i64: $47,
+ f64_to_i64: $48,
+ f32_to_u64: $49,
+ f64_to_u64: $50
};
}