From b1680f7b2053fa2a1dcbdd2b1445390a2f534d49 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 26 Oct 2020 18:19:48 +0200 Subject: [PATCH 1/4] slightly optimize Math.mod --- std/assembly/math.ts | 16 +- tests/compiler/binary.untouched.wat | 22 +- tests/compiler/std/math.optimized.wat | 480 ++++++++++---------- tests/compiler/std/math.untouched.wat | 22 +- tests/compiler/std/mod.optimized.wat | 480 ++++++++++---------- tests/compiler/std/mod.untouched.wat | 22 +- tests/compiler/std/typedarray.optimized.wat | 394 ++++++++-------- tests/compiler/std/typedarray.untouched.wat | 22 +- 8 files changed, 733 insertions(+), 725 deletions(-) diff --git a/std/assembly/math.ts b/std/assembly/math.ts index ffc20132b8..4b37306fe9 100644 --- a/std/assembly/math.ts +++ b/std/assembly/math.ts @@ -1575,7 +1575,7 @@ export namespace NativeMath { var uy = reinterpret(y); var ex = (ux >> 52 & 0x7FF); var ey = (uy >> 52 & 0x7FF); - var sx = ux >> 63; + var sm = ux & 0x8000000000000000; var uy1 = uy << 1; if (uy1 == 0 || ex == 0x7FF || isNaN(y)) { let m = x * y; @@ -1583,8 +1583,7 @@ export namespace NativeMath { } var ux1 = ux << 1; if (ux1 <= uy1) { - if (ux1 == uy1) return 0 * x; - return x; + return ux1 == uy1 ? 0 * x : x; } if (!ex) { ex -= builtin_clz(ux << 12); @@ -1622,8 +1621,7 @@ export namespace NativeMath { } else { ux >>= -ex + 1; } - ux |= sx << 63; - return reinterpret(ux); + return reinterpret(ux | sm); } export function rem(x: f64, y: f64): f64 { // see: musl/src/math/remquo.c @@ -2884,7 +2882,7 @@ export namespace NativeMathf { var uy = reinterpret(y); var ex = (ux >> 23 & 0xFF); var ey = (uy >> 23 & 0xFF); - var sx = ux & 0x80000000; + var sm = ux & 0x80000000; var uy1 = uy << 1; if (uy1 == 0 || ex == 0xFF || isNaN(y)) { let m = x * y; @@ -2892,8 +2890,7 @@ export namespace NativeMathf { } var ux1 = ux << 1; if (ux1 <= uy1) { - if (ux1 == uy1) return 0 * x; - return x; + return ux1 == uy1 ? 0 * x : x; } if (!ex) { ex -= builtin_clz(ux << 9); @@ -2931,8 +2928,7 @@ export namespace NativeMathf { } else { ux >>= -ex + 1; } - ux |= sx; - return reinterpret(ux); + return reinterpret(ux | sm); } export function rem(x: f32, y: f32): f32 { // see: musl/src/math/remquof.c diff --git a/tests/compiler/binary.untouched.wat b/tests/compiler/binary.untouched.wat index a7a522d0ef..7a32ac7e7d 100644 --- a/tests/compiler/binary.untouched.wat +++ b/tests/compiler/binary.untouched.wat @@ -1291,13 +1291,13 @@ local.get $9 local.get $7 i32.eq - if + if (result f32) f32.const 0 local.get $0 f32.mul - return + else + local.get $0 end - local.get $0 return end local.get $4 @@ -1460,8 +1460,6 @@ local.get $2 local.get $6 i32.or - local.set $2 - local.get $2 f32.reinterpret_i32 ) (func $~lib/math/NativeMathf.pow (param $0 f32) (param $1 f32) (result f32) @@ -2121,8 +2119,8 @@ i64.and local.set $5 local.get $2 - i64.const 63 - i64.shr_u + i64.const -9223372036854775808 + i64.and local.set $6 local.get $3 i64.const 1 @@ -2166,13 +2164,13 @@ local.get $9 local.get $7 i64.eq - if + if (result f64) f64.const 0 local.get $0 f64.mul - return + else + local.get $0 end - local.get $0 return end local.get $4 @@ -2338,11 +2336,7 @@ end local.get $2 local.get $6 - i64.const 63 - i64.shl i64.or - local.set $2 - local.get $2 f64.reinterpret_i64 ) (func $start:binary diff --git a/tests/compiler/std/math.optimized.wat b/tests/compiler/std/math.optimized.wat index 0be7bd82f2..8449ad1b56 100644 --- a/tests/compiler/std/math.optimized.wat +++ b/tests/compiler/std/math.optimized.wat @@ -6487,8 +6487,8 @@ local.get $0 i64.reinterpret_f64 local.tee $2 - i64.const 63 - i64.shr_u + i64.const -9223372036854775808 + i64.and local.set $7 i32.const 1 local.get $1 @@ -6519,146 +6519,151 @@ f64.div return end - block $folding-inner0 + local.get $2 + i64.const 1 + i64.shl + local.tee $8 + local.get $6 + i64.le_u + if + local.get $0 + f64.const 0 + f64.mul + local.get $0 + local.get $6 + local.get $8 + i64.eq + select + return + end + local.get $4 + i64.eqz + if (result i64) local.get $2 i64.const 1 + local.get $4 + local.get $2 + i64.const 12 i64.shl - local.tee $8 - local.get $6 - i64.le_u - if - local.get $6 - local.get $8 - i64.eq - br_if $folding-inner0 - local.get $0 - return - end + i64.clz + i64.sub + local.tee $4 + i64.sub + i64.shl + else + local.get $2 + i64.const 4503599627370495 + i64.and + i64.const 4503599627370496 + i64.or + end + local.set $2 + local.get $5 + i64.eqz + if (result i64) + local.get $3 + i64.const 1 + local.get $5 + local.get $3 + i64.const 12 + i64.shl + i64.clz + i64.sub + local.tee $5 + i64.sub + i64.shl + else + local.get $3 + i64.const 4503599627370495 + i64.and + i64.const 4503599627370496 + i64.or + end + local.set $3 + loop $while-continue|0 local.get $4 - i64.eqz - if (result i64) - local.get $2 - i64.const 1 - local.get $4 - local.get $2 - i64.const 12 - i64.shl - i64.clz - i64.sub - local.tee $4 - i64.sub - i64.shl - else - local.get $2 - i64.const 4503599627370495 - i64.and - i64.const 4503599627370496 - i64.or - end - local.set $2 local.get $5 - i64.eqz - if (result i64) - local.get $3 - i64.const 1 - local.get $5 - local.get $3 - i64.const 12 - i64.shl - i64.clz - i64.sub - local.tee $5 - i64.sub - i64.shl - else + i64.gt_s + if + local.get $2 local.get $3 - i64.const 4503599627370495 - i64.and - i64.const 4503599627370496 - i64.or - end - local.set $3 - loop $while-continue|0 - local.get $4 - local.get $5 - i64.gt_s - if + i64.ge_u + if (result i64) local.get $2 local.get $3 - i64.ge_u - if (result i64) - local.get $2 - local.get $3 - i64.eq - br_if $folding-inner0 - local.get $2 - local.get $3 - i64.sub - else - local.get $2 + i64.eq + if + local.get $0 + f64.const 0 + f64.mul + return end - i64.const 1 - i64.shl - local.set $2 - local.get $4 - i64.const 1 + local.get $2 + local.get $3 i64.sub - local.set $4 - br $while-continue|0 + else + local.get $2 end + i64.const 1 + i64.shl + local.set $2 + local.get $4 + i64.const 1 + i64.sub + local.set $4 + br $while-continue|0 end + end + local.get $2 + local.get $3 + i64.ge_u + if local.get $2 local.get $3 - i64.ge_u + i64.eq if - local.get $2 - local.get $3 - i64.eq - br_if $folding-inner0 - local.get $2 - local.get $3 - i64.sub - local.set $2 + local.get $0 + f64.const 0 + f64.mul + return end local.get $2 - local.get $2 - i64.const 11 - i64.shl - i64.clz - local.tee $3 - i64.shl - local.set $2 - local.get $4 local.get $3 i64.sub - local.tee $4 - i64.const 0 - i64.gt_s - if (result i64) - local.get $2 - i64.const 4503599627370496 - i64.sub - local.get $4 - i64.const 52 - i64.shl - i64.or - else - local.get $2 - i64.const 1 - local.get $4 - i64.sub - i64.shr_u - end - local.get $7 - i64.const 63 + local.set $2 + end + local.get $2 + local.get $2 + i64.const 11 + i64.shl + i64.clz + local.tee $3 + i64.shl + local.set $2 + local.get $4 + local.get $3 + i64.sub + local.tee $4 + i64.const 0 + i64.gt_s + if (result i64) + local.get $2 + i64.const 4503599627370496 + i64.sub + local.get $4 + i64.const 52 i64.shl i64.or - f64.reinterpret_i64 - return + else + local.get $2 + i64.const 1 + local.get $4 + i64.sub + i64.shr_u end - local.get $0 - f64.const 0 - f64.mul + local.get $7 + i64.or + f64.reinterpret_i64 ) (func $std/math/test_mod (param $0 f64) (param $1 f64) (param $2 f64) (result i32) local.get $0 @@ -6741,142 +6746,149 @@ f32.div return end - block $folding-inner0 + local.get $2 + i32.const 1 + i32.shl + local.tee $8 + local.get $6 + i32.le_u + if + local.get $0 + f32.const 0 + f32.mul + local.get $0 + local.get $6 + local.get $8 + i32.eq + select + return + end + local.get $4 + if (result i32) + local.get $2 + i32.const 8388607 + i32.and + i32.const 8388608 + i32.or + else local.get $2 i32.const 1 + local.get $4 + local.get $2 + i32.const 9 i32.shl - local.tee $8 - local.get $6 - i32.le_u - if - local.get $6 - local.get $8 - i32.eq - br_if $folding-inner0 - local.get $0 - return - end + i32.clz + i32.sub + local.tee $4 + i32.sub + i32.shl + end + local.set $2 + local.get $5 + if (result i32) + local.get $3 + i32.const 8388607 + i32.and + i32.const 8388608 + i32.or + else + local.get $3 + i32.const 1 + local.get $5 + local.get $3 + i32.const 9 + i32.shl + i32.clz + i32.sub + local.tee $5 + i32.sub + i32.shl + end + local.set $3 + loop $while-continue|0 local.get $4 - if (result i32) - local.get $2 - i32.const 8388607 - i32.and - i32.const 8388608 - i32.or - else - local.get $2 - i32.const 1 - local.get $4 - local.get $2 - i32.const 9 - i32.shl - i32.clz - i32.sub - local.tee $4 - i32.sub - i32.shl - end - local.set $2 local.get $5 - if (result i32) - local.get $3 - i32.const 8388607 - i32.and - i32.const 8388608 - i32.or - else - local.get $3 - i32.const 1 - local.get $5 + i32.gt_s + if + local.get $2 local.get $3 - i32.const 9 - i32.shl - i32.clz - i32.sub - local.tee $5 - i32.sub - i32.shl - end - local.set $3 - loop $while-continue|0 - local.get $4 - local.get $5 - i32.gt_s - if + i32.ge_u + if (result i32) local.get $2 local.get $3 - i32.ge_u - if (result i32) - local.get $2 - local.get $3 - i32.eq - br_if $folding-inner0 - local.get $2 - local.get $3 - i32.sub - else - local.get $2 + i32.eq + if + local.get $0 + f32.const 0 + f32.mul + return end - i32.const 1 - i32.shl - local.set $2 - local.get $4 - i32.const 1 + local.get $2 + local.get $3 i32.sub - local.set $4 - br $while-continue|0 + else + local.get $2 end + i32.const 1 + i32.shl + local.set $2 + local.get $4 + i32.const 1 + i32.sub + local.set $4 + br $while-continue|0 end + end + local.get $2 + local.get $3 + i32.ge_u + if local.get $2 local.get $3 - i32.ge_u + i32.eq if - local.get $2 - local.get $3 - i32.eq - br_if $folding-inner0 - local.get $2 - local.get $3 - i32.sub - local.set $2 + local.get $0 + f32.const 0 + f32.mul + return end local.get $2 + local.get $3 + i32.sub + local.set $2 + end + local.get $2 + local.get $2 + i32.const 8 + i32.shl + i32.clz + local.tee $3 + i32.shl + local.set $2 + local.get $4 + local.get $3 + i32.sub + local.tee $4 + i32.const 0 + i32.gt_s + if (result i32) local.get $2 - i32.const 8 - i32.shl - i32.clz - local.tee $3 + i32.const 8388608 + i32.sub + local.get $4 + i32.const 23 i32.shl - local.set $2 + i32.or + else + local.get $2 + i32.const 1 local.get $4 - local.get $3 i32.sub - local.tee $4 - i32.const 0 - i32.gt_s - if (result i32) - local.get $2 - i32.const 8388608 - i32.sub - local.get $4 - i32.const 23 - i32.shl - i32.or - else - local.get $2 - i32.const 1 - local.get $4 - i32.sub - i32.shr_u - end - local.get $7 - i32.or - f32.reinterpret_i32 - return + i32.shr_u end - local.get $0 - f32.const 0 - f32.mul + local.get $7 + i32.or + f32.reinterpret_i32 ) (func $~lib/math/NativeMath.pow (param $0 f64) (param $1 f64) (result f64) (local $2 f64) diff --git a/tests/compiler/std/math.untouched.wat b/tests/compiler/std/math.untouched.wat index 22a4c8bbc2..5a4750e43c 100644 --- a/tests/compiler/std/math.untouched.wat +++ b/tests/compiler/std/math.untouched.wat @@ -9185,8 +9185,8 @@ i64.and local.set $5 local.get $2 - i64.const 63 - i64.shr_u + i64.const -9223372036854775808 + i64.and local.set $6 local.get $3 i64.const 1 @@ -9230,13 +9230,13 @@ local.get $9 local.get $7 i64.eq - if + if (result f64) f64.const 0 local.get $0 f64.mul - return + else + local.get $0 end - local.get $0 return end local.get $4 @@ -9402,11 +9402,7 @@ end local.get $2 local.get $6 - i64.const 63 - i64.shl i64.or - local.set $2 - local.get $2 f64.reinterpret_i64 ) (func $std/math/test_mod (param $0 f64) (param $1 f64) (param $2 f64) (param $3 f64) (param $4 i32) (result i32) @@ -9523,13 +9519,13 @@ local.get $9 local.get $7 i32.eq - if + if (result f32) f32.const 0 local.get $0 f32.mul - return + else + local.get $0 end - local.get $0 return end local.get $4 @@ -9692,8 +9688,6 @@ local.get $2 local.get $6 i32.or - local.set $2 - local.get $2 f32.reinterpret_i32 ) (func $std/math/test_modf (param $0 f32) (param $1 f32) (param $2 f32) (param $3 f32) (param $4 i32) (result i32) diff --git a/tests/compiler/std/mod.optimized.wat b/tests/compiler/std/mod.optimized.wat index bb2ae1418a..c5df7a91f2 100644 --- a/tests/compiler/std/mod.optimized.wat +++ b/tests/compiler/std/mod.optimized.wat @@ -45,8 +45,8 @@ local.get $0 i64.reinterpret_f64 local.tee $2 - i64.const 63 - i64.shr_u + i64.const -9223372036854775808 + i64.and local.set $7 i32.const 1 local.get $1 @@ -77,146 +77,151 @@ f64.div return end - block $folding-inner0 + local.get $2 + i64.const 1 + i64.shl + local.tee $8 + local.get $6 + i64.le_u + if + local.get $0 + f64.const 0 + f64.mul + local.get $0 + local.get $6 + local.get $8 + i64.eq + select + return + end + local.get $4 + i64.eqz + if (result i64) local.get $2 i64.const 1 + local.get $4 + local.get $2 + i64.const 12 i64.shl - local.tee $8 - local.get $6 - i64.le_u - if - local.get $6 - local.get $8 - i64.eq - br_if $folding-inner0 - local.get $0 - return - end + i64.clz + i64.sub + local.tee $4 + i64.sub + i64.shl + else + local.get $2 + i64.const 4503599627370495 + i64.and + i64.const 4503599627370496 + i64.or + end + local.set $2 + local.get $5 + i64.eqz + if (result i64) + local.get $3 + i64.const 1 + local.get $5 + local.get $3 + i64.const 12 + i64.shl + i64.clz + i64.sub + local.tee $5 + i64.sub + i64.shl + else + local.get $3 + i64.const 4503599627370495 + i64.and + i64.const 4503599627370496 + i64.or + end + local.set $3 + loop $while-continue|0 local.get $4 - i64.eqz - if (result i64) - local.get $2 - i64.const 1 - local.get $4 - local.get $2 - i64.const 12 - i64.shl - i64.clz - i64.sub - local.tee $4 - i64.sub - i64.shl - else - local.get $2 - i64.const 4503599627370495 - i64.and - i64.const 4503599627370496 - i64.or - end - local.set $2 local.get $5 - i64.eqz - if (result i64) - local.get $3 - i64.const 1 - local.get $5 - local.get $3 - i64.const 12 - i64.shl - i64.clz - i64.sub - local.tee $5 - i64.sub - i64.shl - else + i64.gt_s + if + local.get $2 local.get $3 - i64.const 4503599627370495 - i64.and - i64.const 4503599627370496 - i64.or - end - local.set $3 - loop $while-continue|0 - local.get $4 - local.get $5 - i64.gt_s - if + i64.ge_u + if (result i64) local.get $2 local.get $3 - i64.ge_u - if (result i64) - local.get $2 - local.get $3 - i64.eq - br_if $folding-inner0 - local.get $2 - local.get $3 - i64.sub - else - local.get $2 + i64.eq + if + local.get $0 + f64.const 0 + f64.mul + return end - i64.const 1 - i64.shl - local.set $2 - local.get $4 - i64.const 1 + local.get $2 + local.get $3 i64.sub - local.set $4 - br $while-continue|0 + else + local.get $2 end + i64.const 1 + i64.shl + local.set $2 + local.get $4 + i64.const 1 + i64.sub + local.set $4 + br $while-continue|0 end + end + local.get $2 + local.get $3 + i64.ge_u + if local.get $2 local.get $3 - i64.ge_u + i64.eq if - local.get $2 - local.get $3 - i64.eq - br_if $folding-inner0 - local.get $2 - local.get $3 - i64.sub - local.set $2 + local.get $0 + f64.const 0 + f64.mul + return end local.get $2 - local.get $2 - i64.const 11 - i64.shl - i64.clz - local.tee $3 - i64.shl - local.set $2 - local.get $4 local.get $3 i64.sub - local.tee $4 - i64.const 0 - i64.gt_s - if (result i64) - local.get $2 - i64.const 4503599627370496 - i64.sub - local.get $4 - i64.const 52 - i64.shl - i64.or - else - local.get $2 - i64.const 1 - local.get $4 - i64.sub - i64.shr_u - end - local.get $7 - i64.const 63 + local.set $2 + end + local.get $2 + local.get $2 + i64.const 11 + i64.shl + i64.clz + local.tee $3 + i64.shl + local.set $2 + local.get $4 + local.get $3 + i64.sub + local.tee $4 + i64.const 0 + i64.gt_s + if (result i64) + local.get $2 + i64.const 4503599627370496 + i64.sub + local.get $4 + i64.const 52 i64.shl i64.or - f64.reinterpret_i64 - return + else + local.get $2 + i64.const 1 + local.get $4 + i64.sub + i64.shr_u end - local.get $0 - f64.const 0 - f64.mul + local.get $7 + i64.or + f64.reinterpret_i64 ) (func $std/mod/check (param $0 f64) (param $1 f64) (result i32) local.get $1 @@ -324,142 +329,149 @@ f32.div return end - block $folding-inner0 + local.get $2 + i32.const 1 + i32.shl + local.tee $8 + local.get $6 + i32.le_u + if + local.get $0 + f32.const 0 + f32.mul + local.get $0 + local.get $6 + local.get $8 + i32.eq + select + return + end + local.get $4 + if (result i32) + local.get $2 + i32.const 8388607 + i32.and + i32.const 8388608 + i32.or + else local.get $2 i32.const 1 + local.get $4 + local.get $2 + i32.const 9 i32.shl - local.tee $8 - local.get $6 - i32.le_u - if - local.get $6 - local.get $8 - i32.eq - br_if $folding-inner0 - local.get $0 - return - end + i32.clz + i32.sub + local.tee $4 + i32.sub + i32.shl + end + local.set $2 + local.get $5 + if (result i32) + local.get $3 + i32.const 8388607 + i32.and + i32.const 8388608 + i32.or + else + local.get $3 + i32.const 1 + local.get $5 + local.get $3 + i32.const 9 + i32.shl + i32.clz + i32.sub + local.tee $5 + i32.sub + i32.shl + end + local.set $3 + loop $while-continue|0 local.get $4 - if (result i32) - local.get $2 - i32.const 8388607 - i32.and - i32.const 8388608 - i32.or - else - local.get $2 - i32.const 1 - local.get $4 - local.get $2 - i32.const 9 - i32.shl - i32.clz - i32.sub - local.tee $4 - i32.sub - i32.shl - end - local.set $2 local.get $5 - if (result i32) - local.get $3 - i32.const 8388607 - i32.and - i32.const 8388608 - i32.or - else - local.get $3 - i32.const 1 - local.get $5 + i32.gt_s + if + local.get $2 local.get $3 - i32.const 9 - i32.shl - i32.clz - i32.sub - local.tee $5 - i32.sub - i32.shl - end - local.set $3 - loop $while-continue|0 - local.get $4 - local.get $5 - i32.gt_s - if + i32.ge_u + if (result i32) local.get $2 local.get $3 - i32.ge_u - if (result i32) - local.get $2 - local.get $3 - i32.eq - br_if $folding-inner0 - local.get $2 - local.get $3 - i32.sub - else - local.get $2 + i32.eq + if + local.get $0 + f32.const 0 + f32.mul + return end - i32.const 1 - i32.shl - local.set $2 - local.get $4 - i32.const 1 + local.get $2 + local.get $3 i32.sub - local.set $4 - br $while-continue|0 + else + local.get $2 end + i32.const 1 + i32.shl + local.set $2 + local.get $4 + i32.const 1 + i32.sub + local.set $4 + br $while-continue|0 end + end + local.get $2 + local.get $3 + i32.ge_u + if local.get $2 local.get $3 - i32.ge_u + i32.eq if - local.get $2 - local.get $3 - i32.eq - br_if $folding-inner0 - local.get $2 - local.get $3 - i32.sub - local.set $2 + local.get $0 + f32.const 0 + f32.mul + return end local.get $2 + local.get $3 + i32.sub + local.set $2 + end + local.get $2 + local.get $2 + i32.const 8 + i32.shl + i32.clz + local.tee $3 + i32.shl + local.set $2 + local.get $4 + local.get $3 + i32.sub + local.tee $4 + i32.const 0 + i32.gt_s + if (result i32) local.get $2 - i32.const 8 - i32.shl - i32.clz - local.tee $3 + i32.const 8388608 + i32.sub + local.get $4 + i32.const 23 i32.shl - local.set $2 + i32.or + else + local.get $2 + i32.const 1 local.get $4 - local.get $3 i32.sub - local.tee $4 - i32.const 0 - i32.gt_s - if (result i32) - local.get $2 - i32.const 8388608 - i32.sub - local.get $4 - i32.const 23 - i32.shl - i32.or - else - local.get $2 - i32.const 1 - local.get $4 - i32.sub - i32.shr_u - end - local.get $7 - i32.or - f32.reinterpret_i32 - return + i32.shr_u end - local.get $0 - f32.const 0 - f32.mul + local.get $7 + i32.or + f32.reinterpret_i32 ) (func $std/mod/test_fmodf (param $0 f32) (param $1 f32) (param $2 f32) (result i32) block $__inlined_func$std/mod/check (result i32) diff --git a/tests/compiler/std/mod.untouched.wat b/tests/compiler/std/mod.untouched.wat index 3edcfeadf3..5790978826 100644 --- a/tests/compiler/std/mod.untouched.wat +++ b/tests/compiler/std/mod.untouched.wat @@ -59,8 +59,8 @@ i64.and local.set $5 local.get $2 - i64.const 63 - i64.shr_u + i64.const -9223372036854775808 + i64.and local.set $6 local.get $3 i64.const 1 @@ -104,13 +104,13 @@ local.get $9 local.get $7 i64.eq - if + if (result f64) f64.const 0 local.get $0 f64.mul - return + else + local.get $0 end - local.get $0 return end local.get $4 @@ -276,11 +276,7 @@ end local.get $2 local.get $6 - i64.const 63 - i64.shl i64.or - local.set $2 - local.get $2 f64.reinterpret_i64 ) (func $std/mod/check (param $0 f64) (param $1 f64) (result i32) @@ -421,13 +417,13 @@ local.get $9 local.get $7 i32.eq - if + if (result f32) f32.const 0 local.get $0 f32.mul - return + else + local.get $0 end - local.get $0 return end local.get $4 @@ -590,8 +586,6 @@ local.get $2 local.get $6 i32.or - local.set $2 - local.get $2 f32.reinterpret_i32 ) (func $std/mod/check (param $0 f32) (param $1 f32) (result i32) diff --git a/tests/compiler/std/typedarray.optimized.wat b/tests/compiler/std/typedarray.optimized.wat index 2b7d584dfd..899b03046d 100644 --- a/tests/compiler/std/typedarray.optimized.wat +++ b/tests/compiler/std/typedarray.optimized.wat @@ -9616,121 +9616,128 @@ f32.div return end - block $folding-inner0 + local.get $1 + i32.const 1 + i32.shl + local.tee $3 + i32.const -2147483648 + i32.le_u + if + local.get $0 + f32.const 0 + f32.mul + local.get $0 + local.get $3 + i32.const -2147483648 + i32.eq + select + return + end + local.get $2 + if (result i32) + local.get $1 + i32.const 8388607 + i32.and + i32.const 8388608 + i32.or + else local.get $1 i32.const 1 + local.get $2 + local.get $1 + i32.const 9 i32.shl - local.tee $3 - i32.const -2147483648 - i32.le_u - if - local.get $3 - i32.const -2147483648 - i32.eq - br_if $folding-inner0 - local.get $0 - return - end + i32.clz + i32.sub + local.tee $2 + i32.sub + i32.shl + end + local.set $1 + loop $while-continue|0 local.get $2 - if (result i32) + i32.const 128 + i32.gt_s + if local.get $1 - i32.const 8388607 - i32.and i32.const 8388608 - i32.or - else - local.get $1 - i32.const 1 - local.get $2 - local.get $1 - i32.const 9 - i32.shl - i32.clz - i32.sub - local.tee $2 - i32.sub - i32.shl - end - local.set $1 - loop $while-continue|0 - local.get $2 - i32.const 128 - i32.gt_s - if + i32.ge_u + if (result i32) local.get $1 i32.const 8388608 - i32.ge_u - if (result i32) - local.get $1 - i32.const 8388608 - i32.eq - br_if $folding-inner0 - local.get $1 - i32.const 8388608 - i32.sub - else - local.get $1 + i32.eq + if + local.get $0 + f32.const 0 + f32.mul + return end - i32.const 1 - i32.shl - local.set $1 - local.get $2 - i32.const 1 + local.get $1 + i32.const 8388608 i32.sub - local.set $2 - br $while-continue|0 + else + local.get $1 end + i32.const 1 + i32.shl + local.set $1 + local.get $2 + i32.const 1 + i32.sub + local.set $2 + br $while-continue|0 end + end + local.get $1 + i32.const 8388608 + i32.ge_u + if local.get $1 i32.const 8388608 - i32.ge_u + i32.eq if - local.get $1 - i32.const 8388608 - i32.eq - br_if $folding-inner0 - local.get $1 - i32.const 8388608 - i32.sub - local.set $1 + local.get $0 + f32.const 0 + f32.mul + return end local.get $1 + i32.const 8388608 + i32.sub + local.set $1 + end + local.get $1 + local.get $1 + i32.const 8 + i32.shl + i32.clz + local.tee $3 + i32.shl + local.set $1 + local.get $2 + local.get $3 + i32.sub + local.tee $2 + i32.const 0 + i32.gt_s + if (result i32) local.get $1 - i32.const 8 - i32.shl - i32.clz - local.tee $3 + i32.const 8388608 + i32.sub + local.get $2 + i32.const 23 i32.shl - local.set $1 + i32.or + else + local.get $1 + i32.const 1 local.get $2 - local.get $3 i32.sub - local.tee $2 - i32.const 0 - i32.gt_s - if (result i32) - local.get $1 - i32.const 8388608 - i32.sub - local.get $2 - i32.const 23 - i32.shl - i32.or - else - local.get $1 - i32.const 1 - local.get $2 - i32.sub - i32.shr_u - end - local.get $4 - i32.or - f32.reinterpret_i32 - return + i32.shr_u end - local.get $0 - f32.const 0 - f32.mul + local.get $4 + i32.or + f32.reinterpret_i32 ) (func $std/typedarray/testArrayEvery<~lib/typedarray/Float32Array,f32>~anonymous|0 (param $0 f32) (param $1 i32) (param $2 i32) (result i32) local.get $2 @@ -9818,8 +9825,8 @@ local.get $0 i64.reinterpret_f64 local.tee $1 - i64.const 63 - i64.shr_u + i64.const -9223372036854775808 + i64.and local.set $4 local.get $1 i64.const 52 @@ -9838,124 +9845,129 @@ f64.div return end - block $folding-inner0 + local.get $1 + i64.const 1 + i64.shl + local.tee $3 + i64.const -9223372036854775808 + i64.le_u + if + local.get $0 + f64.const 0 + f64.mul + local.get $0 + local.get $3 + i64.const -9223372036854775808 + i64.eq + select + return + end + local.get $2 + i64.eqz + if (result i64) local.get $1 i64.const 1 + local.get $2 + local.get $1 + i64.const 12 i64.shl - local.tee $3 - i64.const -9223372036854775808 - i64.le_u - if - local.get $3 - i64.const -9223372036854775808 - i64.eq - br_if $folding-inner0 - local.get $0 - return - end + i64.clz + i64.sub + local.tee $2 + i64.sub + i64.shl + else + local.get $1 + i64.const 4503599627370495 + i64.and + i64.const 4503599627370496 + i64.or + end + local.set $1 + loop $while-continue|0 local.get $2 - i64.eqz - if (result i64) - local.get $1 - i64.const 1 - local.get $2 - local.get $1 - i64.const 12 - i64.shl - i64.clz - i64.sub - local.tee $2 - i64.sub - i64.shl - else + i64.const 1024 + i64.gt_s + if local.get $1 - i64.const 4503599627370495 - i64.and i64.const 4503599627370496 - i64.or - end - local.set $1 - loop $while-continue|0 - local.get $2 - i64.const 1024 - i64.gt_s - if + i64.ge_u + if (result i64) local.get $1 i64.const 4503599627370496 - i64.ge_u - if (result i64) - local.get $1 - i64.const 4503599627370496 - i64.eq - br_if $folding-inner0 - local.get $1 - i64.const 4503599627370496 - i64.sub - else - local.get $1 + i64.eq + if + local.get $0 + f64.const 0 + f64.mul + return end - i64.const 1 - i64.shl - local.set $1 - local.get $2 - i64.const 1 + local.get $1 + i64.const 4503599627370496 i64.sub - local.set $2 - br $while-continue|0 + else + local.get $1 end + i64.const 1 + i64.shl + local.set $1 + local.get $2 + i64.const 1 + i64.sub + local.set $2 + br $while-continue|0 end + end + local.get $1 + i64.const 4503599627370496 + i64.ge_u + if local.get $1 i64.const 4503599627370496 - i64.ge_u + i64.eq if - local.get $1 - i64.const 4503599627370496 - i64.eq - br_if $folding-inner0 - local.get $1 - i64.const 4503599627370496 - i64.sub - local.set $1 + local.get $0 + f64.const 0 + f64.mul + return end local.get $1 - local.get $1 - i64.const 11 - i64.shl - i64.clz - local.tee $3 - i64.shl + i64.const 4503599627370496 + i64.sub local.set $1 - local.get $2 - local.get $3 + end + local.get $1 + local.get $1 + i64.const 11 + i64.shl + i64.clz + local.tee $3 + i64.shl + local.set $1 + local.get $2 + local.get $3 + i64.sub + local.tee $2 + i64.const 0 + i64.gt_s + if (result i64) + local.get $1 + i64.const 4503599627370496 i64.sub - local.tee $2 - i64.const 0 - i64.gt_s - if (result i64) - local.get $1 - i64.const 4503599627370496 - i64.sub - local.get $2 - i64.const 52 - i64.shl - i64.or - else - local.get $1 - i64.const 1 - local.get $2 - i64.sub - i64.shr_u - end - local.get $4 - i64.const 63 + local.get $2 + i64.const 52 i64.shl i64.or - f64.reinterpret_i64 - return + else + local.get $1 + i64.const 1 + local.get $2 + i64.sub + i64.shr_u end - local.get $0 - f64.const 0 - f64.mul + local.get $4 + i64.or + f64.reinterpret_i64 ) (func $std/typedarray/testArrayEvery<~lib/typedarray/Float64Array,f64>~anonymous|0 (param $0 f64) (param $1 i32) (param $2 i32) (result i32) local.get $2 diff --git a/tests/compiler/std/typedarray.untouched.wat b/tests/compiler/std/typedarray.untouched.wat index ddc0bedaf9..477af1e666 100644 --- a/tests/compiler/std/typedarray.untouched.wat +++ b/tests/compiler/std/typedarray.untouched.wat @@ -19104,13 +19104,13 @@ local.get $9 local.get $7 i32.eq - if + if (result f32) f32.const 0 local.get $0 f32.mul - return + else + local.get $0 end - local.get $0 return end local.get $4 @@ -19273,8 +19273,6 @@ local.get $2 local.get $6 i32.or - local.set $2 - local.get $2 f32.reinterpret_i32 ) (func $std/typedarray/testArrayEvery<~lib/typedarray/Float32Array,f32>~anonymous|0 (param $0 f32) (param $1 i32) (param $2 i32) (result i32) @@ -19486,8 +19484,8 @@ i64.and local.set $5 local.get $2 - i64.const 63 - i64.shr_u + i64.const -9223372036854775808 + i64.and local.set $6 local.get $3 i64.const 1 @@ -19531,13 +19529,13 @@ local.get $9 local.get $7 i64.eq - if + if (result f64) f64.const 0 local.get $0 f64.mul - return + else + local.get $0 end - local.get $0 return end local.get $4 @@ -19703,11 +19701,7 @@ end local.get $2 local.get $6 - i64.const 63 - i64.shl i64.or - local.set $2 - local.get $2 f64.reinterpret_i64 ) (func $std/typedarray/testArrayEvery<~lib/typedarray/Float64Array,f64>~anonymous|0 (param $0 f64) (param $1 i32) (param $2 i32) (result i32) From 7787cf3ff298a9cfdd71479d660ae42faef4dd72 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 26 Oct 2020 18:30:13 +0200 Subject: [PATCH 2/4] more --- std/assembly/math.ts | 4 ++-- tests/compiler/binary.untouched.wat | 24 +++++++-------------- tests/compiler/std/math.optimized.wat | 16 ++++++-------- tests/compiler/std/math.untouched.wat | 24 +++++++-------------- tests/compiler/std/mod.optimized.wat | 16 ++++++-------- tests/compiler/std/mod.untouched.wat | 24 +++++++-------------- tests/compiler/std/typedarray.optimized.wat | 16 ++++++-------- tests/compiler/std/typedarray.untouched.wat | 24 +++++++-------------- 8 files changed, 52 insertions(+), 96 deletions(-) diff --git a/std/assembly/math.ts b/std/assembly/math.ts index 4b37306fe9..2a1533070f 100644 --- a/std/assembly/math.ts +++ b/std/assembly/math.ts @@ -1583,7 +1583,7 @@ export namespace NativeMath { } var ux1 = ux << 1; if (ux1 <= uy1) { - return ux1 == uy1 ? 0 * x : x; + return x * f64(ux1 != uy1); } if (!ex) { ex -= builtin_clz(ux << 12); @@ -2890,7 +2890,7 @@ export namespace NativeMathf { } var ux1 = ux << 1; if (ux1 <= uy1) { - return ux1 == uy1 ? 0 * x : x; + return x * f32(ux1 != uy1); } if (!ex) { ex -= builtin_clz(ux << 9); diff --git a/tests/compiler/binary.untouched.wat b/tests/compiler/binary.untouched.wat index 7a32ac7e7d..bf31c6078e 100644 --- a/tests/compiler/binary.untouched.wat +++ b/tests/compiler/binary.untouched.wat @@ -1288,16 +1288,12 @@ local.get $7 i32.le_u if + local.get $0 local.get $9 local.get $7 - i32.eq - if (result f32) - f32.const 0 - local.get $0 - f32.mul - else - local.get $0 - end + i32.ne + f32.convert_i32_u + f32.mul return end local.get $4 @@ -2161,16 +2157,12 @@ local.get $7 i64.le_u if + local.get $0 local.get $9 local.get $7 - i64.eq - if (result f64) - f64.const 0 - local.get $0 - f64.mul - else - local.get $0 - end + i64.ne + f64.convert_i32_u + f64.mul return end local.get $4 diff --git a/tests/compiler/std/math.optimized.wat b/tests/compiler/std/math.optimized.wat index 8449ad1b56..f929d6b24c 100644 --- a/tests/compiler/std/math.optimized.wat +++ b/tests/compiler/std/math.optimized.wat @@ -6526,14 +6526,12 @@ local.get $6 i64.le_u if - local.get $0 - f64.const 0 - f64.mul local.get $0 local.get $6 local.get $8 - i64.eq - select + i64.ne + f64.convert_i32_u + f64.mul return end local.get $4 @@ -6753,14 +6751,12 @@ local.get $6 i32.le_u if - local.get $0 - f32.const 0 - f32.mul local.get $0 local.get $6 local.get $8 - i32.eq - select + i32.ne + f32.convert_i32_u + f32.mul return end local.get $4 diff --git a/tests/compiler/std/math.untouched.wat b/tests/compiler/std/math.untouched.wat index 5a4750e43c..57505df8c0 100644 --- a/tests/compiler/std/math.untouched.wat +++ b/tests/compiler/std/math.untouched.wat @@ -9227,16 +9227,12 @@ local.get $7 i64.le_u if + local.get $0 local.get $9 local.get $7 - i64.eq - if (result f64) - f64.const 0 - local.get $0 - f64.mul - else - local.get $0 - end + i64.ne + f64.convert_i32_u + f64.mul return end local.get $4 @@ -9516,16 +9512,12 @@ local.get $7 i32.le_u if + local.get $0 local.get $9 local.get $7 - i32.eq - if (result f32) - f32.const 0 - local.get $0 - f32.mul - else - local.get $0 - end + i32.ne + f32.convert_i32_u + f32.mul return end local.get $4 diff --git a/tests/compiler/std/mod.optimized.wat b/tests/compiler/std/mod.optimized.wat index c5df7a91f2..6c399febf5 100644 --- a/tests/compiler/std/mod.optimized.wat +++ b/tests/compiler/std/mod.optimized.wat @@ -84,14 +84,12 @@ local.get $6 i64.le_u if - local.get $0 - f64.const 0 - f64.mul local.get $0 local.get $6 local.get $8 - i64.eq - select + i64.ne + f64.convert_i32_u + f64.mul return end local.get $4 @@ -336,14 +334,12 @@ local.get $6 i32.le_u if - local.get $0 - f32.const 0 - f32.mul local.get $0 local.get $6 local.get $8 - i32.eq - select + i32.ne + f32.convert_i32_u + f32.mul return end local.get $4 diff --git a/tests/compiler/std/mod.untouched.wat b/tests/compiler/std/mod.untouched.wat index 5790978826..3b4e02c1b6 100644 --- a/tests/compiler/std/mod.untouched.wat +++ b/tests/compiler/std/mod.untouched.wat @@ -101,16 +101,12 @@ local.get $7 i64.le_u if + local.get $0 local.get $9 local.get $7 - i64.eq - if (result f64) - f64.const 0 - local.get $0 - f64.mul - else - local.get $0 - end + i64.ne + f64.convert_i32_u + f64.mul return end local.get $4 @@ -414,16 +410,12 @@ local.get $7 i32.le_u if + local.get $0 local.get $9 local.get $7 - i32.eq - if (result f32) - f32.const 0 - local.get $0 - f32.mul - else - local.get $0 - end + i32.ne + f32.convert_i32_u + f32.mul return end local.get $4 diff --git a/tests/compiler/std/typedarray.optimized.wat b/tests/compiler/std/typedarray.optimized.wat index 899b03046d..499de64f02 100644 --- a/tests/compiler/std/typedarray.optimized.wat +++ b/tests/compiler/std/typedarray.optimized.wat @@ -9623,14 +9623,12 @@ i32.const -2147483648 i32.le_u if - local.get $0 - f32.const 0 - f32.mul local.get $0 local.get $3 i32.const -2147483648 - i32.eq - select + i32.ne + f32.convert_i32_u + f32.mul return end local.get $2 @@ -9852,14 +9850,12 @@ i64.const -9223372036854775808 i64.le_u if - local.get $0 - f64.const 0 - f64.mul local.get $0 local.get $3 i64.const -9223372036854775808 - i64.eq - select + i64.ne + f64.convert_i32_u + f64.mul return end local.get $2 diff --git a/tests/compiler/std/typedarray.untouched.wat b/tests/compiler/std/typedarray.untouched.wat index 477af1e666..973b491a2b 100644 --- a/tests/compiler/std/typedarray.untouched.wat +++ b/tests/compiler/std/typedarray.untouched.wat @@ -19101,16 +19101,12 @@ local.get $7 i32.le_u if + local.get $0 local.get $9 local.get $7 - i32.eq - if (result f32) - f32.const 0 - local.get $0 - f32.mul - else - local.get $0 - end + i32.ne + f32.convert_i32_u + f32.mul return end local.get $4 @@ -19526,16 +19522,12 @@ local.get $7 i64.le_u if + local.get $0 local.get $9 local.get $7 - i64.eq - if (result f64) - f64.const 0 - local.get $0 - f64.mul - else - local.get $0 - end + i64.ne + f64.convert_i32_u + f64.mul return end local.get $4 From fe5a9d40cf97ef742cc3d45212568295c3ab6b3d Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Tue, 27 Oct 2020 11:26:06 +0200 Subject: [PATCH 3/4] revert sign extraction for f64.mod --- std/assembly/math.ts | 4 ++-- tests/compiler/binary.untouched.wat | 6 ++++-- tests/compiler/std/math.optimized.wat | 6 ++++-- tests/compiler/std/math.untouched.wat | 6 ++++-- tests/compiler/std/mod.optimized.wat | 6 ++++-- tests/compiler/std/mod.untouched.wat | 6 ++++-- tests/compiler/std/typedarray.optimized.wat | 6 ++++-- tests/compiler/std/typedarray.untouched.wat | 6 ++++-- 8 files changed, 30 insertions(+), 16 deletions(-) diff --git a/std/assembly/math.ts b/std/assembly/math.ts index 2a1533070f..47241f079b 100644 --- a/std/assembly/math.ts +++ b/std/assembly/math.ts @@ -1575,7 +1575,7 @@ export namespace NativeMath { var uy = reinterpret(y); var ex = (ux >> 52 & 0x7FF); var ey = (uy >> 52 & 0x7FF); - var sm = ux & 0x8000000000000000; + var sx = ux >> 63; var uy1 = uy << 1; if (uy1 == 0 || ex == 0x7FF || isNaN(y)) { let m = x * y; @@ -1621,7 +1621,7 @@ export namespace NativeMath { } else { ux >>= -ex + 1; } - return reinterpret(ux | sm); + return reinterpret(ux | (sx << 63)); } export function rem(x: f64, y: f64): f64 { // see: musl/src/math/remquo.c diff --git a/tests/compiler/binary.untouched.wat b/tests/compiler/binary.untouched.wat index bf31c6078e..87a57a2b41 100644 --- a/tests/compiler/binary.untouched.wat +++ b/tests/compiler/binary.untouched.wat @@ -2115,8 +2115,8 @@ i64.and local.set $5 local.get $2 - i64.const -9223372036854775808 - i64.and + i64.const 63 + i64.shr_u local.set $6 local.get $3 i64.const 1 @@ -2328,6 +2328,8 @@ end local.get $2 local.get $6 + i64.const 63 + i64.shl i64.or f64.reinterpret_i64 ) diff --git a/tests/compiler/std/math.optimized.wat b/tests/compiler/std/math.optimized.wat index f929d6b24c..b3418d80b0 100644 --- a/tests/compiler/std/math.optimized.wat +++ b/tests/compiler/std/math.optimized.wat @@ -6487,8 +6487,8 @@ local.get $0 i64.reinterpret_f64 local.tee $2 - i64.const -9223372036854775808 - i64.and + i64.const 63 + i64.shr_u local.set $7 i32.const 1 local.get $1 @@ -6660,6 +6660,8 @@ i64.shr_u end local.get $7 + i64.const 63 + i64.shl i64.or f64.reinterpret_i64 ) diff --git a/tests/compiler/std/math.untouched.wat b/tests/compiler/std/math.untouched.wat index 57505df8c0..3ceaaf94f0 100644 --- a/tests/compiler/std/math.untouched.wat +++ b/tests/compiler/std/math.untouched.wat @@ -9185,8 +9185,8 @@ i64.and local.set $5 local.get $2 - i64.const -9223372036854775808 - i64.and + i64.const 63 + i64.shr_u local.set $6 local.get $3 i64.const 1 @@ -9398,6 +9398,8 @@ end local.get $2 local.get $6 + i64.const 63 + i64.shl i64.or f64.reinterpret_i64 ) diff --git a/tests/compiler/std/mod.optimized.wat b/tests/compiler/std/mod.optimized.wat index 6c399febf5..e399f928d3 100644 --- a/tests/compiler/std/mod.optimized.wat +++ b/tests/compiler/std/mod.optimized.wat @@ -45,8 +45,8 @@ local.get $0 i64.reinterpret_f64 local.tee $2 - i64.const -9223372036854775808 - i64.and + i64.const 63 + i64.shr_u local.set $7 i32.const 1 local.get $1 @@ -218,6 +218,8 @@ i64.shr_u end local.get $7 + i64.const 63 + i64.shl i64.or f64.reinterpret_i64 ) diff --git a/tests/compiler/std/mod.untouched.wat b/tests/compiler/std/mod.untouched.wat index 3b4e02c1b6..d97129d1d2 100644 --- a/tests/compiler/std/mod.untouched.wat +++ b/tests/compiler/std/mod.untouched.wat @@ -59,8 +59,8 @@ i64.and local.set $5 local.get $2 - i64.const -9223372036854775808 - i64.and + i64.const 63 + i64.shr_u local.set $6 local.get $3 i64.const 1 @@ -272,6 +272,8 @@ end local.get $2 local.get $6 + i64.const 63 + i64.shl i64.or f64.reinterpret_i64 ) diff --git a/tests/compiler/std/typedarray.optimized.wat b/tests/compiler/std/typedarray.optimized.wat index 499de64f02..c34566198c 100644 --- a/tests/compiler/std/typedarray.optimized.wat +++ b/tests/compiler/std/typedarray.optimized.wat @@ -9823,8 +9823,8 @@ local.get $0 i64.reinterpret_f64 local.tee $1 - i64.const -9223372036854775808 - i64.and + i64.const 63 + i64.shr_u local.set $4 local.get $1 i64.const 52 @@ -9962,6 +9962,8 @@ i64.shr_u end local.get $4 + i64.const 63 + i64.shl i64.or f64.reinterpret_i64 ) diff --git a/tests/compiler/std/typedarray.untouched.wat b/tests/compiler/std/typedarray.untouched.wat index 973b491a2b..08a7fbbe07 100644 --- a/tests/compiler/std/typedarray.untouched.wat +++ b/tests/compiler/std/typedarray.untouched.wat @@ -19480,8 +19480,8 @@ i64.and local.set $5 local.get $2 - i64.const -9223372036854775808 - i64.and + i64.const 63 + i64.shr_u local.set $6 local.get $3 i64.const 1 @@ -19693,6 +19693,8 @@ end local.get $2 local.get $6 + i64.const 63 + i64.shl i64.or f64.reinterpret_i64 ) From 145d9703fe0f6dcb3d7b6efe3b87fb28130618fe Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Tue, 27 Oct 2020 12:02:08 +0200 Subject: [PATCH 4/4] refactoring --- std/assembly/math.ts | 16 +++++------ tests/compiler/binary.untouched.wat | 16 +++-------- tests/compiler/std/math.untouched.wat | 32 ++++++--------------- tests/compiler/std/mod.untouched.wat | 16 +++-------- tests/compiler/std/typedarray.untouched.wat | 16 +++-------- 5 files changed, 28 insertions(+), 68 deletions(-) diff --git a/std/assembly/math.ts b/std/assembly/math.ts index 47241f079b..0b4313a61d 100644 --- a/std/assembly/math.ts +++ b/std/assembly/math.ts @@ -1587,14 +1587,14 @@ export namespace NativeMath { } if (!ex) { ex -= builtin_clz(ux << 12); - ux <<= -ex + 1; + ux <<= 1 - ex; } else { ux &= -1 >> 12; ux |= 1 << 52; } if (!ey) { ey -= builtin_clz(uy << 12); - uy <<= -ey + 1; + uy <<= 1 - ey; } else { uy &= -1 >> 12; uy |= 1 << 52; @@ -1638,14 +1638,14 @@ export namespace NativeMath { var uxi = ux; if (!ex) { ex -= builtin_clz(uxi << 12); - uxi <<= -ex + 1; + uxi <<= 1 - ex; } else { uxi &= -1 >> 12; uxi |= 1 << 52; } if (!ey) { ey -= builtin_clz(uy << 12); - uy <<= -ey + 1; + uy <<= 1 - ey; } else { uy &= -1 >> 12; uy |= 1 << 52; @@ -2894,14 +2894,14 @@ export namespace NativeMathf { } if (!ex) { ex -= builtin_clz(ux << 9); - ux <<= -ex + 1; + ux <<= 1 - ex; } else { ux &= -1 >> 9; ux |= 1 << 23; } if (!ey) { ey -= builtin_clz(uy << 9); - uy <<= -ey + 1; + uy <<= 1 - ey; } else { uy &= -1 >> 9; uy |= 1 << 23; @@ -2942,14 +2942,14 @@ export namespace NativeMathf { if (ux << 1 == 0) return x; if (!ex) { ex -= builtin_clz(uxi << 9); - uxi <<= -ex + 1; + uxi <<= 1 - ex; } else { uxi &= -1 >> 9; uxi |= 1 << 23; } if (!ey) { ey -= builtin_clz(uy << 9); - uy <<= -ey + 1; + uy <<= 1 - ey; } else { uy &= -1 >> 9; uy |= 1 << 23; diff --git a/tests/compiler/binary.untouched.wat b/tests/compiler/binary.untouched.wat index 87a57a2b41..fe63b928b4 100644 --- a/tests/compiler/binary.untouched.wat +++ b/tests/compiler/binary.untouched.wat @@ -1307,11 +1307,9 @@ i32.sub local.set $4 local.get $2 - i32.const 0 + i32.const 1 local.get $4 i32.sub - i32.const 1 - i32.add i32.shl local.set $2 else @@ -1339,11 +1337,9 @@ i32.sub local.set $5 local.get $3 - i32.const 0 + i32.const 1 local.get $5 i32.sub - i32.const 1 - i32.add i32.shl local.set $3 else @@ -2178,11 +2174,9 @@ i64.sub local.set $4 local.get $2 - i64.const 0 + i64.const 1 local.get $4 i64.sub - i64.const 1 - i64.add i64.shl local.set $2 else @@ -2212,11 +2206,9 @@ i64.sub local.set $5 local.get $3 - i64.const 0 + i64.const 1 local.get $5 i64.sub - i64.const 1 - i64.add i64.shl local.set $3 else diff --git a/tests/compiler/std/math.untouched.wat b/tests/compiler/std/math.untouched.wat index 3ceaaf94f0..271d353465 100644 --- a/tests/compiler/std/math.untouched.wat +++ b/tests/compiler/std/math.untouched.wat @@ -9248,11 +9248,9 @@ i64.sub local.set $4 local.get $2 - i64.const 0 + i64.const 1 local.get $4 i64.sub - i64.const 1 - i64.add i64.shl local.set $2 else @@ -9282,11 +9280,9 @@ i64.sub local.set $5 local.get $3 - i64.const 0 + i64.const 1 local.get $5 i64.sub - i64.const 1 - i64.add i64.shl local.set $3 else @@ -9533,11 +9529,9 @@ i32.sub local.set $4 local.get $2 - i32.const 0 + i32.const 1 local.get $4 i32.sub - i32.const 1 - i32.add i32.shl local.set $2 else @@ -9565,11 +9559,9 @@ i32.sub local.set $5 local.get $3 - i32.const 0 + i32.const 1 local.get $5 i32.sub - i32.const 1 - i32.add i32.shl local.set $3 else @@ -11741,11 +11733,9 @@ i64.sub local.set $4 local.get $8 - i64.const 0 + i64.const 1 local.get $4 i64.sub - i64.const 1 - i64.add i64.shl local.set $8 else @@ -11775,11 +11765,9 @@ i64.sub local.set $5 local.get $3 - i64.const 0 + i64.const 1 local.get $5 i64.sub - i64.const 1 - i64.add i64.shl local.set $3 else @@ -12063,11 +12051,9 @@ i32.sub local.set $4 local.get $7 - i32.const 0 + i32.const 1 local.get $4 i32.sub - i32.const 1 - i32.add i32.shl local.set $7 else @@ -12095,11 +12081,9 @@ i32.sub local.set $5 local.get $3 - i32.const 0 + i32.const 1 local.get $5 i32.sub - i32.const 1 - i32.add i32.shl local.set $3 else diff --git a/tests/compiler/std/mod.untouched.wat b/tests/compiler/std/mod.untouched.wat index d97129d1d2..5ef26eb943 100644 --- a/tests/compiler/std/mod.untouched.wat +++ b/tests/compiler/std/mod.untouched.wat @@ -122,11 +122,9 @@ i64.sub local.set $4 local.get $2 - i64.const 0 + i64.const 1 local.get $4 i64.sub - i64.const 1 - i64.add i64.shl local.set $2 else @@ -156,11 +154,9 @@ i64.sub local.set $5 local.get $3 - i64.const 0 + i64.const 1 local.get $5 i64.sub - i64.const 1 - i64.add i64.shl local.set $3 else @@ -431,11 +427,9 @@ i32.sub local.set $4 local.get $2 - i32.const 0 + i32.const 1 local.get $4 i32.sub - i32.const 1 - i32.add i32.shl local.set $2 else @@ -463,11 +457,9 @@ i32.sub local.set $5 local.get $3 - i32.const 0 + i32.const 1 local.get $5 i32.sub - i32.const 1 - i32.add i32.shl local.set $3 else diff --git a/tests/compiler/std/typedarray.untouched.wat b/tests/compiler/std/typedarray.untouched.wat index 08a7fbbe07..329b76adb2 100644 --- a/tests/compiler/std/typedarray.untouched.wat +++ b/tests/compiler/std/typedarray.untouched.wat @@ -19120,11 +19120,9 @@ i32.sub local.set $4 local.get $2 - i32.const 0 + i32.const 1 local.get $4 i32.sub - i32.const 1 - i32.add i32.shl local.set $2 else @@ -19152,11 +19150,9 @@ i32.sub local.set $5 local.get $3 - i32.const 0 + i32.const 1 local.get $5 i32.sub - i32.const 1 - i32.add i32.shl local.set $3 else @@ -19543,11 +19539,9 @@ i64.sub local.set $4 local.get $2 - i64.const 0 + i64.const 1 local.get $4 i64.sub - i64.const 1 - i64.add i64.shl local.set $2 else @@ -19577,11 +19571,9 @@ i64.sub local.set $5 local.get $3 - i64.const 0 + i64.const 1 local.get $5 i64.sub - i64.const 1 - i64.add i64.shl local.set $3 else