diff --git a/std/assembly/math.ts b/std/assembly/math.ts index c934e9dce7..42b9fdbbc6 100644 --- a/std/assembly/math.ts +++ b/std/assembly/math.ts @@ -381,7 +381,7 @@ function dtoi32(x: f64): i32 { let v = (u & ((1 << 52) - 1)) | (1 << 52); v = v << e - 1023 - 52 + 32; result = (v >> 32); - result = select(-result, result, u >> 63); + result = select(-result, result, u < 0); } return result; } @@ -470,7 +470,7 @@ export namespace NativeMath { if (ix >= 0x3FF00000) { let lx = reinterpret(x); if ((ix - 0x3FF00000 | lx) == 0) { - if (hx >> 31) return 2 * pio2_hi + Ox1p_120f; + if (hx < 0) return 2 * pio2_hi + Ox1p_120f; return 0; } return 0 / (x - x); @@ -480,7 +480,7 @@ export namespace NativeMath { return pio2_hi - (x - (pio2_lo - x * R(x * x))); } var s: f64, w: f64, z: f64; - if (hx >> 31) { + if (hx < 0) { // z = (1.0 + x) * 0.5; z = 0.5 + x * 0.5; s = builtin_sqrt(z); @@ -535,8 +535,7 @@ export namespace NativeMath { let c = (z - f * f) / (s + f); x = 0.5 * pio2_hi - (2 * s * r - (pio2_lo - 2 * c) - (0.5 * pio2_hi - 2 * f)); } - if (hx >> 31) return -x; - return x; + return select(-x, x, hx < 0); } export function asinh(x: f64): f64 { // see: musl/src/math/asinh.c @@ -733,21 +732,21 @@ export namespace NativeMath { export function cos(x: f64): f64 { // see: musl/src/math/cos.c var u = reinterpret(x); - var ix = (u >> 32); - var sign = ix >> 31; + var ux = u32(u >> 32); + var sign = ux >> 31; - ix &= 0x7FFFFFFF; + ux &= 0x7FFFFFFF; // |x| ~< pi/4 - if (ix <= 0x3FE921FB) { - if (ix < 0x3E46A09E) { // |x| < 2**-27 * sqrt(2) + if (ux <= 0x3FE921FB) { + if (ux < 0x3E46A09E) { // |x| < 2**-27 * sqrt(2) return 1.0; } return cos_kern(x, 0); } // sin(Inf or NaN) is NaN - if (ix >= 0x7FF00000) return x - x; + if (ux >= 0x7FF00000) return x - x; // argument reduction needed var n = rempio2(x, u, sign); @@ -795,8 +794,8 @@ export namespace NativeMath { underflow = reinterpret(0xC0874910D52D3051), // -745.13321910194110842 Ox1p1023 = reinterpret(0x7FE0000000000000); // 0x1p1023 - let hx = (reinterpret(x) >> 32); - let sign_ = (hx >> 31); + let hx = u32(reinterpret(x) >> 32); + let sign = hx >> 31; hx &= 0x7FFFFFFF; if (hx >= 0x4086232B) { if (isNaN(x)) return x; @@ -807,9 +806,9 @@ export namespace NativeMath { let k = 0; if (hx > 0x3FD62E42) { if (hx >= 0x3FF0A2B2) { - k = (invln2 * x + builtin_copysign(0.5, x)); + k = i32(invln2 * x + builtin_copysign(0.5, x)); } else { - k = 1 - (sign_ << 1); + k = 1 - (sign << 1); } hi = x - k * ln2hi; lo = k * ln2lo; @@ -844,18 +843,19 @@ export namespace NativeMath { Ox1p1023 = reinterpret(0x7FE0000000000000); // 0x1p1023 var u = reinterpret(x); - var hx = (u >> 32 & 0x7FFFFFFF); - var k = 0, sign_ = (u >> 63); + var hx = u32(u >> 32) & 0x7FFFFFFF; + var sign = u32(u >> 63); + var k = 0; if (hx >= 0x4043687A) { if (isNaN(x)) return x; - if (sign_) return -1; + if (sign) return -1; if (x > o_threshold) return x * Ox1p1023; } var c = 0.0, t: f64; if (hx > 0x3FD62E42) { k = select( - 1 - (sign_ << 1), - (invln2 * x + builtin_copysign(0.5, x)), + 1 - (sign << 1), + i32(invln2 * x + builtin_copysign(0.5, x)), hx < 0x3FF0A2B2 ); t = k; @@ -922,8 +922,8 @@ export namespace NativeMath { ux = uy; uy = ut; } - var ex = (ux >> 52); - var ey = (uy >> 52); + var ex = i32(ux >> 52); + var ey = i32(uy >> 52); y = reinterpret(uy); if (ey == 0x7FF) return y; x = reinterpret(ux); @@ -980,15 +980,16 @@ export namespace NativeMath { Ox1p54 = reinterpret(0x4350000000000000); // 0x1p54 let u = reinterpret(x); - let hx = (u >> 32); + let hx = u32(u >> 32); let k = 0; - if (hx < 0x00100000 || (hx >> 31)) { + let sign = hx >> 31; + if (sign || hx < 0x00100000) { if (u << 1 == 0) return -1 / (x * x); - if (hx >> 31) return (x - x) / 0.0; + if (sign) return (x - x) / 0.0; k -= 54; x *= Ox1p54; u = reinterpret(x); - hx = (u >> 32); + hx = u32(u >> 32); } else if (hx >= 0x7FF00000) { return x; } else if (hx == 0x3FF00000 && u << 32 == 0) { @@ -1028,22 +1029,23 @@ export namespace NativeMath { Ox1p54 = reinterpret(0x4350000000000000); // 0x1p54 var u = reinterpret(x); - var hx = (u >> 32); + var hx = u32(u >> 32); var k = 0; - if (hx < 0x00100000 || (hx >> 31)) { + var sign = hx >> 31; + if (sign || hx < 0x00100000) { if (u << 1 == 0) return -1 / (x * x); - if (hx >> 31) return (x - x) / 0.0; + if (sign) return (x - x) / 0.0; k -= 54; x *= Ox1p54; u = reinterpret(x); - hx = (u >> 32); + hx = u32(u >> 32); } else if (hx >= 0x7FF00000) { return x; } else if (hx == 0x3FF00000 && u << 32 == 0) { return 0; } hx += 0x3FF00000 - 0x3FE6A09E; - k += (hx >> 20) - 0x3FF; + k += i32(hx >> 20) - 0x3FF; hx = (hx & 0x000FFFFF) + 0x3FE6A09E; u = hx << 32 | (u & 0xFFFFFFFF); x = reinterpret(u); @@ -1082,10 +1084,10 @@ export namespace NativeMath { Lg7 = reinterpret(0x3FC2F112DF3E5244); // 1.479819860511658591e-01 var u = reinterpret(x); - var hx = (u >> 32); + var hx = u32(u >> 32); var k = 1; var c = 0.0, f = 0.0; - if (hx < 0x3FDA827A || (hx >> 31)) { + if (hx < 0x3FDA827A || bool(hx >> 31)) { if (hx >= 0xBFF00000) { if (x == -1) return x / 0.0; return (x - x) / 0.0; @@ -1099,9 +1101,9 @@ export namespace NativeMath { } else if (hx >= 0x7FF00000) return x; if (k) { u = reinterpret(1 + x); - let hu = (u >> 32); + let hu = u32(u >> 32); hu += 0x3FF00000 - 0x3FE6A09E; - k = (hu >> 20) - 0x3FF; + k = i32(hu >> 20) - 0x3FF; if (k < 54) { let uf = reinterpret(u); c = k >= 2 ? 1 - (uf - x) : x - (uf - 1); @@ -1139,22 +1141,23 @@ export namespace NativeMath { Ox1p54 = reinterpret(0x4350000000000000); // 1p54 let u = reinterpret(x); - let hx = (u >> 32); + let hx = u32(u >> 32); let k = 0; - if (hx < 0x00100000 || (hx >> 31)) { + let sign = hx >> 31; + if (sign || hx < 0x00100000) { if (u << 1 == 0) return -1 / (x * x); - if (hx >> 31) return (x - x) / 0.0; + if (sign) return (x - x) / 0.0; k -= 54; x *= Ox1p54; u = reinterpret(x); - hx = (u >> 32); + hx = u32(u >> 32); } else if (hx >= 0x7FF00000) { return x; } else if (hx == 0x3FF00000 && u << 32 == 0) { return 0; } hx += 0x3FF00000 - 0x3FE6A09E; - k += (hx >> 20) - 0x3FF; + k += i32(hx >> 20) - 0x3FF; hx = (hx & 0x000FFFFF) + 0x3FE6A09E; u = hx << 32 | (u & 0xFFFFFFFF); x = reinterpret(u); @@ -1241,10 +1244,10 @@ export namespace NativeMath { inv3 = reinterpret(0x3FD5555555555555); // 0.3333333333333333333333 let u_ = reinterpret(x); - let hx = (u_ >> 32); + let hx = i32(u_ >> 32); let lx = u_; u_ = reinterpret(y); - let hy = (u_ >> 32); + let hy = i32(u_ >> 32); let ly = u_; let ix = hx & 0x7FFFFFFF; let iy = hy & 0x7FFFFFFF; @@ -1343,7 +1346,7 @@ export namespace NativeMath { ss = u * v; s_h = ss; s_h = reinterpret(reinterpret(s_h) & 0xFFFFFFFF00000000); - t_h = reinterpret((((ix >> 1) | 0x20000000) + 0x00080000 + (k << 18)) << 32); + t_h = reinterpret(u64(((ix >> 1) | 0x20000000) + 0x00080000 + (k << 18)) << 32); t_l = ax - (t_h - bp); s_l = v * ((u - s_h * t_h) - s_h * t_l); s2 = ss * ss; @@ -1373,7 +1376,7 @@ export namespace NativeMath { p_h = y1 * t1; z = p_l + p_h; u_ = reinterpret(z); - j = (u_ >> 32); + j = u32(u_ >> 32); let i = u_; if (j >= 0x40900000) { if (((j - 0x40900000) | i) != 0) return s * huge * huge; @@ -1389,7 +1392,7 @@ export namespace NativeMath { n = j + (0x00100000 >> (k + 1)); k = ((n & 0x7FFFFFFF) >> 20) - 0x3FF; t = 0.0; - t = reinterpret((n & ~(0x000FFFFF >> k)) << 32); + t = reinterpret(u64(n & ~(0x000FFFFF >> k)) << 32); n = ((n & 0x000FFFFF) | 0x00100000) >> (20 - k); if (j < 0) n = -n; p_h -= t; @@ -1404,7 +1407,7 @@ export namespace NativeMath { t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); r = (z * t1) / (t1 - 2.0) - (w + z * w); z = 1.0 - (r - z); - j = (reinterpret(z) >> 32); + j = u32(reinterpret(z) >> 32); j += n << 20; if ((j >> 20) <= 0) z = scalbn(z, n); else z = reinterpret(reinterpret(z) & 0xFFFFFFFF | (j << 32)); @@ -1458,26 +1461,26 @@ export namespace NativeMath { // @ts-ignore: decorator @inline export function signbit(x: f64): bool { - return (reinterpret(x) >>> 63); + return bool(reinterpret(x) >>> 63); } export function sin(x: f64): f64 { // see: musl/src/math/sin.c var u = reinterpret(x); - var ix = (u >> 32); - var sign = ix >> 31; + var ux = u32(u >> 32); + var sign = ux >> 31; - ix &= 0x7FFFFFFF; + ux &= 0x7FFFFFFF; // |x| ~< pi/4 - if (ix <= 0x3FE921FB) { - if (ix < 0x3E500000) { // |x| < 2**-26 + if (ux <= 0x3FE921FB) { + if (ux < 0x3E500000) { // |x| < 2**-26 return x; } return sin_kern(x, 0.0, 0); } // sin(Inf or NaN) is NaN - if (ix >= 0x7FF00000) return x - x; + if (ux >= 0x7FF00000) return x - x; // argument reduction needed var n = rempio2(x, u, sign); @@ -1491,7 +1494,7 @@ export namespace NativeMath { export function sinh(x: f64): f64 { // see: musl/src/math/sinh.c var u = reinterpret(x) & 0x7FFFFFFFFFFFFFFF; var a = reinterpret(u); - var w = (u >> 32); + var w = u32(u >> 32); var h = builtin_copysign(0.5, x); if (w < 0x40862E42) { let t = expm1(a); @@ -1512,21 +1515,21 @@ export namespace NativeMath { export function tan(x: f64): f64 { // see: musl/src/math/tan.c var u = reinterpret(x); - var ix = (u >> 32); - var sign = ix >>> 31; + var ux = u32(u >> 32); + var sign = ux >>> 31; - ix &= 0x7FFFFFFF; + ux &= 0x7FFFFFFF; // |x| ~< pi/4 - if (ix <= 0x3FE921FB) { - if (ix < 0x3E400000) { // |x| < 2**-27 + if (ux <= 0x3FE921FB) { + if (ux < 0x3E400000) { // |x| < 2**-27 return x; } return tan_kern(x, 0.0, 1); } // tan(Inf or NaN) is NaN - if (ix >= 0x7FF00000) return x - x; + if (ux >= 0x7FF00000) return x - x; var n = rempio2(x, u, sign); return tan_kern(rempio2_y0, rempio2_y1, 1 - ((n & 1) << 1)); @@ -1536,7 +1539,7 @@ export namespace NativeMath { var u = reinterpret(x); u &= 0x7FFFFFFFFFFFFFFF; var y = reinterpret(u); - var w = (u >> 32); + var w = u32(u >> 32); var t: f64; if (w > 0x3FE193EA) { if (w > 0x40340000) { @@ -1597,8 +1600,8 @@ export namespace NativeMath { } var ux = reinterpret(x); var uy = reinterpret(y); - var ex = (ux >> 52 & 0x7FF); - var ey = (uy >> 52 & 0x7FF); + var ex = i64(ux >> 52 & 0x7FF); + var ey = i64(uy >> 52 & 0x7FF); var sx = ux >> 63; var uy1 = uy << 1; if (uy1 == 0 || ex == 0x7FF || isNaN(y)) { @@ -1613,14 +1616,14 @@ export namespace NativeMath { ex -= builtin_clz(ux << 12); ux <<= 1 - ex; } else { - ux &= -1 >> 12; + ux &= u64(-1) >> 12; ux |= 1 << 52; } if (!ey) { ey -= builtin_clz(uy << 12); uy <<= 1 - ey; } else { - uy &= -1 >> 12; + uy &= u64(-1) >> 12; uy |= 1 << 52; } while (ex > ey) { @@ -1651,9 +1654,8 @@ export namespace NativeMath { export function rem(x: f64, y: f64): f64 { // see: musl/src/math/remquo.c var ux = reinterpret(x); var uy = reinterpret(y); - var ex = (ux >> 52 & 0x7FF); - var ey = (uy >> 52 & 0x7FF); - var sx = (ux >> 63); + var ex = i64(ux >> 52 & 0x7FF); + var ey = i64(uy >> 52 & 0x7FF); if (uy << 1 == 0 || ex == 0x7FF || isNaN(y)) { let m = x * y; return m / m; @@ -1664,14 +1666,14 @@ export namespace NativeMath { ex -= builtin_clz(uxi << 12); uxi <<= 1 - ex; } else { - uxi &= -1 >> 12; + uxi &= u64(-1) >> 12; uxi |= 1 << 52; } if (!ey) { ey -= builtin_clz(uy << 12); uy <<= 1 - ey; } else { - uy &= -1 >> 12; + uy &= u64(-1) >> 12; uy |= 1 << 52; } var q: u32 = 0; @@ -1715,17 +1717,17 @@ export namespace NativeMath { x -= y; // ++q; } - return sx ? -x : x; + return ux < 0 ? -x : x; } export function sincos(x: f64): void { // see: musl/tree/src/math/sincos.c var u = reinterpret(x); - var ix = (u >> 32); - var sign = ix >> 31; - ix &= 0x7FFFFFFF; + var ux = u32(u >> 32); + var sign = ux >> 31; + ux &= 0x7FFFFFFF; - if (ix <= 0x3FE921FB) { // |x| ~<= π/4 - if (ix < 0x3E46A09E) { // if |x| < 2**-27 * sqrt(2) + if (ux <= 0x3FE921FB) { // |x| ~<= π/4 + if (ux < 0x3E46A09E) { // if |x| < 2**-27 * sqrt(2) sincos_sin = x; sincos_cos = 1; return; @@ -1735,7 +1737,7 @@ export namespace NativeMath { return; } // sin(Inf or NaN) is NaN - if (ix >= 0x7F800000) { + if (ux >= 0x7F800000) { let xx = x - x; sincos_sin = xx; sincos_cos = xx; @@ -1790,7 +1792,7 @@ function expo2f(x: f32, sign: 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 >> 1)) << 23); + var scale = reinterpret(u32(0x7F + (k >> 1)) << 23); // in directed rounding correct sign before rounding or overflow is important return NativeMathf.exp(x - kln2) * (sign * scale) * scale; } @@ -1801,7 +1803,7 @@ function pio2f_large_quot(x: f32, u: i32): i32 { // see: jdh8/metallic/blob/mast const coeff = reinterpret(0x3BF921FB54442D18); // π * 0x1p-65 = 8.51530395021638647334e-20 var offset = (u >> 23) - 152; - var shift = (offset & 63); + var shift = u64(offset & 63); var tblPtr = PIO2F_TABLE + (offset >> 6 << 3); var b0 = load(tblPtr, 0 << 3); @@ -1820,7 +1822,7 @@ function pio2f_large_quot(x: f32, u: i32): i32 { // see: jdh8/metallic/blob/mast var mantissa: u64 = (u & 0x007FFFFF) | 0x00800000; var product = mantissa * hi + (mantissa * lo >> 32); var r: i64 = product << 2; - var q = ((product >> 62) + (r >>> 63)); + var q = i32((product >> 62) + (r >>> 63)); rempio2f_y = copysign(coeff, x) * r; return q; } @@ -1857,7 +1859,7 @@ function sin_kernf(x: f64): f32 { // see: musl/tree/src/math/__sindf.c var w = z * z; var r = S3 + z * S4; var s = z * x; - return ((x + s * (S1 + z * S2)) + s * w * r); + return f32((x + s * (S1 + z * S2)) + s * w * r); } // |cos(x) - c(x)| < 2**-34.1 (~[-5.37e-11, 5.295e-11]). @@ -1873,7 +1875,7 @@ function cos_kernf(x: f64): f32 { // see: musl/tree/src/math/__cosdf.c var z = x * x; var w = z * z; var r = C2 + z * C3; - return (((1 + z * C0) + w * C1) + (w * z) * r); + return f32(((1 + z * C0) + w * C1) + (w * z) * r); } // |tan(x)/x - t(x)| < 2**-25.5 (~[-2e-08, 2e-08]). @@ -1896,7 +1898,7 @@ function tan_kernf(x: f64, odd: i32): f32 { // see: musl/tree/src/math/__tandf.c var u = T0 + z * T1; r = (x + s * u) + (s * w) * (t + w * r); - return (odd ? -1 / r : r); + return f32(odd ? -1 / r : r); } // See: jdh8/metallic/src/math/float/log2f.c and jdh8/metallic/src/math/float/kernel/atanh.h @@ -1999,8 +2001,7 @@ export namespace NativeMathf { var ix = hx & 0x7FFFFFFF; if (ix >= 0x3F800000) { if (ix == 0x3F800000) { - if (hx >> 31) return 2 * pio2_hi + Ox1p_120f; - return 0; + return select(2 * pio2_hi + Ox1p_120f, 0, hx < 0); } return 0 / (x - x); } @@ -2009,7 +2010,7 @@ export namespace NativeMathf { return pio2_hi - (x - (pio2_lo - x * Rf(x * x))); } var z: f32, w: f32, s: f32; - if (hx >> 31) { + if (hx < 0) { // z = (1 + x) * 0.5; z = 0.5 + x * 0.5; s = builtin_sqrt(z); @@ -2059,7 +2060,7 @@ export namespace NativeMathf { // var z: f32 = (1 - builtin_abs(x)) * 0.5; var z: f32 = 0.5 - builtin_abs(x) * 0.5; var s = builtin_sqrt(z); // sic - x = (pio2 - 2 * (s + s * Rf(z))); + x = f32(pio2 - 2 * (s + s * Rf(z))); return builtin_copysign(x, sx); } @@ -2157,7 +2158,7 @@ export namespace NativeMathf { var ix = reinterpret(x); var iy = reinterpret(y); if (ix == 0x3F800000) return atan(y); - var m = (((iy >> 31) & 1) | ((ix >> 30) & 2)); + var m = u32(((iy >> 31) & 1) | ((ix >> 30) & 2)); ix &= 0x7FFFFFFF; iy &= 0x7FFFFFFF; if (iy == 0) { @@ -2237,12 +2238,12 @@ export namespace NativeMathf { c3pio2 = reinterpret(0x4012D97C7F3321D2), // M_PI_2 * 3 c4pio2 = reinterpret(0x401921FB54442D18); // M_PI_2 * 4 - var ix = reinterpret(x); - var sign = ix >> 31; - ix &= 0x7FFFFFFF; + var ux = reinterpret(x); + var sign = ux >> 31; + ux &= 0x7FFFFFFF; - if (ix <= 0x3F490FDA) { // |x| ~<= π/4 - if (ix < 0x39800000) { // |x| < 2**-12 + if (ux <= 0x3F490FDA) { // |x| ~<= π/4 + if (ux < 0x39800000) { // |x| < 2**-12 // raise inexact if x != 0 return 1; } @@ -2250,15 +2251,15 @@ export namespace NativeMathf { } if (ASC_SHRINK_LEVEL < 1) { - if (ix <= 0x407B53D1) { // |x| ~<= 5π/4 - if (ix > 0x4016CBE3) { // |x| ~> 3π/4 + if (ux <= 0x407B53D1) { // |x| ~<= 5π/4 + if (ux > 0x4016CBE3) { // |x| ~> 3π/4 return -cos_kernf(sign ? x + c2pio2 : x - c2pio2); } else { return sign ? sin_kernf(x + c1pio2) : sin_kernf(c1pio2 - x); } } - if (ix <= 0x40E231D5) { // |x| ~<= 9π/4 - if (ix > 0x40AFEDDF) { // |x| ~> 7π/4 + if (ux <= 0x40E231D5) { // |x| ~<= 9π/4 + if (ux > 0x40AFEDDF) { // |x| ~> 7π/4 return cos_kernf(sign ? x + c4pio2 : x - c4pio2); } else { return sign ? sin_kernf(-x - c3pio2) : sin_kernf(x - c3pio2); @@ -2267,10 +2268,10 @@ export namespace NativeMathf { } // cos(Inf or NaN) is NaN - if (ix >= 0x7F800000) return x - x; + if (ux >= 0x7F800000) return x - x; // general argument reduction needed - var n = rempio2f(x, ix, sign); + var n = rempio2f(x, ux, sign); var y = rempio2f_y; var t = n & 1 ? sin_kernf(y) : cos_kernf(y); @@ -2314,12 +2315,12 @@ export namespace NativeMathf { Ox1p127f = reinterpret(0x7F000000); // 0x1p+127f let hx = reinterpret(x); - let sign_ = (hx >> 31); + let sign = hx >> 31; hx &= 0x7FFFFFFF; if (hx >= 0x42AEAC50) { if (hx > 0x7F800000) return x; // NaN if (hx >= 0x42B17218) { - if (!sign_) return x * Ox1p127f; + if (!sign) return x * Ox1p127f; else if (hx >= 0x42CFF1B5) return 0; } } @@ -2327,9 +2328,9 @@ export namespace NativeMathf { let k: i32; if (hx > 0x3EB17218) { if (hx > 0x3F851592) { - k = (invln2 * x + builtin_copysign(0.5, x)); + k = i32(invln2 * x + builtin_copysign(0.5, x)); } else { - k = 1 - (sign_ << 1); + k = 1 - (sign << 1); } hi = x - k * ln2hi; lo = k * ln2lo; @@ -2363,10 +2364,10 @@ export namespace NativeMathf { var u = reinterpret(x); var hx = u & 0x7FFFFFFF; - var sign_ = (u >> 31); + var sign = u >> 31; if (hx >= 0x4195B844) { if (hx > 0x7F800000) return x; - if (sign_) return -1; + if (sign) return -1; if (hx > 0x42B17217) { // x > log(FLT_MAX) x *= Ox1p127f; return x; @@ -2375,8 +2376,8 @@ export namespace NativeMathf { var c: f32 = 0.0, t: f32, k: i32; if (hx > 0x3EB17218) { k = select( - 1 - (sign_ << 1), - (invln2 * x + builtin_copysign(0.5, x)), + 1 - (sign << 1), + i32(invln2 * x + builtin_copysign(0.5, x)), hx < 0x3F851592 ); t = k; @@ -2450,7 +2451,7 @@ export namespace NativeMathf { x *= Ox1p90f; y *= Ox1p90f; } - return z * builtin_sqrt((x * x + y * y)); + return z * builtin_sqrt(f32(x * x + y * y)); } // @ts-ignore: decorator @@ -2481,9 +2482,10 @@ export namespace NativeMathf { let u = reinterpret(x); let k = 0; - if (u < 0x00800000 || (u >> 31)) { + let sign = u >> 31; + if (sign || u < 0x00800000) { if (u << 1 == 0) return -1 / (x * x); - if (u >> 31) return (x - x) / 0; + if (sign) return (x - x) / 0; k -= 25; x *= Ox1p25f; u = reinterpret(x); @@ -2493,7 +2495,7 @@ export namespace NativeMathf { return 0; } u += 0x3F800000 - 0x3F3504F3; - k += (u >> 23) - 0x7F; + k += i32(u >> 23) - 0x7F; u = (u & 0x007FFFFF) + 0x3F3504F3; x = reinterpret(u); let f = x - 1.0; @@ -2521,23 +2523,24 @@ export namespace NativeMathf { Lg4 = reinterpret(0x3E789E26), // 0xf89e26.0p-26f, 0.24279078841f Ox1p25f = reinterpret(0x4C000000); // 0x1p25f - var ix = reinterpret(x); + var ux = reinterpret(x); var k = 0; - if (ix < 0x00800000 || (ix >> 31)) { - if (ix << 1 == 0) return -1 / (x * x); - if (ix >> 31) return (x - x) / 0.0; + var sign = ux >> 31; + if (sign || ux < 0x00800000) { + if (ux << 1 == 0) return -1 / (x * x); + if (sign) return (x - x) / 0.0; k -= 25; x *= Ox1p25f; - ix = reinterpret(x); - } else if (ix >= 0x7F800000) { + ux = reinterpret(x); + } else if (ux >= 0x7F800000) { return x; - } else if (ix == 0x3F800000) { + } else if (ux == 0x3F800000) { return 0; } - ix += 0x3F800000 - 0x3F3504F3; - k += (ix >> 23) - 0x7F; - ix = (ix & 0x007FFFFF) + 0x3F3504F3; - x = reinterpret(ix); + ux += 0x3F800000 - 0x3F3504F3; + k += i32(ux >> 23) - 0x7F; + ux = (ux & 0x007FFFFF) + 0x3F3504F3; + x = reinterpret(ux); var f = x - 1.0; var s = f / (2.0 + f); var z = s * s; @@ -2547,9 +2550,9 @@ export namespace NativeMathf { var r = t2 + t1; var hfsq: f32 = 0.5 * f * f; var hi = f - hfsq; - ix = reinterpret(hi); - ix &= 0xFFFFF000; - hi = reinterpret(ix); + ux = reinterpret(hi); + ux &= 0xFFFFF000; + hi = reinterpret(ux); var lo = f - hi - hfsq + s * (hfsq + r); var dk = k; return dk * log10_2lo + (lo + hi) * ivln10lo + lo * ivln10hi + hi * ivln10hi + dk * log10_2hi; @@ -2565,9 +2568,10 @@ export namespace NativeMathf { Lg4 = reinterpret(0x3E789E26); // 0xf89e26.0p-26f, 0.24279078841f var ix = reinterpret(x); - var c: f32 = 0, f: f32 = 0; - var k: i32 = 1; - if (ix < 0x3ED413D0 || (ix >> 31)) { + var c: f32 = 0; + var f: f32 = 0; + var k = 1; + if (ix < 0x3ED413D0 || bool(ix >> 31)) { if (ix >= 0xBF800000) { if (x == -1) return x / 0.0; return (x - x) / 0.0; @@ -2583,7 +2587,7 @@ export namespace NativeMathf { let uf: f32 = 1 + x; let iu = reinterpret(uf); iu += 0x3F800000 - 0x3F3504F3; - k = (iu >> 23) - 0x7F; + k = i32(iu >> 23) - 0x7F; if (k < 25) { c = k >= 2 ? 1 - (uf - x) : x - (uf - 1); c /= uf; @@ -2615,23 +2619,24 @@ export namespace NativeMathf { Lg4 = reinterpret(0x3E789E26), // 0xf89e26.0p-26f, 0.24279078841f Ox1p25f = reinterpret(0x4C000000); // 0x1p25f - let ix = reinterpret(x); - let k: i32 = 0; - if (ix < 0x00800000 || (ix >> 31)) { - if (ix << 1 == 0) return -1 / (x * x); - if (ix >> 31) return (x - x) / 0.0; + let ux = reinterpret(x); + let k = 0; + let sign = ux >> 31; + if (sign || ux < 0x00800000) { + if (ux << 1 == 0) return -1 / (x * x); + if (sign) return (x - x) / 0.0; k -= 25; x *= Ox1p25f; - ix = reinterpret(x); - } else if (ix >= 0x7F800000) { + ux = reinterpret(x); + } else if (ux >= 0x7F800000) { return x; - } else if (ix == 0x3F800000) { + } else if (ux == 0x3F800000) { return 0; } - ix += 0x3F800000 - 0x3F3504F3; - k += (ix >> 23) - 0x7F; - ix = (ix & 0x007FFFFF) + 0x3F3504F3; - x = reinterpret(ix); + ux += 0x3F800000 - 0x3F3504F3; + k += i32(ux >> 23) - 0x7F; + ux = (ux & 0x007FFFFF) + 0x3F3504F3; + x = reinterpret(ux); let f = x - 1.0; let s = f / (2.0 + f); let z = s * s; @@ -2701,9 +2706,9 @@ export namespace NativeMathf { if (ux == 0x3F800000) { // x == 1 m = sx | u32((uy & 0x7FFFFFFF) == 0x7F800000) ? 0x7FC00000 : 0x3F800000; } else if (ux == 0) { - m = uy >> 31 ? 0x7F800000 : 0; + m = uy < 0 ? 0x7F800000 : 0; } else if (ux == 0x7F800000) { - m = uy >> 31 ? 0 : 0x7F800000; + m = uy < 0 ? 0 : 0x7F800000; } else if (sx) { m = 0x7FC00000; } else { @@ -2764,27 +2769,27 @@ export namespace NativeMathf { s3pio2 = reinterpret(0x4012D97C7F3321D2), // M_PI_2 * 3 s4pio2 = reinterpret(0x401921FB54442D18); // M_PI_2 * 4 - var ix = reinterpret(x); - var sign = ix >> 31; - ix &= 0x7FFFFFFF; + var ux = reinterpret(x); + var sign = ux >> 31; + ux &= 0x7FFFFFFF; - if (ix <= 0x3F490FDA) { // |x| ~<= π/4 - if (ix < 0x39800000) { // |x| < 2**-12 + if (ux <= 0x3F490FDA) { // |x| ~<= π/4 + if (ux < 0x39800000) { // |x| < 2**-12 return x; } return sin_kernf(x); } if (ASC_SHRINK_LEVEL < 1) { - if (ix <= 0x407B53D1) { // |x| ~<= 5π/4 - if (ix <= 0x4016CBE3) { // |x| ~<= 3π/4 + if (ux <= 0x407B53D1) { // |x| ~<= 5π/4 + if (ux <= 0x4016CBE3) { // |x| ~<= 3π/4 return sign ? -cos_kernf(x + s1pio2) : cos_kernf(x - s1pio2); } return sin_kernf(-(sign ? x + s2pio2 : x - s2pio2)); } - if (ix <= 0x40E231D5) { // |x| ~<= 9π/4 - if (ix <= 0x40AFEDDF) { // |x| ~<= 7π/4 + if (ux <= 0x40E231D5) { // |x| ~<= 9π/4 + if (ux <= 0x40AFEDDF) { // |x| ~<= 7π/4 return sign ? cos_kernf(x + s3pio2) : -cos_kernf(x - s3pio2); } return sin_kernf(sign ? x + s4pio2 : x - s4pio2); @@ -2792,9 +2797,9 @@ export namespace NativeMathf { } // sin(Inf or NaN) is NaN - if (ix >= 0x7F800000) return x - x; + if (ux >= 0x7F800000) return x - x; - var n = rempio2f(x, ix, sign); + var n = rempio2f(x, ux, sign); var y = rempio2f_y; var t = n & 1 ? cos_kernf(y) : sin_kernf(y); @@ -2829,27 +2834,27 @@ export namespace NativeMathf { t3pio2 = reinterpret(0x4012D97C7F3321D2), // 3 * M_PI_2 t4pio2 = reinterpret(0x401921FB54442D18); // 4 * M_PI_2 - var ix = reinterpret(x); - var sign = ix >> 31; - ix &= 0x7FFFFFFF; + var ux = reinterpret(x); + var sign = ux >> 31; + ux &= 0x7FFFFFFF; - if (ix <= 0x3F490FDA) { // |x| ~<= π/4 - if (ix < 0x39800000) { // |x| < 2**-12 + if (ux <= 0x3F490FDA) { // |x| ~<= π/4 + if (ux < 0x39800000) { // |x| < 2**-12 return x; } return tan_kernf(x, 0); } if (ASC_SHRINK_LEVEL < 1) { - if (ix <= 0x407B53D1) { // |x| ~<= 5π/4 - if (ix <= 0x4016CBE3) { // |x| ~<= 3π/4 + if (ux <= 0x407B53D1) { // |x| ~<= 5π/4 + if (ux <= 0x4016CBE3) { // |x| ~<= 3π/4 return tan_kernf((sign ? x + t1pio2 : x - t1pio2), 1); } else { return tan_kernf((sign ? x + t2pio2 : x - t2pio2), 0); } } - if (ix <= 0x40E231D5) { // |x| ~<= 9π/4 - if (ix <= 0x40AFEDDF) { // |x| ~<= 7π/4 + if (ux <= 0x40E231D5) { // |x| ~<= 9π/4 + if (ux <= 0x40AFEDDF) { // |x| ~<= 7π/4 return tan_kernf((sign ? x + t3pio2 : x - t3pio2), 1); } else { return tan_kernf((sign ? x + t4pio2 : x - t4pio2), 0); @@ -2858,10 +2863,10 @@ export namespace NativeMathf { } // tan(Inf or NaN) is NaN - if (ix >= 0x7F800000) return x - x; + if (ux >= 0x7F800000) return x - x; // argument reduction - var n = rempio2f(x, ix, sign); + var n = rempio2f(x, ux, sign); var y = rempio2f_y; return tan_kernf(y, n & 1); } @@ -2927,8 +2932,8 @@ export namespace NativeMathf { } var ux = reinterpret(x); var uy = reinterpret(y); - var ex = (ux >> 23 & 0xFF); - var ey = (uy >> 23 & 0xFF); + var ex = i32(ux >> 23 & 0xFF); + var ey = i32(uy >> 23 & 0xFF); var sm = ux & 0x80000000; var uy1 = uy << 1; if (uy1 == 0 || ex == 0xFF || isNaN(y)) { @@ -2950,7 +2955,7 @@ export namespace NativeMathf { ey -= builtin_clz(uy << 9); uy <<= 1 - ey; } else { - uy &= -1 >> 9; + uy &= u32(-1) >> 9; uy |= 1 << 23; } while (ex > ey) { @@ -2981,9 +2986,8 @@ export namespace NativeMathf { export function rem(x: f32, y: f32): f32 { // see: musl/src/math/remquof.c var ux = reinterpret(x); var uy = reinterpret(y); - var ex = (ux >> 23 & 0xFF); - var ey = (uy >> 23 & 0xFF); - var sx = (ux >> 31); + var ex = i32(ux >> 23 & 0xFF); + var ey = i32(uy >> 23 & 0xFF); var uxi = ux; if (uy << 1 == 0 || ex == 0xFF || isNaN(y)) return (x * y) / (x * y); if (ux << 1 == 0) return x; @@ -2991,14 +2995,14 @@ export namespace NativeMathf { ex -= builtin_clz(uxi << 9); uxi <<= 1 - ex; } else { - uxi &= -1 >> 9; + uxi &= u32(-1) >> 9; uxi |= 1 << 23; } if (!ey) { ey -= builtin_clz(uy << 9); uy <<= 1 - ey; } else { - uy &= -1 >> 9; + uy &= u32(-1) >> 9; uy |= 1 << 23; } var q = 0; @@ -3038,11 +3042,11 @@ export namespace NativeMathf { x = reinterpret(uxi); y = builtin_abs(y); var x2 = x + x; - if (ex == ey || (ex + 1 == ey && (x2 > y || (x2 == y && (q & 1))))) { + if (ex == ey || (ex + 1 == ey && (x2 > y || (x2 == y && bool(q & 1))))) { x -= y; // q++; } - return sx ? -x : x; + return ux < 0 ? -x : x; } export function sincos(x: f32): void { // see: musl/tree/src/math/sincosf.c @@ -3052,12 +3056,12 @@ export namespace NativeMathf { s3pio2 = reinterpret(0x4012D97C7F3321D2), // 3 * M_PI_2 s4pio2 = reinterpret(0x401921FB54442D18); // 4 * M_PI_2 - var ix = reinterpret(x); - var sign = ix >> 31; - ix &= 0x7FFFFFFF; + var ux = reinterpret(x); + var sign = ux >> 31; + ux &= 0x7FFFFFFF; - if (ix <= 0x3F490FDA) { // |x| ~<= π/4 - if (ix < 0x39800000) { // |x| < 2**-12 + if (ux <= 0x3F490FDA) { // |x| ~<= π/4 + if (ux < 0x39800000) { // |x| < 2**-12 sincos_sin = x; sincos_cos = 1; return; @@ -3067,8 +3071,8 @@ export namespace NativeMathf { return; } if (ASC_SHRINK_LEVEL < 1) { - if (ix <= 0x407B53D1) { // |x| ~<= 5π/4 - if (ix <= 0x4016CBE3) { // |x| ~<= 3π/4 + if (ux <= 0x407B53D1) { // |x| ~<= 5π/4 + if (ux <= 0x4016CBE3) { // |x| ~<= 3π/4 if (sign) { sincos_sin = -cos_kernf(x + s1pio2); sincos_cos = sin_kernf(x + s1pio2); @@ -3083,8 +3087,8 @@ export namespace NativeMathf { sincos_cos = -cos_kernf(sign ? x + s2pio2 : x - s2pio2); return; } - if (ix <= 0x40E231D5) { // |x| ~<= 9π/4 - if (ix <= 0x40AFEDDF) { // |x| ~<= 7π/4 + if (ux <= 0x40E231D5) { // |x| ~<= 9π/4 + if (ux <= 0x40AFEDDF) { // |x| ~<= 7π/4 if (sign) { sincos_sin = cos_kernf(x + s3pio2); sincos_cos = -sin_kernf(x + s3pio2); @@ -3100,14 +3104,14 @@ export namespace NativeMathf { } } // sin(Inf or NaN) is NaN - if (ix >= 0x7F800000) { + if (ux >= 0x7F800000) { let xx = x - x; sincos_sin = xx; sincos_cos = xx; return; } // general argument reduction needed - var n = rempio2f(x, ix, sign); + var n = rempio2f(x, ux, sign); var y = rempio2f_y; var s = sin_kernf(y); var c = cos_kernf(y); diff --git a/std/assembly/util/math.ts b/std/assembly/util/math.ts index da31d474de..7f77f3f41c 100644 --- a/std/assembly/util/math.ts +++ b/std/assembly/util/math.ts @@ -320,10 +320,10 @@ function log2f_inline(ux: u32): f64 { // The range is split into N subintervals. // The ith subinterval contains z and c is near its center. var tmp = ux - 0x3F330000; - var i = ((tmp >> (23 - LOG2F_TABLE_BITS)) & N_MASK); + var i = usize((tmp >> (23 - LOG2F_TABLE_BITS)) & N_MASK); var top = tmp & 0xFF800000; var uz = ux - top; - var k = (top >> 23); + var k = top >> 23; var invc = load(LOG2F_DATA_TAB + (i << (1 + alignof())), 0 << alignof()); var logc = load(LOG2F_DATA_TAB + (i << (1 + alignof())), 1 << alignof()); @@ -423,10 +423,10 @@ export function powf_lut(x: f32, y: f32): f32 { if (zeroinfnanf(ix)) { let x2 = x * x; if ((ix >> 31) && checkintf(iy) == 1) x2 = -x2; - return iy >> 31 ? 1 / x2 : x2; + return iy < 0 ? 1 / x2 : x2; } // x and y are non-zero finite. - if (ix >> 31) { + if (ix < 0) { // Finite x < 0. let yint = checkintf(iy); if (yint == 0) return (x - x) / (x - x); @@ -651,13 +651,16 @@ export function exp_lut(x: f64): f64 { C5 = reinterpret(0x3F81111167A4D017); // __exp_data.poly[3] (0x1.1111167a4d017p-7) var ux = reinterpret(x); - var abstop = (ux >> 52 & 0x7FF); + var abstop = u32(ux >> 52) & 0x7FF; if (abstop - 0x3C9 >= 0x03F) { if (abstop - 0x3C9 >= 0x80000000) return 1; if (abstop >= 0x409) { if (ux == 0xFFF0000000000000) return 0; - if (abstop >= 0x7FF) return 1.0 + x; - return select(0, Infinity, ux >> 63); + if (abstop >= 0x7FF) { + return 1.0 + x; + } else { + return select(0, Infinity, ux < 0); + } } // Large x is special cased below. abstop = 0; @@ -682,7 +685,7 @@ export function exp_lut(x: f64): f64 { // #endif var r = x + kd * NegLn2hiN + kd * NegLn2loN; // 2^(k/N) ~= scale * (1 + tail). - var idx = ((ki & N_MASK) << 1); + var idx = usize((ki & N_MASK) << 1); var top = ki << (52 - EXP_TABLE_BITS); var tail = reinterpret(load(EXP_DATA_TAB + (idx << alignof()))); // T[idx] @@ -757,13 +760,13 @@ export function exp2_lut(x: f64): f64 { C5 = reinterpret(0x3F55D7E09B4E3A84); // 0x1.5d7e09b4e3a84p-10 var ux = reinterpret(x); - var abstop = (ux >> 52 & 0x7ff); + var abstop = u32(ux >> 52) & 0x7ff; if (abstop - 0x3C9 >= 0x03F) { if (abstop - 0x3C9 >= 0x80000000) return 1.0; if (abstop >= 0x409) { if (ux == 0xFFF0000000000000) return 0; if (abstop >= 0x7FF) return 1.0 + x; - if (!(ux >> 63)) return Infinity; + if (ux >= 0) return Infinity; else if (ux >= 0xC090CC0000000000) return 0; } if ((ux << 1) > 0x811A000000000000) abstop = 0; // Large x is special cased below. @@ -776,7 +779,7 @@ export function exp2_lut(x: f64): f64 { kd -= shift; // k/N for int k var r = x - kd; // 2^(k/N) ~= scale * (1 + tail) - var idx = ((ki & N_MASK) << 1); + var idx = usize((ki & N_MASK) << 1); var top = ki << (52 - EXP_TABLE_BITS); var tail = reinterpret(load(EXP_DATA_TAB + (idx << alignof()), 0 << alignof())); // T[idx]) @@ -1023,7 +1026,7 @@ export function log2_lut(x: f64): f64 { r4 * (B6 + r * B7 + r2 * (B8 + r * B9))); return y + lo; } - var top = (ix >> 48); + var top = u32(ix >> 48); if (top - 0x0010 >= 0x7ff0 - 0x0010) { // x < 0x1p-1022 or inf or nan. if ((ix << 1) == 0) return -1.0 / (x * x); @@ -1715,7 +1718,7 @@ function log_inline(ix: u64): f64 { // The range is split into N subintervals. // The ith subinterval contains z and c is near its center. var tmp = ix - 0x3fE6955500000000; - var i = ((tmp >> (52 - POW_LOG_TABLE_BITS)) & N_MASK); + var i = usize((tmp >> (52 - POW_LOG_TABLE_BITS)) & N_MASK); var k = tmp >> 52; var iz = ix - (tmp & u64(0xFFF) << 52); var z = reinterpret(iz); @@ -1791,7 +1794,7 @@ function exp_inline(x: f64, xtail: f64, sign_bias: u32): f64 { var kd: f64, z: f64, r: f64, r2: f64, scale: f64, tail: f64, tmp: f64; var ux = reinterpret(x); - abstop = (ux >> 52) & 0x7FF; + abstop = u32(ux >> 52) & 0x7FF; if (abstop - 0x3C9 >= 0x03F) { if (abstop - 0x3C9 >= 0x80000000) { // Avoid spurious underflow for tiny x. @@ -1800,7 +1803,9 @@ function exp_inline(x: f64, xtail: f64, sign_bias: u32): f64 { } if (abstop >= 0x409) { // top12(1024.0) // Note: inf and nan are already handled. - return ux >> 63 ? uflow(sign_bias) : oflow(sign_bias); + return ux < 0 + ? uflow(sign_bias) + : oflow(sign_bias); } // Large x is special cased below. abstop = 0; @@ -1828,7 +1833,7 @@ function exp_inline(x: f64, xtail: f64, sign_bias: u32): f64 { // The code assumes 2^-200 < |xtail| < 2^-8/N r += xtail; // 2^(k/N) ~= scale * (1 + tail) - idx = ((ki & N_MASK) << 1); + idx = usize((ki & N_MASK) << 1); top = (ki + sign_bias) << (52 - EXP_TABLE_BITS); tail = reinterpret(load(EXP_DATA_TAB + (idx << alignof()))); @@ -1874,10 +1879,10 @@ export function pow_lut(x: f64, y: f64): f64 { if (zeroinfnan(ix)) { let x2 = x * x; if (i32(ix >> 63) && checkint(iy) == 1) x2 = -x2; - return iy >> 63 ? 1 / x2 : x2; + return iy < 0 ? 1 / x2 : x2; } // Here x and y are non-zero finite - if (ix >> 63) { + if (ix < 0) { // Finite x < 0 let yint = checkint(iy); if (yint == 0) return (x - x) / (x - x); diff --git a/tests/compiler/binary.debug.wat b/tests/compiler/binary.debug.wat index ec74a8dcf0..9d9e568bd7 100644 --- a/tests/compiler/binary.debug.wat +++ b/tests/compiler/binary.debug.wat @@ -549,10 +549,8 @@ local.set $10 end local.get $6 - i64.const 63 - i64.shr_u i64.const 0 - i64.ne + i64.lt_s if (result f64) f64.const 1 local.get $10 @@ -563,10 +561,8 @@ br $~lib/util/math/pow_lut|inlined.0 end local.get $5 - i64.const 63 - i64.shr_u i64.const 0 - i64.ne + i64.lt_s if block $~lib/util/math/checkint|inlined.1 (result i32) local.get $6 @@ -980,10 +976,8 @@ i32.ge_u if local.get $9 - i64.const 63 - i64.shr_u i64.const 0 - i64.ne + i64.lt_s if (result f64) local.get $12 local.set $41 @@ -1755,8 +1749,8 @@ local.set $9 end local.get $6 - i32.const 31 - i32.shr_u + i32.const 0 + i32.lt_s if (result f32) f32.const 1 local.get $9 @@ -1767,8 +1761,8 @@ br $~lib/util/math/powf_lut|inlined.0 end local.get $5 - i32.const 31 - i32.shr_u + i32.const 0 + i32.lt_s if block $~lib/util/math/checkintf|inlined.1 (result i32) local.get $6 diff --git a/tests/compiler/resolve-binary.debug.wat b/tests/compiler/resolve-binary.debug.wat index 5185290586..2928bbed33 100644 --- a/tests/compiler/resolve-binary.debug.wat +++ b/tests/compiler/resolve-binary.debug.wat @@ -3061,10 +3061,8 @@ local.set $10 end local.get $6 - i64.const 63 - i64.shr_u i64.const 0 - i64.ne + i64.lt_s if (result f64) f64.const 1 local.get $10 @@ -3075,10 +3073,8 @@ br $~lib/util/math/pow_lut|inlined.0 end local.get $5 - i64.const 63 - i64.shr_u i64.const 0 - i64.ne + i64.lt_s if block $~lib/util/math/checkint|inlined.1 (result i32) local.get $6 @@ -3492,10 +3488,8 @@ i32.ge_u if local.get $9 - i64.const 63 - i64.shr_u i64.const 0 - i64.ne + i64.lt_s if (result f64) local.get $12 local.set $41 diff --git a/tests/compiler/std/math.debug.wat b/tests/compiler/std/math.debug.wat index c781f2c6d0..41c0fc8b70 100644 --- a/tests/compiler/std/math.debug.wat +++ b/tests/compiler/std/math.debug.wat @@ -721,8 +721,8 @@ i32.eq if local.get $1 - i32.const 31 - i32.shr_u + i32.const 0 + i32.lt_s if f64.const 2 f64.const 1.5707963267948966 @@ -771,8 +771,8 @@ return end local.get $1 - i32.const 31 - i32.shr_u + i32.const 0 + i32.lt_s if f64.const 0.5 local.get $0 @@ -903,18 +903,16 @@ i32.const 1065353216 i32.eq if - local.get $1 - i32.const 31 - i32.shr_u - if - f32.const 2 - f32.const 1.570796251296997 - f32.mul - f32.const 7.52316384526264e-37 - f32.add - return - end + f32.const 2 + f32.const 1.570796251296997 + f32.mul + f32.const 7.52316384526264e-37 + f32.add f32.const 0 + local.get $1 + i32.const 0 + i32.lt_s + select return end f32.const 0 @@ -952,8 +950,8 @@ return end local.get $1 - i32.const 31 - i32.shr_u + i32.const 0 + i32.lt_s if f32.const 0.5 local.get $0 @@ -2304,15 +2302,13 @@ f64.sub local.set $0 end - local.get $1 - i32.const 31 - i32.shr_u - if - local.get $0 - f64.neg - return - end local.get $0 + f64.neg + local.get $0 + local.get $1 + i32.const 0 + i32.lt_s + select ) (func $std/math/test_asin (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) local.get $0 @@ -5795,16 +5791,16 @@ local.get $1 i64.const 32 i64.shr_u - i64.const 2147483647 - i64.and i32.wrap_i64 + i32.const 2147483647 + i32.and local.set $2 - i32.const 0 - local.set $3 local.get $1 i64.const 63 i64.shr_u i32.wrap_i64 + local.set $3 + i32.const 0 local.set $4 local.get $2 i32.const 1078159482 @@ -5817,7 +5813,7 @@ local.get $0 return end - local.get $4 + local.get $3 if f64.const -1 return @@ -5839,7 +5835,7 @@ i32.gt_u if i32.const 1 - local.get $4 + local.get $3 i32.const 1 i32.shl i32.sub @@ -5855,8 +5851,8 @@ i32.const 1072734898 i32.lt_u select - local.set $3 - local.get $3 + local.set $4 + local.get $4 f64.convert_i32_s local.set $6 local.get $0 @@ -5940,7 +5936,7 @@ f64.div f64.mul local.set $13 - local.get $3 + local.get $4 i32.const 0 i32.eq if @@ -5965,7 +5961,7 @@ local.get $10 f64.sub local.set $13 - local.get $3 + local.get $4 i32.const -1 i32.eq if @@ -5978,7 +5974,7 @@ f64.sub return end - local.get $3 + local.get $4 i32.const 1 i32.eq if @@ -6005,7 +6001,7 @@ return end i64.const 1023 - local.get $3 + local.get $4 i64.extend_i32_s i64.add i64.const 52 @@ -6014,13 +6010,13 @@ local.get $1 f64.reinterpret_i64 local.set $14 - local.get $3 + local.get $4 i32.const 0 i32.lt_s if (result i32) i32.const 1 else - local.get $3 + local.get $4 i32.const 56 i32.gt_s end @@ -6031,7 +6027,7 @@ f64.const 1 f64.add local.set $15 - local.get $3 + local.get $4 i32.const 1024 i32.eq if @@ -6053,7 +6049,7 @@ return end i64.const 1023 - local.get $3 + local.get $4 i64.extend_i32_s i64.sub i64.const 52 @@ -6062,7 +6058,7 @@ local.get $1 f64.reinterpret_i64 local.set $15 - local.get $3 + local.get $4 i32.const 20 i32.lt_s if @@ -6121,9 +6117,9 @@ local.get $2 i64.const 52 i64.shr_u - i64.const 2047 - i64.and i32.wrap_i64 + i32.const 2047 + i32.and local.set $3 local.get $3 i32.const 969 @@ -6159,16 +6155,16 @@ local.get $1 f64.add br $~lib/util/math/exp_lut|inlined.0 + else + f64.const 0 + f64.const inf + local.get $2 + i64.const 0 + i64.lt_s + select + br $~lib/util/math/exp_lut|inlined.0 end - f64.const 0 - f64.const inf - local.get $2 - i64.const 63 - i64.shr_u - i64.const 0 - i64.ne - select - br $~lib/util/math/exp_lut|inlined.0 + unreachable end i32.const 0 local.set $3 @@ -7092,9 +7088,9 @@ local.get $2 i64.const 52 i64.shr_u - i64.const 2047 - i64.and i32.wrap_i64 + i32.const 2047 + i32.and local.set $3 local.get $3 i32.const 969 @@ -7132,11 +7128,8 @@ br $~lib/util/math/exp2_lut|inlined.0 end local.get $2 - i64.const 63 - i64.shr_u i64.const 0 - i64.ne - i32.eqz + i64.ge_s if f64.const inf br $~lib/util/math/exp2_lut|inlined.0 @@ -7893,7 +7886,7 @@ (local $1 i64) (local $2 i32) (local $3 i32) - (local $4 f64) + (local $4 i32) (local $5 f64) (local $6 f64) (local $7 f64) @@ -7907,6 +7900,7 @@ (local $15 f64) (local $16 f64) (local $17 f64) + (local $18 f64) local.get $0 i64.reinterpret_f64 local.set $1 @@ -7918,14 +7912,16 @@ i32.const 0 local.set $3 local.get $2 - i32.const 1048576 - i32.lt_u + i32.const 31 + i32.shr_u + local.set $4 + local.get $4 if (result i32) i32.const 1 else local.get $2 - i32.const 31 - i32.shr_u + i32.const 1048576 + i32.lt_u end if local.get $1 @@ -7941,9 +7937,7 @@ f64.div return end - local.get $2 - i32.const 31 - i32.shr_u + local.get $4 if local.get $0 local.get $0 @@ -8029,46 +8023,46 @@ local.get $0 f64.const 1 f64.sub - local.set $4 + local.set $5 f64.const 0.5 - local.get $4 + local.get $5 f64.mul - local.get $4 + local.get $5 f64.mul - local.set $5 - local.get $4 + local.set $6 + local.get $5 f64.const 2 - local.get $4 + local.get $5 f64.add f64.div - local.set $6 - local.get $6 - local.get $6 - f64.mul local.set $7 local.get $7 local.get $7 f64.mul local.set $8 local.get $8 - f64.const 0.3999999999940942 local.get $8 + f64.mul + local.set $9 + local.get $9 + f64.const 0.3999999999940942 + local.get $9 f64.const 0.22222198432149784 - local.get $8 + local.get $9 f64.const 0.15313837699209373 f64.mul f64.add f64.mul f64.add f64.mul - local.set $9 - local.get $7 - f64.const 0.6666666666666735 + local.set $10 local.get $8 + f64.const 0.6666666666666735 + local.get $9 f64.const 0.2857142874366239 - local.get $8 + local.get $9 f64.const 0.1818357216161805 - local.get $8 + local.get $9 f64.const 0.14798198605116586 f64.mul f64.add @@ -8077,16 +8071,16 @@ f64.mul f64.add f64.mul - local.set $10 + local.set $11 + local.get $11 local.get $10 - local.get $9 f64.add - local.set $11 - local.get $4 + local.set $12 local.get $5 + local.get $6 f64.sub - local.set $12 - local.get $12 + local.set $13 + local.get $13 i64.reinterpret_f64 local.set $1 local.get $1 @@ -8095,58 +8089,58 @@ local.set $1 local.get $1 f64.reinterpret_i64 - local.set $12 - local.get $4 - local.get $12 - f64.sub + local.set $13 local.get $5 + local.get $13 f64.sub local.get $6 - local.get $5 - local.get $11 + f64.sub + local.get $7 + local.get $6 + local.get $12 f64.add f64.mul f64.add - local.set $13 - local.get $12 + local.set $14 + local.get $13 f64.const 0.4342944818781689 f64.mul - local.set $14 + local.set $15 local.get $3 f64.convert_i32_s - local.set $15 - local.get $15 + local.set $16 + local.get $16 f64.const 0.30102999566361177 f64.mul - local.set $16 - local.get $15 + local.set $17 + local.get $16 f64.const 3.694239077158931e-13 f64.mul + local.get $14 local.get $13 - local.get $12 f64.add f64.const 2.5082946711645275e-11 f64.mul f64.add - local.get $13 + local.get $14 f64.const 0.4342944818781689 f64.mul f64.add - local.set $17 - local.get $16 - local.get $14 + local.set $18 + local.get $17 + local.get $15 f64.add - local.set $8 + local.set $9 + local.get $18 local.get $17 - local.get $16 - local.get $8 + local.get $9 f64.sub - local.get $14 + local.get $15 f64.add f64.add - local.set $17 - local.get $17 - local.get $8 + local.set $18 + local.get $18 + local.get $9 f64.add ) (func $std/math/test_log10 (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) @@ -8170,7 +8164,7 @@ (func $~lib/math/NativeMathf.log10 (param $0 f32) (result f32) (local $1 i32) (local $2 i32) - (local $3 f32) + (local $3 i32) (local $4 f32) (local $5 f32) (local $6 f32) @@ -8181,20 +8175,23 @@ (local $11 f32) (local $12 f32) (local $13 f32) + (local $14 f32) local.get $0 i32.reinterpret_f32 local.set $1 i32.const 0 local.set $2 local.get $1 - i32.const 8388608 - i32.lt_u + i32.const 31 + i32.shr_u + local.set $3 + local.get $3 if (result i32) i32.const 1 else local.get $1 - i32.const 31 - i32.shr_u + i32.const 8388608 + i32.lt_u end if local.get $1 @@ -8210,9 +8207,7 @@ f32.div return end - local.get $1 - i32.const 31 - i32.shr_u + local.get $3 if local.get $0 local.get $0 @@ -8275,52 +8270,52 @@ local.get $0 f32.const 1 f32.sub - local.set $3 - local.get $3 - f32.const 2 - local.get $3 - f32.add - f32.div local.set $4 local.get $4 + f32.const 2 local.get $4 - f32.mul + f32.add + f32.div local.set $5 local.get $5 local.get $5 f32.mul local.set $6 local.get $6 - f32.const 0.40000972151756287 local.get $6 + f32.mul + local.set $7 + local.get $7 + f32.const 0.40000972151756287 + local.get $7 f32.const 0.24279078841209412 f32.mul f32.add f32.mul - local.set $7 - local.get $5 - f32.const 0.6666666269302368 + local.set $8 local.get $6 - f32.const 0.2849878668785095 + f32.const 0.6666666269302368 + local.get $7 + f32.const 0.2849878668785095 f32.mul f32.add f32.mul - local.set $8 + local.set $9 + local.get $9 local.get $8 - local.get $7 f32.add - local.set $9 + local.set $10 f32.const 0.5 - local.get $3 + local.get $4 f32.mul - local.get $3 + local.get $4 f32.mul - local.set $10 - local.get $3 - local.get $10 - f32.sub local.set $11 + local.get $4 local.get $11 + f32.sub + local.set $12 + local.get $12 i32.reinterpret_f32 local.set $1 local.get $1 @@ -8329,40 +8324,40 @@ local.set $1 local.get $1 f32.reinterpret_i32 - local.set $11 - local.get $3 - local.get $11 + local.set $12 + local.get $4 + local.get $12 f32.sub - local.get $10 + local.get $11 f32.sub - local.get $4 + local.get $5 + local.get $11 local.get $10 - local.get $9 f32.add f32.mul f32.add - local.set $12 + local.set $13 local.get $2 f32.convert_i32_s - local.set $13 - local.get $13 + local.set $14 + local.get $14 f32.const 7.903415166765626e-07 f32.mul + local.get $13 local.get $12 - local.get $11 f32.add f32.const -3.168997136526741e-05 f32.mul f32.add - local.get $12 + local.get $13 f32.const 0.434326171875 f32.mul f32.add - local.get $11 + local.get $12 f32.const 0.434326171875 f32.mul f32.add - local.get $13 + local.get $14 f32.const 0.3010292053222656 f32.mul f32.add @@ -9882,10 +9877,8 @@ local.set $10 end local.get $6 - i64.const 63 - i64.shr_u i64.const 0 - i64.ne + i64.lt_s if (result f64) f64.const 1 local.get $10 @@ -9896,10 +9889,8 @@ br $~lib/util/math/pow_lut|inlined.0 end local.get $5 - i64.const 63 - i64.shr_u i64.const 0 - i64.ne + i64.lt_s if block $~lib/util/math/checkint|inlined.1 (result i32) local.get $6 @@ -10313,10 +10304,8 @@ i32.ge_u if local.get $9 - i64.const 63 - i64.shr_u i64.const 0 - i64.ne + i64.lt_s if (result f64) local.get $12 local.set $41 @@ -10857,8 +10846,8 @@ local.set $9 end local.get $6 - i32.const 31 - i32.shr_u + i32.const 0 + i32.lt_s if (result f32) f32.const 1 local.get $9 @@ -10869,8 +10858,8 @@ br $~lib/util/math/powf_lut|inlined.0 end local.get $5 - i32.const 31 - i32.shr_u + i32.const 0 + i32.lt_s if block $~lib/util/math/checkintf|inlined.1 (result i32) local.get $6 @@ -11522,13 +11511,12 @@ (local $3 i64) (local $4 i64) (local $5 i64) - (local $6 i32) - (local $7 f64) - (local $8 i64) + (local $6 f64) + (local $7 i64) + (local $8 i32) (local $9 i32) - (local $10 i32) - (local $11 i64) - (local $12 f64) + (local $10 i64) + (local $11 f64) local.get $0 i64.reinterpret_f64 local.set $2 @@ -11547,11 +11535,6 @@ i64.const 2047 i64.and local.set $5 - local.get $2 - i64.const 63 - i64.shr_u - i32.wrap_i64 - local.set $6 local.get $3 i64.const 1 i64.shl @@ -11575,9 +11558,9 @@ local.get $0 local.get $1 f64.mul - local.set $7 - local.get $7 - local.get $7 + local.set $6 + local.get $6 + local.get $6 f64.div return end @@ -11591,38 +11574,38 @@ return end local.get $2 - local.set $8 + local.set $7 local.get $4 i64.const 0 i64.ne i32.eqz if local.get $4 - local.get $8 + local.get $7 i64.const 12 i64.shl i64.clz i64.sub local.set $4 - local.get $8 + local.get $7 i64.const 1 local.get $4 i64.sub i64.shl - local.set $8 + local.set $7 else - local.get $8 + local.get $7 i64.const -1 i64.const 12 i64.shr_u i64.and - local.set $8 - local.get $8 + local.set $7 + local.get $7 i64.const 1 i64.const 52 i64.shl i64.or - local.set $8 + local.set $7 end local.get $5 i64.const 0 @@ -11657,7 +11640,7 @@ local.set $3 end i32.const 0 - local.set $9 + local.set $8 block $do-break|0 loop $do-loop|0 local.get $4 @@ -11679,30 +11662,30 @@ local.get $4 local.get $5 i64.gt_s - local.set $10 - local.get $10 + local.set $9 + local.get $9 if - local.get $8 + local.get $7 local.get $3 i64.ge_u if - local.get $8 + local.get $7 local.get $3 i64.sub - local.set $8 - local.get $9 + local.set $7 + local.get $8 i32.const 1 i32.add - local.set $9 + local.set $8 end - local.get $8 + local.get $7 i64.const 1 i64.shl - local.set $8 - local.get $9 + local.set $7 + local.get $8 i32.const 1 i32.shl - local.set $9 + local.set $8 local.get $4 i64.const 1 i64.sub @@ -11710,39 +11693,39 @@ br $while-continue|1 end end - local.get $8 + local.get $7 local.get $3 i64.ge_u if - local.get $8 + local.get $7 local.get $3 i64.sub - local.set $8 - local.get $9 + local.set $7 + local.get $8 i32.const 1 i32.add - local.set $9 + local.set $8 end - local.get $8 + local.get $7 i64.const 0 i64.eq if i64.const -60 local.set $4 else - local.get $8 + local.get $7 i64.const 11 i64.shl i64.clz - local.set $11 + local.set $10 local.get $4 - local.get $11 + local.get $10 i64.sub local.set $4 - local.get $8 - local.get $11 + local.get $7 + local.get $10 i64.shl - local.set $8 + local.set $7 end br $do-break|0 end @@ -11752,29 +11735,29 @@ i64.const 0 i64.gt_s if - local.get $8 + local.get $7 i64.const 1 i64.const 52 i64.shl i64.sub - local.set $8 - local.get $8 + local.set $7 + local.get $7 local.get $4 i64.const 52 i64.shl i64.or - local.set $8 + local.set $7 else - local.get $8 + local.get $7 i64.const 0 local.get $4 i64.sub i64.const 1 i64.add i64.shr_u - local.set $8 + local.set $7 end - local.get $8 + local.get $7 f64.reinterpret_i64 local.set $0 local.get $1 @@ -11783,7 +11766,7 @@ local.get $0 local.get $0 f64.add - local.set $12 + local.set $11 local.get $4 local.get $5 i64.eq @@ -11796,17 +11779,17 @@ local.get $5 i64.eq if (result i32) - local.get $12 + local.get $11 local.get $1 f64.gt if (result i32) i32.const 1 else - local.get $12 + local.get $11 local.get $1 f64.eq if (result i32) - local.get $9 + local.get $8 i32.const 1 i32.and else @@ -11823,7 +11806,9 @@ f64.sub local.set $0 end - local.get $6 + local.get $2 + i64.const 0 + i64.lt_s if (result f64) local.get $0 f64.neg @@ -11848,8 +11833,7 @@ (local $6 i32) (local $7 i32) (local $8 i32) - (local $9 i32) - (local $10 f32) + (local $9 f32) local.get $0 i32.reinterpret_f32 local.set $2 @@ -11869,11 +11853,7 @@ i32.and local.set $5 local.get $2 - i32.const 31 - i32.shr_u local.set $6 - local.get $2 - local.set $7 local.get $3 i32.const 1 i32.shl @@ -11916,31 +11896,31 @@ i32.eqz if local.get $4 - local.get $7 + local.get $6 i32.const 9 i32.shl i32.clz i32.sub local.set $4 - local.get $7 + local.get $6 i32.const 1 local.get $4 i32.sub i32.shl - local.set $7 + local.set $6 else - local.get $7 + local.get $6 i32.const -1 i32.const 9 i32.shr_u i32.and - local.set $7 - local.get $7 + local.set $6 + local.get $6 i32.const 1 i32.const 23 i32.shl i32.or - local.set $7 + local.set $6 end local.get $5 i32.eqz @@ -11973,7 +11953,7 @@ local.set $3 end i32.const 0 - local.set $8 + local.set $7 block $do-break|0 loop $do-loop|0 local.get $4 @@ -11995,30 +11975,30 @@ local.get $4 local.get $5 i32.gt_s - local.set $9 - local.get $9 + local.set $8 + local.get $8 if - local.get $7 + local.get $6 local.get $3 i32.ge_u if - local.get $7 + local.get $6 local.get $3 i32.sub - local.set $7 - local.get $8 + local.set $6 + local.get $7 i32.const 1 i32.add - local.set $8 + local.set $7 end - local.get $7 + local.get $6 i32.const 1 i32.shl - local.set $7 - local.get $8 + local.set $6 + local.get $7 i32.const 1 i32.shl - local.set $8 + local.set $7 local.get $4 i32.const 1 i32.sub @@ -12026,39 +12006,39 @@ br $while-continue|1 end end - local.get $7 + local.get $6 local.get $3 i32.ge_u if - local.get $7 + local.get $6 local.get $3 i32.sub - local.set $7 - local.get $8 + local.set $6 + local.get $7 i32.const 1 i32.add - local.set $8 + local.set $7 end - local.get $7 + local.get $6 i32.const 0 i32.eq if i32.const -30 local.set $4 else - local.get $7 + local.get $6 i32.const 8 i32.shl i32.clz - local.set $9 + local.set $8 local.get $4 - local.get $9 + local.get $8 i32.sub local.set $4 - local.get $7 - local.get $9 + local.get $6 + local.get $8 i32.shl - local.set $7 + local.set $6 end br $do-break|0 end @@ -12068,29 +12048,29 @@ i32.const 0 i32.gt_s if - local.get $7 + local.get $6 i32.const 1 i32.const 23 i32.shl i32.sub - local.set $7 - local.get $7 + local.set $6 + local.get $6 local.get $4 i32.const 23 i32.shl i32.or - local.set $7 + local.set $6 else - local.get $7 + local.get $6 i32.const 0 local.get $4 i32.sub i32.const 1 i32.add i32.shr_u - local.set $7 + local.set $6 end - local.get $7 + local.get $6 f32.reinterpret_i32 local.set $0 local.get $1 @@ -12099,7 +12079,7 @@ local.get $0 local.get $0 f32.add - local.set $10 + local.set $9 local.get $4 local.get $5 i32.eq @@ -12112,17 +12092,17 @@ local.get $5 i32.eq if (result i32) - local.get $10 + local.get $9 local.get $1 f32.gt if (result i32) i32.const 1 else - local.get $10 + local.get $9 local.get $1 f32.eq if (result i32) - local.get $8 + local.get $7 i32.const 1 i32.and else @@ -12139,7 +12119,9 @@ f32.sub local.set $0 end - local.get $6 + local.get $2 + i32.const 0 + i32.lt_s if (result f32) local.get $0 f32.neg @@ -13827,11 +13809,11 @@ local.set $2 local.get $2 i32.const 1072243195 - i32.le_s + i32.le_u if local.get $2 i32.const 1044381696 - i32.lt_s + i32.lt_u if local.get $0 return @@ -13844,7 +13826,7 @@ end local.get $2 i32.const 2146435072 - i32.ge_s + i32.ge_u if local.get $0 local.get $0 @@ -15751,10 +15733,8 @@ i32.sub local.get $1 local.get $2 - i64.const 63 - i64.shr_u i64.const 0 - i64.ne + i64.lt_s select local.set $1 end diff --git a/tests/compiler/std/math.release.wat b/tests/compiler/std/math.release.wat index 2976d7d875..fc4fb58d9b 100644 --- a/tests/compiler/std/math.release.wat +++ b/tests/compiler/std/math.release.wat @@ -586,8 +586,8 @@ i32.eqz if local.get $2 - i32.const 31 - i32.shr_u + i32.const 0 + i32.lt_s if f64.const 3.141592653589793 return @@ -668,8 +668,8 @@ return end local.get $2 - i32.const 31 - i32.shr_u + i32.const 0 + i32.lt_s if f64.const 1.5707963267948966 local.get $0 @@ -819,14 +819,12 @@ i32.const 1065353216 i32.eq if - local.get $2 - i32.const 31 - i32.shr_u - if - f32.const 3.141592502593994 - return - end + f32.const 3.141592502593994 f32.const 0 + local.get $2 + i32.const 0 + i32.lt_s + select return end f32.const 0 @@ -878,8 +876,8 @@ return end local.get $2 - i32.const 31 - i32.shr_u + i32.const 0 + i32.lt_s if f32.const 1.570796251296997 local.get $0 @@ -2018,16 +2016,13 @@ f64.sub f64.sub end - local.set $0 - local.get $2 - i32.const 31 - i32.shr_u - if - local.get $0 - f64.neg - return - end + local.tee $0 + f64.neg local.get $0 + local.get $2 + i32.const 0 + i32.lt_s + select ) (func $~lib/math/NativeMathf.asin (param $0 f32) (result f32) (local $1 i32) @@ -4585,9 +4580,9 @@ local.tee $5 i64.const 32 i64.shr_u - i64.const 2147483647 - i64.and i32.wrap_i64 + i32.const 2147483647 + i32.and local.set $3 local.get $5 i64.const 63 @@ -4857,9 +4852,9 @@ local.tee $2 i64.const 52 i64.shr_u - i64.const 2047 - i64.and i32.wrap_i64 + i32.const 2047 + i32.and local.tee $1 i32.const 969 i32.sub @@ -4895,9 +4890,8 @@ f64.const 0 f64.const inf local.get $2 - i64.const 63 - i64.shr_u - i32.wrap_i64 + i64.const 0 + i64.lt_s select br $~lib/util/math/exp_lut|inlined.0 end @@ -5554,9 +5548,9 @@ local.tee $4 i64.const 52 i64.shr_u - i64.const 2047 - i64.and i32.wrap_i64 + i32.const 2047 + i32.and local.tee $3 i32.const 969 i32.sub @@ -5591,9 +5585,8 @@ drop f64.const inf local.get $4 - i64.const 63 - i64.shr_u - i64.eqz + i64.const 0 + i64.ge_s br_if $~lib/util/math/exp2_lut|inlined.0 drop f64.const 0 @@ -6126,12 +6119,13 @@ (local $3 i32) (local $4 i64) (local $5 i32) - (local $6 f64) + (local $6 i32) (local $7 f64) (local $8 f64) (local $9 f64) (local $10 f64) (local $11 f64) + (local $12 f64) block $__inlined_func$~lib/math/NativeMath.log10 (result f64) local.get $0 i64.reinterpret_f64 @@ -6142,6 +6136,7 @@ local.tee $3 i32.const 31 i32.shr_u + local.tee $6 local.get $3 i32.const 1048576 i32.lt_u @@ -6163,9 +6158,7 @@ f64.sub f64.const 0 f64.div - local.get $3 - i32.const 31 - i32.shr_u + local.get $6 br_if $__inlined_func$~lib/math/NativeMath.log10 drop i32.const -54 @@ -6218,42 +6211,42 @@ f64.reinterpret_i64 f64.const 1 f64.sub - local.tee $6 + local.tee $7 f64.const 0.5 f64.mul - local.get $6 + local.get $7 f64.mul - local.set $7 - local.get $6 - local.get $6 + local.set $8 + local.get $7 + local.get $7 f64.const 2 f64.add f64.div - local.tee $8 - local.get $8 - f64.mul local.tee $9 local.get $9 f64.mul - local.set $10 - local.get $6 - local.get $6 + local.tee $10 + local.get $10 + f64.mul + local.set $11 + local.get $7 local.get $7 + local.get $8 f64.sub i64.reinterpret_f64 i64.const -4294967296 i64.and f64.reinterpret_i64 - local.tee $11 - f64.sub - local.get $7 + local.tee $12 f64.sub local.get $8 - local.get $7 + f64.sub local.get $9 + local.get $8 local.get $10 - local.get $10 - local.get $10 + local.get $11 + local.get $11 + local.get $11 f64.const 0.14798198605116586 f64.mul f64.const 0.1818357216161805 @@ -6265,9 +6258,9 @@ f64.const 0.6666666666666735 f64.add f64.mul - local.get $10 - local.get $10 - local.get $10 + local.get $11 + local.get $11 + local.get $11 f64.const 0.15313837699209373 f64.mul f64.const 0.22222198432149784 @@ -6280,7 +6273,7 @@ f64.add f64.mul f64.add - local.set $7 + local.set $8 local.get $5 local.get $3 i32.const 20 @@ -6289,36 +6282,36 @@ i32.sub i32.add f64.convert_i32_s - local.tee $8 + local.tee $9 f64.const 0.30102999566361177 f64.mul - local.tee $9 - local.get $11 + local.tee $10 + local.get $12 f64.const 0.4342944818781689 f64.mul - local.tee $10 + local.tee $11 f64.add - local.set $6 - local.get $8 + local.set $7 + local.get $9 f64.const 3.694239077158931e-13 f64.mul - local.get $7 - local.get $11 + local.get $8 + local.get $12 f64.add f64.const 2.5082946711645275e-11 f64.mul f64.add - local.get $7 + local.get $8 f64.const 0.4342944818781689 f64.mul f64.add - local.get $9 - local.get $6 - f64.sub local.get $10 + local.get $7 + f64.sub + local.get $11 f64.add f64.add - local.get $6 + local.get $7 f64.add end local.get $1 @@ -6338,16 +6331,18 @@ (local $3 i32) (local $4 f32) (local $5 i32) - (local $6 f32) + (local $6 i32) (local $7 f32) (local $8 f32) (local $9 f32) + (local $10 f32) block $__inlined_func$~lib/math/NativeMathf.log10 (result f32) local.get $0 i32.reinterpret_f32 local.tee $3 i32.const 31 i32.shr_u + local.tee $5 local.get $3 i32.const 8388608 i32.lt_u @@ -6369,13 +6364,11 @@ f32.sub f32.const 0 f32.div - local.get $3 - i32.const 31 - i32.shr_u + local.get $5 br_if $__inlined_func$~lib/math/NativeMathf.log10 drop i32.const -25 - local.set $5 + local.set $6 local.get $0 f32.const 33554432 f32.mul @@ -6408,8 +6401,8 @@ f32.reinterpret_i32 f32.const 1 f32.sub - local.tee $7 - local.get $7 + local.tee $8 + local.get $8 f32.const 2 f32.add f32.div @@ -6419,8 +6412,8 @@ local.tee $4 local.get $4 f32.mul - local.set $8 - local.get $5 + local.set $9 + local.get $6 local.get $3 i32.const 23 i32.shr_u @@ -6428,37 +6421,37 @@ i32.sub i32.add f32.convert_i32_s - local.tee $6 + local.tee $7 f32.const 7.903415166765626e-07 f32.mul - local.get $7 - local.get $7 - local.get $7 + local.get $8 + local.get $8 + local.get $8 f32.const 0.5 f32.mul - local.get $7 + local.get $8 f32.mul - local.tee $7 + local.tee $8 f32.sub i32.reinterpret_f32 i32.const -4096 i32.and f32.reinterpret_i32 - local.tee $9 + local.tee $10 f32.sub - local.get $7 + local.get $8 f32.sub local.get $0 - local.get $7 - local.get $4 local.get $8 + local.get $4 + local.get $9 f32.const 0.2849878668785095 f32.mul f32.const 0.6666666269302368 f32.add f32.mul - local.get $8 - local.get $8 + local.get $9 + local.get $9 f32.const 0.24279078841209412 f32.mul f32.const 0.40000972151756287 @@ -6469,7 +6462,7 @@ f32.mul f32.add local.tee $0 - local.get $9 + local.get $10 f32.add f32.const -3.168997136526741e-05 f32.mul @@ -6478,11 +6471,11 @@ f32.const 0.434326171875 f32.mul f32.add - local.get $9 + local.get $10 f32.const 0.434326171875 f32.mul f32.add - local.get $6 + local.get $7 f32.const 0.3010292053222656 f32.mul f32.add @@ -7541,16 +7534,14 @@ f64.div local.get $0 local.get $12 - i64.const 63 - i64.shr_u - i32.wrap_i64 + i64.const 0 + i64.lt_s select br $~lib/util/math/pow_lut|inlined.0 end local.get $2 - i64.const 63 - i64.shr_u - i32.wrap_i64 + i64.const 0 + i64.lt_s if block $~lib/util/math/checkint|inlined.1 (result i32) i32.const 0 @@ -7839,9 +7830,8 @@ br_if $~lib/util/math/exp_inline|inlined.0 drop local.get $2 - i64.const 63 - i64.shr_u - i32.wrap_i64 + i64.const 0 + i64.lt_s if (result f64) f64.const -1.2882297539194267e-231 f64.const 1.2882297539194267e-231 @@ -8257,14 +8247,14 @@ f32.div local.get $0 local.get $7 - i32.const 31 - i32.shr_u + i32.const 0 + i32.lt_s select br $~lib/util/math/powf_lut|inlined.0 end local.get $2 - i32.const 31 - i32.shr_u + i32.const 0 + i32.lt_s if block $~lib/util/math/checkintf|inlined.1 (result i32) i32.const 0 @@ -8682,7 +8672,7 @@ (local $3 i64) (local $4 i64) (local $5 i32) - (local $6 i32) + (local $6 i64) (local $7 i64) (local $8 f64) local.get $1 @@ -8699,7 +8689,7 @@ i64.eqz local.get $0 i64.reinterpret_f64 - local.tee $2 + local.tee $6 i64.const 52 i64.shr_u i64.const 2047 @@ -8721,7 +8711,7 @@ f64.div return end - local.get $2 + local.get $6 i64.const 1 i64.shl i64.eqz @@ -8729,18 +8719,13 @@ local.get $0 return end - local.get $2 - i64.const 63 - i64.shr_u - i32.wrap_i64 - local.set $6 local.get $3 i64.eqz if (result i64) - local.get $2 + local.get $6 i64.const 1 local.get $3 - local.get $2 + local.get $6 i64.const 12 i64.shl i64.clz @@ -8749,7 +8734,7 @@ i64.sub i64.shl else - local.get $2 + local.get $6 i64.const 4503599627370495 i64.and i64.const 4503599627370496 @@ -8914,6 +8899,8 @@ f64.neg local.get $0 local.get $6 + i64.const 0 + i64.lt_s select ) (func $~lib/math/NativeMathf.rem (param $0 f32) (param $1 f32) (result f32) @@ -8938,7 +8925,7 @@ f32.ne local.get $0 i32.reinterpret_f32 - local.tee $2 + local.tee $6 i32.const 23 i32.shr_u i32.const 255 @@ -8961,7 +8948,7 @@ f32.div return end - local.get $2 + local.get $6 i32.const 1 i32.shl i32.eqz @@ -8969,22 +8956,18 @@ local.get $0 return end - local.get $2 - i32.const 31 - i32.shr_u - local.set $6 local.get $3 if (result i32) - local.get $2 + local.get $6 i32.const 8388607 i32.and i32.const 8388608 i32.or else - local.get $2 + local.get $6 i32.const 1 local.get $3 - local.get $2 + local.get $6 i32.const 9 i32.shl i32.clz @@ -9150,6 +9133,8 @@ f32.neg local.get $0 local.get $6 + i32.const 0 + i32.lt_s select ) (func $~lib/math/NativeMath.sin (param $0 f64) (result f64) @@ -11686,9 +11671,8 @@ i32.sub local.get $2 local.get $3 - i64.const 63 - i64.shr_u - i32.wrap_i64 + i64.const 0 + i64.lt_s select else i32.const 0 @@ -11729,9 +11713,8 @@ i32.sub local.get $2 local.get $3 - i64.const 63 - i64.shr_u - i32.wrap_i64 + i64.const 0 + i64.lt_s select else i32.const 0