From 82c2151397ccf02fb433c3e536e4576c81574232 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Fri, 18 Jan 2019 20:35:16 +0200 Subject: [PATCH 01/10] minor math tweaks --- std/assembly/math.ts | 48 +- tests/compiler/binary.untouched.wat | 883 +++++++-------- tests/compiler/std/array.optimized.wat | 4 +- tests/compiler/std/array.untouched.wat | 4 +- tests/compiler/std/libm.optimized.wat | 315 +++--- tests/compiler/std/libm.untouched.wat | 570 +++++----- tests/compiler/std/math.optimized.wat | 453 ++++---- tests/compiler/std/math.untouched.wat | 1007 ++++++++--------- .../std/operator-overloading.optimized.wat | 306 ++--- .../std/operator-overloading.untouched.wat | 559 ++++----- 10 files changed, 2077 insertions(+), 2072 deletions(-) diff --git a/std/assembly/math.ts b/std/assembly/math.ts index e399d81ca8..1aeeb4b2c1 100644 --- a/std/assembly/math.ts +++ b/std/assembly/math.ts @@ -343,8 +343,7 @@ export namespace NativeMath { t = reinterpret((reinterpret(t) + 0x80000000) & 0xFFFFFFFFC0000000); var s = t * t; r = x / s; - var w = t + t; - r = (r - t) / (w + r); + r = (r - t) / (2 * t + r); t = t + t * r; return t; } @@ -402,10 +401,7 @@ export namespace NativeMath { hx &= 0x7FFFFFFF; if (hx >= 0x4086232B) { if (isNaN(x)) return x; - if (x > overflow) { - x *= Ox1p1023; - return x; - } + if (x > overflow) return x * Ox1p1023; if (x < underflow) return 0; } var hi: f64, lo: f64 = 0; @@ -808,8 +804,9 @@ export namespace NativeMath { if (iy >= 0x43400000) yisint = 2; else if (iy >= 0x3FF00000) { k = (iy >> 20) - 0x3FF; - let offset = select(52, 20, k > 20) - k; - let Ly = select(ly, iy, k > 20); + let kcond = k > 20; + let offset = select(52, 20, kcond) - k; + let Ly = select(ly, iy, kcond); let jj = Ly >> offset; if ((jj << offset) == Ly) yisint = 2 - (jj & 1); } @@ -831,19 +828,24 @@ export namespace NativeMath { } var ax = builtin_abs(x), z: f64; if (lx == 0) { - if (ix == 0x7FF00000 || ix == 0 || ix == 0x3FF00000) { + if (ix == 0 || ix == 0x7FF00000 || ix == 0x3FF00000) { z = ax; if (hy < 0) z = 1.0 / z; if (hx < 0) { - if (((ix - 0x3FF00000) | yisint) == 0) z = (z - z) / (z - z); - else if (yisint == 1) z = -z; + if (((ix - 0x3FF00000) | yisint) == 0) { + let d = z - z; + z = d / d; + } else if (yisint == 1) z = -z; } return z; } } var s = 1.0; if (hx < 0) { - if (yisint == 0) return (x - x) / (x - x); + if (yisint == 0) { + let d = x - x; + return d / d; + } if (yisint == 1) s = -1.0; } var t1: f64, t2: f64, p_h: f64, p_l: f64, r: f64, t: f64, u: f64, v: f64, w: f64; @@ -1146,7 +1148,10 @@ export namespace NativeMath { var ex = (ux >> 52 & 0x7FF); var ey = (uy >> 52 & 0x7FF); var sx = (ux >> 63); - if (uy << 1 == 0 || ex == 0x7FF || isNaN(y)) return (x * y) / (x * y); + if (uy << 1 == 0 || ex == 0x7FF || isNaN(y)) { + let m = x * y; + return m / m; + } if (ux << 1 == 0) return x; var uxi = ux; if (!ex) { @@ -1225,7 +1230,7 @@ function expo2f(x: f32): f32 { // exp(x)/2 for x >= log(DBL_MAX) const // see: musl/src/math/__expo2f.c k = 235, kln2 = reinterpret(0x4322E3BC); // 0x1.45c778p+7f - var scale = reinterpret((0x7F + k / 2) << 23); + var scale = reinterpret((0x7F + (k >> 1)) << 23); return NativeMathf.exp(x - kln2) * scale * scale; } @@ -1878,8 +1883,9 @@ export namespace NativeMathf { if (iy >= 0x4B800000) yisint = 2; else if (iy >= 0x3F800000) { k = (iy >> 23) - 0x7F; - j = iy >> (23 - k); - if ((j << (23 - k)) == iy) yisint = 2 - (j & 1); + let ki = 23 - k; + j = iy >> ki; + if ((j << ki) == iy) yisint = 2 - (j & 1); } } if (iy == 0x7F800000) { // y is +-inf @@ -1898,14 +1904,20 @@ export namespace NativeMathf { z = ax; if (hy < 0) z = 1.0 / z; if (hx < 0) { - if (((ix - 0x3F800000) | yisint) == 0) z = (z - z) / (z - z); + if (((ix - 0x3F800000) | yisint) == 0) { + let d = z - z; + z = d / d; + } else if (yisint == 1) z = -z; } return z; } var sn = 1.0; if (hx < 0) { - if (yisint == 0) return (x - x) / (x - x); + if (yisint == 0) { + let d = x - x; + return d / d; + } if (yisint == 1) sn = -1.0; } var t1: f32, t2: f32, r: f32, s: f32, t: f32, u: f32, v: f32, w: f32, p_h: f32, p_l: f32; diff --git a/tests/compiler/binary.untouched.wat b/tests/compiler/binary.untouched.wat index 6443b5070d..0c6ab4e3b5 100644 --- a/tests/compiler/binary.untouched.wat +++ b/tests/compiler/binary.untouched.wat @@ -121,7 +121,7 @@ (local $11 i32) (local $12 i32) (local $13 i32) - (local $14 f64) + (local $14 i32) (local $15 f64) (local $16 f64) (local $17 f64) @@ -133,10 +133,10 @@ (local $23 f64) (local $24 f64) (local $25 f64) - (local $26 i32) - (local $27 i32) - (local $28 f64) - (local $29 f64) + (local $26 f64) + (local $27 f64) + (local $28 i32) + (local $29 i32) (local $30 f64) (local $31 f64) (local $32 f64) @@ -147,7 +147,8 @@ (local $37 f64) (local $38 f64) (local $39 f64) - (local $40 i32) + (local $40 f64) + (local $41 i32) get_local $0 i64.reinterpret/f64 set_local $2 @@ -259,34 +260,34 @@ i32.const 1023 i32.sub set_local $11 - i32.const 52 - i32.const 20 get_local $11 i32.const 20 i32.gt_s + set_local $9 + i32.const 52 + i32.const 20 + get_local $9 select get_local $11 i32.sub - set_local $9 + set_local $12 get_local $6 get_local $8 - get_local $11 - i32.const 20 - i32.gt_s - select - set_local $12 - get_local $12 get_local $9 - i32.shr_s + select set_local $13 get_local $13 - get_local $9 - i32.shl get_local $12 + i32.shr_s + set_local $14 + get_local $14 + get_local $12 + i32.shl + get_local $13 i32.eq if i32.const 2 - get_local $13 + get_local $14 i32.const 1 i32.and i32.sub @@ -385,41 +386,41 @@ end get_local $0 f64.abs - set_local $14 + set_local $15 get_local $4 i32.const 0 i32.eq if get_local $7 - i32.const 2146435072 + i32.const 0 i32.eq - tee_local $13 + tee_local $14 if (result i32) - get_local $13 + get_local $14 else get_local $7 - i32.const 0 + i32.const 2146435072 i32.eq end - tee_local $13 + tee_local $14 if (result i32) - get_local $13 + get_local $14 else get_local $7 i32.const 1072693248 i32.eq end if - get_local $14 - set_local $15 + get_local $15 + set_local $16 get_local $5 i32.const 0 i32.lt_s if f64.const 1 - get_local $15 + get_local $16 f64.div - set_local $15 + set_local $16 end get_local $3 i32.const 0 @@ -433,31 +434,31 @@ i32.const 0 i32.eq if - get_local $15 - get_local $15 - f64.sub - get_local $15 - get_local $15 + get_local $16 + get_local $16 f64.sub + set_local $17 + get_local $17 + get_local $17 f64.div - set_local $15 + set_local $16 else get_local $10 i32.const 1 i32.eq if - get_local $15 + get_local $16 f64.neg - set_local $15 + set_local $16 end end end - get_local $15 + get_local $16 return end end f64.const 1 - set_local $16 + set_local $18 get_local $3 i32.const 0 i32.lt_s @@ -469,9 +470,9 @@ get_local $0 get_local $0 f64.sub - get_local $0 - get_local $0 - f64.sub + set_local $17 + get_local $17 + get_local $17 f64.div return end @@ -480,7 +481,7 @@ i32.eq if f64.const -1 - set_local $16 + set_local $18 end end get_local $8 @@ -536,13 +537,13 @@ i32.const 0 i32.lt_s if (result f64) - get_local $16 + get_local $18 f64.const 1.e+300 f64.mul f64.const 1.e+300 f64.mul else - get_local $16 + get_local $18 f64.const 1e-300 f64.mul f64.const 1e-300 @@ -558,13 +559,13 @@ i32.const 0 i32.gt_s if (result f64) - get_local $16 + get_local $18 f64.const 1.e+300 f64.mul f64.const 1.e+300 f64.mul else - get_local $16 + get_local $18 f64.const 1e-300 f64.mul f64.const 1e-300 @@ -572,98 +573,98 @@ end return end - get_local $14 + get_local $15 f64.const 1 f64.sub - set_local $22 - get_local $22 - get_local $22 + set_local $24 + get_local $24 + get_local $24 f64.mul f64.const 0.5 - get_local $22 + get_local $24 f64.const 0.3333333333333333 - get_local $22 + get_local $24 f64.const 0.25 f64.mul f64.sub f64.mul f64.sub f64.mul - set_local $25 + set_local $27 f64.const 1.4426950216293335 - get_local $22 + get_local $24 f64.mul - set_local $23 - get_local $22 + set_local $25 + get_local $24 f64.const 1.9259629911266175e-08 f64.mul - get_local $25 + get_local $27 f64.const 1.4426950408889634 f64.mul f64.sub - set_local $24 - get_local $23 - get_local $24 + set_local $26 + get_local $25 + get_local $26 f64.add - set_local $17 - get_local $17 + set_local $19 + get_local $19 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - set_local $17 - get_local $24 - get_local $17 - get_local $23 + set_local $19 + get_local $26 + get_local $19 + get_local $25 f64.sub f64.sub - set_local $18 + set_local $20 else i32.const 0 - set_local $27 + set_local $29 get_local $7 i32.const 1048576 i32.lt_s if - get_local $14 + get_local $15 f64.const 9007199254740992 f64.mul - set_local $14 - get_local $27 + set_local $15 + get_local $29 i32.const 53 i32.sub - set_local $27 - get_local $14 + set_local $29 + get_local $15 i64.reinterpret/f64 i64.const 32 i64.shr_u i32.wrap/i64 set_local $7 end - get_local $27 + get_local $29 get_local $7 i32.const 20 i32.shr_s i32.const 1023 i32.sub i32.add - set_local $27 + set_local $29 get_local $7 i32.const 1048575 i32.and - set_local $26 - get_local $26 + set_local $28 + get_local $28 i32.const 1072693248 i32.or set_local $7 - get_local $26 + get_local $28 i32.const 235662 i32.le_s if i32.const 0 set_local $11 else - get_local $26 + get_local $28 i32.const 767610 i32.lt_s if @@ -672,17 +673,17 @@ else i32.const 0 set_local $11 - get_local $27 + get_local $29 i32.const 1 i32.add - set_local $27 + set_local $29 get_local $7 i32.const 1048576 i32.sub set_local $7 end end - get_local $14 + get_local $15 i64.reinterpret/f64 i64.const 4294967295 i64.and @@ -692,34 +693,34 @@ i64.shl i64.or f64.reinterpret/i64 - set_local $14 + set_local $15 f64.const 1.5 f64.const 1 get_local $11 select - set_local $34 - get_local $14 - get_local $34 + set_local $35 + get_local $15 + get_local $35 f64.sub - set_local $23 + set_local $25 f64.const 1 - get_local $14 - get_local $34 + get_local $15 + get_local $35 f64.add f64.div - set_local $24 - get_local $23 - get_local $24 + set_local $26 + get_local $25 + get_local $26 f64.mul - set_local $28 - get_local $28 - set_local $30 - get_local $30 + set_local $17 + get_local $17 + set_local $31 + get_local $31 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - set_local $30 + set_local $31 get_local $7 i32.const 1 i32.shr_s @@ -735,42 +736,42 @@ i64.const 32 i64.shl f64.reinterpret/i64 - set_local $32 - get_local $14 - get_local $32 - get_local $34 + set_local $33 + get_local $15 + get_local $33 + get_local $35 f64.sub f64.sub - set_local $33 - get_local $24 - get_local $23 - get_local $30 - get_local $32 + set_local $34 + get_local $26 + get_local $25 + get_local $31 + get_local $33 f64.mul f64.sub - get_local $30 - get_local $33 + get_local $31 + get_local $34 f64.mul f64.sub f64.mul - set_local $31 - get_local $28 - get_local $28 + set_local $32 + get_local $17 + get_local $17 f64.mul - set_local $29 - get_local $29 - get_local $29 + set_local $30 + get_local $30 + get_local $30 f64.mul f64.const 0.5999999999999946 - get_local $29 + get_local $30 f64.const 0.4285714285785502 - get_local $29 + get_local $30 f64.const 0.33333332981837743 - get_local $29 + get_local $30 f64.const 0.272728123808534 - get_local $29 + get_local $30 f64.const 0.23066074577556175 - get_local $29 + get_local $30 f64.const 0.20697501780033842 f64.mul f64.add @@ -783,184 +784,184 @@ f64.mul f64.add f64.mul - set_local $21 - get_local $21 + set_local $23 + get_local $23 + get_local $32 get_local $31 - get_local $30 - get_local $28 + get_local $17 f64.add f64.mul f64.add - set_local $21 - get_local $30 - get_local $30 + set_local $23 + get_local $31 + get_local $31 f64.mul - set_local $29 + set_local $30 f64.const 3 - get_local $29 + get_local $30 f64.add - get_local $21 + get_local $23 f64.add - set_local $32 - get_local $32 + set_local $33 + get_local $33 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - set_local $32 - get_local $21 - get_local $32 + set_local $33 + get_local $23 + get_local $33 f64.const 3 f64.sub - get_local $29 + get_local $30 f64.sub f64.sub - set_local $33 - get_local $30 - get_local $32 - f64.mul - set_local $23 + set_local $34 get_local $31 - get_local $32 + get_local $33 f64.mul + set_local $25 + get_local $32 get_local $33 - get_local $28 + f64.mul + get_local $34 + get_local $17 f64.mul f64.add - set_local $24 - get_local $23 - get_local $24 + set_local $26 + get_local $25 + get_local $26 f64.add - set_local $19 - get_local $19 + set_local $21 + get_local $21 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - set_local $19 - get_local $24 - get_local $19 - get_local $23 + set_local $21 + get_local $26 + get_local $21 + get_local $25 f64.sub f64.sub - set_local $20 + set_local $22 f64.const 0.9617967009544373 - get_local $19 + get_local $21 f64.mul - set_local $35 + set_local $36 f64.const 1.350039202129749e-08 f64.const 0 get_local $11 select - set_local $36 + set_local $37 f64.const -7.028461650952758e-09 - get_local $19 + get_local $21 f64.mul - get_local $20 + get_local $22 f64.const 0.9617966939259756 f64.mul f64.add - get_local $36 + get_local $37 f64.add - set_local $37 - get_local $27 + set_local $38 + get_local $29 f64.convert_s/i32 - set_local $22 + set_local $24 f64.const 0.5849624872207642 f64.const 0 get_local $11 select - set_local $38 - get_local $35 - get_local $37 - f64.add + set_local $39 + get_local $36 get_local $38 f64.add - get_local $22 + get_local $39 f64.add - set_local $17 - get_local $17 + get_local $24 + f64.add + set_local $19 + get_local $19 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - set_local $17 - get_local $37 - get_local $17 - get_local $22 - f64.sub + set_local $19 get_local $38 + get_local $19 + get_local $24 f64.sub - get_local $35 + get_local $39 f64.sub + get_local $36 f64.sub - set_local $18 + f64.sub + set_local $20 end get_local $1 - set_local $39 - get_local $39 + set_local $40 + get_local $40 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - set_local $39 + set_local $40 get_local $1 - get_local $39 + get_local $40 f64.sub - get_local $17 + get_local $19 f64.mul get_local $1 - get_local $18 + get_local $20 f64.mul f64.add - set_local $20 - get_local $39 - get_local $17 - f64.mul - set_local $19 - get_local $20 + set_local $22 + get_local $40 get_local $19 + f64.mul + set_local $21 + get_local $22 + get_local $21 f64.add - set_local $15 - get_local $15 + set_local $16 + get_local $16 i64.reinterpret/f64 set_local $2 get_local $2 i64.const 32 i64.shr_u i32.wrap/i64 - set_local $26 + set_local $28 get_local $2 i32.wrap/i64 - set_local $40 - get_local $26 + set_local $41 + get_local $28 i32.const 1083179008 i32.ge_s if - get_local $26 + get_local $28 i32.const 1083179008 i32.sub - get_local $40 + get_local $41 i32.or i32.const 0 i32.ne if - get_local $16 + get_local $18 f64.const 1.e+300 f64.mul f64.const 1.e+300 f64.mul return end - get_local $20 + get_local $22 f64.const 8.008566259537294e-17 f64.add - get_local $15 - get_local $19 + get_local $16 + get_local $21 f64.sub f64.gt if - get_local $16 + get_local $18 f64.const 1.e+300 f64.mul f64.const 1.e+300 @@ -968,34 +969,34 @@ return end else - get_local $26 + get_local $28 i32.const 2147483647 i32.and i32.const 1083231232 i32.ge_s if - get_local $26 + get_local $28 i32.const -1064252416 i32.sub - get_local $40 + get_local $41 i32.or i32.const 0 i32.ne if - get_local $16 + get_local $18 f64.const 1e-300 f64.mul f64.const 1e-300 f64.mul return end - get_local $20 - get_local $15 - get_local $19 + get_local $22 + get_local $16 + get_local $21 f64.sub f64.le if - get_local $16 + get_local $18 f64.const 1e-300 f64.mul f64.const 1e-300 @@ -1004,31 +1005,31 @@ end end end - get_local $26 + get_local $28 i32.const 2147483647 i32.and - set_local $40 - get_local $40 + set_local $41 + get_local $41 i32.const 20 i32.shr_s i32.const 1023 i32.sub set_local $11 i32.const 0 - set_local $27 - get_local $40 + set_local $29 + get_local $41 i32.const 1071644672 i32.gt_s if - get_local $26 + get_local $28 i32.const 1048576 get_local $11 i32.const 1 i32.add i32.shr_s i32.add - set_local $27 - get_local $27 + set_local $29 + get_local $29 i32.const 2147483647 i32.and i32.const 20 @@ -1037,8 +1038,8 @@ i32.sub set_local $11 f64.const 0 - set_local $22 - get_local $27 + set_local $24 + get_local $29 i32.const 1048575 get_local $11 i32.shr_s @@ -1049,8 +1050,8 @@ i64.const 32 i64.shl f64.reinterpret/i64 - set_local $22 - get_local $27 + set_local $24 + get_local $29 i32.const 1048575 i32.and i32.const 1048576 @@ -1059,71 +1060,71 @@ get_local $11 i32.sub i32.shr_s - set_local $27 - get_local $26 + set_local $29 + get_local $28 i32.const 0 i32.lt_s if i32.const 0 - get_local $27 + get_local $29 i32.sub - set_local $27 + set_local $29 end - get_local $19 - get_local $22 + get_local $21 + get_local $24 f64.sub - set_local $19 + set_local $21 end - get_local $20 - get_local $19 - f64.add - set_local $22 get_local $22 + get_local $21 + f64.add + set_local $24 + get_local $24 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - set_local $22 - get_local $22 + set_local $24 + get_local $24 f64.const 0.6931471824645996 f64.mul - set_local $23 - get_local $20 + set_local $25 get_local $22 - get_local $19 + get_local $24 + get_local $21 f64.sub f64.sub f64.const 0.6931471805599453 f64.mul - get_local $22 + get_local $24 f64.const -1.904654299957768e-09 f64.mul f64.add - set_local $24 - get_local $23 - get_local $24 + set_local $26 + get_local $25 + get_local $26 f64.add - set_local $15 - get_local $24 - get_local $15 - get_local $23 + set_local $16 + get_local $26 + get_local $16 + get_local $25 f64.sub f64.sub - set_local $25 - get_local $15 - get_local $15 + set_local $27 + get_local $16 + get_local $16 f64.mul - set_local $22 - get_local $15 - get_local $22 + set_local $24 + get_local $16 + get_local $24 f64.const 0.16666666666666602 - get_local $22 + get_local $24 f64.const -2.7777777777015593e-03 - get_local $22 + get_local $24 f64.const 6.613756321437934e-05 - get_local $22 + get_local $24 f64.const -1.6533902205465252e-06 - get_local $22 + get_local $24 f64.const 4.1381367970572385e-08 f64.mul f64.add @@ -1135,64 +1136,64 @@ f64.add f64.mul f64.sub - set_local $17 - get_local $15 - get_local $17 + set_local $19 + get_local $16 + get_local $19 f64.mul - get_local $17 + get_local $19 f64.const 2 f64.sub f64.div - get_local $25 - get_local $15 - get_local $25 + get_local $27 + get_local $16 + get_local $27 f64.mul f64.add f64.sub - set_local $21 + set_local $23 f64.const 1 - get_local $21 - get_local $15 + get_local $23 + get_local $16 f64.sub f64.sub - set_local $15 - get_local $15 + set_local $16 + get_local $16 i64.reinterpret/f64 i64.const 32 i64.shr_u i32.wrap/i64 - set_local $26 - get_local $26 - get_local $27 + set_local $28 + get_local $28 + get_local $29 i32.const 20 i32.shl i32.add - set_local $26 - get_local $26 + set_local $28 + get_local $28 i32.const 20 i32.shr_s i32.const 0 i32.le_s if - get_local $15 - get_local $27 + get_local $16 + get_local $29 call $~lib/math/NativeMath.scalbn - set_local $15 + set_local $16 else - get_local $15 + get_local $16 i64.reinterpret/f64 i64.const 4294967295 i64.and - get_local $26 + get_local $28 i64.extend_s/i32 i64.const 32 i64.shl i64.or f64.reinterpret/i64 - set_local $15 + set_local $16 end + get_local $18 get_local $16 - get_local $15 f64.mul ) (func $~lib/math/NativeMathf.mod (; 2 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32) @@ -1560,9 +1561,9 @@ (local $20 f32) (local $21 f32) (local $22 f32) - (local $23 i32) + (local $23 f32) (local $24 i32) - (local $25 f32) + (local $25 i32) (local $26 f32) (local $27 f32) (local $28 f32) @@ -1635,16 +1636,16 @@ i32.const 127 i32.sub set_local $9 - get_local $5 i32.const 23 get_local $9 i32.sub + set_local $6 + get_local $5 + get_local $6 i32.shr_s set_local $8 get_local $8 - i32.const 23 - get_local $9 - i32.sub + get_local $6 i32.shl get_local $5 i32.eq @@ -1787,9 +1788,9 @@ get_local $11 get_local $11 f32.sub - get_local $11 - get_local $11 - f32.sub + set_local $12 + get_local $12 + get_local $12 f32.div set_local $11 else @@ -1807,7 +1808,7 @@ return end f32.const 1 - set_local $12 + set_local $13 get_local $2 i32.const 0 i32.lt_s @@ -1819,9 +1820,9 @@ get_local $0 get_local $0 f32.sub - get_local $0 - get_local $0 - f32.sub + set_local $12 + get_local $12 + get_local $12 f32.div return end @@ -1830,7 +1831,7 @@ i32.eq if f32.const -1 - set_local $12 + set_local $13 end end get_local $5 @@ -1845,13 +1846,13 @@ i32.const 0 i32.lt_s if (result f32) - get_local $12 + get_local $13 f32.const 1000000015047466219876688e6 f32.mul f32.const 1000000015047466219876688e6 f32.mul else - get_local $12 + get_local $13 f32.const 1.0000000031710769e-30 f32.mul f32.const 1.0000000031710769e-30 @@ -1867,13 +1868,13 @@ i32.const 0 i32.gt_s if (result f32) - get_local $12 + get_local $13 f32.const 1000000015047466219876688e6 f32.mul f32.const 1000000015047466219876688e6 f32.mul else - get_local $12 + get_local $13 f32.const 1.0000000031710769e-30 f32.mul f32.const 1.0000000031710769e-30 @@ -1884,54 +1885,54 @@ get_local $10 f32.const 1 f32.sub - set_local $17 - get_local $17 - get_local $17 + set_local $18 + get_local $18 + get_local $18 f32.mul f32.const 0.5 - get_local $17 + get_local $18 f32.const 0.3333333432674408 - get_local $17 + get_local $18 f32.const 0.25 f32.mul f32.sub f32.mul f32.sub f32.mul - set_local $20 + set_local $21 f32.const 1.44268798828125 - get_local $17 + get_local $18 f32.mul - set_local $18 - get_local $17 + set_local $19 + get_local $18 f32.const 7.052607543300837e-06 f32.mul - get_local $20 + get_local $21 f32.const 1.4426950216293335 f32.mul f32.sub - set_local $19 - get_local $18 + set_local $20 get_local $19 + get_local $20 f32.add - set_local $13 - get_local $13 + set_local $14 + get_local $14 i32.reinterpret/f32 - set_local $24 - get_local $24 + set_local $25 + get_local $25 i32.const -4096 i32.and f32.reinterpret/i32 - set_local $13 + set_local $14 + get_local $20 + get_local $14 get_local $19 - get_local $13 - get_local $18 f32.sub f32.sub - set_local $14 + set_local $15 else i32.const 0 - set_local $23 + set_local $24 get_local $4 i32.const 8388608 i32.lt_s @@ -1940,22 +1941,22 @@ f32.const 16777216 f32.mul set_local $10 - get_local $23 + get_local $24 i32.const 24 i32.sub - set_local $23 + set_local $24 get_local $10 i32.reinterpret/f32 set_local $4 end - get_local $23 + get_local $24 get_local $4 i32.const 23 i32.shr_s i32.const 127 i32.sub i32.add - set_local $23 + set_local $24 get_local $4 i32.const 8388607 i32.and @@ -1980,10 +1981,10 @@ else i32.const 0 set_local $9 - get_local $23 + get_local $24 i32.const 1 i32.add - set_local $23 + set_local $24 get_local $4 i32.const 8388608 i32.sub @@ -2001,23 +2002,23 @@ get_local $10 get_local $30 f32.sub - set_local $18 + set_local $19 f32.const 1 get_local $10 get_local $30 f32.add f32.div - set_local $19 - get_local $18 + set_local $20 get_local $19 + get_local $20 f32.mul - set_local $16 - get_local $16 + set_local $17 + get_local $17 set_local $26 get_local $26 i32.reinterpret/f32 - set_local $24 - get_local $24 + set_local $25 + get_local $25 i32.const -4096 i32.and f32.reinterpret/i32 @@ -2029,8 +2030,8 @@ i32.and i32.const 536870912 i32.or - set_local $24 - get_local $24 + set_local $25 + get_local $25 i32.const 4194304 i32.add get_local $9 @@ -2045,8 +2046,8 @@ f32.sub f32.sub set_local $29 + get_local $20 get_local $19 - get_local $18 get_local $26 get_local $28 f32.mul @@ -2057,23 +2058,23 @@ f32.sub f32.mul set_local $27 - get_local $16 - get_local $16 + get_local $17 + get_local $17 f32.mul - set_local $25 - get_local $25 - get_local $25 + set_local $12 + get_local $12 + get_local $12 f32.mul f32.const 0.6000000238418579 - get_local $25 + get_local $12 f32.const 0.4285714328289032 - get_local $25 + get_local $12 f32.const 0.3333333432674408 - get_local $25 + get_local $12 f32.const 0.2727281153202057 - get_local $25 + get_local $12 f32.const 0.23066075146198273 - get_local $25 + get_local $12 f32.const 0.20697501301765442 f32.mul f32.add @@ -2086,73 +2087,73 @@ f32.mul f32.add f32.mul - set_local $15 - get_local $15 + set_local $16 + get_local $16 get_local $27 get_local $26 - get_local $16 + get_local $17 f32.add f32.mul f32.add - set_local $15 + set_local $16 get_local $26 get_local $26 f32.mul - set_local $25 + set_local $12 f32.const 3 - get_local $25 + get_local $12 f32.add - get_local $15 + get_local $16 f32.add set_local $28 get_local $28 i32.reinterpret/f32 - set_local $24 - get_local $24 + set_local $25 + get_local $25 i32.const -4096 i32.and f32.reinterpret/i32 set_local $28 - get_local $15 + get_local $16 get_local $28 f32.const 3 f32.sub - get_local $25 + get_local $12 f32.sub f32.sub set_local $29 get_local $26 get_local $28 f32.mul - set_local $18 + set_local $19 get_local $27 get_local $28 f32.mul get_local $29 - get_local $16 + get_local $17 f32.mul f32.add - set_local $19 - get_local $18 + set_local $20 get_local $19 + get_local $20 f32.add - set_local $21 - get_local $21 + set_local $22 + get_local $22 i32.reinterpret/f32 - set_local $24 - get_local $24 + set_local $25 + get_local $25 i32.const -4096 i32.and f32.reinterpret/i32 - set_local $21 + set_local $22 + get_local $20 + get_local $22 get_local $19 - get_local $21 - get_local $18 f32.sub f32.sub - set_local $22 + set_local $23 f32.const 0.9619140625 - get_local $21 + get_local $22 f32.mul set_local $31 f32.const 1.5632208487659227e-06 @@ -2161,18 +2162,18 @@ select set_local $32 f32.const -1.1736857413779944e-04 - get_local $21 - f32.mul get_local $22 + f32.mul + get_local $23 f32.const 0.9617967009544373 f32.mul f32.add get_local $32 f32.add set_local $33 - get_local $23 + get_local $24 f32.convert_s/i32 - set_local $17 + set_local $18 f32.const 0.5849609375 f32.const 0 get_local $9 @@ -2183,32 +2184,32 @@ f32.add get_local $34 f32.add - get_local $17 + get_local $18 f32.add - set_local $13 - get_local $13 + set_local $14 + get_local $14 i32.reinterpret/f32 - set_local $24 - get_local $24 + set_local $25 + get_local $25 i32.const -4096 i32.and f32.reinterpret/i32 - set_local $13 + set_local $14 get_local $33 - get_local $13 - get_local $17 + get_local $14 + get_local $18 f32.sub get_local $34 f32.sub get_local $31 f32.sub f32.sub - set_local $14 + set_local $15 end get_local $1 i32.reinterpret/f32 - set_local $24 - get_local $24 + set_local $25 + get_local $25 i32.const -4096 i32.and f32.reinterpret/i32 @@ -2216,19 +2217,19 @@ get_local $1 get_local $35 f32.sub - get_local $13 + get_local $14 f32.mul get_local $1 - get_local $14 + get_local $15 f32.mul f32.add - set_local $22 + set_local $23 get_local $35 - get_local $13 + get_local $14 f32.mul - set_local $21 + set_local $22 + get_local $23 get_local $22 - get_local $21 f32.add set_local $11 get_local $11 @@ -2238,7 +2239,7 @@ i32.const 1124073472 i32.gt_s if - get_local $12 + get_local $13 f32.const 1000000015047466219876688e6 f32.mul f32.const 1000000015047466219876688e6 @@ -2249,15 +2250,15 @@ i32.const 1124073472 i32.eq if - get_local $22 + get_local $23 f32.const 4.299566569443414e-08 f32.add get_local $11 - get_local $21 + get_local $22 f32.sub f32.gt if - get_local $12 + get_local $13 f32.const 1000000015047466219876688e6 f32.mul f32.const 1000000015047466219876688e6 @@ -2271,7 +2272,7 @@ i32.const 1125515264 i32.gt_s if - get_local $12 + get_local $13 f32.const 1.0000000031710769e-30 f32.mul f32.const 1.0000000031710769e-30 @@ -2282,13 +2283,13 @@ i32.const -1021968384 i32.eq if - get_local $22 + get_local $23 get_local $11 - get_local $21 + get_local $22 f32.sub f32.le if - get_local $12 + get_local $13 f32.const 1.0000000031710769e-30 f32.mul f32.const 1.0000000031710769e-30 @@ -2310,7 +2311,7 @@ i32.sub set_local $9 i32.const 0 - set_local $23 + set_local $24 get_local $36 i32.const 1056964608 i32.gt_s @@ -2322,8 +2323,8 @@ i32.add i32.shr_s i32.add - set_local $23 - get_local $23 + set_local $24 + get_local $24 i32.const 2147483647 i32.and i32.const 23 @@ -2331,7 +2332,7 @@ i32.const 127 i32.sub set_local $9 - get_local $23 + get_local $24 i32.const 8388607 get_local $9 i32.shr_s @@ -2339,8 +2340,8 @@ i32.xor i32.and f32.reinterpret/i32 - set_local $17 - get_local $23 + set_local $18 + get_local $24 i32.const 8388607 i32.and i32.const 8388608 @@ -2349,73 +2350,73 @@ get_local $9 i32.sub i32.shr_s - set_local $23 + set_local $24 get_local $8 i32.const 0 i32.lt_s if i32.const 0 - get_local $23 + get_local $24 i32.sub - set_local $23 + set_local $24 end - get_local $21 - get_local $17 + get_local $22 + get_local $18 f32.sub - set_local $21 + set_local $22 end + get_local $23 get_local $22 - get_local $21 f32.add - set_local $17 - get_local $17 + set_local $18 + get_local $18 i32.reinterpret/f32 - set_local $24 - get_local $24 + set_local $25 + get_local $25 i32.const -32768 i32.and f32.reinterpret/i32 - set_local $17 - get_local $17 + set_local $18 + get_local $18 f32.const 0.693145751953125 f32.mul - set_local $18 + set_local $19 + get_local $23 + get_local $18 get_local $22 - get_local $17 - get_local $21 f32.sub f32.sub f32.const 0.6931471824645996 f32.mul - get_local $17 + get_local $18 f32.const 1.4286065379565116e-06 f32.mul f32.add - set_local $19 - get_local $18 + set_local $20 get_local $19 + get_local $20 f32.add set_local $11 - get_local $19 + get_local $20 get_local $11 - get_local $18 + get_local $19 f32.sub f32.sub - set_local $20 + set_local $21 get_local $11 get_local $11 f32.mul - set_local $17 + set_local $18 get_local $11 - get_local $17 + get_local $18 f32.const 0.1666666716337204 - get_local $17 + get_local $18 f32.const -2.7777778450399637e-03 - get_local $17 + get_local $18 f32.const 6.61375597701408e-05 - get_local $17 + get_local $18 f32.const -1.6533901998627698e-06 - get_local $17 + get_local $18 f32.const 4.138136944220605e-08 f32.mul f32.add @@ -2427,23 +2428,23 @@ f32.add f32.mul f32.sub - set_local $13 + set_local $14 get_local $11 - get_local $13 + get_local $14 f32.mul - get_local $13 + get_local $14 f32.const 2 f32.sub f32.div - get_local $20 + get_local $21 get_local $11 - get_local $20 + get_local $21 f32.mul f32.add f32.sub - set_local $15 + set_local $16 f32.const 1 - get_local $15 + get_local $16 get_local $11 f32.sub f32.sub @@ -2452,7 +2453,7 @@ i32.reinterpret/f32 set_local $8 get_local $8 - get_local $23 + get_local $24 i32.const 23 i32.shl i32.add @@ -2464,7 +2465,7 @@ i32.le_s if get_local $11 - get_local $23 + get_local $24 call $~lib/math/NativeMathf.scalbn set_local $11 else @@ -2472,7 +2473,7 @@ f32.reinterpret/i32 set_local $11 end - get_local $12 + get_local $13 get_local $11 f32.mul ) diff --git a/tests/compiler/std/array.optimized.wat b/tests/compiler/std/array.optimized.wat index 2d7b389fc6..6775aadcd7 100644 --- a/tests/compiler/std/array.optimized.wat +++ b/tests/compiler/std/array.optimized.wat @@ -3813,7 +3813,7 @@ if i32.const 0 i32.const 2816 - i32.const 959 + i32.const 961 i32.const 4 call $~lib/env/abort unreachable @@ -5479,7 +5479,7 @@ if i32.const 0 i32.const 2816 - i32.const 968 + i32.const 970 i32.const 24 call $~lib/env/abort unreachable diff --git a/tests/compiler/std/array.untouched.wat b/tests/compiler/std/array.untouched.wat index 8fb97a4ee8..2f4ebf58eb 100644 --- a/tests/compiler/std/array.untouched.wat +++ b/tests/compiler/std/array.untouched.wat @@ -5225,7 +5225,7 @@ if i32.const 0 i32.const 2816 - i32.const 959 + i32.const 961 i32.const 4 call $~lib/env/abort unreachable @@ -8241,7 +8241,7 @@ if i32.const 0 i32.const 2816 - i32.const 968 + i32.const 970 i32.const 24 call $~lib/env/abort unreachable diff --git a/tests/compiler/std/libm.optimized.wat b/tests/compiler/std/libm.optimized.wat index 71f6e154e7..c7f308a4f9 100644 --- a/tests/compiler/std/libm.optimized.wat +++ b/tests/compiler/std/libm.optimized.wat @@ -1506,6 +1506,7 @@ f64.div f64.mul set_local $2 + get_local $0 get_local $1 f64.const 1.87595182427177 get_local $2 @@ -1538,18 +1539,16 @@ tee_local $1 get_local $1 f64.mul + f64.div set_local $2 get_local $1 get_local $1 - get_local $0 get_local $2 - f64.div - tee_local $2 get_local $1 f64.sub + f64.const 2 get_local $1 - get_local $1 - f64.add + f64.mul get_local $2 f64.add f64.div @@ -2806,19 +2805,20 @@ (local $5 i32) (local $6 f64) (local $7 i32) - (local $8 i32) - (local $9 f64) - (local $10 i32) - (local $11 f64) + (local $8 f64) + (local $9 i32) + (local $10 f64) + (local $11 i32) (local $12 i32) (local $13 i32) - (local $14 i32) - (local $15 f64) + (local $14 f64) + (local $15 i32) (local $16 f64) (local $17 i64) (local $18 i32) (local $19 f64) (local $20 i32) + (local $21 i32) get_local $0 i64.reinterpret/f64 tee_local $17 @@ -2832,7 +2832,7 @@ get_local $18 i32.const 2147483647 i32.and - set_local $4 + set_local $5 get_local $1 i64.reinterpret/f64 tee_local $17 @@ -2842,57 +2842,57 @@ tee_local $13 i32.const 2147483647 i32.and - set_local $12 - get_local $12 + set_local $11 + get_local $11 get_local $17 i32.wrap/i64 - tee_local $7 + tee_local $21 i32.or i32.eqz if f64.const 1 return end - get_local $4 + get_local $5 i32.const 2146435072 i32.gt_s - tee_local $8 + tee_local $4 i32.eqz if - get_local $4 + get_local $5 i32.const 2146435072 i32.eq - tee_local $8 + tee_local $4 if get_local $20 i32.const 0 i32.ne - set_local $8 + set_local $4 end end - get_local $8 + get_local $4 i32.eqz if - get_local $12 + get_local $11 i32.const 2146435072 i32.gt_s - set_local $8 + set_local $4 end - get_local $8 + get_local $4 i32.eqz if - get_local $12 + get_local $11 i32.const 2146435072 i32.eq - tee_local $8 + tee_local $4 if - get_local $7 + get_local $21 i32.const 0 i32.ne - set_local $8 + set_local $4 end end - get_local $8 + get_local $4 if get_local $0 get_local $1 @@ -2903,71 +2903,70 @@ i32.const 0 i32.lt_s if - get_local $12 + get_local $11 i32.const 1128267776 i32.ge_s if (result i32) i32.const 2 else - get_local $12 + get_local $11 i32.const 1072693248 i32.ge_s if (result i32) - i32.const 52 - i32.const 20 - get_local $12 + get_local $21 + get_local $11 + get_local $11 i32.const 20 i32.shr_s i32.const 1023 i32.sub - tee_local $10 + tee_local $12 i32.const 20 i32.gt_s - tee_local $5 + tee_local $4 select - get_local $10 - i32.sub - set_local $8 - get_local $7 - get_local $12 - get_local $5 + tee_local $7 + i32.const 52 + i32.const 20 + get_local $4 select - tee_local $10 - get_local $8 + get_local $12 + i32.sub + tee_local $9 i32.shr_s - set_local $5 + set_local $4 i32.const 2 - get_local $5 + get_local $4 i32.const 1 i32.and i32.sub i32.const 0 - get_local $5 - get_local $8 + get_local $4 + get_local $9 i32.shl - get_local $10 + get_local $7 i32.eq select else i32.const 0 end end - set_local $14 + set_local $15 end - get_local $7 + get_local $21 i32.eqz if - get_local $12 + get_local $11 i32.const 2146435072 i32.eq if - get_local $4 + get_local $5 i32.const 1072693248 i32.sub get_local $20 i32.or if - get_local $4 + get_local $5 i32.const 1072693248 i32.ge_s if @@ -2997,7 +2996,7 @@ end unreachable end - get_local $12 + get_local $11 i32.const 1072693248 i32.eq if @@ -3042,25 +3041,25 @@ get_local $20 i32.eqz if - get_local $4 - i32.const 2146435072 - i32.eq - tee_local $5 + get_local $5 + i32.eqz + tee_local $4 i32.eqz if - get_local $4 - i32.eqz - set_local $5 + get_local $5 + i32.const 2146435072 + i32.eq + set_local $4 end - get_local $5 + get_local $4 i32.eqz if - get_local $4 + get_local $5 i32.const 1072693248 i32.eq - set_local $5 + set_local $4 end - get_local $5 + get_local $4 if f64.const 1 get_local $2 @@ -3075,16 +3074,16 @@ i32.const 0 i32.lt_s if (result f64) - get_local $4 + get_local $5 i32.const 1072693248 i32.sub - get_local $14 + get_local $15 i32.or if (result f64) get_local $2 f64.neg get_local $2 - get_local $14 + get_local $15 i32.const 1 i32.eq select @@ -3092,8 +3091,8 @@ get_local $2 get_local $2 f64.sub - tee_local $0 - get_local $0 + tee_local $14 + get_local $14 f64.div end else @@ -3103,39 +3102,39 @@ end end f64.const 1 - set_local $11 + set_local $10 get_local $18 i32.const 0 i32.lt_s if - get_local $14 + get_local $15 i32.eqz if get_local $0 get_local $0 f64.sub - tee_local $0 - get_local $0 + tee_local $14 + get_local $14 f64.div return end f64.const -1 f64.const 1 - get_local $14 + get_local $15 i32.const 1 i32.eq select - set_local $11 + set_local $10 end - get_local $12 + get_local $11 i32.const 1105199104 i32.gt_s if (result f64) - get_local $12 + get_local $11 i32.const 1139802112 i32.gt_s if - get_local $4 + get_local $5 i32.const 1072693247 i32.le_s if @@ -3147,7 +3146,7 @@ select return end - get_local $4 + get_local $5 i32.const 1072693248 i32.ge_s if @@ -3160,7 +3159,7 @@ return end end - get_local $4 + get_local $5 i32.const 1072693247 i32.lt_s if @@ -3168,13 +3167,13 @@ i32.const 0 i32.lt_s if (result f64) - get_local $11 + get_local $10 f64.const 1.e+300 f64.mul f64.const 1.e+300 f64.mul else - get_local $11 + get_local $10 f64.const 1e-300 f64.mul f64.const 1e-300 @@ -3182,7 +3181,7 @@ end return end - get_local $4 + get_local $5 i32.const 1072693248 i32.gt_s if @@ -3190,13 +3189,13 @@ i32.const 0 i32.gt_s if (result f64) - get_local $11 + get_local $10 f64.const 1.e+300 f64.mul f64.const 1.e+300 f64.mul else - get_local $11 + get_local $10 f64.const 1e-300 f64.mul f64.const 1e-300 @@ -3234,21 +3233,21 @@ f64.sub tee_local $6 f64.add - set_local $9 + set_local $8 get_local $6 - get_local $9 + get_local $8 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - tee_local $9 + tee_local $8 get_local $16 f64.sub f64.sub else i32.const 0 set_local $7 - get_local $4 + get_local $5 i32.const 1048576 i32.lt_s if (result i32) @@ -3260,32 +3259,32 @@ i64.const 32 i64.shr_u i32.wrap/i64 - set_local $4 + set_local $5 i32.const -53 else i32.const 0 end - get_local $4 + get_local $5 i32.const 20 i32.shr_s i32.const 1023 i32.sub i32.add set_local $7 - get_local $4 + get_local $5 i32.const 1048575 i32.and - tee_local $5 + tee_local $9 i32.const 1072693248 i32.or - set_local $4 - get_local $5 + set_local $5 + get_local $9 i32.const 235662 i32.le_s if (result i32) i32.const 0 else - get_local $5 + get_local $9 i32.const 767610 i32.lt_s if (result i32) @@ -3295,19 +3294,19 @@ i32.const 1 i32.add set_local $7 - get_local $4 + get_local $5 i32.const -1048576 i32.add - set_local $4 + set_local $5 i32.const 0 end end - set_local $10 + set_local $12 get_local $2 i64.reinterpret/f64 i64.const 4294967295 i64.and - get_local $4 + get_local $5 i64.extend_s/i32 i64.const 32 i64.shl @@ -3316,7 +3315,7 @@ tee_local $2 f64.const 1.5 f64.const 1 - get_local $10 + get_local $12 select tee_local $0 f64.sub @@ -3328,16 +3327,16 @@ f64.div tee_local $6 f64.mul - set_local $9 + set_local $14 get_local $2 - get_local $4 + get_local $5 i32.const 1 i32.shr_s i32.const 536870912 i32.or i32.const 524288 i32.add - get_local $10 + get_local $12 i32.const 18 i32.shl i32.add @@ -3345,27 +3344,27 @@ i64.const 32 i64.shl f64.reinterpret/i64 - tee_local $3 + tee_local $8 get_local $0 f64.sub f64.sub set_local $2 - get_local $9 - get_local $9 + get_local $14 + get_local $14 f64.mul - tee_local $15 - get_local $15 + tee_local $3 + get_local $3 f64.mul f64.const 0.5999999999999946 - get_local $15 + get_local $3 f64.const 0.4285714285785502 - get_local $15 + get_local $3 f64.const 0.33333332981837743 - get_local $15 + get_local $3 f64.const 0.272728123808534 - get_local $15 + get_local $3 f64.const 0.23066074577556175 - get_local $15 + get_local $3 f64.const 0.20697501780033842 f64.mul f64.add @@ -3381,13 +3380,13 @@ set_local $19 get_local $6 get_local $16 - get_local $9 + get_local $14 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 tee_local $6 - get_local $3 + get_local $8 f64.mul f64.sub get_local $6 @@ -3400,40 +3399,40 @@ get_local $6 get_local $6 f64.mul - tee_local $15 + tee_local $3 f64.add get_local $19 get_local $0 get_local $6 - get_local $9 + get_local $14 f64.add f64.mul f64.add tee_local $19 f64.add - set_local $3 + set_local $8 get_local $19 - get_local $3 + get_local $8 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - tee_local $3 + tee_local $8 f64.const 3 f64.sub - get_local $15 + get_local $3 f64.sub f64.sub set_local $2 get_local $6 - get_local $3 + get_local $8 f64.mul tee_local $16 get_local $0 - get_local $3 + get_local $8 f64.mul get_local $2 - get_local $9 + get_local $14 f64.mul f64.add tee_local $6 @@ -3463,14 +3462,14 @@ f64.add f64.const 1.350039202129749e-08 f64.const 0 - get_local $10 + get_local $12 select f64.add tee_local $2 f64.add f64.const 0.5849624872207642 f64.const 0 - get_local $10 + get_local $12 select tee_local $0 f64.add @@ -3478,14 +3477,14 @@ f64.convert_s/i32 tee_local $3 f64.add - set_local $9 + set_local $8 get_local $2 - get_local $9 + get_local $8 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - tee_local $9 + tee_local $8 get_local $3 f64.sub get_local $0 @@ -3503,7 +3502,7 @@ f64.reinterpret/i64 tee_local $0 f64.sub - get_local $9 + get_local $8 f64.mul get_local $1 get_local $2 @@ -3511,7 +3510,7 @@ f64.add tee_local $6 get_local $0 - get_local $9 + get_local $8 f64.mul tee_local $0 f64.add @@ -3519,21 +3518,21 @@ i64.reinterpret/f64 tee_local $17 i32.wrap/i64 - set_local $8 + set_local $4 block $folding-inner1 block $folding-inner0 get_local $17 i64.const 32 i64.shr_u i32.wrap/i64 - tee_local $5 + tee_local $9 i32.const 1083179008 i32.ge_s if - get_local $5 + get_local $9 i32.const 1083179008 i32.sub - get_local $8 + get_local $4 i32.or br_if $folding-inner0 get_local $6 @@ -3545,16 +3544,16 @@ f64.gt br_if $folding-inner0 else - get_local $5 + get_local $9 i32.const 2147483647 i32.and i32.const 1083231232 i32.ge_s if - get_local $5 + get_local $9 i32.const -1064252416 i32.sub - get_local $8 + get_local $4 i32.or br_if $folding-inner1 get_local $6 @@ -3565,27 +3564,27 @@ br_if $folding-inner1 end end - get_local $5 + get_local $9 i32.const 2147483647 i32.and - tee_local $8 + tee_local $4 i32.const 20 i32.shr_s i32.const 1023 i32.sub - set_local $10 + set_local $12 i32.const 0 set_local $7 - get_local $8 + get_local $4 i32.const 1071644672 i32.gt_s if i32.const 1048576 - get_local $10 + get_local $12 i32.const 1 i32.add i32.shr_s - get_local $5 + get_local $9 i32.add tee_local $7 i32.const 2147483647 @@ -3594,9 +3593,9 @@ i32.shr_s i32.const 1023 i32.sub - set_local $10 + set_local $12 i32.const 1048575 - get_local $10 + get_local $12 i32.shr_s i32.const -1 i32.xor @@ -3613,7 +3612,7 @@ i32.const 1048576 i32.or i32.const 20 - get_local $10 + get_local $12 i32.sub i32.shr_s set_local $7 @@ -3621,7 +3620,7 @@ get_local $7 i32.sub get_local $7 - get_local $5 + get_local $9 i32.const 0 i32.lt_s select @@ -3659,7 +3658,7 @@ get_local $2 f64.mul set_local $3 - get_local $11 + get_local $10 f64.const 1 get_local $2 get_local $2 @@ -3683,9 +3682,9 @@ f64.add f64.mul f64.sub - tee_local $9 + tee_local $8 f64.mul - get_local $9 + get_local $8 f64.const 2 f64.sub f64.div @@ -3712,7 +3711,7 @@ i32.const 20 i32.shl i32.add - tee_local $5 + tee_local $9 i32.const 20 i32.shr_s i32.const 0 @@ -3726,7 +3725,7 @@ i64.reinterpret/f64 i64.const 4294967295 i64.and - get_local $5 + get_local $9 i64.extend_s/i32 i64.const 32 i64.shl @@ -3736,14 +3735,14 @@ f64.mul return end - get_local $11 + get_local $10 f64.const 1.e+300 f64.mul f64.const 1.e+300 f64.mul return end - get_local $11 + get_local $10 f64.const 1e-300 f64.mul f64.const 1e-300 diff --git a/tests/compiler/std/libm.untouched.wat b/tests/compiler/std/libm.untouched.wat index 3e85fe996e..5920c0a8dc 100644 --- a/tests/compiler/std/libm.untouched.wat +++ b/tests/compiler/std/libm.untouched.wat @@ -1772,7 +1772,6 @@ (local $3 f64) (local $4 f64) (local $5 f64) - (local $6 f64) get_local $0 i64.reinterpret/f64 set_local $1 @@ -1893,14 +1892,12 @@ get_local $5 f64.div set_local $4 - get_local $3 - get_local $3 - f64.add - set_local $6 get_local $4 get_local $3 f64.sub - get_local $6 + f64.const 2 + get_local $3 + f64.mul get_local $4 f64.add f64.div @@ -2381,8 +2378,6 @@ get_local $0 f64.const 8988465674311579538646525e283 f64.mul - set_local $0 - get_local $0 return end get_local $0 @@ -3396,7 +3391,7 @@ (local $11 i32) (local $12 i32) (local $13 i32) - (local $14 f64) + (local $14 i32) (local $15 f64) (local $16 f64) (local $17 f64) @@ -3408,10 +3403,10 @@ (local $23 f64) (local $24 f64) (local $25 f64) - (local $26 i32) - (local $27 i32) - (local $28 f64) - (local $29 f64) + (local $26 f64) + (local $27 f64) + (local $28 i32) + (local $29 i32) (local $30 f64) (local $31 f64) (local $32 f64) @@ -3422,7 +3417,8 @@ (local $37 f64) (local $38 f64) (local $39 f64) - (local $40 i32) + (local $40 f64) + (local $41 i32) get_local $0 i64.reinterpret/f64 set_local $2 @@ -3534,34 +3530,34 @@ i32.const 1023 i32.sub set_local $11 - i32.const 52 - i32.const 20 get_local $11 i32.const 20 i32.gt_s + set_local $9 + i32.const 52 + i32.const 20 + get_local $9 select get_local $11 i32.sub - set_local $9 + set_local $12 get_local $6 get_local $8 - get_local $11 - i32.const 20 - i32.gt_s - select - set_local $12 - get_local $12 get_local $9 - i32.shr_s + select set_local $13 get_local $13 - get_local $9 - i32.shl get_local $12 + i32.shr_s + set_local $14 + get_local $14 + get_local $12 + i32.shl + get_local $13 i32.eq if i32.const 2 - get_local $13 + get_local $14 i32.const 1 i32.and i32.sub @@ -3660,41 +3656,41 @@ end get_local $0 f64.abs - set_local $14 + set_local $15 get_local $4 i32.const 0 i32.eq if get_local $7 - i32.const 2146435072 + i32.const 0 i32.eq - tee_local $13 + tee_local $14 if (result i32) - get_local $13 + get_local $14 else get_local $7 - i32.const 0 + i32.const 2146435072 i32.eq end - tee_local $13 + tee_local $14 if (result i32) - get_local $13 + get_local $14 else get_local $7 i32.const 1072693248 i32.eq end if - get_local $14 - set_local $15 + get_local $15 + set_local $16 get_local $5 i32.const 0 i32.lt_s if f64.const 1 - get_local $15 + get_local $16 f64.div - set_local $15 + set_local $16 end get_local $3 i32.const 0 @@ -3708,31 +3704,31 @@ i32.const 0 i32.eq if - get_local $15 - get_local $15 - f64.sub - get_local $15 - get_local $15 + get_local $16 + get_local $16 f64.sub + set_local $17 + get_local $17 + get_local $17 f64.div - set_local $15 + set_local $16 else get_local $10 i32.const 1 i32.eq if - get_local $15 + get_local $16 f64.neg - set_local $15 + set_local $16 end end end - get_local $15 + get_local $16 return end end f64.const 1 - set_local $16 + set_local $18 get_local $3 i32.const 0 i32.lt_s @@ -3744,9 +3740,9 @@ get_local $0 get_local $0 f64.sub - get_local $0 - get_local $0 - f64.sub + set_local $17 + get_local $17 + get_local $17 f64.div return end @@ -3755,7 +3751,7 @@ i32.eq if f64.const -1 - set_local $16 + set_local $18 end end get_local $8 @@ -3811,13 +3807,13 @@ i32.const 0 i32.lt_s if (result f64) - get_local $16 + get_local $18 f64.const 1.e+300 f64.mul f64.const 1.e+300 f64.mul else - get_local $16 + get_local $18 f64.const 1e-300 f64.mul f64.const 1e-300 @@ -3833,13 +3829,13 @@ i32.const 0 i32.gt_s if (result f64) - get_local $16 + get_local $18 f64.const 1.e+300 f64.mul f64.const 1.e+300 f64.mul else - get_local $16 + get_local $18 f64.const 1e-300 f64.mul f64.const 1e-300 @@ -3847,98 +3843,98 @@ end return end - get_local $14 + get_local $15 f64.const 1 f64.sub - set_local $22 - get_local $22 - get_local $22 + set_local $24 + get_local $24 + get_local $24 f64.mul f64.const 0.5 - get_local $22 + get_local $24 f64.const 0.3333333333333333 - get_local $22 + get_local $24 f64.const 0.25 f64.mul f64.sub f64.mul f64.sub f64.mul - set_local $25 + set_local $27 f64.const 1.4426950216293335 - get_local $22 + get_local $24 f64.mul - set_local $23 - get_local $22 + set_local $25 + get_local $24 f64.const 1.9259629911266175e-08 f64.mul - get_local $25 + get_local $27 f64.const 1.4426950408889634 f64.mul f64.sub - set_local $24 - get_local $23 - get_local $24 + set_local $26 + get_local $25 + get_local $26 f64.add - set_local $17 - get_local $17 + set_local $19 + get_local $19 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - set_local $17 - get_local $24 - get_local $17 - get_local $23 + set_local $19 + get_local $26 + get_local $19 + get_local $25 f64.sub f64.sub - set_local $18 + set_local $20 else i32.const 0 - set_local $27 + set_local $29 get_local $7 i32.const 1048576 i32.lt_s if - get_local $14 + get_local $15 f64.const 9007199254740992 f64.mul - set_local $14 - get_local $27 + set_local $15 + get_local $29 i32.const 53 i32.sub - set_local $27 - get_local $14 + set_local $29 + get_local $15 i64.reinterpret/f64 i64.const 32 i64.shr_u i32.wrap/i64 set_local $7 end - get_local $27 + get_local $29 get_local $7 i32.const 20 i32.shr_s i32.const 1023 i32.sub i32.add - set_local $27 + set_local $29 get_local $7 i32.const 1048575 i32.and - set_local $26 - get_local $26 + set_local $28 + get_local $28 i32.const 1072693248 i32.or set_local $7 - get_local $26 + get_local $28 i32.const 235662 i32.le_s if i32.const 0 set_local $11 else - get_local $26 + get_local $28 i32.const 767610 i32.lt_s if @@ -3947,17 +3943,17 @@ else i32.const 0 set_local $11 - get_local $27 + get_local $29 i32.const 1 i32.add - set_local $27 + set_local $29 get_local $7 i32.const 1048576 i32.sub set_local $7 end end - get_local $14 + get_local $15 i64.reinterpret/f64 i64.const 4294967295 i64.and @@ -3967,34 +3963,34 @@ i64.shl i64.or f64.reinterpret/i64 - set_local $14 + set_local $15 f64.const 1.5 f64.const 1 get_local $11 select - set_local $34 - get_local $14 - get_local $34 + set_local $35 + get_local $15 + get_local $35 f64.sub - set_local $23 + set_local $25 f64.const 1 - get_local $14 - get_local $34 + get_local $15 + get_local $35 f64.add f64.div - set_local $24 - get_local $23 - get_local $24 + set_local $26 + get_local $25 + get_local $26 f64.mul - set_local $28 - get_local $28 - set_local $30 - get_local $30 + set_local $17 + get_local $17 + set_local $31 + get_local $31 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - set_local $30 + set_local $31 get_local $7 i32.const 1 i32.shr_s @@ -4010,42 +4006,42 @@ i64.const 32 i64.shl f64.reinterpret/i64 - set_local $32 - get_local $14 - get_local $32 - get_local $34 + set_local $33 + get_local $15 + get_local $33 + get_local $35 f64.sub f64.sub - set_local $33 - get_local $24 - get_local $23 - get_local $30 - get_local $32 + set_local $34 + get_local $26 + get_local $25 + get_local $31 + get_local $33 f64.mul f64.sub - get_local $30 - get_local $33 + get_local $31 + get_local $34 f64.mul f64.sub f64.mul - set_local $31 - get_local $28 - get_local $28 + set_local $32 + get_local $17 + get_local $17 f64.mul - set_local $29 - get_local $29 - get_local $29 + set_local $30 + get_local $30 + get_local $30 f64.mul f64.const 0.5999999999999946 - get_local $29 + get_local $30 f64.const 0.4285714285785502 - get_local $29 + get_local $30 f64.const 0.33333332981837743 - get_local $29 + get_local $30 f64.const 0.272728123808534 - get_local $29 + get_local $30 f64.const 0.23066074577556175 - get_local $29 + get_local $30 f64.const 0.20697501780033842 f64.mul f64.add @@ -4058,184 +4054,184 @@ f64.mul f64.add f64.mul - set_local $21 - get_local $21 + set_local $23 + get_local $23 + get_local $32 get_local $31 - get_local $30 - get_local $28 + get_local $17 f64.add f64.mul f64.add - set_local $21 - get_local $30 - get_local $30 + set_local $23 + get_local $31 + get_local $31 f64.mul - set_local $29 + set_local $30 f64.const 3 - get_local $29 + get_local $30 f64.add - get_local $21 + get_local $23 f64.add - set_local $32 - get_local $32 + set_local $33 + get_local $33 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - set_local $32 - get_local $21 - get_local $32 + set_local $33 + get_local $23 + get_local $33 f64.const 3 f64.sub - get_local $29 + get_local $30 f64.sub f64.sub - set_local $33 - get_local $30 - get_local $32 - f64.mul - set_local $23 + set_local $34 get_local $31 - get_local $32 + get_local $33 f64.mul + set_local $25 + get_local $32 get_local $33 - get_local $28 + f64.mul + get_local $34 + get_local $17 f64.mul f64.add - set_local $24 - get_local $23 - get_local $24 + set_local $26 + get_local $25 + get_local $26 f64.add - set_local $19 - get_local $19 + set_local $21 + get_local $21 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - set_local $19 - get_local $24 - get_local $19 - get_local $23 + set_local $21 + get_local $26 + get_local $21 + get_local $25 f64.sub f64.sub - set_local $20 + set_local $22 f64.const 0.9617967009544373 - get_local $19 + get_local $21 f64.mul - set_local $35 + set_local $36 f64.const 1.350039202129749e-08 f64.const 0 get_local $11 select - set_local $36 + set_local $37 f64.const -7.028461650952758e-09 - get_local $19 + get_local $21 f64.mul - get_local $20 + get_local $22 f64.const 0.9617966939259756 f64.mul f64.add - get_local $36 + get_local $37 f64.add - set_local $37 - get_local $27 + set_local $38 + get_local $29 f64.convert_s/i32 - set_local $22 + set_local $24 f64.const 0.5849624872207642 f64.const 0 get_local $11 select - set_local $38 - get_local $35 - get_local $37 - f64.add + set_local $39 + get_local $36 get_local $38 f64.add - get_local $22 + get_local $39 f64.add - set_local $17 - get_local $17 + get_local $24 + f64.add + set_local $19 + get_local $19 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - set_local $17 - get_local $37 - get_local $17 - get_local $22 - f64.sub + set_local $19 get_local $38 + get_local $19 + get_local $24 f64.sub - get_local $35 + get_local $39 + f64.sub + get_local $36 f64.sub f64.sub - set_local $18 + set_local $20 end get_local $1 - set_local $39 - get_local $39 + set_local $40 + get_local $40 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - set_local $39 + set_local $40 get_local $1 - get_local $39 + get_local $40 f64.sub - get_local $17 + get_local $19 f64.mul get_local $1 - get_local $18 + get_local $20 f64.mul f64.add - set_local $20 - get_local $39 - get_local $17 - f64.mul - set_local $19 - get_local $20 + set_local $22 + get_local $40 get_local $19 + f64.mul + set_local $21 + get_local $22 + get_local $21 f64.add - set_local $15 - get_local $15 + set_local $16 + get_local $16 i64.reinterpret/f64 set_local $2 get_local $2 i64.const 32 i64.shr_u i32.wrap/i64 - set_local $26 + set_local $28 get_local $2 i32.wrap/i64 - set_local $40 - get_local $26 + set_local $41 + get_local $28 i32.const 1083179008 i32.ge_s if - get_local $26 + get_local $28 i32.const 1083179008 i32.sub - get_local $40 + get_local $41 i32.or i32.const 0 i32.ne if - get_local $16 + get_local $18 f64.const 1.e+300 f64.mul f64.const 1.e+300 f64.mul return end - get_local $20 + get_local $22 f64.const 8.008566259537294e-17 f64.add - get_local $15 - get_local $19 + get_local $16 + get_local $21 f64.sub f64.gt if - get_local $16 + get_local $18 f64.const 1.e+300 f64.mul f64.const 1.e+300 @@ -4243,34 +4239,34 @@ return end else - get_local $26 + get_local $28 i32.const 2147483647 i32.and i32.const 1083231232 i32.ge_s if - get_local $26 + get_local $28 i32.const -1064252416 i32.sub - get_local $40 + get_local $41 i32.or i32.const 0 i32.ne if - get_local $16 + get_local $18 f64.const 1e-300 f64.mul f64.const 1e-300 f64.mul return end - get_local $20 - get_local $15 - get_local $19 + get_local $22 + get_local $16 + get_local $21 f64.sub f64.le if - get_local $16 + get_local $18 f64.const 1e-300 f64.mul f64.const 1e-300 @@ -4279,31 +4275,31 @@ end end end - get_local $26 + get_local $28 i32.const 2147483647 i32.and - set_local $40 - get_local $40 + set_local $41 + get_local $41 i32.const 20 i32.shr_s i32.const 1023 i32.sub set_local $11 i32.const 0 - set_local $27 - get_local $40 + set_local $29 + get_local $41 i32.const 1071644672 i32.gt_s if - get_local $26 + get_local $28 i32.const 1048576 get_local $11 i32.const 1 i32.add i32.shr_s i32.add - set_local $27 - get_local $27 + set_local $29 + get_local $29 i32.const 2147483647 i32.and i32.const 20 @@ -4312,8 +4308,8 @@ i32.sub set_local $11 f64.const 0 - set_local $22 - get_local $27 + set_local $24 + get_local $29 i32.const 1048575 get_local $11 i32.shr_s @@ -4324,8 +4320,8 @@ i64.const 32 i64.shl f64.reinterpret/i64 - set_local $22 - get_local $27 + set_local $24 + get_local $29 i32.const 1048575 i32.and i32.const 1048576 @@ -4334,71 +4330,71 @@ get_local $11 i32.sub i32.shr_s - set_local $27 - get_local $26 + set_local $29 + get_local $28 i32.const 0 i32.lt_s if i32.const 0 - get_local $27 + get_local $29 i32.sub - set_local $27 + set_local $29 end - get_local $19 - get_local $22 + get_local $21 + get_local $24 f64.sub - set_local $19 + set_local $21 end - get_local $20 - get_local $19 - f64.add - set_local $22 get_local $22 + get_local $21 + f64.add + set_local $24 + get_local $24 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - set_local $22 - get_local $22 + set_local $24 + get_local $24 f64.const 0.6931471824645996 f64.mul - set_local $23 - get_local $20 + set_local $25 get_local $22 - get_local $19 + get_local $24 + get_local $21 f64.sub f64.sub f64.const 0.6931471805599453 f64.mul - get_local $22 + get_local $24 f64.const -1.904654299957768e-09 f64.mul f64.add - set_local $24 - get_local $23 - get_local $24 + set_local $26 + get_local $25 + get_local $26 f64.add - set_local $15 - get_local $24 - get_local $15 - get_local $23 + set_local $16 + get_local $26 + get_local $16 + get_local $25 f64.sub f64.sub - set_local $25 - get_local $15 - get_local $15 + set_local $27 + get_local $16 + get_local $16 f64.mul - set_local $22 - get_local $15 - get_local $22 + set_local $24 + get_local $16 + get_local $24 f64.const 0.16666666666666602 - get_local $22 + get_local $24 f64.const -2.7777777777015593e-03 - get_local $22 + get_local $24 f64.const 6.613756321437934e-05 - get_local $22 + get_local $24 f64.const -1.6533902205465252e-06 - get_local $22 + get_local $24 f64.const 4.1381367970572385e-08 f64.mul f64.add @@ -4410,64 +4406,64 @@ f64.add f64.mul f64.sub - set_local $17 - get_local $15 - get_local $17 + set_local $19 + get_local $16 + get_local $19 f64.mul - get_local $17 + get_local $19 f64.const 2 f64.sub f64.div - get_local $25 - get_local $15 - get_local $25 + get_local $27 + get_local $16 + get_local $27 f64.mul f64.add f64.sub - set_local $21 + set_local $23 f64.const 1 - get_local $21 - get_local $15 + get_local $23 + get_local $16 f64.sub f64.sub - set_local $15 - get_local $15 + set_local $16 + get_local $16 i64.reinterpret/f64 i64.const 32 i64.shr_u i32.wrap/i64 - set_local $26 - get_local $26 - get_local $27 + set_local $28 + get_local $28 + get_local $29 i32.const 20 i32.shl i32.add - set_local $26 - get_local $26 + set_local $28 + get_local $28 i32.const 20 i32.shr_s i32.const 0 i32.le_s if - get_local $15 - get_local $27 + get_local $16 + get_local $29 call $~lib/math/NativeMath.scalbn - set_local $15 + set_local $16 else - get_local $15 + get_local $16 i64.reinterpret/f64 i64.const 4294967295 i64.and - get_local $26 + get_local $28 i64.extend_s/i32 i64.const 32 i64.shl i64.or f64.reinterpret/i64 - set_local $15 + set_local $16 end + get_local $18 get_local $16 - get_local $15 f64.mul ) (func $std/libm/pow (; 47 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) diff --git a/tests/compiler/std/math.optimized.wat b/tests/compiler/std/math.optimized.wat index 228c54ea9d..195ec166f1 100644 --- a/tests/compiler/std/math.optimized.wat +++ b/tests/compiler/std/math.optimized.wat @@ -3292,6 +3292,7 @@ f64.div f64.mul set_local $2 + get_local $0 get_local $1 f64.const 1.87595182427177 get_local $2 @@ -3324,18 +3325,16 @@ tee_local $1 get_local $1 f64.mul + f64.div set_local $2 get_local $1 get_local $1 - get_local $0 get_local $2 - f64.div - tee_local $2 get_local $1 f64.sub + f64.const 2 get_local $1 - get_local $1 - f64.add + f64.mul get_local $2 f64.add f64.div @@ -6178,19 +6177,20 @@ (local $5 i32) (local $6 f64) (local $7 i32) - (local $8 i32) - (local $9 f64) - (local $10 i32) - (local $11 f64) + (local $8 f64) + (local $9 i32) + (local $10 f64) + (local $11 i32) (local $12 i32) (local $13 i32) - (local $14 i32) - (local $15 f64) + (local $14 f64) + (local $15 i32) (local $16 f64) (local $17 i64) (local $18 i32) (local $19 f64) (local $20 i32) + (local $21 i32) get_local $0 i64.reinterpret/f64 tee_local $17 @@ -6204,7 +6204,7 @@ get_local $18 i32.const 2147483647 i32.and - set_local $4 + set_local $5 get_local $1 i64.reinterpret/f64 tee_local $17 @@ -6214,57 +6214,57 @@ tee_local $13 i32.const 2147483647 i32.and - set_local $12 - get_local $12 + set_local $11 + get_local $11 get_local $17 i32.wrap/i64 - tee_local $7 + tee_local $21 i32.or i32.eqz if f64.const 1 return end - get_local $4 + get_local $5 i32.const 2146435072 i32.gt_s - tee_local $8 + tee_local $4 i32.eqz if - get_local $4 + get_local $5 i32.const 2146435072 i32.eq - tee_local $8 + tee_local $4 if get_local $20 i32.const 0 i32.ne - set_local $8 + set_local $4 end end - get_local $8 + get_local $4 i32.eqz if - get_local $12 + get_local $11 i32.const 2146435072 i32.gt_s - set_local $8 + set_local $4 end - get_local $8 + get_local $4 i32.eqz if - get_local $12 + get_local $11 i32.const 2146435072 i32.eq - tee_local $8 + tee_local $4 if - get_local $7 + get_local $21 i32.const 0 i32.ne - set_local $8 + set_local $4 end end - get_local $8 + get_local $4 if get_local $0 get_local $1 @@ -6275,71 +6275,70 @@ i32.const 0 i32.lt_s if - get_local $12 + get_local $11 i32.const 1128267776 i32.ge_s if (result i32) i32.const 2 else - get_local $12 + get_local $11 i32.const 1072693248 i32.ge_s if (result i32) - i32.const 52 - i32.const 20 - get_local $12 + get_local $21 + get_local $11 + get_local $11 i32.const 20 i32.shr_s i32.const 1023 i32.sub - tee_local $10 + tee_local $12 i32.const 20 i32.gt_s - tee_local $5 + tee_local $4 select - get_local $10 - i32.sub - set_local $8 - get_local $7 - get_local $12 - get_local $5 + tee_local $7 + i32.const 52 + i32.const 20 + get_local $4 select - tee_local $10 - get_local $8 + get_local $12 + i32.sub + tee_local $9 i32.shr_s - set_local $5 + set_local $4 i32.const 2 - get_local $5 + get_local $4 i32.const 1 i32.and i32.sub i32.const 0 - get_local $5 - get_local $8 + get_local $4 + get_local $9 i32.shl - get_local $10 + get_local $7 i32.eq select else i32.const 0 end end - set_local $14 + set_local $15 end - get_local $7 + get_local $21 i32.eqz if - get_local $12 + get_local $11 i32.const 2146435072 i32.eq if - get_local $4 + get_local $5 i32.const 1072693248 i32.sub get_local $20 i32.or if - get_local $4 + get_local $5 i32.const 1072693248 i32.ge_s if @@ -6369,7 +6368,7 @@ end unreachable end - get_local $12 + get_local $11 i32.const 1072693248 i32.eq if @@ -6414,25 +6413,25 @@ get_local $20 i32.eqz if - get_local $4 - i32.const 2146435072 - i32.eq - tee_local $5 + get_local $5 + i32.eqz + tee_local $4 i32.eqz if - get_local $4 - i32.eqz - set_local $5 + get_local $5 + i32.const 2146435072 + i32.eq + set_local $4 end - get_local $5 + get_local $4 i32.eqz if - get_local $4 + get_local $5 i32.const 1072693248 i32.eq - set_local $5 + set_local $4 end - get_local $5 + get_local $4 if f64.const 1 get_local $2 @@ -6447,16 +6446,16 @@ i32.const 0 i32.lt_s if (result f64) - get_local $4 + get_local $5 i32.const 1072693248 i32.sub - get_local $14 + get_local $15 i32.or if (result f64) get_local $2 f64.neg get_local $2 - get_local $14 + get_local $15 i32.const 1 i32.eq select @@ -6464,8 +6463,8 @@ get_local $2 get_local $2 f64.sub - tee_local $0 - get_local $0 + tee_local $14 + get_local $14 f64.div end else @@ -6475,39 +6474,39 @@ end end f64.const 1 - set_local $11 + set_local $10 get_local $18 i32.const 0 i32.lt_s if - get_local $14 + get_local $15 i32.eqz if get_local $0 get_local $0 f64.sub - tee_local $0 - get_local $0 + tee_local $14 + get_local $14 f64.div return end f64.const -1 f64.const 1 - get_local $14 + get_local $15 i32.const 1 i32.eq select - set_local $11 + set_local $10 end - get_local $12 + get_local $11 i32.const 1105199104 i32.gt_s if (result f64) - get_local $12 + get_local $11 i32.const 1139802112 i32.gt_s if - get_local $4 + get_local $5 i32.const 1072693247 i32.le_s if @@ -6519,7 +6518,7 @@ select return end - get_local $4 + get_local $5 i32.const 1072693248 i32.ge_s if @@ -6532,7 +6531,7 @@ return end end - get_local $4 + get_local $5 i32.const 1072693247 i32.lt_s if @@ -6540,13 +6539,13 @@ i32.const 0 i32.lt_s if (result f64) - get_local $11 + get_local $10 f64.const 1.e+300 f64.mul f64.const 1.e+300 f64.mul else - get_local $11 + get_local $10 f64.const 1e-300 f64.mul f64.const 1e-300 @@ -6554,7 +6553,7 @@ end return end - get_local $4 + get_local $5 i32.const 1072693248 i32.gt_s if @@ -6562,13 +6561,13 @@ i32.const 0 i32.gt_s if (result f64) - get_local $11 + get_local $10 f64.const 1.e+300 f64.mul f64.const 1.e+300 f64.mul else - get_local $11 + get_local $10 f64.const 1e-300 f64.mul f64.const 1e-300 @@ -6606,21 +6605,21 @@ f64.sub tee_local $6 f64.add - set_local $9 + set_local $8 get_local $6 - get_local $9 + get_local $8 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - tee_local $9 + tee_local $8 get_local $16 f64.sub f64.sub else i32.const 0 set_local $7 - get_local $4 + get_local $5 i32.const 1048576 i32.lt_s if (result i32) @@ -6632,32 +6631,32 @@ i64.const 32 i64.shr_u i32.wrap/i64 - set_local $4 + set_local $5 i32.const -53 else i32.const 0 end - get_local $4 + get_local $5 i32.const 20 i32.shr_s i32.const 1023 i32.sub i32.add set_local $7 - get_local $4 + get_local $5 i32.const 1048575 i32.and - tee_local $5 + tee_local $9 i32.const 1072693248 i32.or - set_local $4 - get_local $5 + set_local $5 + get_local $9 i32.const 235662 i32.le_s if (result i32) i32.const 0 else - get_local $5 + get_local $9 i32.const 767610 i32.lt_s if (result i32) @@ -6667,19 +6666,19 @@ i32.const 1 i32.add set_local $7 - get_local $4 + get_local $5 i32.const -1048576 i32.add - set_local $4 + set_local $5 i32.const 0 end end - set_local $10 + set_local $12 get_local $2 i64.reinterpret/f64 i64.const 4294967295 i64.and - get_local $4 + get_local $5 i64.extend_s/i32 i64.const 32 i64.shl @@ -6688,7 +6687,7 @@ tee_local $2 f64.const 1.5 f64.const 1 - get_local $10 + get_local $12 select tee_local $0 f64.sub @@ -6700,16 +6699,16 @@ f64.div tee_local $6 f64.mul - set_local $9 + set_local $14 get_local $2 - get_local $4 + get_local $5 i32.const 1 i32.shr_s i32.const 536870912 i32.or i32.const 524288 i32.add - get_local $10 + get_local $12 i32.const 18 i32.shl i32.add @@ -6717,27 +6716,27 @@ i64.const 32 i64.shl f64.reinterpret/i64 - tee_local $3 + tee_local $8 get_local $0 f64.sub f64.sub set_local $2 - get_local $9 - get_local $9 + get_local $14 + get_local $14 f64.mul - tee_local $15 - get_local $15 + tee_local $3 + get_local $3 f64.mul f64.const 0.5999999999999946 - get_local $15 + get_local $3 f64.const 0.4285714285785502 - get_local $15 + get_local $3 f64.const 0.33333332981837743 - get_local $15 + get_local $3 f64.const 0.272728123808534 - get_local $15 + get_local $3 f64.const 0.23066074577556175 - get_local $15 + get_local $3 f64.const 0.20697501780033842 f64.mul f64.add @@ -6753,13 +6752,13 @@ set_local $19 get_local $6 get_local $16 - get_local $9 + get_local $14 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 tee_local $6 - get_local $3 + get_local $8 f64.mul f64.sub get_local $6 @@ -6772,40 +6771,40 @@ get_local $6 get_local $6 f64.mul - tee_local $15 + tee_local $3 f64.add get_local $19 get_local $0 get_local $6 - get_local $9 + get_local $14 f64.add f64.mul f64.add tee_local $19 f64.add - set_local $3 + set_local $8 get_local $19 - get_local $3 + get_local $8 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - tee_local $3 + tee_local $8 f64.const 3 f64.sub - get_local $15 + get_local $3 f64.sub f64.sub set_local $2 get_local $6 - get_local $3 + get_local $8 f64.mul tee_local $16 get_local $0 - get_local $3 + get_local $8 f64.mul get_local $2 - get_local $9 + get_local $14 f64.mul f64.add tee_local $6 @@ -6835,14 +6834,14 @@ f64.add f64.const 1.350039202129749e-08 f64.const 0 - get_local $10 + get_local $12 select f64.add tee_local $2 f64.add f64.const 0.5849624872207642 f64.const 0 - get_local $10 + get_local $12 select tee_local $0 f64.add @@ -6850,14 +6849,14 @@ f64.convert_s/i32 tee_local $3 f64.add - set_local $9 + set_local $8 get_local $2 - get_local $9 + get_local $8 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - tee_local $9 + tee_local $8 get_local $3 f64.sub get_local $0 @@ -6875,7 +6874,7 @@ f64.reinterpret/i64 tee_local $0 f64.sub - get_local $9 + get_local $8 f64.mul get_local $1 get_local $2 @@ -6883,7 +6882,7 @@ f64.add tee_local $6 get_local $0 - get_local $9 + get_local $8 f64.mul tee_local $0 f64.add @@ -6891,21 +6890,21 @@ i64.reinterpret/f64 tee_local $17 i32.wrap/i64 - set_local $8 + set_local $4 block $folding-inner1 block $folding-inner0 get_local $17 i64.const 32 i64.shr_u i32.wrap/i64 - tee_local $5 + tee_local $9 i32.const 1083179008 i32.ge_s if - get_local $5 + get_local $9 i32.const 1083179008 i32.sub - get_local $8 + get_local $4 i32.or br_if $folding-inner0 get_local $6 @@ -6917,16 +6916,16 @@ f64.gt br_if $folding-inner0 else - get_local $5 + get_local $9 i32.const 2147483647 i32.and i32.const 1083231232 i32.ge_s if - get_local $5 + get_local $9 i32.const -1064252416 i32.sub - get_local $8 + get_local $4 i32.or br_if $folding-inner1 get_local $6 @@ -6937,27 +6936,27 @@ br_if $folding-inner1 end end - get_local $5 + get_local $9 i32.const 2147483647 i32.and - tee_local $8 + tee_local $4 i32.const 20 i32.shr_s i32.const 1023 i32.sub - set_local $10 + set_local $12 i32.const 0 set_local $7 - get_local $8 + get_local $4 i32.const 1071644672 i32.gt_s if i32.const 1048576 - get_local $10 + get_local $12 i32.const 1 i32.add i32.shr_s - get_local $5 + get_local $9 i32.add tee_local $7 i32.const 2147483647 @@ -6966,9 +6965,9 @@ i32.shr_s i32.const 1023 i32.sub - set_local $10 + set_local $12 i32.const 1048575 - get_local $10 + get_local $12 i32.shr_s i32.const -1 i32.xor @@ -6985,7 +6984,7 @@ i32.const 1048576 i32.or i32.const 20 - get_local $10 + get_local $12 i32.sub i32.shr_s set_local $7 @@ -6993,7 +6992,7 @@ get_local $7 i32.sub get_local $7 - get_local $5 + get_local $9 i32.const 0 i32.lt_s select @@ -7031,7 +7030,7 @@ get_local $2 f64.mul set_local $3 - get_local $11 + get_local $10 f64.const 1 get_local $2 get_local $2 @@ -7055,9 +7054,9 @@ f64.add f64.mul f64.sub - tee_local $9 + tee_local $8 f64.mul - get_local $9 + get_local $8 f64.const 2 f64.sub f64.div @@ -7084,7 +7083,7 @@ i32.const 20 i32.shl i32.add - tee_local $5 + tee_local $9 i32.const 20 i32.shr_s i32.const 0 @@ -7098,7 +7097,7 @@ i64.reinterpret/f64 i64.const 4294967295 i64.and - get_local $5 + get_local $9 i64.extend_s/i32 i64.const 32 i64.shl @@ -7108,14 +7107,14 @@ f64.mul return end - get_local $11 + get_local $10 f64.const 1.e+300 f64.mul f64.const 1.e+300 f64.mul return end - get_local $11 + get_local $10 f64.const 1e-300 f64.mul f64.const 1e-300 @@ -7152,9 +7151,9 @@ (local $9 f32) (local $10 f32) (local $11 f32) - (local $12 i32) + (local $12 f32) (local $13 i32) - (local $14 f32) + (local $14 i32) (local $15 f32) (local $16 f32) (local $17 f32) @@ -7166,10 +7165,10 @@ set_local $6 get_local $1 i32.reinterpret/f32 - tee_local $13 + tee_local $14 i32.const 2147483647 i32.and - tee_local $12 + tee_local $13 i32.eqz if f32.const 1 @@ -7181,7 +7180,7 @@ tee_local $5 i32.eqz if - get_local $12 + get_local $13 i32.const 2139095040 i32.gt_s set_local $5 @@ -7197,19 +7196,19 @@ i32.const 0 i32.lt_s if - get_local $12 + get_local $13 i32.const 1266679808 i32.ge_s if (result i32) i32.const 2 else - get_local $12 + get_local $13 i32.const 1065353216 i32.ge_s if (result i32) - get_local $12 + get_local $13 i32.const 150 - get_local $12 + get_local $13 i32.const 23 i32.shr_s i32.sub @@ -7218,7 +7217,7 @@ tee_local $8 get_local $5 i32.shl - get_local $12 + get_local $13 i32.eq if (result i32) i32.const 2 @@ -7235,7 +7234,7 @@ end set_local $4 end - get_local $12 + get_local $13 i32.const 2139095040 i32.eq if @@ -7250,7 +7249,7 @@ i32.const 1065353216 i32.gt_s if - get_local $13 + get_local $14 i32.const 0 i32.lt_s if @@ -7263,7 +7262,7 @@ f32.const 0 get_local $1 f32.neg - get_local $13 + get_local $14 i32.const 0 i32.ge_s select @@ -7273,11 +7272,11 @@ end unreachable end - get_local $12 + get_local $13 i32.const 1065353216 i32.eq if - get_local $13 + get_local $14 i32.const 0 i32.lt_s if @@ -7289,7 +7288,7 @@ get_local $0 return end - get_local $13 + get_local $14 i32.const 1073741824 i32.eq if @@ -7298,7 +7297,7 @@ f32.mul return end - get_local $13 + get_local $14 i32.const 1056964608 i32.eq if @@ -7338,7 +7337,7 @@ get_local $2 f32.div get_local $2 - get_local $13 + get_local $14 i32.const 0 i32.lt_s select @@ -7364,8 +7363,8 @@ get_local $2 get_local $2 f32.sub - tee_local $0 - get_local $0 + tee_local $9 + get_local $9 f32.div end else @@ -7374,7 +7373,7 @@ return end f32.const 1 - set_local $9 + set_local $10 get_local $7 i32.const 0 i32.lt_s @@ -7385,8 +7384,8 @@ get_local $0 get_local $0 f32.sub - tee_local $0 - get_local $0 + tee_local $9 + get_local $9 f32.div return end @@ -7396,9 +7395,9 @@ i32.const 1 i32.eq select - set_local $9 + set_local $10 end - get_local $12 + get_local $13 i32.const 1291845632 i32.gt_s if (result f32) @@ -7406,17 +7405,17 @@ i32.const 1065353208 i32.lt_s if - get_local $13 + get_local $14 i32.const 0 i32.lt_s if (result f32) - get_local $9 + get_local $10 f32.const 1000000015047466219876688e6 f32.mul f32.const 1000000015047466219876688e6 f32.mul else - get_local $9 + get_local $10 f32.const 1.0000000031710769e-30 f32.mul f32.const 1.0000000031710769e-30 @@ -7428,17 +7427,17 @@ i32.const 1065353223 i32.gt_s if - get_local $13 + get_local $14 i32.const 0 i32.gt_s if (result f32) - get_local $9 + get_local $10 f32.const 1000000015047466219876688e6 f32.mul f32.const 1000000015047466219876688e6 f32.mul else - get_local $9 + get_local $10 f32.const 1.0000000031710769e-30 f32.mul f32.const 1.0000000031710769e-30 @@ -7483,7 +7482,7 @@ i32.const -4096 i32.and f32.reinterpret/i32 - tee_local $11 + tee_local $12 get_local $15 f32.sub f32.sub @@ -7558,7 +7557,7 @@ f32.div tee_local $16 f32.mul - tee_local $10 + tee_local $11 i32.reinterpret/f32 i32.const -4096 i32.and @@ -7579,27 +7578,27 @@ i32.shl i32.add f32.reinterpret/i32 - tee_local $11 + tee_local $12 get_local $0 f32.sub f32.sub set_local $2 - get_local $10 - get_local $10 + get_local $11 + get_local $11 f32.mul - tee_local $14 - get_local $14 + tee_local $9 + get_local $9 f32.mul f32.const 0.6000000238418579 - get_local $14 + get_local $9 f32.const 0.4285714328289032 - get_local $14 + get_local $9 f32.const 0.3333333432674408 - get_local $14 + get_local $9 f32.const 0.2727281153202057 - get_local $14 + get_local $9 f32.const 0.23066075146198273 - get_local $14 + get_local $9 f32.const 0.20697501301765442 f32.mul f32.add @@ -7617,13 +7616,13 @@ get_local $3 get_local $3 f32.mul - tee_local $14 + tee_local $9 f32.add get_local $17 get_local $16 get_local $15 get_local $3 - get_local $11 + get_local $12 f32.mul f32.sub get_local $3 @@ -7633,7 +7632,7 @@ f32.mul tee_local $0 get_local $3 - get_local $10 + get_local $11 f32.add f32.mul f32.add @@ -7646,22 +7645,22 @@ i32.const -4096 i32.and f32.reinterpret/i32 - tee_local $11 + tee_local $12 f32.const 3 f32.sub - get_local $14 + get_local $9 f32.sub f32.sub set_local $2 get_local $3 - get_local $11 + get_local $12 f32.mul tee_local $15 get_local $0 - get_local $11 + get_local $12 f32.mul get_local $2 - get_local $10 + get_local $11 f32.mul f32.add tee_local $16 @@ -7677,7 +7676,7 @@ get_local $15 f32.sub f32.sub - set_local $10 + set_local $11 f32.const 0.9619140625 get_local $0 f32.mul @@ -7685,7 +7684,7 @@ f32.const -1.1736857413779944e-04 get_local $0 f32.mul - get_local $10 + get_local $11 f32.const 0.9617967009544373 f32.mul f32.add @@ -7713,7 +7712,7 @@ i32.const -4096 i32.and f32.reinterpret/i32 - tee_local $11 + tee_local $12 get_local $3 f32.sub get_local $0 @@ -7732,15 +7731,15 @@ f32.reinterpret/i32 tee_local $0 f32.sub - get_local $11 + get_local $12 f32.mul get_local $1 get_local $2 f32.mul f32.add - tee_local $10 + tee_local $11 get_local $0 - get_local $11 + get_local $12 f32.mul tee_local $0 f32.add @@ -7755,7 +7754,7 @@ i32.const 1124073472 i32.eq if - get_local $10 + get_local $11 f32.const 4.299566569443414e-08 f32.add get_local $2 @@ -7776,7 +7775,7 @@ i32.const -1021968384 i32.eq if - get_local $10 + get_local $11 get_local $2 get_local $0 f32.sub @@ -7848,7 +7847,7 @@ f32.sub set_local $0 end - get_local $10 + get_local $11 get_local $0 f32.add i32.reinterpret/f32 @@ -7859,7 +7858,7 @@ f32.const 0.693145751953125 f32.mul tee_local $15 - get_local $10 + get_local $11 get_local $3 get_local $0 f32.sub @@ -7876,7 +7875,7 @@ get_local $2 f32.mul set_local $3 - get_local $9 + get_local $10 f32.const 1 get_local $2 get_local $2 @@ -7900,9 +7899,9 @@ f32.add f32.mul f32.sub - tee_local $11 + tee_local $12 f32.mul - get_local $11 + get_local $12 f32.const 2 f32.sub f32.div @@ -7942,14 +7941,14 @@ f32.mul return end - get_local $9 + get_local $10 f32.const 1.0000000031710769e-30 f32.mul f32.const 1.0000000031710769e-30 f32.mul return end - get_local $9 + get_local $10 f32.const 1000000015047466219876688e6 f32.mul f32.const 1000000015047466219876688e6 @@ -8002,7 +8001,7 @@ if i32.const 0 i32.const 40 - i32.const 959 + i32.const 961 i32.const 4 call $~lib/env/abort unreachable @@ -8068,7 +8067,7 @@ if i32.const 0 i32.const 40 - i32.const 968 + i32.const 970 i32.const 24 call $~lib/env/abort unreachable @@ -8115,7 +8114,7 @@ if i32.const 0 i32.const 40 - i32.const 2029 + i32.const 2041 i32.const 24 call $~lib/env/abort unreachable diff --git a/tests/compiler/std/math.untouched.wat b/tests/compiler/std/math.untouched.wat index 8eeaaf96ee..7d44b9d2a2 100644 --- a/tests/compiler/std/math.untouched.wat +++ b/tests/compiler/std/math.untouched.wat @@ -3951,7 +3951,6 @@ (local $3 f64) (local $4 f64) (local $5 f64) - (local $6 f64) get_local $0 i64.reinterpret/f64 set_local $1 @@ -4072,14 +4071,12 @@ get_local $5 f64.div set_local $4 - get_local $3 - get_local $3 - f64.add - set_local $6 get_local $4 get_local $3 f64.sub - get_local $6 + f64.const 2 + get_local $3 + f64.mul get_local $4 f64.add f64.div @@ -4637,8 +4634,6 @@ get_local $0 f64.const 8988465674311579538646525e283 f64.mul - set_local $0 - get_local $0 return end get_local $0 @@ -5386,8 +5381,8 @@ block $~lib/math/expo2f|inlined.0 (result f32) i32.const 127 i32.const 235 - i32.const 2 - i32.div_u + i32.const 1 + i32.shr_u i32.add i32.const 23 i32.shl @@ -7593,7 +7588,7 @@ (local $11 i32) (local $12 i32) (local $13 i32) - (local $14 f64) + (local $14 i32) (local $15 f64) (local $16 f64) (local $17 f64) @@ -7605,10 +7600,10 @@ (local $23 f64) (local $24 f64) (local $25 f64) - (local $26 i32) - (local $27 i32) - (local $28 f64) - (local $29 f64) + (local $26 f64) + (local $27 f64) + (local $28 i32) + (local $29 i32) (local $30 f64) (local $31 f64) (local $32 f64) @@ -7619,7 +7614,8 @@ (local $37 f64) (local $38 f64) (local $39 f64) - (local $40 i32) + (local $40 f64) + (local $41 i32) get_local $0 i64.reinterpret/f64 set_local $2 @@ -7731,34 +7727,34 @@ i32.const 1023 i32.sub set_local $11 - i32.const 52 - i32.const 20 get_local $11 i32.const 20 i32.gt_s + set_local $9 + i32.const 52 + i32.const 20 + get_local $9 select get_local $11 i32.sub - set_local $9 + set_local $12 get_local $6 get_local $8 - get_local $11 - i32.const 20 - i32.gt_s - select - set_local $12 - get_local $12 get_local $9 - i32.shr_s + select set_local $13 get_local $13 - get_local $9 - i32.shl get_local $12 + i32.shr_s + set_local $14 + get_local $14 + get_local $12 + i32.shl + get_local $13 i32.eq if i32.const 2 - get_local $13 + get_local $14 i32.const 1 i32.and i32.sub @@ -7857,41 +7853,41 @@ end get_local $0 f64.abs - set_local $14 + set_local $15 get_local $4 i32.const 0 i32.eq if get_local $7 - i32.const 2146435072 + i32.const 0 i32.eq - tee_local $13 + tee_local $14 if (result i32) - get_local $13 + get_local $14 else get_local $7 - i32.const 0 + i32.const 2146435072 i32.eq end - tee_local $13 + tee_local $14 if (result i32) - get_local $13 + get_local $14 else get_local $7 i32.const 1072693248 i32.eq end if - get_local $14 - set_local $15 + get_local $15 + set_local $16 get_local $5 i32.const 0 i32.lt_s if f64.const 1 - get_local $15 + get_local $16 f64.div - set_local $15 + set_local $16 end get_local $3 i32.const 0 @@ -7905,31 +7901,31 @@ i32.const 0 i32.eq if - get_local $15 - get_local $15 - f64.sub - get_local $15 - get_local $15 + get_local $16 + get_local $16 f64.sub + set_local $17 + get_local $17 + get_local $17 f64.div - set_local $15 + set_local $16 else get_local $10 i32.const 1 i32.eq if - get_local $15 + get_local $16 f64.neg - set_local $15 + set_local $16 end end end - get_local $15 + get_local $16 return end end f64.const 1 - set_local $16 + set_local $18 get_local $3 i32.const 0 i32.lt_s @@ -7941,9 +7937,9 @@ get_local $0 get_local $0 f64.sub - get_local $0 - get_local $0 - f64.sub + set_local $17 + get_local $17 + get_local $17 f64.div return end @@ -7952,7 +7948,7 @@ i32.eq if f64.const -1 - set_local $16 + set_local $18 end end get_local $8 @@ -8008,13 +8004,13 @@ i32.const 0 i32.lt_s if (result f64) - get_local $16 + get_local $18 f64.const 1.e+300 f64.mul f64.const 1.e+300 f64.mul else - get_local $16 + get_local $18 f64.const 1e-300 f64.mul f64.const 1e-300 @@ -8030,13 +8026,13 @@ i32.const 0 i32.gt_s if (result f64) - get_local $16 + get_local $18 f64.const 1.e+300 f64.mul f64.const 1.e+300 f64.mul else - get_local $16 + get_local $18 f64.const 1e-300 f64.mul f64.const 1e-300 @@ -8044,98 +8040,98 @@ end return end - get_local $14 + get_local $15 f64.const 1 f64.sub - set_local $22 - get_local $22 - get_local $22 + set_local $24 + get_local $24 + get_local $24 f64.mul f64.const 0.5 - get_local $22 + get_local $24 f64.const 0.3333333333333333 - get_local $22 + get_local $24 f64.const 0.25 f64.mul f64.sub f64.mul f64.sub f64.mul - set_local $25 + set_local $27 f64.const 1.4426950216293335 - get_local $22 + get_local $24 f64.mul - set_local $23 - get_local $22 + set_local $25 + get_local $24 f64.const 1.9259629911266175e-08 f64.mul - get_local $25 + get_local $27 f64.const 1.4426950408889634 f64.mul f64.sub - set_local $24 - get_local $23 - get_local $24 + set_local $26 + get_local $25 + get_local $26 f64.add - set_local $17 - get_local $17 + set_local $19 + get_local $19 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - set_local $17 - get_local $24 - get_local $17 - get_local $23 + set_local $19 + get_local $26 + get_local $19 + get_local $25 f64.sub f64.sub - set_local $18 + set_local $20 else i32.const 0 - set_local $27 + set_local $29 get_local $7 i32.const 1048576 i32.lt_s if - get_local $14 + get_local $15 f64.const 9007199254740992 f64.mul - set_local $14 - get_local $27 + set_local $15 + get_local $29 i32.const 53 i32.sub - set_local $27 - get_local $14 + set_local $29 + get_local $15 i64.reinterpret/f64 i64.const 32 i64.shr_u i32.wrap/i64 set_local $7 end - get_local $27 + get_local $29 get_local $7 i32.const 20 i32.shr_s i32.const 1023 i32.sub i32.add - set_local $27 + set_local $29 get_local $7 i32.const 1048575 i32.and - set_local $26 - get_local $26 + set_local $28 + get_local $28 i32.const 1072693248 i32.or set_local $7 - get_local $26 + get_local $28 i32.const 235662 i32.le_s if i32.const 0 set_local $11 else - get_local $26 + get_local $28 i32.const 767610 i32.lt_s if @@ -8144,17 +8140,17 @@ else i32.const 0 set_local $11 - get_local $27 + get_local $29 i32.const 1 i32.add - set_local $27 + set_local $29 get_local $7 i32.const 1048576 i32.sub set_local $7 end end - get_local $14 + get_local $15 i64.reinterpret/f64 i64.const 4294967295 i64.and @@ -8164,34 +8160,34 @@ i64.shl i64.or f64.reinterpret/i64 - set_local $14 + set_local $15 f64.const 1.5 f64.const 1 get_local $11 select - set_local $34 - get_local $14 - get_local $34 + set_local $35 + get_local $15 + get_local $35 f64.sub - set_local $23 + set_local $25 f64.const 1 - get_local $14 - get_local $34 + get_local $15 + get_local $35 f64.add f64.div - set_local $24 - get_local $23 - get_local $24 + set_local $26 + get_local $25 + get_local $26 f64.mul - set_local $28 - get_local $28 - set_local $30 - get_local $30 + set_local $17 + get_local $17 + set_local $31 + get_local $31 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - set_local $30 + set_local $31 get_local $7 i32.const 1 i32.shr_s @@ -8207,42 +8203,42 @@ i64.const 32 i64.shl f64.reinterpret/i64 - set_local $32 - get_local $14 - get_local $32 - get_local $34 + set_local $33 + get_local $15 + get_local $33 + get_local $35 f64.sub f64.sub - set_local $33 - get_local $24 - get_local $23 - get_local $30 - get_local $32 + set_local $34 + get_local $26 + get_local $25 + get_local $31 + get_local $33 f64.mul f64.sub - get_local $30 - get_local $33 + get_local $31 + get_local $34 f64.mul f64.sub f64.mul - set_local $31 - get_local $28 - get_local $28 + set_local $32 + get_local $17 + get_local $17 f64.mul - set_local $29 - get_local $29 - get_local $29 + set_local $30 + get_local $30 + get_local $30 f64.mul f64.const 0.5999999999999946 - get_local $29 + get_local $30 f64.const 0.4285714285785502 - get_local $29 + get_local $30 f64.const 0.33333332981837743 - get_local $29 + get_local $30 f64.const 0.272728123808534 - get_local $29 + get_local $30 f64.const 0.23066074577556175 - get_local $29 + get_local $30 f64.const 0.20697501780033842 f64.mul f64.add @@ -8255,184 +8251,184 @@ f64.mul f64.add f64.mul - set_local $21 - get_local $21 + set_local $23 + get_local $23 + get_local $32 get_local $31 - get_local $30 - get_local $28 + get_local $17 f64.add f64.mul f64.add - set_local $21 - get_local $30 - get_local $30 + set_local $23 + get_local $31 + get_local $31 f64.mul - set_local $29 + set_local $30 f64.const 3 - get_local $29 + get_local $30 f64.add - get_local $21 + get_local $23 f64.add - set_local $32 - get_local $32 + set_local $33 + get_local $33 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - set_local $32 - get_local $21 - get_local $32 + set_local $33 + get_local $23 + get_local $33 f64.const 3 f64.sub - get_local $29 + get_local $30 f64.sub f64.sub - set_local $33 - get_local $30 - get_local $32 - f64.mul - set_local $23 + set_local $34 get_local $31 - get_local $32 + get_local $33 f64.mul + set_local $25 + get_local $32 get_local $33 - get_local $28 + f64.mul + get_local $34 + get_local $17 f64.mul f64.add - set_local $24 - get_local $23 - get_local $24 + set_local $26 + get_local $25 + get_local $26 f64.add - set_local $19 - get_local $19 - i64.reinterpret/f64 + set_local $21 + get_local $21 + i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - set_local $19 - get_local $24 - get_local $19 - get_local $23 + set_local $21 + get_local $26 + get_local $21 + get_local $25 f64.sub f64.sub - set_local $20 + set_local $22 f64.const 0.9617967009544373 - get_local $19 + get_local $21 f64.mul - set_local $35 + set_local $36 f64.const 1.350039202129749e-08 f64.const 0 get_local $11 select - set_local $36 + set_local $37 f64.const -7.028461650952758e-09 - get_local $19 + get_local $21 f64.mul - get_local $20 + get_local $22 f64.const 0.9617966939259756 f64.mul f64.add - get_local $36 + get_local $37 f64.add - set_local $37 - get_local $27 + set_local $38 + get_local $29 f64.convert_s/i32 - set_local $22 + set_local $24 f64.const 0.5849624872207642 f64.const 0 get_local $11 select - set_local $38 - get_local $35 - get_local $37 - f64.add + set_local $39 + get_local $36 get_local $38 f64.add - get_local $22 + get_local $39 f64.add - set_local $17 - get_local $17 + get_local $24 + f64.add + set_local $19 + get_local $19 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - set_local $17 - get_local $37 - get_local $17 - get_local $22 - f64.sub + set_local $19 get_local $38 + get_local $19 + get_local $24 f64.sub - get_local $35 + get_local $39 f64.sub + get_local $36 f64.sub - set_local $18 + f64.sub + set_local $20 end get_local $1 - set_local $39 - get_local $39 + set_local $40 + get_local $40 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - set_local $39 + set_local $40 get_local $1 - get_local $39 + get_local $40 f64.sub - get_local $17 + get_local $19 f64.mul get_local $1 - get_local $18 + get_local $20 f64.mul f64.add - set_local $20 - get_local $39 - get_local $17 - f64.mul - set_local $19 - get_local $20 + set_local $22 + get_local $40 get_local $19 + f64.mul + set_local $21 + get_local $22 + get_local $21 f64.add - set_local $15 - get_local $15 + set_local $16 + get_local $16 i64.reinterpret/f64 set_local $2 get_local $2 i64.const 32 i64.shr_u i32.wrap/i64 - set_local $26 + set_local $28 get_local $2 i32.wrap/i64 - set_local $40 - get_local $26 + set_local $41 + get_local $28 i32.const 1083179008 i32.ge_s if - get_local $26 + get_local $28 i32.const 1083179008 i32.sub - get_local $40 + get_local $41 i32.or i32.const 0 i32.ne if - get_local $16 + get_local $18 f64.const 1.e+300 f64.mul f64.const 1.e+300 f64.mul return end - get_local $20 + get_local $22 f64.const 8.008566259537294e-17 f64.add - get_local $15 - get_local $19 + get_local $16 + get_local $21 f64.sub f64.gt if - get_local $16 + get_local $18 f64.const 1.e+300 f64.mul f64.const 1.e+300 @@ -8440,34 +8436,34 @@ return end else - get_local $26 + get_local $28 i32.const 2147483647 i32.and i32.const 1083231232 i32.ge_s if - get_local $26 + get_local $28 i32.const -1064252416 i32.sub - get_local $40 + get_local $41 i32.or i32.const 0 i32.ne if - get_local $16 + get_local $18 f64.const 1e-300 f64.mul f64.const 1e-300 f64.mul return end - get_local $20 - get_local $15 - get_local $19 + get_local $22 + get_local $16 + get_local $21 f64.sub f64.le if - get_local $16 + get_local $18 f64.const 1e-300 f64.mul f64.const 1e-300 @@ -8476,31 +8472,31 @@ end end end - get_local $26 + get_local $28 i32.const 2147483647 i32.and - set_local $40 - get_local $40 + set_local $41 + get_local $41 i32.const 20 i32.shr_s i32.const 1023 i32.sub set_local $11 i32.const 0 - set_local $27 - get_local $40 + set_local $29 + get_local $41 i32.const 1071644672 i32.gt_s if - get_local $26 + get_local $28 i32.const 1048576 get_local $11 i32.const 1 i32.add i32.shr_s i32.add - set_local $27 - get_local $27 + set_local $29 + get_local $29 i32.const 2147483647 i32.and i32.const 20 @@ -8509,8 +8505,8 @@ i32.sub set_local $11 f64.const 0 - set_local $22 - get_local $27 + set_local $24 + get_local $29 i32.const 1048575 get_local $11 i32.shr_s @@ -8521,8 +8517,8 @@ i64.const 32 i64.shl f64.reinterpret/i64 - set_local $22 - get_local $27 + set_local $24 + get_local $29 i32.const 1048575 i32.and i32.const 1048576 @@ -8531,71 +8527,71 @@ get_local $11 i32.sub i32.shr_s - set_local $27 - get_local $26 + set_local $29 + get_local $28 i32.const 0 i32.lt_s if i32.const 0 - get_local $27 + get_local $29 i32.sub - set_local $27 + set_local $29 end - get_local $19 - get_local $22 + get_local $21 + get_local $24 f64.sub - set_local $19 + set_local $21 end - get_local $20 - get_local $19 - f64.add - set_local $22 get_local $22 + get_local $21 + f64.add + set_local $24 + get_local $24 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - set_local $22 - get_local $22 + set_local $24 + get_local $24 f64.const 0.6931471824645996 f64.mul - set_local $23 - get_local $20 + set_local $25 get_local $22 - get_local $19 + get_local $24 + get_local $21 f64.sub f64.sub f64.const 0.6931471805599453 f64.mul - get_local $22 + get_local $24 f64.const -1.904654299957768e-09 f64.mul f64.add - set_local $24 - get_local $23 - get_local $24 + set_local $26 + get_local $25 + get_local $26 f64.add - set_local $15 - get_local $24 - get_local $15 - get_local $23 + set_local $16 + get_local $26 + get_local $16 + get_local $25 f64.sub f64.sub - set_local $25 - get_local $15 - get_local $15 + set_local $27 + get_local $16 + get_local $16 f64.mul - set_local $22 - get_local $15 - get_local $22 + set_local $24 + get_local $16 + get_local $24 f64.const 0.16666666666666602 - get_local $22 + get_local $24 f64.const -2.7777777777015593e-03 - get_local $22 + get_local $24 f64.const 6.613756321437934e-05 - get_local $22 + get_local $24 f64.const -1.6533902205465252e-06 - get_local $22 + get_local $24 f64.const 4.1381367970572385e-08 f64.mul f64.add @@ -8607,64 +8603,64 @@ f64.add f64.mul f64.sub - set_local $17 - get_local $15 - get_local $17 + set_local $19 + get_local $16 + get_local $19 f64.mul - get_local $17 + get_local $19 f64.const 2 f64.sub f64.div - get_local $25 - get_local $15 - get_local $25 + get_local $27 + get_local $16 + get_local $27 f64.mul f64.add f64.sub - set_local $21 + set_local $23 f64.const 1 - get_local $21 - get_local $15 + get_local $23 + get_local $16 f64.sub f64.sub - set_local $15 - get_local $15 + set_local $16 + get_local $16 i64.reinterpret/f64 i64.const 32 i64.shr_u i32.wrap/i64 - set_local $26 - get_local $26 - get_local $27 + set_local $28 + get_local $28 + get_local $29 i32.const 20 i32.shl i32.add - set_local $26 - get_local $26 + set_local $28 + get_local $28 i32.const 20 i32.shr_s i32.const 0 i32.le_s if - get_local $15 - get_local $27 + get_local $16 + get_local $29 call $~lib/math/NativeMath.scalbn - set_local $15 + set_local $16 else - get_local $15 + get_local $16 i64.reinterpret/f64 i64.const 4294967295 i64.and - get_local $26 + get_local $28 i64.extend_s/i32 i64.const 32 i64.shl i64.or f64.reinterpret/i64 - set_local $15 + set_local $16 end + get_local $18 get_local $16 - get_local $15 f64.mul ) (func $std/math/test_pow (; 125 ;) (type $FFFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 f64) (param $4 i32) (result i32) @@ -8718,9 +8714,9 @@ (local $20 f32) (local $21 f32) (local $22 f32) - (local $23 i32) + (local $23 f32) (local $24 i32) - (local $25 f32) + (local $25 i32) (local $26 f32) (local $27 f32) (local $28 f32) @@ -8793,16 +8789,16 @@ i32.const 127 i32.sub set_local $9 - get_local $5 i32.const 23 get_local $9 i32.sub + set_local $6 + get_local $5 + get_local $6 i32.shr_s set_local $8 get_local $8 - i32.const 23 - get_local $9 - i32.sub + get_local $6 i32.shl get_local $5 i32.eq @@ -8945,9 +8941,9 @@ get_local $11 get_local $11 f32.sub - get_local $11 - get_local $11 - f32.sub + set_local $12 + get_local $12 + get_local $12 f32.div set_local $11 else @@ -8965,7 +8961,7 @@ return end f32.const 1 - set_local $12 + set_local $13 get_local $2 i32.const 0 i32.lt_s @@ -8977,9 +8973,9 @@ get_local $0 get_local $0 f32.sub - get_local $0 - get_local $0 - f32.sub + set_local $12 + get_local $12 + get_local $12 f32.div return end @@ -8988,7 +8984,7 @@ i32.eq if f32.const -1 - set_local $12 + set_local $13 end end get_local $5 @@ -9003,13 +8999,13 @@ i32.const 0 i32.lt_s if (result f32) - get_local $12 + get_local $13 f32.const 1000000015047466219876688e6 f32.mul f32.const 1000000015047466219876688e6 f32.mul else - get_local $12 + get_local $13 f32.const 1.0000000031710769e-30 f32.mul f32.const 1.0000000031710769e-30 @@ -9025,13 +9021,13 @@ i32.const 0 i32.gt_s if (result f32) - get_local $12 + get_local $13 f32.const 1000000015047466219876688e6 f32.mul f32.const 1000000015047466219876688e6 f32.mul else - get_local $12 + get_local $13 f32.const 1.0000000031710769e-30 f32.mul f32.const 1.0000000031710769e-30 @@ -9042,54 +9038,54 @@ get_local $10 f32.const 1 f32.sub - set_local $17 - get_local $17 - get_local $17 + set_local $18 + get_local $18 + get_local $18 f32.mul f32.const 0.5 - get_local $17 + get_local $18 f32.const 0.3333333432674408 - get_local $17 + get_local $18 f32.const 0.25 f32.mul f32.sub f32.mul f32.sub f32.mul - set_local $20 + set_local $21 f32.const 1.44268798828125 - get_local $17 + get_local $18 f32.mul - set_local $18 - get_local $17 + set_local $19 + get_local $18 f32.const 7.052607543300837e-06 f32.mul - get_local $20 + get_local $21 f32.const 1.4426950216293335 f32.mul f32.sub - set_local $19 - get_local $18 + set_local $20 get_local $19 + get_local $20 f32.add - set_local $13 - get_local $13 + set_local $14 + get_local $14 i32.reinterpret/f32 - set_local $24 - get_local $24 + set_local $25 + get_local $25 i32.const -4096 i32.and f32.reinterpret/i32 - set_local $13 + set_local $14 + get_local $20 + get_local $14 get_local $19 - get_local $13 - get_local $18 f32.sub f32.sub - set_local $14 + set_local $15 else i32.const 0 - set_local $23 + set_local $24 get_local $4 i32.const 8388608 i32.lt_s @@ -9098,22 +9094,22 @@ f32.const 16777216 f32.mul set_local $10 - get_local $23 + get_local $24 i32.const 24 i32.sub - set_local $23 + set_local $24 get_local $10 i32.reinterpret/f32 set_local $4 end - get_local $23 + get_local $24 get_local $4 i32.const 23 i32.shr_s i32.const 127 i32.sub i32.add - set_local $23 + set_local $24 get_local $4 i32.const 8388607 i32.and @@ -9138,10 +9134,10 @@ else i32.const 0 set_local $9 - get_local $23 + get_local $24 i32.const 1 i32.add - set_local $23 + set_local $24 get_local $4 i32.const 8388608 i32.sub @@ -9159,23 +9155,23 @@ get_local $10 get_local $30 f32.sub - set_local $18 + set_local $19 f32.const 1 get_local $10 get_local $30 f32.add f32.div - set_local $19 - get_local $18 + set_local $20 get_local $19 + get_local $20 f32.mul - set_local $16 - get_local $16 + set_local $17 + get_local $17 set_local $26 get_local $26 i32.reinterpret/f32 - set_local $24 - get_local $24 + set_local $25 + get_local $25 i32.const -4096 i32.and f32.reinterpret/i32 @@ -9187,8 +9183,8 @@ i32.and i32.const 536870912 i32.or - set_local $24 - get_local $24 + set_local $25 + get_local $25 i32.const 4194304 i32.add get_local $9 @@ -9203,8 +9199,8 @@ f32.sub f32.sub set_local $29 + get_local $20 get_local $19 - get_local $18 get_local $26 get_local $28 f32.mul @@ -9215,23 +9211,23 @@ f32.sub f32.mul set_local $27 - get_local $16 - get_local $16 + get_local $17 + get_local $17 f32.mul - set_local $25 - get_local $25 - get_local $25 + set_local $12 + get_local $12 + get_local $12 f32.mul f32.const 0.6000000238418579 - get_local $25 + get_local $12 f32.const 0.4285714328289032 - get_local $25 + get_local $12 f32.const 0.3333333432674408 - get_local $25 + get_local $12 f32.const 0.2727281153202057 - get_local $25 + get_local $12 f32.const 0.23066075146198273 - get_local $25 + get_local $12 f32.const 0.20697501301765442 f32.mul f32.add @@ -9244,73 +9240,73 @@ f32.mul f32.add f32.mul - set_local $15 - get_local $15 + set_local $16 + get_local $16 get_local $27 get_local $26 - get_local $16 + get_local $17 f32.add f32.mul f32.add - set_local $15 + set_local $16 get_local $26 get_local $26 f32.mul - set_local $25 + set_local $12 f32.const 3 - get_local $25 + get_local $12 f32.add - get_local $15 + get_local $16 f32.add set_local $28 get_local $28 i32.reinterpret/f32 - set_local $24 - get_local $24 + set_local $25 + get_local $25 i32.const -4096 i32.and f32.reinterpret/i32 set_local $28 - get_local $15 + get_local $16 get_local $28 f32.const 3 f32.sub - get_local $25 + get_local $12 f32.sub f32.sub set_local $29 get_local $26 get_local $28 f32.mul - set_local $18 + set_local $19 get_local $27 get_local $28 f32.mul get_local $29 - get_local $16 + get_local $17 f32.mul f32.add - set_local $19 - get_local $18 + set_local $20 get_local $19 + get_local $20 f32.add - set_local $21 - get_local $21 + set_local $22 + get_local $22 i32.reinterpret/f32 - set_local $24 - get_local $24 + set_local $25 + get_local $25 i32.const -4096 i32.and f32.reinterpret/i32 - set_local $21 + set_local $22 + get_local $20 + get_local $22 get_local $19 - get_local $21 - get_local $18 f32.sub f32.sub - set_local $22 + set_local $23 f32.const 0.9619140625 - get_local $21 + get_local $22 f32.mul set_local $31 f32.const 1.5632208487659227e-06 @@ -9319,18 +9315,18 @@ select set_local $32 f32.const -1.1736857413779944e-04 - get_local $21 - f32.mul get_local $22 + f32.mul + get_local $23 f32.const 0.9617967009544373 f32.mul f32.add get_local $32 f32.add set_local $33 - get_local $23 + get_local $24 f32.convert_s/i32 - set_local $17 + set_local $18 f32.const 0.5849609375 f32.const 0 get_local $9 @@ -9341,32 +9337,32 @@ f32.add get_local $34 f32.add - get_local $17 + get_local $18 f32.add - set_local $13 - get_local $13 + set_local $14 + get_local $14 i32.reinterpret/f32 - set_local $24 - get_local $24 + set_local $25 + get_local $25 i32.const -4096 i32.and f32.reinterpret/i32 - set_local $13 + set_local $14 get_local $33 - get_local $13 - get_local $17 + get_local $14 + get_local $18 f32.sub get_local $34 f32.sub get_local $31 f32.sub f32.sub - set_local $14 + set_local $15 end get_local $1 i32.reinterpret/f32 - set_local $24 - get_local $24 + set_local $25 + get_local $25 i32.const -4096 i32.and f32.reinterpret/i32 @@ -9374,19 +9370,19 @@ get_local $1 get_local $35 f32.sub - get_local $13 + get_local $14 f32.mul get_local $1 - get_local $14 + get_local $15 f32.mul f32.add - set_local $22 + set_local $23 get_local $35 - get_local $13 + get_local $14 f32.mul - set_local $21 + set_local $22 + get_local $23 get_local $22 - get_local $21 f32.add set_local $11 get_local $11 @@ -9396,7 +9392,7 @@ i32.const 1124073472 i32.gt_s if - get_local $12 + get_local $13 f32.const 1000000015047466219876688e6 f32.mul f32.const 1000000015047466219876688e6 @@ -9407,15 +9403,15 @@ i32.const 1124073472 i32.eq if - get_local $22 + get_local $23 f32.const 4.299566569443414e-08 f32.add get_local $11 - get_local $21 + get_local $22 f32.sub f32.gt if - get_local $12 + get_local $13 f32.const 1000000015047466219876688e6 f32.mul f32.const 1000000015047466219876688e6 @@ -9429,7 +9425,7 @@ i32.const 1125515264 i32.gt_s if - get_local $12 + get_local $13 f32.const 1.0000000031710769e-30 f32.mul f32.const 1.0000000031710769e-30 @@ -9440,13 +9436,13 @@ i32.const -1021968384 i32.eq if - get_local $22 + get_local $23 get_local $11 - get_local $21 + get_local $22 f32.sub f32.le if - get_local $12 + get_local $13 f32.const 1.0000000031710769e-30 f32.mul f32.const 1.0000000031710769e-30 @@ -9468,7 +9464,7 @@ i32.sub set_local $9 i32.const 0 - set_local $23 + set_local $24 get_local $36 i32.const 1056964608 i32.gt_s @@ -9480,8 +9476,8 @@ i32.add i32.shr_s i32.add - set_local $23 - get_local $23 + set_local $24 + get_local $24 i32.const 2147483647 i32.and i32.const 23 @@ -9489,7 +9485,7 @@ i32.const 127 i32.sub set_local $9 - get_local $23 + get_local $24 i32.const 8388607 get_local $9 i32.shr_s @@ -9497,8 +9493,8 @@ i32.xor i32.and f32.reinterpret/i32 - set_local $17 - get_local $23 + set_local $18 + get_local $24 i32.const 8388607 i32.and i32.const 8388608 @@ -9507,73 +9503,73 @@ get_local $9 i32.sub i32.shr_s - set_local $23 + set_local $24 get_local $8 i32.const 0 i32.lt_s if i32.const 0 - get_local $23 + get_local $24 i32.sub - set_local $23 + set_local $24 end - get_local $21 - get_local $17 + get_local $22 + get_local $18 f32.sub - set_local $21 + set_local $22 end + get_local $23 get_local $22 - get_local $21 f32.add - set_local $17 - get_local $17 + set_local $18 + get_local $18 i32.reinterpret/f32 - set_local $24 - get_local $24 + set_local $25 + get_local $25 i32.const -32768 i32.and f32.reinterpret/i32 - set_local $17 - get_local $17 + set_local $18 + get_local $18 f32.const 0.693145751953125 f32.mul - set_local $18 + set_local $19 + get_local $23 + get_local $18 get_local $22 - get_local $17 - get_local $21 f32.sub f32.sub f32.const 0.6931471824645996 f32.mul - get_local $17 + get_local $18 f32.const 1.4286065379565116e-06 f32.mul f32.add - set_local $19 - get_local $18 + set_local $20 get_local $19 + get_local $20 f32.add set_local $11 - get_local $19 + get_local $20 get_local $11 - get_local $18 + get_local $19 f32.sub f32.sub - set_local $20 + set_local $21 get_local $11 get_local $11 f32.mul - set_local $17 + set_local $18 get_local $11 - get_local $17 + get_local $18 f32.const 0.1666666716337204 - get_local $17 + get_local $18 f32.const -2.7777778450399637e-03 - get_local $17 + get_local $18 f32.const 6.61375597701408e-05 - get_local $17 + get_local $18 f32.const -1.6533901998627698e-06 - get_local $17 + get_local $18 f32.const 4.138136944220605e-08 f32.mul f32.add @@ -9585,23 +9581,23 @@ f32.add f32.mul f32.sub - set_local $13 + set_local $14 get_local $11 - get_local $13 + get_local $14 f32.mul - get_local $13 + get_local $14 f32.const 2 f32.sub f32.div - get_local $20 + get_local $21 get_local $11 - get_local $20 + get_local $21 f32.mul f32.add f32.sub - set_local $15 + set_local $16 f32.const 1 - get_local $15 + get_local $16 get_local $11 f32.sub f32.sub @@ -9610,7 +9606,7 @@ i32.reinterpret/f32 set_local $8 get_local $8 - get_local $23 + get_local $24 i32.const 23 i32.shl i32.add @@ -9622,7 +9618,7 @@ i32.le_s if get_local $11 - get_local $23 + get_local $24 call $~lib/math/NativeMathf.scalbn set_local $11 else @@ -9630,7 +9626,7 @@ f32.reinterpret/i32 set_local $11 end - get_local $12 + get_local $13 get_local $11 f32.mul ) @@ -9713,7 +9709,7 @@ if i32.const 0 i32.const 40 - i32.const 959 + i32.const 961 i32.const 4 call $~lib/env/abort unreachable @@ -9745,7 +9741,7 @@ if i32.const 0 i32.const 40 - i32.const 968 + i32.const 970 i32.const 24 call $~lib/env/abort unreachable @@ -9802,7 +9798,7 @@ if i32.const 0 i32.const 40 - i32.const 2029 + i32.const 2041 i32.const 24 call $~lib/env/abort unreachable @@ -9950,10 +9946,11 @@ (local $5 i64) (local $6 i32) (local $7 i32) - (local $8 i64) - (local $9 i32) - (local $10 i64) - (local $11 f64) + (local $8 f64) + (local $9 i64) + (local $10 i32) + (local $11 i64) + (local $12 f64) get_local $0 i64.reinterpret/f64 set_local $2 @@ -10001,9 +9998,9 @@ get_local $0 get_local $1 f64.mul - get_local $0 - get_local $1 - f64.mul + set_local $8 + get_local $8 + get_local $8 f64.div return end @@ -10017,38 +10014,38 @@ return end get_local $2 - set_local $8 + set_local $9 get_local $4 i64.eqz if get_local $4 - get_local $8 + get_local $9 i64.const 12 i64.shl i64.clz i64.sub set_local $4 - get_local $8 + get_local $9 i64.const 0 get_local $4 i64.sub i64.const 1 i64.add i64.shl - set_local $8 + set_local $9 else - get_local $8 + get_local $9 i64.const -1 i64.const 12 i64.shr_u i64.and - set_local $8 - get_local $8 + set_local $9 + get_local $9 i64.const 1 i64.const 52 i64.shl i64.or - set_local $8 + set_local $9 end get_local $5 i64.eqz @@ -10083,7 +10080,7 @@ set_local $3 end i32.const 0 - set_local $9 + set_local $10 block $break|0 loop $continue|0 get_local $4 @@ -10108,27 +10105,27 @@ i64.gt_s if block - get_local $8 + get_local $9 get_local $3 i64.ge_u if - get_local $8 + get_local $9 get_local $3 i64.sub - set_local $8 - get_local $9 + set_local $9 + get_local $10 i32.const 1 i32.add - set_local $9 + set_local $10 end - get_local $8 + get_local $9 i64.const 1 i64.shl - set_local $8 - get_local $9 + set_local $9 + get_local $10 i32.const 1 i32.shl - set_local $9 + set_local $10 get_local $4 i64.const 1 i64.sub @@ -10138,39 +10135,39 @@ end end end - get_local $8 + get_local $9 get_local $3 i64.ge_u if - get_local $8 + get_local $9 get_local $3 i64.sub - set_local $8 - get_local $9 + set_local $9 + get_local $10 i32.const 1 i32.add - set_local $9 + set_local $10 end - get_local $8 + get_local $9 i64.const 0 i64.eq if i64.const -60 set_local $4 else - get_local $8 + get_local $9 i64.const 11 i64.shl i64.clz - set_local $10 + set_local $11 get_local $4 - get_local $10 + get_local $11 i64.sub set_local $4 - get_local $8 - get_local $10 + get_local $9 + get_local $11 i64.shl - set_local $8 + set_local $9 end br $break|0 unreachable @@ -10182,29 +10179,29 @@ i64.const 0 i64.gt_s if - get_local $8 + get_local $9 i64.const 1 i64.const 52 i64.shl i64.sub - set_local $8 - get_local $8 + set_local $9 + get_local $9 get_local $4 i64.const 52 i64.shl i64.or - set_local $8 + set_local $9 else - get_local $8 + get_local $9 i64.const 0 get_local $4 i64.sub i64.const 1 i64.add i64.shr_u - set_local $8 + set_local $9 end - get_local $8 + get_local $9 f64.reinterpret/i64 set_local $0 get_local $1 @@ -10213,7 +10210,7 @@ get_local $0 get_local $0 f64.add - set_local $11 + set_local $12 get_local $4 get_local $5 i64.eq @@ -10228,19 +10225,19 @@ i64.eq tee_local $7 if (result i32) - get_local $11 + get_local $12 get_local $1 f64.gt tee_local $7 if (result i32) get_local $7 else - get_local $11 + get_local $12 get_local $1 f64.eq tee_local $7 if (result i32) - get_local $9 + get_local $10 i32.const 1 i32.and else @@ -10803,8 +10800,8 @@ block $~lib/math/expo2f|inlined.1 (result f32) i32.const 127 i32.const 235 - i32.const 2 - i32.div_u + i32.const 1 + i32.shr_u i32.add i32.const 23 i32.shl diff --git a/tests/compiler/std/operator-overloading.optimized.wat b/tests/compiler/std/operator-overloading.optimized.wat index 8948e25c61..e1522a87ce 100644 --- a/tests/compiler/std/operator-overloading.optimized.wat +++ b/tests/compiler/std/operator-overloading.optimized.wat @@ -240,19 +240,20 @@ (local $5 i32) (local $6 f64) (local $7 i32) - (local $8 i32) - (local $9 f64) - (local $10 i32) - (local $11 f64) + (local $8 f64) + (local $9 i32) + (local $10 f64) + (local $11 i32) (local $12 i32) (local $13 i32) - (local $14 i32) - (local $15 f64) + (local $14 f64) + (local $15 i32) (local $16 f64) (local $17 i64) (local $18 i32) (local $19 f64) (local $20 i32) + (local $21 i32) get_local $0 i64.reinterpret/f64 tee_local $17 @@ -266,7 +267,7 @@ get_local $18 i32.const 2147483647 i32.and - set_local $4 + set_local $5 get_local $1 i64.reinterpret/f64 tee_local $17 @@ -276,57 +277,57 @@ tee_local $13 i32.const 2147483647 i32.and - set_local $12 - get_local $12 + set_local $11 + get_local $11 get_local $17 i32.wrap/i64 - tee_local $7 + tee_local $21 i32.or i32.eqz if f64.const 1 return end - get_local $4 + get_local $5 i32.const 2146435072 i32.gt_s - tee_local $8 + tee_local $4 i32.eqz if - get_local $4 + get_local $5 i32.const 2146435072 i32.eq - tee_local $8 + tee_local $4 if get_local $20 i32.const 0 i32.ne - set_local $8 + set_local $4 end end - get_local $8 + get_local $4 i32.eqz if - get_local $12 + get_local $11 i32.const 2146435072 i32.gt_s - set_local $8 + set_local $4 end - get_local $8 + get_local $4 i32.eqz if - get_local $12 + get_local $11 i32.const 2146435072 i32.eq - tee_local $8 + tee_local $4 if - get_local $7 + get_local $21 i32.const 0 i32.ne - set_local $8 + set_local $4 end end - get_local $8 + get_local $4 if get_local $0 get_local $1 @@ -337,71 +338,70 @@ i32.const 0 i32.lt_s if - get_local $12 + get_local $11 i32.const 1128267776 i32.ge_s if (result i32) i32.const 2 else - get_local $12 + get_local $11 i32.const 1072693248 i32.ge_s if (result i32) - i32.const 52 - i32.const 20 - get_local $12 + get_local $21 + get_local $11 + get_local $11 i32.const 20 i32.shr_s i32.const 1023 i32.sub - tee_local $10 + tee_local $12 i32.const 20 i32.gt_s - tee_local $5 + tee_local $4 select - get_local $10 - i32.sub - set_local $8 - get_local $7 - get_local $12 - get_local $5 + tee_local $7 + i32.const 52 + i32.const 20 + get_local $4 select - tee_local $10 - get_local $8 + get_local $12 + i32.sub + tee_local $9 i32.shr_s - set_local $5 + set_local $4 i32.const 2 - get_local $5 + get_local $4 i32.const 1 i32.and i32.sub i32.const 0 - get_local $5 - get_local $8 + get_local $4 + get_local $9 i32.shl - get_local $10 + get_local $7 i32.eq select else i32.const 0 end end - set_local $14 + set_local $15 end - get_local $7 + get_local $21 i32.eqz if - get_local $12 + get_local $11 i32.const 2146435072 i32.eq if - get_local $4 + get_local $5 i32.const 1072693248 i32.sub get_local $20 i32.or if - get_local $4 + get_local $5 i32.const 1072693248 i32.ge_s if @@ -431,7 +431,7 @@ end unreachable end - get_local $12 + get_local $11 i32.const 1072693248 i32.eq if @@ -476,25 +476,25 @@ get_local $20 i32.eqz if - get_local $4 - i32.const 2146435072 - i32.eq - tee_local $5 + get_local $5 + i32.eqz + tee_local $4 i32.eqz if - get_local $4 - i32.eqz - set_local $5 + get_local $5 + i32.const 2146435072 + i32.eq + set_local $4 end - get_local $5 + get_local $4 i32.eqz if - get_local $4 + get_local $5 i32.const 1072693248 i32.eq - set_local $5 + set_local $4 end - get_local $5 + get_local $4 if f64.const 1 get_local $2 @@ -509,16 +509,16 @@ i32.const 0 i32.lt_s if (result f64) - get_local $4 + get_local $5 i32.const 1072693248 i32.sub - get_local $14 + get_local $15 i32.or if (result f64) get_local $2 f64.neg get_local $2 - get_local $14 + get_local $15 i32.const 1 i32.eq select @@ -526,8 +526,8 @@ get_local $2 get_local $2 f64.sub - tee_local $0 - get_local $0 + tee_local $14 + get_local $14 f64.div end else @@ -537,39 +537,39 @@ end end f64.const 1 - set_local $11 + set_local $10 get_local $18 i32.const 0 i32.lt_s if - get_local $14 + get_local $15 i32.eqz if get_local $0 get_local $0 f64.sub - tee_local $0 - get_local $0 + tee_local $14 + get_local $14 f64.div return end f64.const -1 f64.const 1 - get_local $14 + get_local $15 i32.const 1 i32.eq select - set_local $11 + set_local $10 end - get_local $12 + get_local $11 i32.const 1105199104 i32.gt_s if (result f64) - get_local $12 + get_local $11 i32.const 1139802112 i32.gt_s if - get_local $4 + get_local $5 i32.const 1072693247 i32.le_s if @@ -581,7 +581,7 @@ select return end - get_local $4 + get_local $5 i32.const 1072693248 i32.ge_s if @@ -594,7 +594,7 @@ return end end - get_local $4 + get_local $5 i32.const 1072693247 i32.lt_s if @@ -602,13 +602,13 @@ i32.const 0 i32.lt_s if (result f64) - get_local $11 + get_local $10 f64.const 1.e+300 f64.mul f64.const 1.e+300 f64.mul else - get_local $11 + get_local $10 f64.const 1e-300 f64.mul f64.const 1e-300 @@ -616,7 +616,7 @@ end return end - get_local $4 + get_local $5 i32.const 1072693248 i32.gt_s if @@ -624,13 +624,13 @@ i32.const 0 i32.gt_s if (result f64) - get_local $11 + get_local $10 f64.const 1.e+300 f64.mul f64.const 1.e+300 f64.mul else - get_local $11 + get_local $10 f64.const 1e-300 f64.mul f64.const 1e-300 @@ -668,21 +668,21 @@ f64.sub tee_local $6 f64.add - set_local $9 + set_local $8 get_local $6 - get_local $9 + get_local $8 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - tee_local $9 + tee_local $8 get_local $16 f64.sub f64.sub else i32.const 0 set_local $7 - get_local $4 + get_local $5 i32.const 1048576 i32.lt_s if (result i32) @@ -694,32 +694,32 @@ i64.const 32 i64.shr_u i32.wrap/i64 - set_local $4 + set_local $5 i32.const -53 else i32.const 0 end - get_local $4 + get_local $5 i32.const 20 i32.shr_s i32.const 1023 i32.sub i32.add set_local $7 - get_local $4 + get_local $5 i32.const 1048575 i32.and - tee_local $5 + tee_local $9 i32.const 1072693248 i32.or - set_local $4 - get_local $5 + set_local $5 + get_local $9 i32.const 235662 i32.le_s if (result i32) i32.const 0 else - get_local $5 + get_local $9 i32.const 767610 i32.lt_s if (result i32) @@ -729,19 +729,19 @@ i32.const 1 i32.add set_local $7 - get_local $4 + get_local $5 i32.const -1048576 i32.add - set_local $4 + set_local $5 i32.const 0 end end - set_local $10 + set_local $12 get_local $2 i64.reinterpret/f64 i64.const 4294967295 i64.and - get_local $4 + get_local $5 i64.extend_s/i32 i64.const 32 i64.shl @@ -750,7 +750,7 @@ tee_local $2 f64.const 1.5 f64.const 1 - get_local $10 + get_local $12 select tee_local $0 f64.sub @@ -762,16 +762,16 @@ f64.div tee_local $6 f64.mul - set_local $9 + set_local $14 get_local $2 - get_local $4 + get_local $5 i32.const 1 i32.shr_s i32.const 536870912 i32.or i32.const 524288 i32.add - get_local $10 + get_local $12 i32.const 18 i32.shl i32.add @@ -779,27 +779,27 @@ i64.const 32 i64.shl f64.reinterpret/i64 - tee_local $3 + tee_local $8 get_local $0 f64.sub f64.sub set_local $2 - get_local $9 - get_local $9 + get_local $14 + get_local $14 f64.mul - tee_local $15 - get_local $15 + tee_local $3 + get_local $3 f64.mul f64.const 0.5999999999999946 - get_local $15 + get_local $3 f64.const 0.4285714285785502 - get_local $15 + get_local $3 f64.const 0.33333332981837743 - get_local $15 + get_local $3 f64.const 0.272728123808534 - get_local $15 + get_local $3 f64.const 0.23066074577556175 - get_local $15 + get_local $3 f64.const 0.20697501780033842 f64.mul f64.add @@ -815,13 +815,13 @@ set_local $19 get_local $6 get_local $16 - get_local $9 + get_local $14 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 tee_local $6 - get_local $3 + get_local $8 f64.mul f64.sub get_local $6 @@ -834,40 +834,40 @@ get_local $6 get_local $6 f64.mul - tee_local $15 + tee_local $3 f64.add get_local $19 get_local $0 get_local $6 - get_local $9 + get_local $14 f64.add f64.mul f64.add tee_local $19 f64.add - set_local $3 + set_local $8 get_local $19 - get_local $3 + get_local $8 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - tee_local $3 + tee_local $8 f64.const 3 f64.sub - get_local $15 + get_local $3 f64.sub f64.sub set_local $2 get_local $6 - get_local $3 + get_local $8 f64.mul tee_local $16 get_local $0 - get_local $3 + get_local $8 f64.mul get_local $2 - get_local $9 + get_local $14 f64.mul f64.add tee_local $6 @@ -897,14 +897,14 @@ f64.add f64.const 1.350039202129749e-08 f64.const 0 - get_local $10 + get_local $12 select f64.add tee_local $2 f64.add f64.const 0.5849624872207642 f64.const 0 - get_local $10 + get_local $12 select tee_local $0 f64.add @@ -912,14 +912,14 @@ f64.convert_s/i32 tee_local $3 f64.add - set_local $9 + set_local $8 get_local $2 - get_local $9 + get_local $8 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - tee_local $9 + tee_local $8 get_local $3 f64.sub get_local $0 @@ -937,7 +937,7 @@ f64.reinterpret/i64 tee_local $0 f64.sub - get_local $9 + get_local $8 f64.mul get_local $1 get_local $2 @@ -945,7 +945,7 @@ f64.add tee_local $6 get_local $0 - get_local $9 + get_local $8 f64.mul tee_local $0 f64.add @@ -953,21 +953,21 @@ i64.reinterpret/f64 tee_local $17 i32.wrap/i64 - set_local $8 + set_local $4 block $folding-inner1 block $folding-inner0 get_local $17 i64.const 32 i64.shr_u i32.wrap/i64 - tee_local $5 + tee_local $9 i32.const 1083179008 i32.ge_s if - get_local $5 + get_local $9 i32.const 1083179008 i32.sub - get_local $8 + get_local $4 i32.or br_if $folding-inner0 get_local $6 @@ -979,16 +979,16 @@ f64.gt br_if $folding-inner0 else - get_local $5 + get_local $9 i32.const 2147483647 i32.and i32.const 1083231232 i32.ge_s if - get_local $5 + get_local $9 i32.const -1064252416 i32.sub - get_local $8 + get_local $4 i32.or br_if $folding-inner1 get_local $6 @@ -999,27 +999,27 @@ br_if $folding-inner1 end end - get_local $5 + get_local $9 i32.const 2147483647 i32.and - tee_local $8 + tee_local $4 i32.const 20 i32.shr_s i32.const 1023 i32.sub - set_local $10 + set_local $12 i32.const 0 set_local $7 - get_local $8 + get_local $4 i32.const 1071644672 i32.gt_s if i32.const 1048576 - get_local $10 + get_local $12 i32.const 1 i32.add i32.shr_s - get_local $5 + get_local $9 i32.add tee_local $7 i32.const 2147483647 @@ -1028,9 +1028,9 @@ i32.shr_s i32.const 1023 i32.sub - set_local $10 + set_local $12 i32.const 1048575 - get_local $10 + get_local $12 i32.shr_s i32.const -1 i32.xor @@ -1047,7 +1047,7 @@ i32.const 1048576 i32.or i32.const 20 - get_local $10 + get_local $12 i32.sub i32.shr_s set_local $7 @@ -1055,7 +1055,7 @@ get_local $7 i32.sub get_local $7 - get_local $5 + get_local $9 i32.const 0 i32.lt_s select @@ -1093,7 +1093,7 @@ get_local $2 f64.mul set_local $3 - get_local $11 + get_local $10 f64.const 1 get_local $2 get_local $2 @@ -1117,9 +1117,9 @@ f64.add f64.mul f64.sub - tee_local $9 + tee_local $8 f64.mul - get_local $9 + get_local $8 f64.const 2 f64.sub f64.div @@ -1146,7 +1146,7 @@ i32.const 20 i32.shl i32.add - tee_local $5 + tee_local $9 i32.const 20 i32.shr_s i32.const 0 @@ -1160,7 +1160,7 @@ i64.reinterpret/f64 i64.const 4294967295 i64.and - get_local $5 + get_local $9 i64.extend_s/i32 i64.const 32 i64.shl @@ -1170,14 +1170,14 @@ f64.mul return end - get_local $11 + get_local $10 f64.const 1.e+300 f64.mul f64.const 1.e+300 f64.mul return end - get_local $11 + get_local $10 f64.const 1e-300 f64.mul f64.const 1e-300 diff --git a/tests/compiler/std/operator-overloading.untouched.wat b/tests/compiler/std/operator-overloading.untouched.wat index 804142cb63..a6edcef338 100644 --- a/tests/compiler/std/operator-overloading.untouched.wat +++ b/tests/compiler/std/operator-overloading.untouched.wat @@ -369,7 +369,7 @@ (local $11 i32) (local $12 i32) (local $13 i32) - (local $14 f64) + (local $14 i32) (local $15 f64) (local $16 f64) (local $17 f64) @@ -381,10 +381,10 @@ (local $23 f64) (local $24 f64) (local $25 f64) - (local $26 i32) - (local $27 i32) - (local $28 f64) - (local $29 f64) + (local $26 f64) + (local $27 f64) + (local $28 i32) + (local $29 i32) (local $30 f64) (local $31 f64) (local $32 f64) @@ -395,7 +395,8 @@ (local $37 f64) (local $38 f64) (local $39 f64) - (local $40 i32) + (local $40 f64) + (local $41 i32) get_local $0 i64.reinterpret/f64 set_local $2 @@ -507,34 +508,34 @@ i32.const 1023 i32.sub set_local $11 - i32.const 52 - i32.const 20 get_local $11 i32.const 20 i32.gt_s + set_local $9 + i32.const 52 + i32.const 20 + get_local $9 select get_local $11 i32.sub - set_local $9 + set_local $12 get_local $6 get_local $8 - get_local $11 - i32.const 20 - i32.gt_s - select - set_local $12 - get_local $12 get_local $9 - i32.shr_s + select set_local $13 get_local $13 - get_local $9 - i32.shl get_local $12 + i32.shr_s + set_local $14 + get_local $14 + get_local $12 + i32.shl + get_local $13 i32.eq if i32.const 2 - get_local $13 + get_local $14 i32.const 1 i32.and i32.sub @@ -633,41 +634,41 @@ end get_local $0 f64.abs - set_local $14 + set_local $15 get_local $4 i32.const 0 i32.eq if get_local $7 - i32.const 2146435072 + i32.const 0 i32.eq - tee_local $13 + tee_local $14 if (result i32) - get_local $13 + get_local $14 else get_local $7 - i32.const 0 + i32.const 2146435072 i32.eq end - tee_local $13 + tee_local $14 if (result i32) - get_local $13 + get_local $14 else get_local $7 i32.const 1072693248 i32.eq end if - get_local $14 - set_local $15 + get_local $15 + set_local $16 get_local $5 i32.const 0 i32.lt_s if f64.const 1 - get_local $15 + get_local $16 f64.div - set_local $15 + set_local $16 end get_local $3 i32.const 0 @@ -681,31 +682,31 @@ i32.const 0 i32.eq if - get_local $15 - get_local $15 - f64.sub - get_local $15 - get_local $15 + get_local $16 + get_local $16 f64.sub + set_local $17 + get_local $17 + get_local $17 f64.div - set_local $15 + set_local $16 else get_local $10 i32.const 1 i32.eq if - get_local $15 + get_local $16 f64.neg - set_local $15 + set_local $16 end end end - get_local $15 + get_local $16 return end end f64.const 1 - set_local $16 + set_local $18 get_local $3 i32.const 0 i32.lt_s @@ -717,9 +718,9 @@ get_local $0 get_local $0 f64.sub - get_local $0 - get_local $0 - f64.sub + set_local $17 + get_local $17 + get_local $17 f64.div return end @@ -728,7 +729,7 @@ i32.eq if f64.const -1 - set_local $16 + set_local $18 end end get_local $8 @@ -784,13 +785,13 @@ i32.const 0 i32.lt_s if (result f64) - get_local $16 + get_local $18 f64.const 1.e+300 f64.mul f64.const 1.e+300 f64.mul else - get_local $16 + get_local $18 f64.const 1e-300 f64.mul f64.const 1e-300 @@ -806,13 +807,13 @@ i32.const 0 i32.gt_s if (result f64) - get_local $16 + get_local $18 f64.const 1.e+300 f64.mul f64.const 1.e+300 f64.mul else - get_local $16 + get_local $18 f64.const 1e-300 f64.mul f64.const 1e-300 @@ -820,98 +821,98 @@ end return end - get_local $14 + get_local $15 f64.const 1 f64.sub - set_local $22 - get_local $22 - get_local $22 + set_local $24 + get_local $24 + get_local $24 f64.mul f64.const 0.5 - get_local $22 + get_local $24 f64.const 0.3333333333333333 - get_local $22 + get_local $24 f64.const 0.25 f64.mul f64.sub f64.mul f64.sub f64.mul - set_local $25 + set_local $27 f64.const 1.4426950216293335 - get_local $22 + get_local $24 f64.mul - set_local $23 - get_local $22 + set_local $25 + get_local $24 f64.const 1.9259629911266175e-08 f64.mul - get_local $25 + get_local $27 f64.const 1.4426950408889634 f64.mul f64.sub - set_local $24 - get_local $23 - get_local $24 + set_local $26 + get_local $25 + get_local $26 f64.add - set_local $17 - get_local $17 + set_local $19 + get_local $19 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - set_local $17 - get_local $24 - get_local $17 - get_local $23 + set_local $19 + get_local $26 + get_local $19 + get_local $25 f64.sub f64.sub - set_local $18 + set_local $20 else i32.const 0 - set_local $27 + set_local $29 get_local $7 i32.const 1048576 i32.lt_s if - get_local $14 + get_local $15 f64.const 9007199254740992 f64.mul - set_local $14 - get_local $27 + set_local $15 + get_local $29 i32.const 53 i32.sub - set_local $27 - get_local $14 + set_local $29 + get_local $15 i64.reinterpret/f64 i64.const 32 i64.shr_u i32.wrap/i64 set_local $7 end - get_local $27 + get_local $29 get_local $7 i32.const 20 i32.shr_s i32.const 1023 i32.sub i32.add - set_local $27 + set_local $29 get_local $7 i32.const 1048575 i32.and - set_local $26 - get_local $26 + set_local $28 + get_local $28 i32.const 1072693248 i32.or set_local $7 - get_local $26 + get_local $28 i32.const 235662 i32.le_s if i32.const 0 set_local $11 else - get_local $26 + get_local $28 i32.const 767610 i32.lt_s if @@ -920,17 +921,17 @@ else i32.const 0 set_local $11 - get_local $27 + get_local $29 i32.const 1 i32.add - set_local $27 + set_local $29 get_local $7 i32.const 1048576 i32.sub set_local $7 end end - get_local $14 + get_local $15 i64.reinterpret/f64 i64.const 4294967295 i64.and @@ -940,34 +941,34 @@ i64.shl i64.or f64.reinterpret/i64 - set_local $14 + set_local $15 f64.const 1.5 f64.const 1 get_local $11 select - set_local $34 - get_local $14 - get_local $34 + set_local $35 + get_local $15 + get_local $35 f64.sub - set_local $23 + set_local $25 f64.const 1 - get_local $14 - get_local $34 + get_local $15 + get_local $35 f64.add f64.div - set_local $24 - get_local $23 - get_local $24 + set_local $26 + get_local $25 + get_local $26 f64.mul - set_local $28 - get_local $28 - set_local $30 - get_local $30 + set_local $17 + get_local $17 + set_local $31 + get_local $31 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - set_local $30 + set_local $31 get_local $7 i32.const 1 i32.shr_s @@ -983,42 +984,42 @@ i64.const 32 i64.shl f64.reinterpret/i64 - set_local $32 - get_local $14 - get_local $32 - get_local $34 + set_local $33 + get_local $15 + get_local $33 + get_local $35 f64.sub f64.sub - set_local $33 - get_local $24 - get_local $23 - get_local $30 - get_local $32 + set_local $34 + get_local $26 + get_local $25 + get_local $31 + get_local $33 f64.mul f64.sub - get_local $30 - get_local $33 + get_local $31 + get_local $34 f64.mul f64.sub f64.mul - set_local $31 - get_local $28 - get_local $28 + set_local $32 + get_local $17 + get_local $17 f64.mul - set_local $29 - get_local $29 - get_local $29 + set_local $30 + get_local $30 + get_local $30 f64.mul f64.const 0.5999999999999946 - get_local $29 + get_local $30 f64.const 0.4285714285785502 - get_local $29 + get_local $30 f64.const 0.33333332981837743 - get_local $29 + get_local $30 f64.const 0.272728123808534 - get_local $29 + get_local $30 f64.const 0.23066074577556175 - get_local $29 + get_local $30 f64.const 0.20697501780033842 f64.mul f64.add @@ -1031,184 +1032,184 @@ f64.mul f64.add f64.mul - set_local $21 - get_local $21 + set_local $23 + get_local $23 + get_local $32 get_local $31 - get_local $30 - get_local $28 + get_local $17 f64.add f64.mul f64.add - set_local $21 - get_local $30 - get_local $30 + set_local $23 + get_local $31 + get_local $31 f64.mul - set_local $29 + set_local $30 f64.const 3 - get_local $29 + get_local $30 f64.add - get_local $21 + get_local $23 f64.add - set_local $32 - get_local $32 + set_local $33 + get_local $33 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - set_local $32 - get_local $21 - get_local $32 + set_local $33 + get_local $23 + get_local $33 f64.const 3 f64.sub - get_local $29 + get_local $30 f64.sub f64.sub - set_local $33 - get_local $30 - get_local $32 - f64.mul - set_local $23 + set_local $34 get_local $31 - get_local $32 + get_local $33 f64.mul + set_local $25 + get_local $32 get_local $33 - get_local $28 + f64.mul + get_local $34 + get_local $17 f64.mul f64.add - set_local $24 - get_local $23 - get_local $24 + set_local $26 + get_local $25 + get_local $26 f64.add - set_local $19 - get_local $19 + set_local $21 + get_local $21 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - set_local $19 - get_local $24 - get_local $19 - get_local $23 + set_local $21 + get_local $26 + get_local $21 + get_local $25 f64.sub f64.sub - set_local $20 + set_local $22 f64.const 0.9617967009544373 - get_local $19 + get_local $21 f64.mul - set_local $35 + set_local $36 f64.const 1.350039202129749e-08 f64.const 0 get_local $11 select - set_local $36 + set_local $37 f64.const -7.028461650952758e-09 - get_local $19 + get_local $21 f64.mul - get_local $20 + get_local $22 f64.const 0.9617966939259756 f64.mul f64.add - get_local $36 + get_local $37 f64.add - set_local $37 - get_local $27 + set_local $38 + get_local $29 f64.convert_s/i32 - set_local $22 + set_local $24 f64.const 0.5849624872207642 f64.const 0 get_local $11 select - set_local $38 - get_local $35 - get_local $37 - f64.add + set_local $39 + get_local $36 get_local $38 f64.add - get_local $22 + get_local $39 f64.add - set_local $17 - get_local $17 + get_local $24 + f64.add + set_local $19 + get_local $19 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - set_local $17 - get_local $37 - get_local $17 - get_local $22 - f64.sub + set_local $19 get_local $38 + get_local $19 + get_local $24 f64.sub - get_local $35 + get_local $39 f64.sub + get_local $36 f64.sub - set_local $18 + f64.sub + set_local $20 end get_local $1 - set_local $39 - get_local $39 + set_local $40 + get_local $40 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - set_local $39 + set_local $40 get_local $1 - get_local $39 + get_local $40 f64.sub - get_local $17 + get_local $19 f64.mul get_local $1 - get_local $18 + get_local $20 f64.mul f64.add - set_local $20 - get_local $39 - get_local $17 - f64.mul - set_local $19 - get_local $20 + set_local $22 + get_local $40 get_local $19 + f64.mul + set_local $21 + get_local $22 + get_local $21 f64.add - set_local $15 - get_local $15 + set_local $16 + get_local $16 i64.reinterpret/f64 set_local $2 get_local $2 i64.const 32 i64.shr_u i32.wrap/i64 - set_local $26 + set_local $28 get_local $2 i32.wrap/i64 - set_local $40 - get_local $26 + set_local $41 + get_local $28 i32.const 1083179008 i32.ge_s if - get_local $26 + get_local $28 i32.const 1083179008 i32.sub - get_local $40 + get_local $41 i32.or i32.const 0 i32.ne if - get_local $16 + get_local $18 f64.const 1.e+300 f64.mul f64.const 1.e+300 f64.mul return end - get_local $20 + get_local $22 f64.const 8.008566259537294e-17 f64.add - get_local $15 - get_local $19 + get_local $16 + get_local $21 f64.sub f64.gt if - get_local $16 + get_local $18 f64.const 1.e+300 f64.mul f64.const 1.e+300 @@ -1216,34 +1217,34 @@ return end else - get_local $26 + get_local $28 i32.const 2147483647 i32.and i32.const 1083231232 i32.ge_s if - get_local $26 + get_local $28 i32.const -1064252416 i32.sub - get_local $40 + get_local $41 i32.or i32.const 0 i32.ne if - get_local $16 + get_local $18 f64.const 1e-300 f64.mul f64.const 1e-300 f64.mul return end - get_local $20 - get_local $15 - get_local $19 + get_local $22 + get_local $16 + get_local $21 f64.sub f64.le if - get_local $16 + get_local $18 f64.const 1e-300 f64.mul f64.const 1e-300 @@ -1252,31 +1253,31 @@ end end end - get_local $26 + get_local $28 i32.const 2147483647 i32.and - set_local $40 - get_local $40 + set_local $41 + get_local $41 i32.const 20 i32.shr_s i32.const 1023 i32.sub set_local $11 i32.const 0 - set_local $27 - get_local $40 + set_local $29 + get_local $41 i32.const 1071644672 i32.gt_s if - get_local $26 + get_local $28 i32.const 1048576 get_local $11 i32.const 1 i32.add i32.shr_s i32.add - set_local $27 - get_local $27 + set_local $29 + get_local $29 i32.const 2147483647 i32.and i32.const 20 @@ -1285,8 +1286,8 @@ i32.sub set_local $11 f64.const 0 - set_local $22 - get_local $27 + set_local $24 + get_local $29 i32.const 1048575 get_local $11 i32.shr_s @@ -1297,8 +1298,8 @@ i64.const 32 i64.shl f64.reinterpret/i64 - set_local $22 - get_local $27 + set_local $24 + get_local $29 i32.const 1048575 i32.and i32.const 1048576 @@ -1307,71 +1308,71 @@ get_local $11 i32.sub i32.shr_s - set_local $27 - get_local $26 + set_local $29 + get_local $28 i32.const 0 i32.lt_s if i32.const 0 - get_local $27 + get_local $29 i32.sub - set_local $27 + set_local $29 end - get_local $19 - get_local $22 + get_local $21 + get_local $24 f64.sub - set_local $19 + set_local $21 end - get_local $20 - get_local $19 - f64.add - set_local $22 get_local $22 + get_local $21 + f64.add + set_local $24 + get_local $24 i64.reinterpret/f64 i64.const -4294967296 i64.and f64.reinterpret/i64 - set_local $22 - get_local $22 + set_local $24 + get_local $24 f64.const 0.6931471824645996 f64.mul - set_local $23 - get_local $20 + set_local $25 get_local $22 - get_local $19 + get_local $24 + get_local $21 f64.sub f64.sub f64.const 0.6931471805599453 f64.mul - get_local $22 + get_local $24 f64.const -1.904654299957768e-09 f64.mul f64.add - set_local $24 - get_local $23 - get_local $24 + set_local $26 + get_local $25 + get_local $26 f64.add - set_local $15 - get_local $24 - get_local $15 - get_local $23 + set_local $16 + get_local $26 + get_local $16 + get_local $25 f64.sub f64.sub - set_local $25 - get_local $15 - get_local $15 + set_local $27 + get_local $16 + get_local $16 f64.mul - set_local $22 - get_local $15 - get_local $22 + set_local $24 + get_local $16 + get_local $24 f64.const 0.16666666666666602 - get_local $22 + get_local $24 f64.const -2.7777777777015593e-03 - get_local $22 + get_local $24 f64.const 6.613756321437934e-05 - get_local $22 + get_local $24 f64.const -1.6533902205465252e-06 - get_local $22 + get_local $24 f64.const 4.1381367970572385e-08 f64.mul f64.add @@ -1383,64 +1384,64 @@ f64.add f64.mul f64.sub - set_local $17 - get_local $15 - get_local $17 + set_local $19 + get_local $16 + get_local $19 f64.mul - get_local $17 + get_local $19 f64.const 2 f64.sub f64.div - get_local $25 - get_local $15 - get_local $25 + get_local $27 + get_local $16 + get_local $27 f64.mul f64.add f64.sub - set_local $21 + set_local $23 f64.const 1 - get_local $21 - get_local $15 + get_local $23 + get_local $16 f64.sub f64.sub - set_local $15 - get_local $15 + set_local $16 + get_local $16 i64.reinterpret/f64 i64.const 32 i64.shr_u i32.wrap/i64 - set_local $26 - get_local $26 - get_local $27 + set_local $28 + get_local $28 + get_local $29 i32.const 20 i32.shl i32.add - set_local $26 - get_local $26 + set_local $28 + get_local $28 i32.const 20 i32.shr_s i32.const 0 i32.le_s if - get_local $15 - get_local $27 + get_local $16 + get_local $29 call $~lib/math/NativeMath.scalbn - set_local $15 + set_local $16 else - get_local $15 + get_local $16 i64.reinterpret/f64 i64.const 4294967295 i64.and - get_local $26 + get_local $28 i64.extend_s/i32 i64.const 32 i64.shl i64.or f64.reinterpret/i64 - set_local $15 + set_local $16 end + get_local $18 get_local $16 - get_local $15 f64.mul ) (func $std/operator-overloading/Tester.pow (; 11 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) From 2f635d905c96c262391f81b6a111ad0490a7feee Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sat, 19 Jan 2019 00:04:22 +0200 Subject: [PATCH 02/10] add ipow32f and ipow64f --- std/assembly/math.ts | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/std/assembly/math.ts b/std/assembly/math.ts index 1aeeb4b2c1..cdef5fd124 100644 --- a/std/assembly/math.ts +++ b/std/assembly/math.ts @@ -2381,3 +2381,43 @@ export function ipow64(x: i64, e: i32): i64 { } return out; } + +function ipow32f(x: f32, e: i32): f32 { + if (ASC_SHRINK_LEVEL < 1) { + switch (e) { + case -2: return 1.0 / (x * x); + case -1: return 1.0 / x; + case 0: return 1.0; + case 1: return x; + case 2: return x * x; + } + } + var sign = e < 0; + var out: f32 = 1; + while (e) { + if (e & 1) out *= x; + e /= 2; + x *= x; + } + return sign ? 1.0 / out : out; +} + +function ipow64f(x: f64, e: i32): f64 { + if (ASC_SHRINK_LEVEL < 1) { + switch (e) { + case -2: return 1.0 / (x * x); + case -1: return 1.0 / x; + case 0: return 1.0; + case 1: return x; + case 2: return x * x; + } + } + var sign = e < 0; + var out = 1.0; + while (e) { + if (e & 1) out *= x; + e /= 2; + x *= x; + } + return sign ? 1.0 / out : out; +} From 0fc3e978f03f49bf55338bfbc2495cf51e77365c Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sat, 19 Jan 2019 00:09:03 +0200 Subject: [PATCH 03/10] force consts to f32 --- std/assembly/math.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/std/assembly/math.ts b/std/assembly/math.ts index cdef5fd124..d71589a44e 100644 --- a/std/assembly/math.ts +++ b/std/assembly/math.ts @@ -2385,9 +2385,9 @@ export function ipow64(x: i64, e: i32): i64 { function ipow32f(x: f32, e: i32): f32 { if (ASC_SHRINK_LEVEL < 1) { switch (e) { - case -2: return 1.0 / (x * x); - case -1: return 1.0 / x; - case 0: return 1.0; + case -2: return 1.0 / (x * x); + case -1: return 1.0 / x; + case 0: return 1.0; case 1: return x; case 2: return x * x; } From cc9e29b147fc65ee01d77b2a76583e776b3af8be Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sun, 20 Jan 2019 01:20:01 +0200 Subject: [PATCH 04/10] improve speed for ipowXXf using unsigned operations --- std/assembly/math.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/std/assembly/math.ts b/std/assembly/math.ts index d71589a44e..4e05f00dad 100644 --- a/std/assembly/math.ts +++ b/std/assembly/math.ts @@ -2393,10 +2393,11 @@ function ipow32f(x: f32, e: i32): f32 { } } var sign = e < 0; + e = abs(e); var out: f32 = 1; while (e) { if (e & 1) out *= x; - e /= 2; + e >>= 1; x *= x; } return sign ? 1.0 / out : out; @@ -2413,10 +2414,11 @@ function ipow64f(x: f64, e: i32): f64 { } } var sign = e < 0; + e = abs(e); var out = 1.0; while (e) { if (e & 1) out *= x; - e /= 2; + e >>= 1; x *= x; } return sign ? 1.0 / out : out; From b43fa590ae783ed955cb1b32d05cd086d8f0739e Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sun, 20 Jan 2019 01:58:07 +0200 Subject: [PATCH 05/10] add tests for ipow32f and ipow64f --- std/assembly/math.ts | 4 +- tests/compiler/std/math.optimized.wat | 690 +++++++++++++++++++++++-- tests/compiler/std/math.ts | 38 ++ tests/compiler/std/math.untouched.wat | 698 +++++++++++++++++++++++++- 4 files changed, 1390 insertions(+), 40 deletions(-) diff --git a/std/assembly/math.ts b/std/assembly/math.ts index 4e05f00dad..69c686d31f 100644 --- a/std/assembly/math.ts +++ b/std/assembly/math.ts @@ -2382,7 +2382,7 @@ export function ipow64(x: i64, e: i32): i64 { return out; } -function ipow32f(x: f32, e: i32): f32 { +export function ipow32f(x: f32, e: i32): f32 { if (ASC_SHRINK_LEVEL < 1) { switch (e) { case -2: return 1.0 / (x * x); @@ -2403,7 +2403,7 @@ function ipow32f(x: f32, e: i32): f32 { return sign ? 1.0 / out : out; } -function ipow64f(x: f64, e: i32): f64 { +export function ipow64f(x: f64, e: i32): f64 { if (ASC_SHRINK_LEVEL < 1) { switch (e) { case -2: return 1.0 / (x * x); diff --git a/tests/compiler/std/math.optimized.wat b/tests/compiler/std/math.optimized.wat index 195ec166f1..df380b57bc 100644 --- a/tests/compiler/std/math.optimized.wat +++ b/tests/compiler/std/math.optimized.wat @@ -9378,11 +9378,211 @@ end get_local $2 ) - (func $start (; 146 ;) (type $v) - (local $0 i32) - (local $1 i32) + (func $~lib/math/ipow32f (; 146 ;) (type $fif) (param $0 f32) (param $1 i32) (result f32) + (local $2 f32) + (local $3 i32) + (local $4 i32) + block $break|0 + block $case4|0 + block $case3|0 + block $case2|0 + block $case1|0 + get_local $1 + i32.const -2 + i32.ne + if + get_local $1 + i32.const -1 + i32.eq + br_if $case1|0 + get_local $1 + i32.eqz + br_if $case2|0 + get_local $1 + i32.const 1 + i32.eq + br_if $case3|0 + get_local $1 + i32.const 2 + i32.eq + br_if $case4|0 + br $break|0 + end + f32.const 1 + get_local $0 + get_local $0 + f32.mul + f32.div + return + end + f32.const 1 + get_local $0 + f32.div + return + end + f32.const 1 + return + end + get_local $0 + return + end + get_local $0 + get_local $0 + f32.mul + return + end + get_local $1 + i32.const 0 + i32.lt_s + set_local $3 + get_local $1 + i32.const 31 + i32.shr_s + tee_local $4 + get_local $1 + get_local $4 + i32.add + i32.xor + set_local $1 + f32.const 1 + set_local $2 + loop $continue|1 + get_local $1 + if + get_local $2 + get_local $0 + f32.mul + get_local $2 + get_local $1 + i32.const 1 + i32.and + select + set_local $2 + get_local $1 + i32.const 1 + i32.shr_s + set_local $1 + get_local $0 + get_local $0 + f32.mul + set_local $0 + br $continue|1 + end + end + get_local $3 + if + f32.const 1 + get_local $2 + f32.div + set_local $2 + end + get_local $2 + ) + (func $~lib/math/ipow64f (; 147 ;) (type $FiF) (param $0 f64) (param $1 i32) (result f64) (local $2 f64) - (local $3 f32) + (local $3 i32) + (local $4 i32) + block $break|0 + block $case4|0 + block $case3|0 + block $case2|0 + block $case1|0 + get_local $1 + i32.const -2 + i32.ne + if + get_local $1 + i32.const -1 + i32.eq + br_if $case1|0 + get_local $1 + i32.eqz + br_if $case2|0 + get_local $1 + i32.const 1 + i32.eq + br_if $case3|0 + get_local $1 + i32.const 2 + i32.eq + br_if $case4|0 + br $break|0 + end + f64.const 1 + get_local $0 + get_local $0 + f64.mul + f64.div + return + end + f64.const 1 + get_local $0 + f64.div + return + end + f64.const 1 + return + end + get_local $0 + return + end + get_local $0 + get_local $0 + f64.mul + return + end + get_local $1 + i32.const 0 + i32.lt_s + set_local $3 + get_local $1 + i32.const 31 + i32.shr_s + tee_local $4 + get_local $1 + get_local $4 + i32.add + i32.xor + set_local $1 + f64.const 1 + set_local $2 + loop $continue|1 + get_local $1 + if + get_local $2 + get_local $0 + f64.mul + get_local $2 + get_local $1 + i32.const 1 + i32.and + select + set_local $2 + get_local $1 + i32.const 1 + i32.shr_s + set_local $1 + get_local $0 + get_local $0 + f64.mul + set_local $0 + br $continue|1 + end + end + get_local $3 + if + f64.const 1 + get_local $2 + f64.div + set_local $2 + end + get_local $2 + ) + (func $start (; 148 ;) (type $v) + (local $0 f64) + (local $1 f32) + (local $2 i32) + (local $3 i32) f64.const 2.718281828459045 get_global $~lib/bindings/Math/E f64.const 0 @@ -31296,30 +31496,28 @@ i64.reinterpret/f64 call $~lib/math/NativeMath.seedRandom loop $repeat|0 - block $break|0 - get_local $0 - f64.convert_s/i32 - f64.const 1e6 - f64.lt - i32.eqz - br_if $break|0 + get_local $2 + f64.convert_s/i32 + f64.const 1e6 + f64.lt + if call $~lib/math/NativeMath.random - tee_local $2 + tee_local $0 f64.const 0 f64.ge - tee_local $1 - if - get_local $2 + tee_local $3 + if (result i32) + get_local $0 f64.const 1 f64.lt - set_local $1 + else + get_local $3 end - get_local $1 if - get_local $0 + get_local $2 i32.const 1 i32.add - set_local $0 + set_local $2 br $repeat|0 else i32.const 0 @@ -31336,32 +31534,30 @@ i64.reinterpret/f64 call $~lib/math/NativeMath.seedRandom i32.const 0 - set_local $0 + set_local $2 loop $repeat|1 - block $break|1 - get_local $0 - f64.convert_s/i32 - f64.const 1e6 - f64.lt - i32.eqz - br_if $break|1 + get_local $2 + f64.convert_s/i32 + f64.const 1e6 + f64.lt + if call $~lib/math/NativeMathf.random - tee_local $3 + tee_local $1 f32.const 0 f32.ge - tee_local $1 - if - get_local $3 + tee_local $3 + if (result i32) + get_local $1 f32.const 1 f32.lt - set_local $1 + else + get_local $3 end - get_local $1 if - get_local $0 + get_local $2 i32.const 1 i32.add - set_local $0 + set_local $2 br $repeat|1 else i32.const 0 @@ -37930,8 +38126,430 @@ call $~lib/env/abort unreachable end + f32.const 0 + i32.const 0 + call $~lib/math/ipow32f + f32.const 1 + f32.ne + if + i32.const 0 + i32.const 8 + i32.const 3311 + i32.const 0 + call $~lib/env/abort + unreachable + end + f32.const nan:0x400000 + i32.const 0 + call $~lib/math/ipow32f + f32.const 1 + f32.ne + if + i32.const 0 + i32.const 8 + i32.const 3312 + i32.const 0 + call $~lib/env/abort + unreachable + end + f32.const nan:0x400000 + i32.const 1 + call $~lib/math/ipow32f + tee_local $1 + get_local $1 + f32.eq + if + i32.const 0 + i32.const 8 + i32.const 3313 + i32.const 0 + call $~lib/env/abort + unreachable + end + f32.const nan:0x400000 + i32.const -1 + call $~lib/math/ipow32f + tee_local $1 + get_local $1 + f32.eq + if + i32.const 0 + i32.const 8 + i32.const 3314 + i32.const 0 + call $~lib/env/abort + unreachable + end + f32.const nan:0x400000 + i32.const 2 + call $~lib/math/ipow32f + tee_local $1 + get_local $1 + f32.eq + if + i32.const 0 + i32.const 8 + i32.const 3315 + i32.const 0 + call $~lib/env/abort + unreachable + end + f32.const inf + i32.const 0 + call $~lib/math/ipow32f + f32.const 1 + f32.ne + if + i32.const 0 + i32.const 8 + i32.const 3316 + i32.const 0 + call $~lib/env/abort + unreachable + end + f32.const inf + i32.const 1 + call $~lib/math/ipow32f + f32.const inf + f32.ne + if + i32.const 0 + i32.const 8 + i32.const 3317 + i32.const 0 + call $~lib/env/abort + unreachable + end + f32.const -inf + i32.const 0 + call $~lib/math/ipow32f + f32.const 1 + f32.ne + if + i32.const 0 + i32.const 8 + i32.const 3318 + i32.const 0 + call $~lib/env/abort + unreachable + end + f32.const -inf + i32.const 1 + call $~lib/math/ipow32f + f32.const -inf + f32.ne + if + i32.const 0 + i32.const 8 + i32.const 3319 + i32.const 0 + call $~lib/env/abort + unreachable + end + f32.const -inf + i32.const 2 + call $~lib/math/ipow32f + f32.const inf + f32.ne + if + i32.const 0 + i32.const 8 + i32.const 3320 + i32.const 0 + call $~lib/env/abort + unreachable + end + f32.const 1 + i32.const 0 + call $~lib/math/ipow32f + f32.const 1 + f32.ne + if + i32.const 0 + i32.const 8 + i32.const 3321 + i32.const 0 + call $~lib/env/abort + unreachable + end + f32.const 3402823466385288598117041e14 + i32.const 2 + call $~lib/math/ipow32f + f32.const inf + f32.ne + if + i32.const 0 + i32.const 8 + i32.const 3322 + i32.const 0 + call $~lib/env/abort + unreachable + end + f32.const 1.401298464324817e-45 + i32.const 2 + call $~lib/math/ipow32f + f32.const 0 + f32.ne + if + i32.const 0 + i32.const 8 + i32.const 3323 + i32.const 0 + call $~lib/env/abort + unreachable + end + f32.const 3402823466385288598117041e14 + i32.const -1 + call $~lib/math/ipow32f + f32.const 2.938735877055719e-39 + f32.ne + if + i32.const 0 + i32.const 8 + i32.const 3324 + i32.const 0 + call $~lib/env/abort + unreachable + end + f32.const 10 + i32.const 36 + call $~lib/math/ipow32f + f32.const 1000000040918478759629753e12 + f32.ne + if + i32.const 0 + i32.const 8 + i32.const 3325 + i32.const 0 + call $~lib/env/abort + unreachable + end + f32.const 10 + i32.const -36 + call $~lib/math/ipow32f + f32.const 9.999999462560281e-37 + f32.ne + if + i32.const 0 + i32.const 8 + i32.const 3326 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const 0 + i32.const 0 + call $~lib/math/ipow64f + f64.const 1 + f64.ne + if + i32.const 0 + i32.const 8 + i32.const 3330 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const nan:0x8000000000000 + i32.const 0 + call $~lib/math/ipow64f + f64.const 1 + f64.ne + if + i32.const 0 + i32.const 8 + i32.const 3331 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const nan:0x8000000000000 + i32.const 1 + call $~lib/math/ipow64f + tee_local $0 + get_local $0 + f64.eq + if + i32.const 0 + i32.const 8 + i32.const 3332 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const nan:0x8000000000000 + i32.const -1 + call $~lib/math/ipow64f + tee_local $0 + get_local $0 + f64.eq + if + i32.const 0 + i32.const 8 + i32.const 3333 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const nan:0x8000000000000 + i32.const 2 + call $~lib/math/ipow64f + tee_local $0 + get_local $0 + f64.eq + if + i32.const 0 + i32.const 8 + i32.const 3334 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const inf + i32.const 0 + call $~lib/math/ipow64f + f64.const 1 + f64.ne + if + i32.const 0 + i32.const 8 + i32.const 3335 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const inf + i32.const 1 + call $~lib/math/ipow64f + f64.const inf + f64.ne + if + i32.const 0 + i32.const 8 + i32.const 3336 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const -inf + i32.const 0 + call $~lib/math/ipow64f + f64.const 1 + f64.ne + if + i32.const 0 + i32.const 8 + i32.const 3337 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const -inf + i32.const 1 + call $~lib/math/ipow64f + f64.const -inf + f64.ne + if + i32.const 0 + i32.const 8 + i32.const 3338 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const -inf + i32.const 2 + call $~lib/math/ipow64f + f64.const inf + f64.ne + if + i32.const 0 + i32.const 8 + i32.const 3339 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const 1 + i32.const 0 + call $~lib/math/ipow64f + f64.const 1 + f64.ne + if + i32.const 0 + i32.const 8 + i32.const 3340 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const 1797693134862315708145274e284 + i32.const 2 + call $~lib/math/ipow64f + f64.const inf + f64.ne + if + i32.const 0 + i32.const 8 + i32.const 3341 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const 5e-324 + i32.const 2 + call $~lib/math/ipow64f + f64.const 0 + f64.ne + if + i32.const 0 + i32.const 8 + i32.const 3342 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const 1797693134862315708145274e284 + i32.const -1 + call $~lib/math/ipow64f + f64.const 5.562684646268003e-309 + f64.ne + if + i32.const 0 + i32.const 8 + i32.const 3343 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const 10 + i32.const 127 + call $~lib/math/ipow64f + f64.const 1000000000000000195419867e103 + f64.ne + if + i32.const 0 + i32.const 8 + i32.const 3344 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const 10 + i32.const -127 + call $~lib/math/ipow64f + f64.const 9.999999999999998e-128 + f64.ne + if + i32.const 0 + i32.const 8 + i32.const 3345 + i32.const 0 + call $~lib/env/abort + unreachable + end ) - (func $null (; 147 ;) (type $v) + (func $null (; 149 ;) (type $v) nop ) ) diff --git a/tests/compiler/std/math.ts b/tests/compiler/std/math.ts index 0a68c7ddda..dc4052b204 100644 --- a/tests/compiler/std/math.ts +++ b/tests/compiler/std/math.ts @@ -3305,3 +3305,41 @@ assert(ipow64(3, 64) == 8733086111712066817); // should overflow assert(ipow64(3, 128) == -9204772141784466943); // should overflow assert(ipow64(57055, 3) + ipow64(339590, 3) == 39347712995520375); // add Buterin's twit example + +// ipow32f ///////////////////////////////////////////////////////////////////////////////////// + +assert(ipow32f(0, 0) == 1.0); +assert(ipow32f(NaN, 0) == 1.0); +assert(isNaN(ipow32f(NaN, 1))); +assert(isNaN(ipow32f(NaN, -1))); +assert(isNaN(ipow32f(NaN, 2))); +assert(ipow32f(Infinity, 0) == 1.0); +assert(ipow32f(Infinity, 1) == Infinity); +assert(ipow32f(-Infinity, 0) == 1.0); +assert(ipow32f(-Infinity, 1) == -Infinity); +assert(ipow32f(-Infinity, 2) == Infinity); +assert(ipow32f(1.0, 0) == 1.0); +assert(ipow32f(f32.MAX_VALUE, 2) == Infinity); +assert(ipow32f(f32.MIN_VALUE, 2) == 0.0); +assert(ipow32f(f32.MAX_VALUE, -1) == 2.938735877055719e-39); +assert(ipow32f(10.0, 36) == 1.0000000409184788e+36); +assert(ipow32f(10.0,-36) == 9.999999462560281e-37); + +// ipow64f ///////////////////////////////////////////////////////////////////////////////////// + +assert(ipow64f(0, 0) == 1.0); +assert(ipow64f(NaN, 0) == 1.0); +assert(isNaN(ipow64f(NaN, 1))); +assert(isNaN(ipow64f(NaN, -1))); +assert(isNaN(ipow64f(NaN, 2))); +assert(ipow64f(Infinity, 0) == 1.0); +assert(ipow64f(Infinity, 1) == Infinity); +assert(ipow64f(-Infinity, 0) == 1.0); +assert(ipow64f(-Infinity, 1) == -Infinity); +assert(ipow64f(-Infinity, 2) == Infinity); +assert(ipow64f(1.0, 0) == 1.0); +assert(ipow64f(f64.MAX_VALUE, 2) == Infinity); +assert(ipow64f(f64.MIN_VALUE, 2) == 0.0); +assert(ipow64f(f64.MAX_VALUE, -1) == 5.562684646268003e-309); +assert(ipow64f(10.0, 127) == 1.0000000000000002e+127); +assert(ipow64f(10.0,-127) == 9.999999999999998e-128); diff --git a/tests/compiler/std/math.untouched.wat b/tests/compiler/std/math.untouched.wat index 7d44b9d2a2..83bb0a6f4c 100644 --- a/tests/compiler/std/math.untouched.wat +++ b/tests/compiler/std/math.untouched.wat @@ -94,6 +94,9 @@ (global $~lib/math/random_state0_32 (mut i32) (i32.const 0)) (global $~lib/math/random_state1_32 (mut i32) (i32.const 0)) (global $ASC_SHRINK_LEVEL i32 (i32.const 0)) + (global $~lib/builtins/f32.MAX_VALUE f32 (f32.const 3402823466385288598117041e14)) + (global $~lib/builtins/f32.MIN_VALUE f32 (f32.const 1.401298464324817e-45)) + (global $~lib/builtins/f64.MAX_VALUE f64 (f64.const 1797693134862315708145274e284)) (global $HEAP_BASE i32 (i32.const 68)) (export "memory" (memory $0)) (export "table" (table $0)) @@ -11351,7 +11354,227 @@ end get_local $2 ) - (func $start (; 154 ;) (type $v) + (func $~lib/math/ipow32f (; 154 ;) (type $fif) (param $0 f32) (param $1 i32) (result f32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 f32) + block $break|0 + block $case4|0 + block $case3|0 + block $case2|0 + block $case1|0 + block $case0|0 + get_local $1 + set_local $2 + get_local $2 + i32.const -2 + i32.eq + br_if $case0|0 + get_local $2 + i32.const -1 + i32.eq + br_if $case1|0 + get_local $2 + i32.const 0 + i32.eq + br_if $case2|0 + get_local $2 + i32.const 1 + i32.eq + br_if $case3|0 + get_local $2 + i32.const 2 + i32.eq + br_if $case4|0 + br $break|0 + end + f32.const 1 + get_local $0 + get_local $0 + f32.mul + f32.div + return + end + f32.const 1 + get_local $0 + f32.div + return + end + f32.const 1 + return + end + get_local $0 + return + end + get_local $0 + get_local $0 + f32.mul + return + end + get_local $1 + i32.const 0 + i32.lt_s + set_local $3 + get_local $1 + tee_local $2 + i32.const 31 + i32.shr_s + tee_local $4 + get_local $2 + i32.add + get_local $4 + i32.xor + set_local $1 + f32.const 1 + set_local $5 + block $break|1 + loop $continue|1 + get_local $1 + if + block + get_local $1 + i32.const 1 + i32.and + if + get_local $5 + get_local $0 + f32.mul + set_local $5 + end + get_local $1 + i32.const 1 + i32.shr_s + set_local $1 + get_local $0 + get_local $0 + f32.mul + set_local $0 + end + br $continue|1 + end + end + end + get_local $3 + if (result f32) + f32.const 1 + get_local $5 + f32.div + else + get_local $5 + end + ) + (func $~lib/math/ipow64f (; 155 ;) (type $FiF) (param $0 f64) (param $1 i32) (result f64) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 f64) + block $break|0 + block $case4|0 + block $case3|0 + block $case2|0 + block $case1|0 + block $case0|0 + get_local $1 + set_local $2 + get_local $2 + i32.const -2 + i32.eq + br_if $case0|0 + get_local $2 + i32.const -1 + i32.eq + br_if $case1|0 + get_local $2 + i32.const 0 + i32.eq + br_if $case2|0 + get_local $2 + i32.const 1 + i32.eq + br_if $case3|0 + get_local $2 + i32.const 2 + i32.eq + br_if $case4|0 + br $break|0 + end + f64.const 1 + get_local $0 + get_local $0 + f64.mul + f64.div + return + end + f64.const 1 + get_local $0 + f64.div + return + end + f64.const 1 + return + end + get_local $0 + return + end + get_local $0 + get_local $0 + f64.mul + return + end + get_local $1 + i32.const 0 + i32.lt_s + set_local $3 + get_local $1 + tee_local $2 + i32.const 31 + i32.shr_s + tee_local $4 + get_local $2 + i32.add + get_local $4 + i32.xor + set_local $1 + f64.const 1 + set_local $5 + block $break|1 + loop $continue|1 + get_local $1 + if + block + get_local $1 + i32.const 1 + i32.and + if + get_local $5 + get_local $0 + f64.mul + set_local $5 + end + get_local $1 + i32.const 1 + i32.shr_s + set_local $1 + get_local $0 + get_local $0 + f64.mul + set_local $0 + end + br $continue|1 + end + end + end + get_local $3 + if (result f64) + f64.const 1 + get_local $5 + f64.div + else + get_local $5 + end + ) + (func $start (; 156 ;) (type $v) (local $0 i32) (local $1 f64) (local $2 i32) @@ -42118,7 +42341,478 @@ call $~lib/env/abort unreachable end + f32.const 0 + i32.const 0 + call $~lib/math/ipow32f + f32.const 1 + f32.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3311 + i32.const 0 + call $~lib/env/abort + unreachable + end + f32.const nan:0x400000 + i32.const 0 + call $~lib/math/ipow32f + f32.const 1 + f32.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3312 + i32.const 0 + call $~lib/env/abort + unreachable + end + block $~lib/builtins/isNaN|inlined.2 (result i32) + f32.const nan:0x400000 + i32.const 1 + call $~lib/math/ipow32f + set_local $4 + get_local $4 + get_local $4 + f32.ne + end + i32.const 0 + i32.ne + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3313 + i32.const 0 + call $~lib/env/abort + unreachable + end + block $~lib/builtins/isNaN|inlined.3 (result i32) + f32.const nan:0x400000 + i32.const -1 + call $~lib/math/ipow32f + set_local $4 + get_local $4 + get_local $4 + f32.ne + end + i32.const 0 + i32.ne + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3314 + i32.const 0 + call $~lib/env/abort + unreachable + end + block $~lib/builtins/isNaN|inlined.4 (result i32) + f32.const nan:0x400000 + i32.const 2 + call $~lib/math/ipow32f + set_local $4 + get_local $4 + get_local $4 + f32.ne + end + i32.const 0 + i32.ne + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3315 + i32.const 0 + call $~lib/env/abort + unreachable + end + f32.const inf + i32.const 0 + call $~lib/math/ipow32f + f32.const 1 + f32.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3316 + i32.const 0 + call $~lib/env/abort + unreachable + end + f32.const inf + i32.const 1 + call $~lib/math/ipow32f + f32.const inf + f32.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3317 + i32.const 0 + call $~lib/env/abort + unreachable + end + f32.const inf + f32.neg + i32.const 0 + call $~lib/math/ipow32f + f32.const 1 + f32.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3318 + i32.const 0 + call $~lib/env/abort + unreachable + end + f32.const inf + f32.neg + i32.const 1 + call $~lib/math/ipow32f + f32.const inf + f32.neg + f32.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3319 + i32.const 0 + call $~lib/env/abort + unreachable + end + f32.const inf + f32.neg + i32.const 2 + call $~lib/math/ipow32f + f32.const inf + f32.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3320 + i32.const 0 + call $~lib/env/abort + unreachable + end + f32.const 1 + i32.const 0 + call $~lib/math/ipow32f + f32.const 1 + f32.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3321 + i32.const 0 + call $~lib/env/abort + unreachable + end + get_global $~lib/builtins/f32.MAX_VALUE + i32.const 2 + call $~lib/math/ipow32f + f32.const inf + f32.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3322 + i32.const 0 + call $~lib/env/abort + unreachable + end + get_global $~lib/builtins/f32.MIN_VALUE + i32.const 2 + call $~lib/math/ipow32f + f32.const 0 + f32.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3323 + i32.const 0 + call $~lib/env/abort + unreachable + end + get_global $~lib/builtins/f32.MAX_VALUE + i32.const -1 + call $~lib/math/ipow32f + f32.const 2.938735877055719e-39 + f32.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3324 + i32.const 0 + call $~lib/env/abort + unreachable + end + f32.const 10 + i32.const 36 + call $~lib/math/ipow32f + f32.const 1000000040918478759629753e12 + f32.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3325 + i32.const 0 + call $~lib/env/abort + unreachable + end + f32.const 10 + i32.const -36 + call $~lib/math/ipow32f + f32.const 9.999999462560281e-37 + f32.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3326 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const 0 + i32.const 0 + call $~lib/math/ipow64f + f64.const 1 + f64.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3330 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const nan:0x8000000000000 + i32.const 0 + call $~lib/math/ipow64f + f64.const 1 + f64.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3331 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const nan:0x8000000000000 + i32.const 1 + call $~lib/math/ipow64f + call $~lib/builtins/isNaN + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3332 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const nan:0x8000000000000 + i32.const -1 + call $~lib/math/ipow64f + call $~lib/builtins/isNaN + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3333 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const nan:0x8000000000000 + i32.const 2 + call $~lib/math/ipow64f + call $~lib/builtins/isNaN + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3334 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const inf + i32.const 0 + call $~lib/math/ipow64f + f64.const 1 + f64.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3335 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const inf + i32.const 1 + call $~lib/math/ipow64f + f64.const inf + f64.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3336 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const inf + f64.neg + i32.const 0 + call $~lib/math/ipow64f + f64.const 1 + f64.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3337 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const inf + f64.neg + i32.const 1 + call $~lib/math/ipow64f + f64.const inf + f64.neg + f64.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3338 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const inf + f64.neg + i32.const 2 + call $~lib/math/ipow64f + f64.const inf + f64.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3339 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const 1 + i32.const 0 + call $~lib/math/ipow64f + f64.const 1 + f64.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3340 + i32.const 0 + call $~lib/env/abort + unreachable + end + get_global $~lib/builtins/f64.MAX_VALUE + i32.const 2 + call $~lib/math/ipow64f + f64.const inf + f64.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3341 + i32.const 0 + call $~lib/env/abort + unreachable + end + get_global $~lib/builtins/f64.MIN_VALUE + i32.const 2 + call $~lib/math/ipow64f + f64.const 0 + f64.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3342 + i32.const 0 + call $~lib/env/abort + unreachable + end + get_global $~lib/builtins/f64.MAX_VALUE + i32.const -1 + call $~lib/math/ipow64f + f64.const 5.562684646268003e-309 + f64.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3343 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const 10 + i32.const 127 + call $~lib/math/ipow64f + f64.const 1000000000000000195419867e103 + f64.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3344 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const 10 + i32.const -127 + call $~lib/math/ipow64f + f64.const 9.999999999999998e-128 + f64.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3345 + i32.const 0 + call $~lib/env/abort + unreachable + end ) - (func $null (; 155 ;) (type $v) + (func $null (; 157 ;) (type $v) ) ) From 589678e06155b48b75bd2208a122d701576759d0 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sun, 20 Jan 2019 02:09:48 +0200 Subject: [PATCH 06/10] use binary shift for retrieve sign --- std/assembly/math.ts | 4 ++-- tests/compiler/std/math.optimized.wat | 8 ++++---- tests/compiler/std/math.untouched.wat | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/std/assembly/math.ts b/std/assembly/math.ts index 69c686d31f..ba215f2465 100644 --- a/std/assembly/math.ts +++ b/std/assembly/math.ts @@ -2392,7 +2392,7 @@ export function ipow32f(x: f32, e: i32): f32 { case 2: return x * x; } } - var sign = e < 0; + var sign = e >>> 31; e = abs(e); var out: f32 = 1; while (e) { @@ -2413,7 +2413,7 @@ export function ipow64f(x: f64, e: i32): f64 { case 2: return x * x; } } - var sign = e < 0; + var sign = e >>> 31; e = abs(e); var out = 1.0; while (e) { diff --git a/tests/compiler/std/math.optimized.wat b/tests/compiler/std/math.optimized.wat index df380b57bc..273d5bb9b4 100644 --- a/tests/compiler/std/math.optimized.wat +++ b/tests/compiler/std/math.optimized.wat @@ -9432,8 +9432,8 @@ return end get_local $1 - i32.const 0 - i32.lt_s + i32.const 31 + i32.shr_u set_local $3 get_local $1 i32.const 31 @@ -9532,8 +9532,8 @@ return end get_local $1 - i32.const 0 - i32.lt_s + i32.const 31 + i32.shr_u set_local $3 get_local $1 i32.const 31 diff --git a/tests/compiler/std/math.untouched.wat b/tests/compiler/std/math.untouched.wat index 83bb0a6f4c..c9a33e550c 100644 --- a/tests/compiler/std/math.untouched.wat +++ b/tests/compiler/std/math.untouched.wat @@ -11413,8 +11413,8 @@ return end get_local $1 - i32.const 0 - i32.lt_s + i32.const 31 + i32.shr_u set_local $3 get_local $1 tee_local $2 @@ -11523,8 +11523,8 @@ return end get_local $1 - i32.const 0 - i32.lt_s + i32.const 31 + i32.shr_u set_local $3 get_local $1 tee_local $2 From 27bf5fb89d9da1bb03c010c27bcfa7a9abee081b Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sun, 20 Jan 2019 03:08:26 +0200 Subject: [PATCH 07/10] reuse sign for bitwise abs --- std/assembly/math.ts | 8 ++--- tests/compiler/std/math.optimized.wat | 18 +++-------- tests/compiler/std/math.untouched.wat | 46 +++++++++++---------------- 3 files changed, 26 insertions(+), 46 deletions(-) diff --git a/std/assembly/math.ts b/std/assembly/math.ts index ba215f2465..77cc4f2672 100644 --- a/std/assembly/math.ts +++ b/std/assembly/math.ts @@ -2392,8 +2392,8 @@ export function ipow32f(x: f32, e: i32): f32 { case 2: return x * x; } } - var sign = e >>> 31; - e = abs(e); + var sign = e >> 31; + e = (e + sign) ^ sign; // abs(e) var out: f32 = 1; while (e) { if (e & 1) out *= x; @@ -2413,8 +2413,8 @@ export function ipow64f(x: f64, e: i32): f64 { case 2: return x * x; } } - var sign = e >>> 31; - e = abs(e); + var sign = e >> 31; + e = (e + sign) ^ sign; // abs(e) var out = 1.0; while (e) { if (e & 1) out *= x; diff --git a/tests/compiler/std/math.optimized.wat b/tests/compiler/std/math.optimized.wat index 273d5bb9b4..246309b9cf 100644 --- a/tests/compiler/std/math.optimized.wat +++ b/tests/compiler/std/math.optimized.wat @@ -9381,7 +9381,6 @@ (func $~lib/math/ipow32f (; 146 ;) (type $fif) (param $0 f32) (param $1 i32) (result f32) (local $2 f32) (local $3 i32) - (local $4 i32) block $break|0 block $case4|0 block $case3|0 @@ -9433,14 +9432,10 @@ end get_local $1 i32.const 31 - i32.shr_u - set_local $3 - get_local $1 - i32.const 31 i32.shr_s - tee_local $4 + tee_local $3 get_local $1 - get_local $4 + get_local $3 i32.add i32.xor set_local $1 @@ -9481,7 +9476,6 @@ (func $~lib/math/ipow64f (; 147 ;) (type $FiF) (param $0 f64) (param $1 i32) (result f64) (local $2 f64) (local $3 i32) - (local $4 i32) block $break|0 block $case4|0 block $case3|0 @@ -9533,14 +9527,10 @@ end get_local $1 i32.const 31 - i32.shr_u - set_local $3 - get_local $1 - i32.const 31 i32.shr_s - tee_local $4 + tee_local $3 get_local $1 - get_local $4 + get_local $3 i32.add i32.xor set_local $1 diff --git a/tests/compiler/std/math.untouched.wat b/tests/compiler/std/math.untouched.wat index c9a33e550c..37a9d1e2b7 100644 --- a/tests/compiler/std/math.untouched.wat +++ b/tests/compiler/std/math.untouched.wat @@ -11357,8 +11357,7 @@ (func $~lib/math/ipow32f (; 154 ;) (type $fif) (param $0 f32) (param $1 i32) (result f32) (local $2 i32) (local $3 i32) - (local $4 i32) - (local $5 f32) + (local $4 f32) block $break|0 block $case4|0 block $case3|0 @@ -11414,20 +11413,16 @@ end get_local $1 i32.const 31 - i32.shr_u + i32.shr_s set_local $3 get_local $1 - tee_local $2 - i32.const 31 - i32.shr_s - tee_local $4 - get_local $2 + get_local $3 i32.add - get_local $4 + get_local $3 i32.xor set_local $1 f32.const 1 - set_local $5 + set_local $4 block $break|1 loop $continue|1 get_local $1 @@ -11437,10 +11432,10 @@ i32.const 1 i32.and if - get_local $5 + get_local $4 get_local $0 f32.mul - set_local $5 + set_local $4 end get_local $1 i32.const 1 @@ -11458,17 +11453,16 @@ get_local $3 if (result f32) f32.const 1 - get_local $5 + get_local $4 f32.div else - get_local $5 + get_local $4 end ) (func $~lib/math/ipow64f (; 155 ;) (type $FiF) (param $0 f64) (param $1 i32) (result f64) (local $2 i32) (local $3 i32) - (local $4 i32) - (local $5 f64) + (local $4 f64) block $break|0 block $case4|0 block $case3|0 @@ -11524,20 +11518,16 @@ end get_local $1 i32.const 31 - i32.shr_u + i32.shr_s set_local $3 get_local $1 - tee_local $2 - i32.const 31 - i32.shr_s - tee_local $4 - get_local $2 + get_local $3 i32.add - get_local $4 + get_local $3 i32.xor set_local $1 f64.const 1 - set_local $5 + set_local $4 block $break|1 loop $continue|1 get_local $1 @@ -11547,10 +11537,10 @@ i32.const 1 i32.and if - get_local $5 + get_local $4 get_local $0 f64.mul - set_local $5 + set_local $4 end get_local $1 i32.const 1 @@ -11568,10 +11558,10 @@ get_local $3 if (result f64) f64.const 1 - get_local $5 + get_local $4 f64.div else - get_local $5 + get_local $4 end ) (func $start (; 156 ;) (type $v) From 3b37908b278a44b5a3f57a810838b107eb055906 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sun, 20 Jan 2019 04:51:44 +0200 Subject: [PATCH 08/10] force select which improve speed on v8 --- std/assembly/math.ts | 30 +++---- tests/compiler/std/math.optimized.wat | 44 +++++------ tests/compiler/std/math.untouched.wat | 108 +++++++++++++------------- 3 files changed, 91 insertions(+), 91 deletions(-) diff --git a/std/assembly/math.ts b/std/assembly/math.ts index 77cc4f2672..455741410c 100644 --- a/std/assembly/math.ts +++ b/std/assembly/math.ts @@ -2291,27 +2291,27 @@ export function ipow32(x: i32, e: i32): i32 { // But some extra cases needs for properly overflowing switch (log) { case 5: { - if (e & 1) out *= x; + out *= select(x, 1, e & 1); e >>= 1; x *= x; } case 4: { - if (e & 1) out *= x; + out *= select(x, 1, e & 1); e >>= 1; x *= x; } case 3: { - if (e & 1) out *= x; + out *= select(x, 1, e & 1); e >>= 1; x *= x; } case 2: { - if (e & 1) out *= x; + out *= select(x, 1, e & 1); e >>= 1; x *= x; } case 1: { - if (e & 1) out *= x; + out *= select(x, 1, e & 1); } } return out; @@ -2319,7 +2319,7 @@ export function ipow32(x: i32, e: i32): i32 { } while (e > 0) { - if (e & 1) out *= x; + out *= select(x, 1, e & 1); e >>= 1; x *= x; } @@ -2342,32 +2342,32 @@ export function ipow64(x: i64, e: i32): i64 { // But some extra cases needs for properly overflowing switch (log) { case 6: { - if (e & 1) out *= x; + out *= select(x, 1, e & 1); e >>= 1; x *= x; } case 5: { - if (e & 1) out *= x; + out *= select(x, 1, e & 1); e >>= 1; x *= x; } case 4: { - if (e & 1) out *= x; + out *= select(x, 1, e & 1); e >>= 1; x *= x; } case 3: { - if (e & 1) out *= x; + out *= select(x, 1, e & 1); e >>= 1; x *= x; } case 2: { - if (e & 1) out *= x; + out *= select(x, 1, e & 1); e >>= 1; x *= x; } case 1: { - if (e & 1) out *= x; + out *= select(x, 1, e & 1); } } return out; @@ -2375,7 +2375,7 @@ export function ipow64(x: i64, e: i32): i64 { } while (e > 0) { - if (e & 1) out *= x; + out *= select(x, 1, e & 1); e >>= 1; x *= x; } @@ -2396,7 +2396,7 @@ export function ipow32f(x: f32, e: i32): f32 { e = (e + sign) ^ sign; // abs(e) var out: f32 = 1; while (e) { - if (e & 1) out *= x; + out *= select(x, 1.0, e & 1); e >>= 1; x *= x; } @@ -2417,7 +2417,7 @@ export function ipow64f(x: f64, e: i32): f64 { e = (e + sign) ^ sign; // abs(e) var out = 1.0; while (e) { - if (e & 1) out *= x; + out *= select(x, 1.0, e & 1); e >>= 1; x *= x; } diff --git a/tests/compiler/std/math.optimized.wat b/tests/compiler/std/math.optimized.wat index 246309b9cf..fc9479b38e 100644 --- a/tests/compiler/std/math.optimized.wat +++ b/tests/compiler/std/math.optimized.wat @@ -9267,13 +9267,13 @@ set_local $0 end get_local $0 - get_local $2 - i64.mul - get_local $2 + i64.const 1 get_local $1 i32.const 1 i32.and select + get_local $2 + i64.mul set_local $2 get_local $1 i32.const 1 @@ -9285,13 +9285,13 @@ set_local $0 end get_local $0 - get_local $2 - i64.mul - get_local $2 + i64.const 1 get_local $1 i32.const 1 i32.and select + get_local $2 + i64.mul set_local $2 get_local $1 i32.const 1 @@ -9303,13 +9303,13 @@ set_local $0 end get_local $0 - get_local $2 - i64.mul - get_local $2 + i64.const 1 get_local $1 i32.const 1 i32.and select + get_local $2 + i64.mul set_local $2 get_local $1 i32.const 1 @@ -9321,13 +9321,13 @@ set_local $0 end get_local $0 - get_local $2 - i64.mul - get_local $2 + i64.const 1 get_local $1 i32.const 1 i32.and select + get_local $2 + i64.mul set_local $2 get_local $1 i32.const 1 @@ -9339,13 +9339,13 @@ set_local $0 end get_local $0 - get_local $2 - i64.mul - get_local $2 + i64.const 1 get_local $1 i32.const 1 i32.and select + get_local $2 + i64.mul set_local $2 end get_local $2 @@ -9357,13 +9357,13 @@ i32.gt_s if get_local $0 - get_local $2 - i64.mul - get_local $2 + i64.const 1 get_local $1 i32.const 1 i32.and select + get_local $2 + i64.mul set_local $2 get_local $1 i32.const 1 @@ -9446,12 +9446,12 @@ if get_local $2 get_local $0 - f32.mul - get_local $2 + f32.const 1 get_local $1 i32.const 1 i32.and select + f32.mul set_local $2 get_local $1 i32.const 1 @@ -9541,12 +9541,12 @@ if get_local $2 get_local $0 - f64.mul - get_local $2 + f64.const 1 get_local $1 i32.const 1 i32.and select + f64.mul set_local $2 get_local $1 i32.const 1 diff --git a/tests/compiler/std/math.untouched.wat b/tests/compiler/std/math.untouched.wat index 37a9d1e2b7..253e43b1c4 100644 --- a/tests/compiler/std/math.untouched.wat +++ b/tests/compiler/std/math.untouched.wat @@ -11211,15 +11211,15 @@ br $break|1 end block + get_local $2 + get_local $0 + i64.const 1 get_local $1 i32.const 1 i32.and - if - get_local $2 - get_local $0 - i64.mul - set_local $2 - end + select + i64.mul + set_local $2 get_local $1 i32.const 1 i32.shr_s @@ -11231,15 +11231,15 @@ end end block + get_local $2 + get_local $0 + i64.const 1 get_local $1 i32.const 1 i32.and - if - get_local $2 - get_local $0 - i64.mul - set_local $2 - end + select + i64.mul + set_local $2 get_local $1 i32.const 1 i32.shr_s @@ -11251,15 +11251,15 @@ end end block + get_local $2 + get_local $0 + i64.const 1 get_local $1 i32.const 1 i32.and - if - get_local $2 - get_local $0 - i64.mul - set_local $2 - end + select + i64.mul + set_local $2 get_local $1 i32.const 1 i32.shr_s @@ -11271,15 +11271,15 @@ end end block + get_local $2 + get_local $0 + i64.const 1 get_local $1 i32.const 1 i32.and - if - get_local $2 - get_local $0 - i64.mul - set_local $2 - end + select + i64.mul + set_local $2 get_local $1 i32.const 1 i32.shr_s @@ -11291,15 +11291,15 @@ end end block + get_local $2 + get_local $0 + i64.const 1 get_local $1 i32.const 1 i32.and - if - get_local $2 - get_local $0 - i64.mul - set_local $2 - end + select + i64.mul + set_local $2 get_local $1 i32.const 1 i32.shr_s @@ -11310,15 +11310,15 @@ set_local $0 end end + get_local $2 + get_local $0 + i64.const 1 get_local $1 i32.const 1 i32.and - if - get_local $2 - get_local $0 - i64.mul - set_local $2 - end + select + i64.mul + set_local $2 end get_local $2 return @@ -11330,15 +11330,15 @@ i32.gt_s if block + get_local $2 + get_local $0 + i64.const 1 get_local $1 i32.const 1 i32.and - if - get_local $2 - get_local $0 - i64.mul - set_local $2 - end + select + i64.mul + set_local $2 get_local $1 i32.const 1 i32.shr_s @@ -11428,15 +11428,15 @@ get_local $1 if block + get_local $4 + get_local $0 + f32.const 1 get_local $1 i32.const 1 i32.and - if - get_local $4 - get_local $0 - f32.mul - set_local $4 - end + select + f32.mul + set_local $4 get_local $1 i32.const 1 i32.shr_s @@ -11533,15 +11533,15 @@ get_local $1 if block + get_local $4 + get_local $0 + f64.const 1 get_local $1 i32.const 1 i32.and - if - get_local $4 - get_local $0 - f64.mul - set_local $4 - end + select + f64.mul + set_local $4 get_local $1 i32.const 1 i32.shr_s From bb7ac07a0adc02e2fe709d018e60a0a2593affaf Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sun, 20 Jan 2019 16:56:41 +0200 Subject: [PATCH 09/10] revert select for ipow32/ipow64 + minor refactoring --- std/assembly/math.ts | 46 ++++----- tests/compiler/binary.untouched.wat | 42 +++++---- tests/compiler/std/math.optimized.wat | 38 ++++---- tests/compiler/std/math.untouched.wat | 130 +++++++++++++------------- tests/compiler/std/mod.untouched.wat | 42 +++++---- 5 files changed, 152 insertions(+), 146 deletions(-) diff --git a/std/assembly/math.ts b/std/assembly/math.ts index 455741410c..80c6395fb8 100644 --- a/std/assembly/math.ts +++ b/std/assembly/math.ts @@ -1096,7 +1096,10 @@ export namespace NativeMath { var ey = (uy >> 52 & 0x7FF); var sx = ux >> 63; var uy1 = uy << 1; - if (uy1 == 0 || ex == 0x7FF || isNaN(y)) return (x * y) / (x * y); + if (uy1 == 0 || ex == 0x7FF || isNaN(y)) { + let m = x * y; + return m / m; + } var ux1 = ux << 1; if (ux1 <= uy1) { if (ux1 == uy1) return 0 * x; @@ -1418,7 +1421,7 @@ export namespace NativeMathf { if (iy == 0) { switch (m) { case 0: - case 1: return y; + case 1: return y; case 2: return pi; case 3: return -pi; } @@ -1532,12 +1535,8 @@ export namespace NativeMathf { hx &= 0x7FFFFFFF; if (hx >= 0x42AEAC50) { if (hx >= 0x42B17218) { - if (!sign_) { - x *= Ox1p127f; - return x; - } else { - if (hx >= 0x42CFF1B5) return 0; - } + if (!sign_) return x * Ox1p127f; + else if (hx >= 0x42CFF1B5) return 0; } } var hi: f32, lo: f32; @@ -2160,7 +2159,10 @@ export namespace NativeMathf { var ey = (uy >> 23 & 0xFF); var sx = ux & 0x80000000; var uy1 = uy << 1; - if (uy1 == 0 || ex == 0xFF || isNaN(y)) return (x * y) / (x * y); + if (uy1 == 0 || ex == 0xFF || isNaN(y)) { + let m = x * y; + return m / m; + } var ux1 = ux << 1; if (ux1 <= uy1) { if (ux1 == uy1) return 0 * x; @@ -2291,27 +2293,27 @@ export function ipow32(x: i32, e: i32): i32 { // But some extra cases needs for properly overflowing switch (log) { case 5: { - out *= select(x, 1, e & 1); + if (e & 1) out *= x; e >>= 1; x *= x; } case 4: { - out *= select(x, 1, e & 1); + if (e & 1) out *= x; e >>= 1; x *= x; } case 3: { - out *= select(x, 1, e & 1); + if (e & 1) out *= x; e >>= 1; x *= x; } case 2: { - out *= select(x, 1, e & 1); + if (e & 1) out *= x; e >>= 1; x *= x; } case 1: { - out *= select(x, 1, e & 1); + if (e & 1) out *= x; } } return out; @@ -2319,7 +2321,7 @@ export function ipow32(x: i32, e: i32): i32 { } while (e > 0) { - out *= select(x, 1, e & 1); + if (e & 1) out *= x; e >>= 1; x *= x; } @@ -2342,32 +2344,32 @@ export function ipow64(x: i64, e: i32): i64 { // But some extra cases needs for properly overflowing switch (log) { case 6: { - out *= select(x, 1, e & 1); + if (e & 1) out *= x; e >>= 1; x *= x; } case 5: { - out *= select(x, 1, e & 1); + if (e & 1) out *= x; e >>= 1; x *= x; } case 4: { - out *= select(x, 1, e & 1); + if (e & 1) out *= x; e >>= 1; x *= x; } case 3: { - out *= select(x, 1, e & 1); + if (e & 1) out *= x; e >>= 1; x *= x; } case 2: { - out *= select(x, 1, e & 1); + if (e & 1) out *= x; e >>= 1; x *= x; } case 1: { - out *= select(x, 1, e & 1); + if (e & 1) out *= x; } } return out; @@ -2375,7 +2377,7 @@ export function ipow64(x: i64, e: i32): i64 { } while (e > 0) { - out *= select(x, 1, e & 1); + if (e & 1) out *= x; e >>= 1; x *= x; } diff --git a/tests/compiler/binary.untouched.wat b/tests/compiler/binary.untouched.wat index 0c6ab4e3b5..fac5baa417 100644 --- a/tests/compiler/binary.untouched.wat +++ b/tests/compiler/binary.untouched.wat @@ -1204,8 +1204,9 @@ (local $6 i32) (local $7 i32) (local $8 i32) - (local $9 i32) + (local $9 f32) (local $10 i32) + (local $11 i32) get_local $0 i32.reinterpret/f32 set_local $2 @@ -1257,21 +1258,21 @@ get_local $0 get_local $1 f32.mul - get_local $0 - get_local $1 - f32.mul + set_local $9 + get_local $9 + get_local $9 f32.div return end get_local $2 i32.const 1 i32.shl - set_local $9 - get_local $9 + set_local $10 + get_local $10 get_local $7 i32.le_u if - get_local $9 + get_local $10 get_local $7 i32.eq if @@ -1407,13 +1408,13 @@ i32.const 8 i32.shl i32.clz - set_local $10 + set_local $11 get_local $4 - get_local $10 + get_local $11 i32.sub set_local $4 get_local $2 - get_local $10 + get_local $11 i32.shl set_local $2 get_local $4 @@ -2485,8 +2486,9 @@ (local $6 i64) (local $7 i64) (local $8 i32) - (local $9 i64) + (local $9 f64) (local $10 i64) + (local $11 i64) get_local $0 i64.reinterpret/f64 set_local $2 @@ -2538,21 +2540,21 @@ get_local $0 get_local $1 f64.mul - get_local $0 - get_local $1 - f64.mul + set_local $9 + get_local $9 + get_local $9 f64.div return end get_local $2 i64.const 1 i64.shl - set_local $9 - get_local $9 + set_local $10 + get_local $10 get_local $7 i64.le_u if - get_local $9 + get_local $10 get_local $7 i64.eq if @@ -2688,13 +2690,13 @@ i64.const 11 i64.shl i64.clz - set_local $10 + set_local $11 get_local $4 - get_local $10 + get_local $11 i64.sub set_local $4 get_local $2 - get_local $10 + get_local $11 i64.shl set_local $2 get_local $4 diff --git a/tests/compiler/std/math.optimized.wat b/tests/compiler/std/math.optimized.wat index fc9479b38e..be5515b06d 100644 --- a/tests/compiler/std/math.optimized.wat +++ b/tests/compiler/std/math.optimized.wat @@ -8114,7 +8114,7 @@ if i32.const 0 i32.const 40 - i32.const 2041 + i32.const 2040 i32.const 24 call $~lib/env/abort unreachable @@ -9267,13 +9267,13 @@ set_local $0 end get_local $0 - i64.const 1 + get_local $2 + i64.mul + get_local $2 get_local $1 i32.const 1 i32.and select - get_local $2 - i64.mul set_local $2 get_local $1 i32.const 1 @@ -9285,13 +9285,13 @@ set_local $0 end get_local $0 - i64.const 1 + get_local $2 + i64.mul + get_local $2 get_local $1 i32.const 1 i32.and select - get_local $2 - i64.mul set_local $2 get_local $1 i32.const 1 @@ -9303,13 +9303,13 @@ set_local $0 end get_local $0 - i64.const 1 + get_local $2 + i64.mul + get_local $2 get_local $1 i32.const 1 i32.and select - get_local $2 - i64.mul set_local $2 get_local $1 i32.const 1 @@ -9321,13 +9321,13 @@ set_local $0 end get_local $0 - i64.const 1 + get_local $2 + i64.mul + get_local $2 get_local $1 i32.const 1 i32.and select - get_local $2 - i64.mul set_local $2 get_local $1 i32.const 1 @@ -9339,13 +9339,13 @@ set_local $0 end get_local $0 - i64.const 1 + get_local $2 + i64.mul + get_local $2 get_local $1 i32.const 1 i32.and select - get_local $2 - i64.mul set_local $2 end get_local $2 @@ -9357,13 +9357,13 @@ i32.gt_s if get_local $0 - i64.const 1 + get_local $2 + i64.mul + get_local $2 get_local $1 i32.const 1 i32.and select - get_local $2 - i64.mul set_local $2 get_local $1 i32.const 1 diff --git a/tests/compiler/std/math.untouched.wat b/tests/compiler/std/math.untouched.wat index 253e43b1c4..35d6274f13 100644 --- a/tests/compiler/std/math.untouched.wat +++ b/tests/compiler/std/math.untouched.wat @@ -5209,8 +5209,6 @@ get_local $0 f32.const 1701411834604692317316873e14 f32.mul - set_local $0 - get_local $0 return else get_local $1 @@ -7040,8 +7038,9 @@ (local $6 i64) (local $7 i64) (local $8 i32) - (local $9 i64) + (local $9 f64) (local $10 i64) + (local $11 i64) get_local $0 i64.reinterpret/f64 set_local $2 @@ -7093,21 +7092,21 @@ get_local $0 get_local $1 f64.mul - get_local $0 - get_local $1 - f64.mul + set_local $9 + get_local $9 + get_local $9 f64.div return end get_local $2 i64.const 1 i64.shl - set_local $9 - get_local $9 + set_local $10 + get_local $10 get_local $7 i64.le_u if - get_local $9 + get_local $10 get_local $7 i64.eq if @@ -7243,13 +7242,13 @@ i64.const 11 i64.shl i64.clz - set_local $10 + set_local $11 get_local $4 - get_local $10 + get_local $11 i64.sub set_local $4 get_local $2 - get_local $10 + get_local $11 i64.shl set_local $2 get_local $4 @@ -7324,8 +7323,9 @@ (local $6 i32) (local $7 i32) (local $8 i32) - (local $9 i32) + (local $9 f32) (local $10 i32) + (local $11 i32) get_local $0 i32.reinterpret/f32 set_local $2 @@ -7377,21 +7377,21 @@ get_local $0 get_local $1 f32.mul - get_local $0 - get_local $1 - f32.mul + set_local $9 + get_local $9 + get_local $9 f32.div return end get_local $2 i32.const 1 i32.shl - set_local $9 - get_local $9 + set_local $10 + get_local $10 get_local $7 i32.le_u if - get_local $9 + get_local $10 get_local $7 i32.eq if @@ -7527,13 +7527,13 @@ i32.const 8 i32.shl i32.clz - set_local $10 + set_local $11 get_local $4 - get_local $10 + get_local $11 i32.sub set_local $4 get_local $2 - get_local $10 + get_local $11 i32.shl set_local $2 get_local $4 @@ -9801,7 +9801,7 @@ if i32.const 0 i32.const 40 - i32.const 2041 + i32.const 2040 i32.const 24 call $~lib/env/abort unreachable @@ -11211,15 +11211,15 @@ br $break|1 end block - get_local $2 - get_local $0 - i64.const 1 get_local $1 i32.const 1 i32.and - select - i64.mul - set_local $2 + if + get_local $2 + get_local $0 + i64.mul + set_local $2 + end get_local $1 i32.const 1 i32.shr_s @@ -11231,15 +11231,15 @@ end end block - get_local $2 - get_local $0 - i64.const 1 get_local $1 i32.const 1 i32.and - select - i64.mul - set_local $2 + if + get_local $2 + get_local $0 + i64.mul + set_local $2 + end get_local $1 i32.const 1 i32.shr_s @@ -11251,15 +11251,15 @@ end end block - get_local $2 - get_local $0 - i64.const 1 get_local $1 i32.const 1 i32.and - select - i64.mul - set_local $2 + if + get_local $2 + get_local $0 + i64.mul + set_local $2 + end get_local $1 i32.const 1 i32.shr_s @@ -11271,15 +11271,15 @@ end end block - get_local $2 - get_local $0 - i64.const 1 get_local $1 i32.const 1 i32.and - select - i64.mul - set_local $2 + if + get_local $2 + get_local $0 + i64.mul + set_local $2 + end get_local $1 i32.const 1 i32.shr_s @@ -11291,15 +11291,15 @@ end end block - get_local $2 - get_local $0 - i64.const 1 get_local $1 i32.const 1 i32.and - select - i64.mul - set_local $2 + if + get_local $2 + get_local $0 + i64.mul + set_local $2 + end get_local $1 i32.const 1 i32.shr_s @@ -11310,15 +11310,15 @@ set_local $0 end end - get_local $2 - get_local $0 - i64.const 1 get_local $1 i32.const 1 i32.and - select - i64.mul - set_local $2 + if + get_local $2 + get_local $0 + i64.mul + set_local $2 + end end get_local $2 return @@ -11330,15 +11330,15 @@ i32.gt_s if block - get_local $2 - get_local $0 - i64.const 1 get_local $1 i32.const 1 i32.and - select - i64.mul - set_local $2 + if + get_local $2 + get_local $0 + i64.mul + set_local $2 + end get_local $1 i32.const 1 i32.shr_s diff --git a/tests/compiler/std/mod.untouched.wat b/tests/compiler/std/mod.untouched.wat index d1e68472ce..7d5996a633 100644 --- a/tests/compiler/std/mod.untouched.wat +++ b/tests/compiler/std/mod.untouched.wat @@ -31,8 +31,9 @@ (local $6 i64) (local $7 i64) (local $8 i32) - (local $9 i64) + (local $9 f64) (local $10 i64) + (local $11 i64) get_local $0 i64.reinterpret/f64 set_local $2 @@ -84,21 +85,21 @@ get_local $0 get_local $1 f64.mul - get_local $0 - get_local $1 - f64.mul + set_local $9 + get_local $9 + get_local $9 f64.div return end get_local $2 i64.const 1 i64.shl - set_local $9 - get_local $9 + set_local $10 + get_local $10 get_local $7 i64.le_u if - get_local $9 + get_local $10 get_local $7 i64.eq if @@ -234,13 +235,13 @@ i64.const 11 i64.shl i64.clz - set_local $10 + set_local $11 get_local $4 - get_local $10 + get_local $11 i64.sub set_local $4 get_local $2 - get_local $10 + get_local $11 i64.shl set_local $2 get_local $4 @@ -342,8 +343,9 @@ (local $6 i32) (local $7 i32) (local $8 i32) - (local $9 i32) + (local $9 f32) (local $10 i32) + (local $11 i32) get_local $0 i32.reinterpret/f32 set_local $2 @@ -395,21 +397,21 @@ get_local $0 get_local $1 f32.mul - get_local $0 - get_local $1 - f32.mul + set_local $9 + get_local $9 + get_local $9 f32.div return end get_local $2 i32.const 1 i32.shl - set_local $9 - get_local $9 + set_local $10 + get_local $10 get_local $7 i32.le_u if - get_local $9 + get_local $10 get_local $7 i32.eq if @@ -545,13 +547,13 @@ i32.const 8 i32.shl i32.clz - set_local $10 + set_local $11 get_local $4 - get_local $10 + get_local $11 i32.sub set_local $4 get_local $2 - get_local $10 + get_local $11 i32.shl set_local $2 get_local $4 From 1fcaff0250adad84f326667c41ea01e58f7d2313 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sun, 20 Jan 2019 17:09:10 +0200 Subject: [PATCH 10/10] discard dists --- std/assembly/math.ts | 18 --- tests/compiler/std/math.optimized.wat | 106 +---------------- tests/compiler/std/math.untouched.wat | 160 +++++--------------------- 3 files changed, 30 insertions(+), 254 deletions(-) diff --git a/std/assembly/math.ts b/std/assembly/math.ts index 80c6395fb8..579d83d992 100644 --- a/std/assembly/math.ts +++ b/std/assembly/math.ts @@ -2385,15 +2385,6 @@ export function ipow64(x: i64, e: i32): i64 { } export function ipow32f(x: f32, e: i32): f32 { - if (ASC_SHRINK_LEVEL < 1) { - switch (e) { - case -2: return 1.0 / (x * x); - case -1: return 1.0 / x; - case 0: return 1.0; - case 1: return x; - case 2: return x * x; - } - } var sign = e >> 31; e = (e + sign) ^ sign; // abs(e) var out: f32 = 1; @@ -2406,15 +2397,6 @@ export function ipow32f(x: f32, e: i32): f32 { } export function ipow64f(x: f64, e: i32): f64 { - if (ASC_SHRINK_LEVEL < 1) { - switch (e) { - case -2: return 1.0 / (x * x); - case -1: return 1.0 / x; - case 0: return 1.0; - case 1: return x; - case 2: return x * x; - } - } var sign = e >> 31; e = (e + sign) ^ sign; // abs(e) var out = 1.0; diff --git a/tests/compiler/std/math.optimized.wat b/tests/compiler/std/math.optimized.wat index be5515b06d..6d9fcae795 100644 --- a/tests/compiler/std/math.optimized.wat +++ b/tests/compiler/std/math.optimized.wat @@ -9381,55 +9381,6 @@ (func $~lib/math/ipow32f (; 146 ;) (type $fif) (param $0 f32) (param $1 i32) (result f32) (local $2 f32) (local $3 i32) - block $break|0 - block $case4|0 - block $case3|0 - block $case2|0 - block $case1|0 - get_local $1 - i32.const -2 - i32.ne - if - get_local $1 - i32.const -1 - i32.eq - br_if $case1|0 - get_local $1 - i32.eqz - br_if $case2|0 - get_local $1 - i32.const 1 - i32.eq - br_if $case3|0 - get_local $1 - i32.const 2 - i32.eq - br_if $case4|0 - br $break|0 - end - f32.const 1 - get_local $0 - get_local $0 - f32.mul - f32.div - return - end - f32.const 1 - get_local $0 - f32.div - return - end - f32.const 1 - return - end - get_local $0 - return - end - get_local $0 - get_local $0 - f32.mul - return - end get_local $1 i32.const 31 i32.shr_s @@ -9441,7 +9392,7 @@ set_local $1 f32.const 1 set_local $2 - loop $continue|1 + loop $continue|0 get_local $1 if get_local $2 @@ -9461,7 +9412,7 @@ get_local $0 f32.mul set_local $0 - br $continue|1 + br $continue|0 end end get_local $3 @@ -9476,55 +9427,6 @@ (func $~lib/math/ipow64f (; 147 ;) (type $FiF) (param $0 f64) (param $1 i32) (result f64) (local $2 f64) (local $3 i32) - block $break|0 - block $case4|0 - block $case3|0 - block $case2|0 - block $case1|0 - get_local $1 - i32.const -2 - i32.ne - if - get_local $1 - i32.const -1 - i32.eq - br_if $case1|0 - get_local $1 - i32.eqz - br_if $case2|0 - get_local $1 - i32.const 1 - i32.eq - br_if $case3|0 - get_local $1 - i32.const 2 - i32.eq - br_if $case4|0 - br $break|0 - end - f64.const 1 - get_local $0 - get_local $0 - f64.mul - f64.div - return - end - f64.const 1 - get_local $0 - f64.div - return - end - f64.const 1 - return - end - get_local $0 - return - end - get_local $0 - get_local $0 - f64.mul - return - end get_local $1 i32.const 31 i32.shr_s @@ -9536,7 +9438,7 @@ set_local $1 f64.const 1 set_local $2 - loop $continue|1 + loop $continue|0 get_local $1 if get_local $2 @@ -9556,7 +9458,7 @@ get_local $0 f64.mul set_local $0 - br $continue|1 + br $continue|0 end end get_local $3 diff --git a/tests/compiler/std/math.untouched.wat b/tests/compiler/std/math.untouched.wat index 35d6274f13..5a28976ce2 100644 --- a/tests/compiler/std/math.untouched.wat +++ b/tests/compiler/std/math.untouched.wat @@ -11356,79 +11356,25 @@ ) (func $~lib/math/ipow32f (; 154 ;) (type $fif) (param $0 f32) (param $1 i32) (result f32) (local $2 i32) - (local $3 i32) - (local $4 f32) - block $break|0 - block $case4|0 - block $case3|0 - block $case2|0 - block $case1|0 - block $case0|0 - get_local $1 - set_local $2 - get_local $2 - i32.const -2 - i32.eq - br_if $case0|0 - get_local $2 - i32.const -1 - i32.eq - br_if $case1|0 - get_local $2 - i32.const 0 - i32.eq - br_if $case2|0 - get_local $2 - i32.const 1 - i32.eq - br_if $case3|0 - get_local $2 - i32.const 2 - i32.eq - br_if $case4|0 - br $break|0 - end - f32.const 1 - get_local $0 - get_local $0 - f32.mul - f32.div - return - end - f32.const 1 - get_local $0 - f32.div - return - end - f32.const 1 - return - end - get_local $0 - return - end - get_local $0 - get_local $0 - f32.mul - return - end + (local $3 f32) get_local $1 i32.const 31 i32.shr_s - set_local $3 + set_local $2 get_local $1 - get_local $3 + get_local $2 i32.add - get_local $3 + get_local $2 i32.xor set_local $1 f32.const 1 - set_local $4 - block $break|1 - loop $continue|1 + set_local $3 + block $break|0 + loop $continue|0 get_local $1 if block - get_local $4 + get_local $3 get_local $0 f32.const 1 get_local $1 @@ -11436,7 +11382,7 @@ i32.and select f32.mul - set_local $4 + set_local $3 get_local $1 i32.const 1 i32.shr_s @@ -11446,94 +11392,40 @@ f32.mul set_local $0 end - br $continue|1 + br $continue|0 end end end - get_local $3 + get_local $2 if (result f32) f32.const 1 - get_local $4 + get_local $3 f32.div else - get_local $4 + get_local $3 end ) (func $~lib/math/ipow64f (; 155 ;) (type $FiF) (param $0 f64) (param $1 i32) (result f64) (local $2 i32) - (local $3 i32) - (local $4 f64) - block $break|0 - block $case4|0 - block $case3|0 - block $case2|0 - block $case1|0 - block $case0|0 - get_local $1 - set_local $2 - get_local $2 - i32.const -2 - i32.eq - br_if $case0|0 - get_local $2 - i32.const -1 - i32.eq - br_if $case1|0 - get_local $2 - i32.const 0 - i32.eq - br_if $case2|0 - get_local $2 - i32.const 1 - i32.eq - br_if $case3|0 - get_local $2 - i32.const 2 - i32.eq - br_if $case4|0 - br $break|0 - end - f64.const 1 - get_local $0 - get_local $0 - f64.mul - f64.div - return - end - f64.const 1 - get_local $0 - f64.div - return - end - f64.const 1 - return - end - get_local $0 - return - end - get_local $0 - get_local $0 - f64.mul - return - end + (local $3 f64) get_local $1 i32.const 31 i32.shr_s - set_local $3 + set_local $2 get_local $1 - get_local $3 + get_local $2 i32.add - get_local $3 + get_local $2 i32.xor set_local $1 f64.const 1 - set_local $4 - block $break|1 - loop $continue|1 + set_local $3 + block $break|0 + loop $continue|0 get_local $1 if block - get_local $4 + get_local $3 get_local $0 f64.const 1 get_local $1 @@ -11541,7 +11433,7 @@ i32.and select f64.mul - set_local $4 + set_local $3 get_local $1 i32.const 1 i32.shr_s @@ -11551,17 +11443,17 @@ f64.mul set_local $0 end - br $continue|1 + br $continue|0 end end end - get_local $3 + get_local $2 if (result f64) f64.const 1 - get_local $4 + get_local $3 f64.div else - get_local $4 + get_local $3 end ) (func $start (; 156 ;) (type $v)