diff --git a/std/assembly/math.ts b/std/assembly/math.ts index c49c24f3..077a082d 100644 --- a/std/assembly/math.ts +++ b/std/assembly/math.ts @@ -1103,19 +1103,17 @@ export namespace NativeMath { uy &= -1 >> 12; uy |= 1 << 52; } - var i: u64; - for (; ex > ey; ex--) { - i = ux - uy; - if (!(i >> 63)) { - if (!i) return 0 * x; - ux = i; + while (ex > ey) { + if (ux >= uy) { + if (ux == uy) return 0 * x; + ux -= uy; } ux <<= 1; + --ex; } - i = ux - uy; - if (!(i >> 63)) { - if (!i) return 0 * x; - ux = i; + if (ux >= uy) { + if (ux == uy) return 0 * x; + ux -= uy; } // for (; !(ux >> 52); ux <<= 1) --ex; var shift = builtin_clz(ux << 11); @@ -1160,19 +1158,17 @@ export namespace NativeMath { if (ex + 1 == ey) break; // goto end return x; } - let i: u64; - for (; ex > ey; --ex) { - i = uxi - uy; - if (i >> 63 == 0) { - uxi = i; + while (ex > ey) { + if (uxi >= uy) { + uxi -= uy; ++q; } uxi <<= 1; q <<= 1; + --ex; } - i = uxi - uy; - if (i >> 63 == 0) { - uxi = i; + if (uxi >= uy) { + uxi -= uy; ++q; } if (uxi == 0) ex = -60; @@ -2156,19 +2152,17 @@ export namespace NativeMathf { uy &= -1 >> 9; uy |= 1 << 23; } - var i: u32; - for (; ex > ey; --ex) { - i = ux - uy; - if (!(i >> 31)) { - if (!i) return 0 * x; - ux = i; + while (ex > ey) { + if (ux >= uy) { + if (ux == uy) return 0 * x; + ux -= uy; } ux <<= 1; + --ex; } - i = ux - uy; - if (!(i >> 31)) { - if (!i) return 0 * x; - ux = i; + if (ux >= uy) { + if (ux == uy) return 0 * x; + ux -= uy; } // for (; !(ux >> 23); ux <<= 1) --ex; var shift = builtin_clz(ux << 8); @@ -2213,19 +2207,17 @@ export namespace NativeMathf { if (ex + 1 == ey) break; // goto end return x; } - let i: u32; - for (; ex > ey; --ex) { - i = uxi - uy; - if (i >> 31 == 0) { - uxi = i; + while (ex > ey) { + if (uxi >= uy) { + uxi -= uy; ++q; } uxi <<= 1; q <<= 1; + --ex; } - i = uxi - uy; - if (i >> 31 == 0) { - uxi = i; + if (uxi >= uy) { + uxi -= uy; ++q; } if (uxi == 0) ex = -30; diff --git a/tests/compiler/binary.optimized.wat b/tests/compiler/binary.optimized.wat index 8628b4ba..58f6faf5 100644 --- a/tests/compiler/binary.optimized.wat +++ b/tests/compiler/binary.optimized.wat @@ -99,7 +99,7 @@ (local $3 i32) (local $4 i32) (block $folding-inner0 - (set_local $3 + (set_local $2 (i32.and (i32.shr_u (tee_local $1 @@ -120,20 +120,20 @@ ) (if (i32.eqz - (tee_local $2 + (tee_local $3 (i32.eq - (get_local $3) + (get_local $2) (i32.const 255) ) ) ) - (set_local $2 + (set_local $3 (i32.const 0) ) ) (if (i32.and - (get_local $2) + (get_local $3) (i32.const 1) ) (return @@ -145,7 +145,7 @@ ) (if (i32.le_u - (tee_local $2 + (tee_local $3 (i32.shl (get_local $1) (i32.const 1) @@ -156,7 +156,7 @@ (block (br_if $folding-inner0 (i32.eq - (get_local $2) + (get_local $3) (i32.const 2130706432) ) ) @@ -167,7 +167,7 @@ ) (set_local $1 (if (result i32) - (get_local $3) + (get_local $2) (i32.or (i32.and (get_local $1) @@ -179,9 +179,9 @@ (get_local $1) (i32.sub (i32.const 1) - (tee_local $3 + (tee_local $2 (i32.sub - (get_local $3) + (get_local $2) (i32.clz (i32.shl (get_local $1) @@ -194,79 +194,73 @@ ) ) ) - (block $break|0 - (loop $repeat|0 - (br_if $break|0 - (i32.le_s - (get_local $3) - (i32.const 127) - ) + (loop $continue|0 + (if + (i32.gt_s + (get_local $2) + (i32.const 127) ) - (if - (i32.eqz - (i32.shr_u - (tee_local $2 + (block + (if + (i32.ge_u + (get_local $1) + (i32.const 8388608) + ) + (block + (br_if $folding-inner0 + (i32.eq + (get_local $1) + (i32.const 8388608) + ) + ) + (set_local $1 (i32.sub (get_local $1) (i32.const 8388608) ) ) - (i32.const 31) ) ) - (block - (br_if $folding-inner0 - (i32.eqz - (get_local $2) - ) + (set_local $1 + (i32.shl + (get_local $1) + (i32.const 1) ) - (set_local $1 + ) + (set_local $2 + (i32.sub (get_local $2) + (i32.const 1) ) ) + (br $continue|0) ) - (set_local $1 - (i32.shl - (get_local $1) - (i32.const 1) - ) - ) - (set_local $3 - (i32.sub - (get_local $3) - (i32.const 1) - ) - ) - (br $repeat|0) ) ) (if - (i32.eqz - (i32.shr_u - (tee_local $2 - (i32.sub - (get_local $1) - (i32.const 8388608) - ) - ) - (i32.const 31) - ) + (i32.ge_u + (get_local $1) + (i32.const 8388608) ) (block (br_if $folding-inner0 - (i32.eqz - (get_local $2) + (i32.eq + (get_local $1) + (i32.const 8388608) ) ) (set_local $1 - (get_local $2) + (i32.sub + (get_local $1) + (i32.const 8388608) + ) ) ) ) (set_local $1 (i32.shl (get_local $1) - (tee_local $2 + (tee_local $3 (i32.clz (i32.shl (get_local $1) @@ -282,10 +276,10 @@ (tee_local $1 (if (result i32) (i32.gt_s - (tee_local $3 + (tee_local $2 (i32.sub - (get_local $3) (get_local $2) + (get_local $3) ) ) (i32.const 0) @@ -296,7 +290,7 @@ (i32.const 8388608) ) (i32.shl - (get_local $3) + (get_local $2) (i32.const 23) ) ) @@ -304,7 +298,7 @@ (get_local $1) (i32.sub (i32.const 1) - (get_local $3) + (get_local $2) ) ) ) @@ -459,72 +453,66 @@ ) ) ) - (block $break|0 - (loop $repeat|0 - (br_if $break|0 - (i64.le_s - (get_local $2) - (i64.const 1023) - ) + (loop $continue|0 + (if + (i64.gt_s + (get_local $2) + (i64.const 1023) ) - (if - (i64.eqz - (i64.shr_u - (tee_local $3 + (block + (if + (i64.ge_u + (get_local $1) + (i64.const 4503599627370496) + ) + (block + (br_if $folding-inner0 + (i64.eq + (get_local $1) + (i64.const 4503599627370496) + ) + ) + (set_local $1 (i64.sub (get_local $1) (i64.const 4503599627370496) ) ) - (i64.const 63) ) ) - (block - (br_if $folding-inner0 - (i64.eqz - (get_local $3) - ) - ) - (set_local $1 - (get_local $3) + (set_local $1 + (i64.shl + (get_local $1) + (i64.const 1) ) ) - ) - (set_local $1 - (i64.shl - (get_local $1) - (i64.const 1) + (set_local $2 + (i64.sub + (get_local $2) + (i64.const 1) + ) ) + (br $continue|0) ) - (set_local $2 - (i64.sub - (get_local $2) - (i64.const 1) - ) - ) - (br $repeat|0) ) ) (if - (i64.eqz - (i64.shr_u - (tee_local $3 - (i64.sub - (get_local $1) - (i64.const 4503599627370496) - ) - ) - (i64.const 63) - ) + (i64.ge_u + (get_local $1) + (i64.const 4503599627370496) ) (block (br_if $folding-inner0 - (i64.eqz - (get_local $3) + (i64.eq + (get_local $1) + (i64.const 4503599627370496) ) ) (set_local $1 - (get_local $3) + (i64.sub + (get_local $1) + (i64.const 4503599627370496) + ) ) ) ) diff --git a/tests/compiler/binary.untouched.wat b/tests/compiler/binary.untouched.wat index b628b60c..08bfbbc2 100644 --- a/tests/compiler/binary.untouched.wat +++ b/tests/compiler/binary.untouched.wat @@ -1697,7 +1697,6 @@ (local $8 i32) (local $9 i32) (local $10 i32) - (local $11 i32) (set_local $2 (i32.reinterpret/f32 (get_local $0) @@ -1909,79 +1908,68 @@ ) ) (block $break|0 - (loop $repeat|0 - (br_if $break|0 - (i32.eqz - (i32.gt_s - (get_local $4) - (get_local $5) - ) + (loop $continue|0 + (if + (i32.gt_s + (get_local $4) + (get_local $5) ) - ) - (block - (set_local $10 - (i32.sub - (get_local $2) - (get_local $3) - ) - ) - (if - (i32.eqz - (i32.shr_u - (get_local $10) - (i32.const 31) - ) - ) + (block (block (if - (i32.eqz - (get_local $10) + (i32.ge_u + (get_local $2) + (get_local $3) ) - (return - (f32.mul - (f32.const 0) - (get_local $0) + (block + (if + (i32.eq + (get_local $2) + (get_local $3) + ) + (return + (f32.mul + (f32.const 0) + (get_local $0) + ) + ) + ) + (set_local $2 + (i32.sub + (get_local $2) + (get_local $3) + ) ) ) ) (set_local $2 - (get_local $10) + (i32.shl + (get_local $2) + (i32.const 1) + ) + ) + (set_local $4 + (i32.sub + (get_local $4) + (i32.const 1) + ) ) ) - ) - (set_local $2 - (i32.shl - (get_local $2) - (i32.const 1) - ) + (br $continue|0) ) ) - (set_local $4 - (i32.sub - (get_local $4) - (i32.const 1) - ) - ) - (br $repeat|0) - ) - ) - (set_local $10 - (i32.sub - (get_local $2) - (get_local $3) ) ) (if - (i32.eqz - (i32.shr_u - (get_local $10) - (i32.const 31) - ) + (i32.ge_u + (get_local $2) + (get_local $3) ) (block (if - (i32.eqz - (get_local $10) + (i32.eq + (get_local $2) + (get_local $3) ) (return (f32.mul @@ -1991,11 +1979,14 @@ ) ) (set_local $2 - (get_local $10) + (i32.sub + (get_local $2) + (get_local $3) + ) ) ) ) - (set_local $11 + (set_local $10 (i32.clz (i32.shl (get_local $2) @@ -2006,13 +1997,13 @@ (set_local $4 (i32.sub (get_local $4) - (get_local $11) + (get_local $10) ) ) (set_local $2 (i32.shl (get_local $2) - (get_local $11) + (get_local $10) ) ) (if @@ -3525,7 +3516,6 @@ (local $8 i32) (local $9 i64) (local $10 i64) - (local $11 i64) (set_local $2 (i64.reinterpret/f64 (get_local $0) @@ -3737,79 +3727,68 @@ ) ) (block $break|0 - (loop $repeat|0 - (br_if $break|0 - (i32.eqz - (i64.gt_s - (get_local $4) - (get_local $5) - ) + (loop $continue|0 + (if + (i64.gt_s + (get_local $4) + (get_local $5) ) - ) - (block - (set_local $10 - (i64.sub - (get_local $2) - (get_local $3) - ) - ) - (if - (i64.eqz - (i64.shr_u - (get_local $10) - (i64.const 63) - ) - ) + (block (block (if - (i64.eqz - (get_local $10) + (i64.ge_u + (get_local $2) + (get_local $3) ) - (return - (f64.mul - (f64.const 0) - (get_local $0) + (block + (if + (i64.eq + (get_local $2) + (get_local $3) + ) + (return + (f64.mul + (f64.const 0) + (get_local $0) + ) + ) + ) + (set_local $2 + (i64.sub + (get_local $2) + (get_local $3) + ) ) ) ) (set_local $2 - (get_local $10) + (i64.shl + (get_local $2) + (i64.const 1) + ) + ) + (set_local $4 + (i64.sub + (get_local $4) + (i64.const 1) + ) ) ) - ) - (set_local $2 - (i64.shl - (get_local $2) - (i64.const 1) - ) + (br $continue|0) ) ) - (set_local $4 - (i64.sub - (get_local $4) - (i64.const 1) - ) - ) - (br $repeat|0) - ) - ) - (set_local $10 - (i64.sub - (get_local $2) - (get_local $3) ) ) (if - (i64.eqz - (i64.shr_u - (get_local $10) - (i64.const 63) - ) + (i64.ge_u + (get_local $2) + (get_local $3) ) (block (if - (i64.eqz - (get_local $10) + (i64.eq + (get_local $2) + (get_local $3) ) (return (f64.mul @@ -3819,11 +3798,14 @@ ) ) (set_local $2 - (get_local $10) + (i64.sub + (get_local $2) + (get_local $3) + ) ) ) ) - (set_local $11 + (set_local $10 (i64.clz (i64.shl (get_local $2) @@ -3834,13 +3816,13 @@ (set_local $4 (i64.sub (get_local $4) - (get_local $11) + (get_local $10) ) ) (set_local $2 (i64.shl (get_local $2) - (get_local $11) + (get_local $10) ) ) (if diff --git a/tests/compiler/std/math.optimized.wat b/tests/compiler/std/math.optimized.wat index 52bb7cd1..ba84e0b6 100644 --- a/tests/compiler/std/math.optimized.wat +++ b/tests/compiler/std/math.optimized.wat @@ -8283,12 +8283,12 @@ (local $3 i64) (local $4 i64) (local $5 i64) - (local $6 i64) - (local $7 i32) + (local $6 i32) + (local $7 i64) (local $8 i64) (local $9 i64) (block $folding-inner0 - (set_local $3 + (set_local $4 (i64.and (i64.shr_u (tee_local $2 @@ -8301,10 +8301,10 @@ (i64.const 2047) ) ) - (set_local $6 + (set_local $5 (i64.and (i64.shr_u - (tee_local $5 + (tee_local $3 (i64.reinterpret/f64 (get_local $1) ) @@ -8322,11 +8322,11 @@ ) (if (i32.eqz - (tee_local $7 + (tee_local $6 (i64.eq - (tee_local $4 + (tee_local $7 (i64.shl - (get_local $5) + (get_local $3) (i64.const 1) ) ) @@ -8334,18 +8334,18 @@ ) ) ) - (set_local $7 + (set_local $6 (i64.eq - (get_local $3) + (get_local $4) (i64.const 2047) ) ) ) (if (i32.eqz - (get_local $7) + (get_local $6) ) - (set_local $7 + (set_local $6 (f64.ne (get_local $1) (get_local $1) @@ -8353,7 +8353,7 @@ ) ) (if - (get_local $7) + (get_local $6) (return (f64.div (tee_local $0 @@ -8374,13 +8374,13 @@ (i64.const 1) ) ) - (get_local $4) + (get_local $7) ) (block (br_if $folding-inner0 (i64.eq (get_local $9) - (get_local $4) + (get_local $7) ) ) (return @@ -8391,16 +8391,16 @@ (set_local $2 (if (result i64) (i64.eqz - (get_local $3) + (get_local $4) ) (i64.shl (get_local $2) (i64.add (i64.sub (i64.const 0) - (tee_local $3 + (tee_local $4 (i64.sub - (get_local $3) + (get_local $4) (i64.clz (i64.shl (get_local $2) @@ -8422,22 +8422,22 @@ ) ) ) - (set_local $5 + (set_local $3 (if (result i64) (i64.eqz - (get_local $6) + (get_local $5) ) (i64.shl - (get_local $5) + (get_local $3) (i64.add (i64.sub (i64.const 0) - (tee_local $6 + (tee_local $5 (i64.sub - (get_local $6) + (get_local $5) (i64.clz (i64.shl - (get_local $5) + (get_local $3) (i64.const 12) ) ) @@ -8449,86 +8449,80 @@ ) (i64.or (i64.and - (get_local $5) + (get_local $3) (i64.const 4503599627370495) ) (i64.const 4503599627370496) ) ) ) - (block $break|0 - (loop $repeat|0 - (br_if $break|0 - (i64.le_s - (get_local $3) - (get_local $6) - ) + (loop $continue|0 + (if + (i64.gt_s + (get_local $4) + (get_local $5) ) - (if - (i64.eqz - (i64.shr_u - (tee_local $4 - (i64.sub + (block + (if + (i64.ge_u + (get_local $2) + (get_local $3) + ) + (block + (br_if $folding-inner0 + (i64.eq (get_local $2) - (get_local $5) + (get_local $3) ) ) - (i64.const 63) - ) - ) - (block - (br_if $folding-inner0 - (i64.eqz - (get_local $4) + (set_local $2 + (i64.sub + (get_local $2) + (get_local $3) + ) ) ) - (set_local $2 - (get_local $4) + ) + (set_local $2 + (i64.shl + (get_local $2) + (i64.const 1) ) ) - ) - (set_local $2 - (i64.shl - (get_local $2) - (i64.const 1) + (set_local $4 + (i64.sub + (get_local $4) + (i64.const 1) + ) ) + (br $continue|0) ) - (set_local $3 - (i64.sub - (get_local $3) - (i64.const 1) - ) - ) - (br $repeat|0) ) ) (if - (i64.eqz - (i64.shr_u - (tee_local $4 - (i64.sub - (get_local $2) - (get_local $5) - ) - ) - (i64.const 63) - ) + (i64.ge_u + (get_local $2) + (get_local $3) ) (block (br_if $folding-inner0 - (i64.eqz - (get_local $4) + (i64.eq + (get_local $2) + (get_local $3) ) ) (set_local $2 - (get_local $4) + (i64.sub + (get_local $2) + (get_local $3) + ) ) ) ) (set_local $2 (i64.shl (get_local $2) - (tee_local $4 + (tee_local $3 (i64.clz (i64.shl (get_local $2) @@ -8544,10 +8538,10 @@ (tee_local $2 (if (result i64) (i64.gt_s - (tee_local $3 + (tee_local $4 (i64.sub - (get_local $3) (get_local $4) + (get_local $3) ) ) (i64.const 0) @@ -8558,7 +8552,7 @@ (i64.const 4503599627370496) ) (i64.shl - (get_local $3) + (get_local $4) (i64.const 52) ) ) @@ -8567,7 +8561,7 @@ (i64.add (i64.sub (i64.const 0) - (get_local $3) + (get_local $4) ) (i64.const 1) ) @@ -8623,7 +8617,7 @@ (local $7 i32) (local $8 i32) (block $folding-inner0 - (set_local $4 + (set_local $3 (i32.and (i32.shr_u (tee_local $2 @@ -8639,7 +8633,7 @@ (set_local $6 (i32.and (i32.shr_u - (tee_local $5 + (tee_local $4 (i32.reinterpret/f32 (get_local $1) ) @@ -8657,29 +8651,29 @@ ) (if (i32.eqz - (tee_local $3 + (tee_local $5 (i32.eqz (tee_local $7 (i32.shl - (get_local $5) + (get_local $4) (i32.const 1) ) ) ) ) ) - (set_local $3 + (set_local $5 (i32.eq - (get_local $4) + (get_local $3) (i32.const 255) ) ) ) (if (i32.eqz - (get_local $3) + (get_local $5) ) - (set_local $3 + (set_local $5 (f32.ne (get_local $1) (get_local $1) @@ -8688,7 +8682,7 @@ ) (if (i32.and - (get_local $3) + (get_local $5) (i32.const 1) ) (return @@ -8705,7 +8699,7 @@ ) (if (i32.le_u - (tee_local $3 + (tee_local $5 (i32.shl (get_local $2) (i32.const 1) @@ -8716,7 +8710,7 @@ (block (br_if $folding-inner0 (i32.eq - (get_local $3) + (get_local $5) (get_local $7) ) ) @@ -8727,7 +8721,7 @@ ) (set_local $2 (if (result i32) - (get_local $4) + (get_local $3) (i32.or (i32.and (get_local $2) @@ -8739,9 +8733,9 @@ (get_local $2) (i32.sub (i32.const 1) - (tee_local $4 + (tee_local $3 (i32.sub - (get_local $4) + (get_local $3) (i32.clz (i32.shl (get_local $2) @@ -8754,18 +8748,18 @@ ) ) ) - (set_local $5 + (set_local $4 (if (result i32) (get_local $6) (i32.or (i32.and - (get_local $5) + (get_local $4) (i32.const 8388607) ) (i32.const 8388608) ) (i32.shl - (get_local $5) + (get_local $4) (i32.sub (i32.const 1) (tee_local $6 @@ -8773,7 +8767,7 @@ (get_local $6) (i32.clz (i32.shl - (get_local $5) + (get_local $4) (i32.const 9) ) ) @@ -8783,79 +8777,73 @@ ) ) ) - (block $break|0 - (loop $repeat|0 - (br_if $break|0 - (i32.le_s - (get_local $4) - (get_local $6) - ) + (loop $continue|0 + (if + (i32.gt_s + (get_local $3) + (get_local $6) ) - (if - (i32.eqz - (i32.shr_u - (tee_local $3 - (i32.sub + (block + (if + (i32.ge_u + (get_local $2) + (get_local $4) + ) + (block + (br_if $folding-inner0 + (i32.eq (get_local $2) - (get_local $5) + (get_local $4) ) ) - (i32.const 31) - ) - ) - (block - (br_if $folding-inner0 - (i32.eqz - (get_local $3) + (set_local $2 + (i32.sub + (get_local $2) + (get_local $4) + ) ) ) - (set_local $2 - (get_local $3) + ) + (set_local $2 + (i32.shl + (get_local $2) + (i32.const 1) ) ) - ) - (set_local $2 - (i32.shl - (get_local $2) - (i32.const 1) + (set_local $3 + (i32.sub + (get_local $3) + (i32.const 1) + ) ) + (br $continue|0) ) - (set_local $4 - (i32.sub - (get_local $4) - (i32.const 1) - ) - ) - (br $repeat|0) ) ) (if - (i32.eqz - (i32.shr_u - (tee_local $3 - (i32.sub - (get_local $2) - (get_local $5) - ) - ) - (i32.const 31) - ) + (i32.ge_u + (get_local $2) + (get_local $4) ) (block (br_if $folding-inner0 - (i32.eqz - (get_local $3) + (i32.eq + (get_local $2) + (get_local $4) ) ) (set_local $2 - (get_local $3) + (i32.sub + (get_local $2) + (get_local $4) + ) ) ) ) (set_local $2 (i32.shl (get_local $2) - (tee_local $3 + (tee_local $5 (i32.clz (i32.shl (get_local $2) @@ -8871,10 +8859,10 @@ (tee_local $2 (if (result i32) (i32.gt_s - (tee_local $4 + (tee_local $3 (i32.sub - (get_local $4) (get_local $3) + (get_local $5) ) ) (i32.const 0) @@ -8885,7 +8873,7 @@ (i32.const 8388608) ) (i32.shl - (get_local $4) + (get_local $3) (i32.const 23) ) ) @@ -8893,7 +8881,7 @@ (get_local $2) (i32.sub (i32.const 1) - (get_local $4) + (get_local $3) ) ) ) @@ -11754,7 +11742,7 @@ (call $~lib/env/abort (i32.const 0) (i32.const 40) - (i32.const 2022) + (i32.const 2018) (i32.const 24) ) (unreachable) @@ -11907,13 +11895,12 @@ (func $~lib/math/NativeMath.rem (; 139 ;) (; has Stack IR ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) (local $2 i64) (local $3 i64) - (local $4 i32) - (local $5 i64) + (local $4 i64) + (local $5 i32) (local $6 i64) (local $7 i32) - (local $8 i64) - (local $9 f64) - (local $10 i32) + (local $8 f64) + (local $9 i32) (set_local $3 (i64.and (i64.shr_u @@ -11927,10 +11914,10 @@ (i64.const 2047) ) ) - (set_local $5 + (set_local $6 (i64.and (i64.shr_u - (tee_local $6 + (tee_local $4 (i64.reinterpret/f64 (get_local $1) ) @@ -11940,7 +11927,7 @@ (i64.const 2047) ) ) - (set_local $10 + (set_local $9 (i32.wrap/i64 (i64.shr_u (get_local $2) @@ -11950,17 +11937,17 @@ ) (if (i32.eqz - (tee_local $4 + (tee_local $5 (i64.eq (i64.shl - (get_local $6) + (get_local $4) (i64.const 1) ) (i64.const 0) ) ) ) - (set_local $4 + (set_local $5 (i64.eq (get_local $3) (i64.const 2047) @@ -11969,16 +11956,16 @@ ) (if (i32.eqz - (get_local $4) + (get_local $5) ) - (set_local $4 + (set_local $5 (call $~lib/builtins/isNaN (get_local $1) ) ) ) (if - (get_local $4) + (get_local $5) (return (f64.div (tee_local $0 @@ -12037,22 +12024,22 @@ ) ) ) - (set_local $6 + (set_local $4 (if (result i64) (i64.eqz - (get_local $5) + (get_local $6) ) (i64.shl - (get_local $6) + (get_local $4) (i64.add (i64.sub (i64.const 0) - (tee_local $5 + (tee_local $6 (i64.sub - (get_local $5) + (get_local $6) (i64.clz (i64.shl - (get_local $6) + (get_local $4) (i64.const 12) ) ) @@ -12064,7 +12051,7 @@ ) (i64.or (i64.and - (get_local $6) + (get_local $4) (i64.const 4503599627370495) ) (i64.const 4503599627370496) @@ -12075,7 +12062,7 @@ (if (i64.lt_s (get_local $3) - (get_local $5) + (get_local $6) ) (block (br_if $break|0 @@ -12084,7 +12071,7 @@ (get_local $3) (i64.const 1) ) - (get_local $5) + (get_local $6) ) ) (return @@ -12092,76 +12079,66 @@ ) ) ) - (block $break|1 - (loop $repeat|1 - (br_if $break|1 - (i64.le_s - (get_local $3) - (get_local $5) - ) + (loop $continue|1 + (if + (i64.gt_s + (get_local $3) + (get_local $6) ) - (if - (i64.eq - (i64.shr_u - (tee_local $8 + (block + (if + (i64.ge_u + (get_local $2) + (get_local $4) + ) + (block + (set_local $2 (i64.sub (get_local $2) - (get_local $6) + (get_local $4) ) ) - (i64.const 63) - ) - (i64.const 0) - ) - (block - (set_local $2 - (get_local $8) - ) - (set_local $7 - (i32.add - (get_local $7) - (i32.const 1) + (set_local $7 + (i32.add + (get_local $7) + (i32.const 1) + ) ) ) ) - ) - (set_local $2 - (i64.shl - (get_local $2) - (i64.const 1) + (set_local $2 + (i64.shl + (get_local $2) + (i64.const 1) + ) ) - ) - (set_local $7 - (i32.shl - (get_local $7) - (i32.const 1) + (set_local $7 + (i32.shl + (get_local $7) + (i32.const 1) + ) ) - ) - (set_local $3 - (i64.sub - (get_local $3) - (i64.const 1) + (set_local $3 + (i64.sub + (get_local $3) + (i64.const 1) + ) ) + (br $continue|1) ) - (br $repeat|1) ) ) (if - (i64.eq - (i64.shr_u - (tee_local $8 - (i64.sub - (get_local $2) - (get_local $6) - ) - ) - (i64.const 63) - ) - (i64.const 0) + (i64.ge_u + (get_local $2) + (get_local $4) ) (block (set_local $2 - (get_local $8) + (i64.sub + (get_local $2) + (get_local $4) + ) ) (set_local $7 (i32.add @@ -12183,7 +12160,7 @@ (set_local $3 (i64.sub (get_local $3) - (tee_local $8 + (tee_local $4 (i64.clz (i64.shl (get_local $2) @@ -12196,7 +12173,7 @@ (set_local $2 (i64.shl (get_local $2) - (get_local $8) + (get_local $4) ) ) ) @@ -12207,7 +12184,7 @@ (get_local $1) ) ) - (set_local $9 + (set_local $8 (f64.add (tee_local $0 (f64.reinterpret/i64 @@ -12246,40 +12223,40 @@ ) (if (i32.eqz - (tee_local $4 + (tee_local $5 (i64.eq (get_local $3) - (get_local $5) + (get_local $6) ) ) ) (if - (tee_local $4 + (tee_local $5 (i64.eq (i64.add (get_local $3) (i64.const 1) ) - (get_local $5) + (get_local $6) ) ) (if (i32.eqz - (tee_local $4 + (tee_local $5 (f64.gt - (get_local $9) + (get_local $8) (get_local $1) ) ) ) (if - (tee_local $4 + (tee_local $5 (f64.eq - (get_local $9) + (get_local $8) (get_local $1) ) ) - (set_local $4 + (set_local $5 (i32.and (get_local $7) (i32.const 1) @@ -12290,7 +12267,7 @@ ) ) (if - (get_local $4) + (get_local $5) (set_local $0 (f64.sub (get_local $0) @@ -12299,7 +12276,7 @@ ) ) (if - (get_local $10) + (get_local $9) (set_local $0 (f64.neg (get_local $0) @@ -12340,10 +12317,10 @@ (i32.const 255) ) ) - (set_local $5 + (set_local $6 (i32.and (i32.shr_u - (tee_local $6 + (tee_local $5 (i32.reinterpret/f32 (get_local $1) ) @@ -12364,7 +12341,7 @@ (tee_local $4 (i32.eqz (i32.shl - (get_local $6) + (get_local $5) (i32.const 1) ) ) @@ -12441,26 +12418,26 @@ ) ) ) - (set_local $6 + (set_local $5 (if (result i32) - (get_local $5) + (get_local $6) (i32.or (i32.and - (get_local $6) + (get_local $5) (i32.const 8388607) ) (i32.const 8388608) ) (i32.shl - (get_local $6) + (get_local $5) (i32.sub (i32.const 1) - (tee_local $5 + (tee_local $6 (i32.sub - (get_local $5) + (get_local $6) (i32.clz (i32.shl - (get_local $6) + (get_local $5) (i32.const 9) ) ) @@ -12474,7 +12451,7 @@ (if (i32.lt_s (get_local $3) - (get_local $5) + (get_local $6) ) (block (br_if $break|0 @@ -12483,7 +12460,7 @@ (get_local $3) (i32.const 1) ) - (get_local $5) + (get_local $6) ) ) (return @@ -12491,74 +12468,66 @@ ) ) ) - (block $break|1 - (loop $repeat|1 - (br_if $break|1 - (i32.le_s - (get_local $3) - (get_local $5) - ) + (loop $continue|1 + (if + (i32.gt_s + (get_local $3) + (get_local $6) ) - (if - (i32.eqz - (i32.shr_u - (tee_local $4 + (block + (if + (i32.ge_u + (get_local $2) + (get_local $5) + ) + (block + (set_local $2 (i32.sub (get_local $2) - (get_local $6) + (get_local $5) ) ) - (i32.const 31) - ) - ) - (block - (set_local $2 - (get_local $4) - ) - (set_local $7 - (i32.add - (get_local $7) - (i32.const 1) + (set_local $7 + (i32.add + (get_local $7) + (i32.const 1) + ) ) ) ) - ) - (set_local $2 - (i32.shl - (get_local $2) - (i32.const 1) + (set_local $2 + (i32.shl + (get_local $2) + (i32.const 1) + ) ) - ) - (set_local $7 - (i32.shl - (get_local $7) - (i32.const 1) + (set_local $7 + (i32.shl + (get_local $7) + (i32.const 1) + ) ) - ) - (set_local $3 - (i32.sub - (get_local $3) - (i32.const 1) + (set_local $3 + (i32.sub + (get_local $3) + (i32.const 1) + ) ) + (br $continue|1) ) - (br $repeat|1) ) ) (if - (i32.eqz - (i32.shr_u - (tee_local $4 - (i32.sub - (get_local $2) - (get_local $6) - ) - ) - (i32.const 31) - ) + (i32.ge_u + (get_local $2) + (get_local $5) ) (block (set_local $2 - (get_local $4) + (i32.sub + (get_local $2) + (get_local $5) + ) ) (set_local $7 (i32.add @@ -12640,7 +12609,7 @@ (tee_local $4 (i32.eq (get_local $3) - (get_local $5) + (get_local $6) ) ) ) @@ -12651,7 +12620,7 @@ (get_local $3) (i32.const 1) ) - (get_local $5) + (get_local $6) ) ) (if diff --git a/tests/compiler/std/math.untouched.wat b/tests/compiler/std/math.untouched.wat index abe2c9a0..a82f4153 100644 --- a/tests/compiler/std/math.untouched.wat +++ b/tests/compiler/std/math.untouched.wat @@ -9715,7 +9715,6 @@ (local $8 i32) (local $9 i64) (local $10 i64) - (local $11 i64) (set_local $2 (i64.reinterpret/f64 (get_local $0) @@ -9927,79 +9926,68 @@ ) ) (block $break|0 - (loop $repeat|0 - (br_if $break|0 - (i32.eqz - (i64.gt_s - (get_local $4) - (get_local $5) - ) + (loop $continue|0 + (if + (i64.gt_s + (get_local $4) + (get_local $5) ) - ) - (block - (set_local $10 - (i64.sub - (get_local $2) - (get_local $3) - ) - ) - (if - (i64.eqz - (i64.shr_u - (get_local $10) - (i64.const 63) - ) - ) + (block (block (if - (i64.eqz - (get_local $10) + (i64.ge_u + (get_local $2) + (get_local $3) ) - (return - (f64.mul - (f64.const 0) - (get_local $0) + (block + (if + (i64.eq + (get_local $2) + (get_local $3) + ) + (return + (f64.mul + (f64.const 0) + (get_local $0) + ) + ) + ) + (set_local $2 + (i64.sub + (get_local $2) + (get_local $3) + ) ) ) ) (set_local $2 - (get_local $10) + (i64.shl + (get_local $2) + (i64.const 1) + ) + ) + (set_local $4 + (i64.sub + (get_local $4) + (i64.const 1) + ) ) ) - ) - (set_local $2 - (i64.shl - (get_local $2) - (i64.const 1) - ) + (br $continue|0) ) ) - (set_local $4 - (i64.sub - (get_local $4) - (i64.const 1) - ) - ) - (br $repeat|0) - ) - ) - (set_local $10 - (i64.sub - (get_local $2) - (get_local $3) ) ) (if - (i64.eqz - (i64.shr_u - (get_local $10) - (i64.const 63) - ) + (i64.ge_u + (get_local $2) + (get_local $3) ) (block (if - (i64.eqz - (get_local $10) + (i64.eq + (get_local $2) + (get_local $3) ) (return (f64.mul @@ -10009,11 +9997,14 @@ ) ) (set_local $2 - (get_local $10) + (i64.sub + (get_local $2) + (get_local $3) + ) ) ) ) - (set_local $11 + (set_local $10 (i64.clz (i64.shl (get_local $2) @@ -10024,13 +10015,13 @@ (set_local $4 (i64.sub (get_local $4) - (get_local $11) + (get_local $10) ) ) (set_local $2 (i64.shl (get_local $2) - (get_local $11) + (get_local $10) ) ) (if @@ -10128,7 +10119,6 @@ (local $8 i32) (local $9 i32) (local $10 i32) - (local $11 i32) (set_local $2 (i32.reinterpret/f32 (get_local $0) @@ -10340,79 +10330,68 @@ ) ) (block $break|0 - (loop $repeat|0 - (br_if $break|0 - (i32.eqz - (i32.gt_s - (get_local $4) - (get_local $5) - ) + (loop $continue|0 + (if + (i32.gt_s + (get_local $4) + (get_local $5) ) - ) - (block - (set_local $10 - (i32.sub - (get_local $2) - (get_local $3) - ) - ) - (if - (i32.eqz - (i32.shr_u - (get_local $10) - (i32.const 31) - ) - ) + (block (block (if - (i32.eqz - (get_local $10) + (i32.ge_u + (get_local $2) + (get_local $3) ) - (return - (f32.mul - (f32.const 0) - (get_local $0) + (block + (if + (i32.eq + (get_local $2) + (get_local $3) + ) + (return + (f32.mul + (f32.const 0) + (get_local $0) + ) + ) + ) + (set_local $2 + (i32.sub + (get_local $2) + (get_local $3) + ) ) ) ) (set_local $2 - (get_local $10) + (i32.shl + (get_local $2) + (i32.const 1) + ) + ) + (set_local $4 + (i32.sub + (get_local $4) + (i32.const 1) + ) ) ) - ) - (set_local $2 - (i32.shl - (get_local $2) - (i32.const 1) - ) + (br $continue|0) ) ) - (set_local $4 - (i32.sub - (get_local $4) - (i32.const 1) - ) - ) - (br $repeat|0) - ) - ) - (set_local $10 - (i32.sub - (get_local $2) - (get_local $3) ) ) (if - (i32.eqz - (i32.shr_u - (get_local $10) - (i32.const 31) - ) + (i32.ge_u + (get_local $2) + (get_local $3) ) (block (if - (i32.eqz - (get_local $10) + (i32.eq + (get_local $2) + (get_local $3) ) (return (f32.mul @@ -10422,11 +10401,14 @@ ) ) (set_local $2 - (get_local $10) + (i32.sub + (get_local $2) + (get_local $3) + ) ) ) ) - (set_local $11 + (set_local $10 (i32.clz (i32.shl (get_local $2) @@ -10437,13 +10419,13 @@ (set_local $4 (i32.sub (get_local $4) - (get_local $11) + (get_local $10) ) ) (set_local $2 (i32.shl (get_local $2) - (get_local $11) + (get_local $10) ) ) (if @@ -13633,7 +13615,7 @@ (call $~lib/env/abort (i32.const 0) (i32.const 40) - (i32.const 2022) + (i32.const 2018) (i32.const 24) ) (unreachable) @@ -13820,8 +13802,7 @@ (local $8 i64) (local $9 i32) (local $10 i64) - (local $11 i64) - (local $12 f64) + (local $11 f64) (set_local $2 (i64.reinterpret/f64 (get_local $0) @@ -14038,81 +14019,69 @@ ) ) (block $break|1 - (loop $repeat|1 - (br_if $break|1 - (i32.eqz - (i64.gt_s - (get_local $4) - (get_local $5) - ) + (loop $continue|1 + (if + (i64.gt_s + (get_local $4) + (get_local $5) ) - ) - (block - (set_local $10 - (i64.sub - (get_local $8) - (get_local $3) - ) - ) - (if - (i64.eq - (i64.shr_u - (get_local $10) - (i64.const 63) - ) - (i64.const 0) - ) + (block (block + (if + (i64.ge_u + (get_local $8) + (get_local $3) + ) + (block + (set_local $8 + (i64.sub + (get_local $8) + (get_local $3) + ) + ) + (set_local $9 + (i32.add + (get_local $9) + (i32.const 1) + ) + ) + ) + ) (set_local $8 - (get_local $10) + (i64.shl + (get_local $8) + (i64.const 1) + ) ) (set_local $9 - (i32.add + (i32.shl (get_local $9) (i32.const 1) ) ) + (set_local $4 + (i64.sub + (get_local $4) + (i64.const 1) + ) + ) ) - ) - (set_local $8 - (i64.shl - (get_local $8) - (i64.const 1) - ) - ) - (set_local $9 - (i32.shl - (get_local $9) - (i32.const 1) - ) + (br $continue|1) ) ) - (set_local $4 - (i64.sub - (get_local $4) - (i64.const 1) - ) - ) - (br $repeat|1) - ) - ) - (set_local $10 - (i64.sub - (get_local $8) - (get_local $3) ) ) (if - (i64.eq - (i64.shr_u - (get_local $10) - (i64.const 63) - ) - (i64.const 0) + (i64.ge_u + (get_local $8) + (get_local $3) ) (block (set_local $8 - (get_local $10) + (i64.sub + (get_local $8) + (get_local $3) + ) ) (set_local $9 (i32.add @@ -14131,7 +14100,7 @@ (i64.const -60) ) (block - (set_local $11 + (set_local $10 (i64.clz (i64.shl (get_local $8) @@ -14142,13 +14111,13 @@ (set_local $4 (i64.sub (get_local $4) - (get_local $11) + (get_local $10) ) ) (set_local $8 (i64.shl (get_local $8) - (get_local $11) + (get_local $10) ) ) ) @@ -14205,7 +14174,7 @@ (get_local $1) ) ) - (set_local $12 + (set_local $11 (f64.add (get_local $0) (get_local $0) @@ -14233,7 +14202,7 @@ (if (result i32) (tee_local $7 (f64.gt - (get_local $12) + (get_local $11) (get_local $1) ) ) @@ -14241,7 +14210,7 @@ (if (result i32) (tee_local $7 (f64.eq - (get_local $12) + (get_local $11) (get_local $1) ) ) @@ -14290,8 +14259,7 @@ (local $7 i32) (local $8 i32) (local $9 i32) - (local $10 i32) - (local $11 f32) + (local $10 f32) (set_local $2 (i32.reinterpret/f32 (get_local $0) @@ -14506,81 +14474,69 @@ ) ) (block $break|1 - (loop $repeat|1 - (br_if $break|1 - (i32.eqz - (i32.gt_s - (get_local $4) - (get_local $5) - ) + (loop $continue|1 + (if + (i32.gt_s + (get_local $4) + (get_local $5) ) - ) - (block - (set_local $8 - (i32.sub - (get_local $7) - (get_local $3) - ) - ) - (if - (i32.eq - (i32.shr_u - (get_local $8) - (i32.const 31) - ) - (i32.const 0) - ) + (block (block + (if + (i32.ge_u + (get_local $7) + (get_local $3) + ) + (block + (set_local $7 + (i32.sub + (get_local $7) + (get_local $3) + ) + ) + (set_local $9 + (i32.add + (get_local $9) + (i32.const 1) + ) + ) + ) + ) (set_local $7 - (get_local $8) + (i32.shl + (get_local $7) + (i32.const 1) + ) ) (set_local $9 - (i32.add + (i32.shl (get_local $9) (i32.const 1) ) ) + (set_local $4 + (i32.sub + (get_local $4) + (i32.const 1) + ) + ) ) - ) - (set_local $7 - (i32.shl - (get_local $7) - (i32.const 1) - ) - ) - (set_local $9 - (i32.shl - (get_local $9) - (i32.const 1) - ) + (br $continue|1) ) ) - (set_local $4 - (i32.sub - (get_local $4) - (i32.const 1) - ) - ) - (br $repeat|1) - ) - ) - (set_local $8 - (i32.sub - (get_local $7) - (get_local $3) ) ) (if - (i32.eq - (i32.shr_u - (get_local $8) - (i32.const 31) - ) - (i32.const 0) + (i32.ge_u + (get_local $7) + (get_local $3) ) (block (set_local $7 - (get_local $8) + (i32.sub + (get_local $7) + (get_local $3) + ) ) (set_local $9 (i32.add @@ -14599,7 +14555,7 @@ (i32.const -30) ) (block - (set_local $10 + (set_local $8 (i32.clz (i32.shl (get_local $7) @@ -14610,13 +14566,13 @@ (set_local $4 (i32.sub (get_local $4) - (get_local $10) + (get_local $8) ) ) (set_local $7 (i32.shl (get_local $7) - (get_local $10) + (get_local $8) ) ) ) @@ -14673,7 +14629,7 @@ (get_local $1) ) ) - (set_local $11 + (set_local $10 (f32.add (get_local $0) (get_local $0) @@ -14701,7 +14657,7 @@ (if (result i32) (tee_local $8 (f32.gt - (get_local $11) + (get_local $10) (get_local $1) ) ) @@ -14709,7 +14665,7 @@ (if (result i32) (tee_local $8 (f32.eq - (get_local $11) + (get_local $10) (get_local $1) ) ) diff --git a/tests/compiler/std/mod.optimized.wat b/tests/compiler/std/mod.optimized.wat index 5b859c44..bc2476de 100644 --- a/tests/compiler/std/mod.optimized.wat +++ b/tests/compiler/std/mod.optimized.wat @@ -24,12 +24,12 @@ (local $3 i64) (local $4 i64) (local $5 i64) - (local $6 i64) - (local $7 i32) + (local $6 i32) + (local $7 i64) (local $8 i64) (local $9 i64) (block $folding-inner0 - (set_local $3 + (set_local $4 (i64.and (i64.shr_u (tee_local $2 @@ -42,10 +42,10 @@ (i64.const 2047) ) ) - (set_local $6 + (set_local $5 (i64.and (i64.shr_u - (tee_local $5 + (tee_local $3 (i64.reinterpret/f64 (get_local $1) ) @@ -63,11 +63,11 @@ ) (if (i32.eqz - (tee_local $7 + (tee_local $6 (i64.eq - (tee_local $4 + (tee_local $7 (i64.shl - (get_local $5) + (get_local $3) (i64.const 1) ) ) @@ -75,18 +75,18 @@ ) ) ) - (set_local $7 + (set_local $6 (i64.eq - (get_local $3) + (get_local $4) (i64.const 2047) ) ) ) (if (i32.eqz - (get_local $7) + (get_local $6) ) - (set_local $7 + (set_local $6 (f64.ne (get_local $1) (get_local $1) @@ -94,7 +94,7 @@ ) ) (if - (get_local $7) + (get_local $6) (return (f64.div (tee_local $0 @@ -115,13 +115,13 @@ (i64.const 1) ) ) - (get_local $4) + (get_local $7) ) (block (br_if $folding-inner0 (i64.eq (get_local $9) - (get_local $4) + (get_local $7) ) ) (return @@ -132,16 +132,16 @@ (set_local $2 (if (result i64) (i64.eqz - (get_local $3) + (get_local $4) ) (i64.shl (get_local $2) (i64.add (i64.sub (i64.const 0) - (tee_local $3 + (tee_local $4 (i64.sub - (get_local $3) + (get_local $4) (i64.clz (i64.shl (get_local $2) @@ -163,22 +163,22 @@ ) ) ) - (set_local $5 + (set_local $3 (if (result i64) (i64.eqz - (get_local $6) + (get_local $5) ) (i64.shl - (get_local $5) + (get_local $3) (i64.add (i64.sub (i64.const 0) - (tee_local $6 + (tee_local $5 (i64.sub - (get_local $6) + (get_local $5) (i64.clz (i64.shl - (get_local $5) + (get_local $3) (i64.const 12) ) ) @@ -190,86 +190,80 @@ ) (i64.or (i64.and - (get_local $5) + (get_local $3) (i64.const 4503599627370495) ) (i64.const 4503599627370496) ) ) ) - (block $break|0 - (loop $repeat|0 - (br_if $break|0 - (i64.le_s - (get_local $3) - (get_local $6) - ) + (loop $continue|0 + (if + (i64.gt_s + (get_local $4) + (get_local $5) ) - (if - (i64.eqz - (i64.shr_u - (tee_local $4 - (i64.sub + (block + (if + (i64.ge_u + (get_local $2) + (get_local $3) + ) + (block + (br_if $folding-inner0 + (i64.eq (get_local $2) - (get_local $5) + (get_local $3) ) ) - (i64.const 63) - ) - ) - (block - (br_if $folding-inner0 - (i64.eqz - (get_local $4) + (set_local $2 + (i64.sub + (get_local $2) + (get_local $3) + ) ) ) - (set_local $2 - (get_local $4) + ) + (set_local $2 + (i64.shl + (get_local $2) + (i64.const 1) ) ) - ) - (set_local $2 - (i64.shl - (get_local $2) - (i64.const 1) + (set_local $4 + (i64.sub + (get_local $4) + (i64.const 1) + ) ) + (br $continue|0) ) - (set_local $3 - (i64.sub - (get_local $3) - (i64.const 1) - ) - ) - (br $repeat|0) ) ) (if - (i64.eqz - (i64.shr_u - (tee_local $4 - (i64.sub - (get_local $2) - (get_local $5) - ) - ) - (i64.const 63) - ) + (i64.ge_u + (get_local $2) + (get_local $3) ) (block (br_if $folding-inner0 - (i64.eqz - (get_local $4) + (i64.eq + (get_local $2) + (get_local $3) ) ) (set_local $2 - (get_local $4) + (i64.sub + (get_local $2) + (get_local $3) + ) ) ) ) (set_local $2 (i64.shl (get_local $2) - (tee_local $4 + (tee_local $3 (i64.clz (i64.shl (get_local $2) @@ -285,10 +279,10 @@ (tee_local $2 (if (result i64) (i64.gt_s - (tee_local $3 + (tee_local $4 (i64.sub - (get_local $3) (get_local $4) + (get_local $3) ) ) (i64.const 0) @@ -299,7 +293,7 @@ (i64.const 4503599627370496) ) (i64.shl - (get_local $3) + (get_local $4) (i64.const 52) ) ) @@ -308,7 +302,7 @@ (i64.add (i64.sub (i64.const 0) - (get_local $3) + (get_local $4) ) (i64.const 1) ) @@ -403,7 +397,7 @@ (local $7 i32) (local $8 i32) (block $folding-inner0 - (set_local $4 + (set_local $3 (i32.and (i32.shr_u (tee_local $2 @@ -419,7 +413,7 @@ (set_local $6 (i32.and (i32.shr_u - (tee_local $5 + (tee_local $4 (i32.reinterpret/f32 (get_local $1) ) @@ -437,29 +431,29 @@ ) (if (i32.eqz - (tee_local $3 + (tee_local $5 (i32.eqz (tee_local $7 (i32.shl - (get_local $5) + (get_local $4) (i32.const 1) ) ) ) ) ) - (set_local $3 + (set_local $5 (i32.eq - (get_local $4) + (get_local $3) (i32.const 255) ) ) ) (if (i32.eqz - (get_local $3) + (get_local $5) ) - (set_local $3 + (set_local $5 (f32.ne (get_local $1) (get_local $1) @@ -468,7 +462,7 @@ ) (if (i32.and - (get_local $3) + (get_local $5) (i32.const 1) ) (return @@ -485,7 +479,7 @@ ) (if (i32.le_u - (tee_local $3 + (tee_local $5 (i32.shl (get_local $2) (i32.const 1) @@ -496,7 +490,7 @@ (block (br_if $folding-inner0 (i32.eq - (get_local $3) + (get_local $5) (get_local $7) ) ) @@ -507,7 +501,7 @@ ) (set_local $2 (if (result i32) - (get_local $4) + (get_local $3) (i32.or (i32.and (get_local $2) @@ -519,9 +513,9 @@ (get_local $2) (i32.sub (i32.const 1) - (tee_local $4 + (tee_local $3 (i32.sub - (get_local $4) + (get_local $3) (i32.clz (i32.shl (get_local $2) @@ -534,18 +528,18 @@ ) ) ) - (set_local $5 + (set_local $4 (if (result i32) (get_local $6) (i32.or (i32.and - (get_local $5) + (get_local $4) (i32.const 8388607) ) (i32.const 8388608) ) (i32.shl - (get_local $5) + (get_local $4) (i32.sub (i32.const 1) (tee_local $6 @@ -553,7 +547,7 @@ (get_local $6) (i32.clz (i32.shl - (get_local $5) + (get_local $4) (i32.const 9) ) ) @@ -563,79 +557,73 @@ ) ) ) - (block $break|0 - (loop $repeat|0 - (br_if $break|0 - (i32.le_s - (get_local $4) - (get_local $6) - ) + (loop $continue|0 + (if + (i32.gt_s + (get_local $3) + (get_local $6) ) - (if - (i32.eqz - (i32.shr_u - (tee_local $3 - (i32.sub + (block + (if + (i32.ge_u + (get_local $2) + (get_local $4) + ) + (block + (br_if $folding-inner0 + (i32.eq (get_local $2) - (get_local $5) + (get_local $4) ) ) - (i32.const 31) - ) - ) - (block - (br_if $folding-inner0 - (i32.eqz - (get_local $3) + (set_local $2 + (i32.sub + (get_local $2) + (get_local $4) + ) ) ) - (set_local $2 - (get_local $3) + ) + (set_local $2 + (i32.shl + (get_local $2) + (i32.const 1) ) ) - ) - (set_local $2 - (i32.shl - (get_local $2) - (i32.const 1) + (set_local $3 + (i32.sub + (get_local $3) + (i32.const 1) + ) ) + (br $continue|0) ) - (set_local $4 - (i32.sub - (get_local $4) - (i32.const 1) - ) - ) - (br $repeat|0) ) ) (if - (i32.eqz - (i32.shr_u - (tee_local $3 - (i32.sub - (get_local $2) - (get_local $5) - ) - ) - (i32.const 31) - ) + (i32.ge_u + (get_local $2) + (get_local $4) ) (block (br_if $folding-inner0 - (i32.eqz - (get_local $3) + (i32.eq + (get_local $2) + (get_local $4) ) ) (set_local $2 - (get_local $3) + (i32.sub + (get_local $2) + (get_local $4) + ) ) ) ) (set_local $2 (i32.shl (get_local $2) - (tee_local $3 + (tee_local $5 (i32.clz (i32.shl (get_local $2) @@ -651,10 +639,10 @@ (tee_local $2 (if (result i32) (i32.gt_s - (tee_local $4 + (tee_local $3 (i32.sub - (get_local $4) (get_local $3) + (get_local $5) ) ) (i32.const 0) @@ -665,7 +653,7 @@ (i32.const 8388608) ) (i32.shl - (get_local $4) + (get_local $3) (i32.const 23) ) ) @@ -673,7 +661,7 @@ (get_local $2) (i32.sub (i32.const 1) - (get_local $4) + (get_local $3) ) ) ) diff --git a/tests/compiler/std/mod.untouched.wat b/tests/compiler/std/mod.untouched.wat index b682dd06..0d6276e5 100644 --- a/tests/compiler/std/mod.untouched.wat +++ b/tests/compiler/std/mod.untouched.wat @@ -33,7 +33,6 @@ (local $8 i32) (local $9 i64) (local $10 i64) - (local $11 i64) (set_local $2 (i64.reinterpret/f64 (get_local $0) @@ -245,79 +244,68 @@ ) ) (block $break|0 - (loop $repeat|0 - (br_if $break|0 - (i32.eqz - (i64.gt_s - (get_local $4) - (get_local $5) - ) + (loop $continue|0 + (if + (i64.gt_s + (get_local $4) + (get_local $5) ) - ) - (block - (set_local $10 - (i64.sub - (get_local $2) - (get_local $3) - ) - ) - (if - (i64.eqz - (i64.shr_u - (get_local $10) - (i64.const 63) - ) - ) + (block (block (if - (i64.eqz - (get_local $10) + (i64.ge_u + (get_local $2) + (get_local $3) ) - (return - (f64.mul - (f64.const 0) - (get_local $0) + (block + (if + (i64.eq + (get_local $2) + (get_local $3) + ) + (return + (f64.mul + (f64.const 0) + (get_local $0) + ) + ) + ) + (set_local $2 + (i64.sub + (get_local $2) + (get_local $3) + ) ) ) ) (set_local $2 - (get_local $10) + (i64.shl + (get_local $2) + (i64.const 1) + ) + ) + (set_local $4 + (i64.sub + (get_local $4) + (i64.const 1) + ) ) ) - ) - (set_local $2 - (i64.shl - (get_local $2) - (i64.const 1) - ) + (br $continue|0) ) ) - (set_local $4 - (i64.sub - (get_local $4) - (i64.const 1) - ) - ) - (br $repeat|0) - ) - ) - (set_local $10 - (i64.sub - (get_local $2) - (get_local $3) ) ) (if - (i64.eqz - (i64.shr_u - (get_local $10) - (i64.const 63) - ) + (i64.ge_u + (get_local $2) + (get_local $3) ) (block (if - (i64.eqz - (get_local $10) + (i64.eq + (get_local $2) + (get_local $3) ) (return (f64.mul @@ -327,11 +315,14 @@ ) ) (set_local $2 - (get_local $10) + (i64.sub + (get_local $2) + (get_local $3) + ) ) ) ) - (set_local $11 + (set_local $10 (i64.clz (i64.shl (get_local $2) @@ -342,13 +333,13 @@ (set_local $4 (i64.sub (get_local $4) - (get_local $11) + (get_local $10) ) ) (set_local $2 (i64.shl (get_local $2) - (get_local $11) + (get_local $10) ) ) (if @@ -484,7 +475,6 @@ (local $8 i32) (local $9 i32) (local $10 i32) - (local $11 i32) (set_local $2 (i32.reinterpret/f32 (get_local $0) @@ -696,79 +686,68 @@ ) ) (block $break|0 - (loop $repeat|0 - (br_if $break|0 - (i32.eqz - (i32.gt_s - (get_local $4) - (get_local $5) - ) + (loop $continue|0 + (if + (i32.gt_s + (get_local $4) + (get_local $5) ) - ) - (block - (set_local $10 - (i32.sub - (get_local $2) - (get_local $3) - ) - ) - (if - (i32.eqz - (i32.shr_u - (get_local $10) - (i32.const 31) - ) - ) + (block (block (if - (i32.eqz - (get_local $10) + (i32.ge_u + (get_local $2) + (get_local $3) ) - (return - (f32.mul - (f32.const 0) - (get_local $0) + (block + (if + (i32.eq + (get_local $2) + (get_local $3) + ) + (return + (f32.mul + (f32.const 0) + (get_local $0) + ) + ) + ) + (set_local $2 + (i32.sub + (get_local $2) + (get_local $3) + ) ) ) ) (set_local $2 - (get_local $10) + (i32.shl + (get_local $2) + (i32.const 1) + ) + ) + (set_local $4 + (i32.sub + (get_local $4) + (i32.const 1) + ) ) ) - ) - (set_local $2 - (i32.shl - (get_local $2) - (i32.const 1) - ) + (br $continue|0) ) ) - (set_local $4 - (i32.sub - (get_local $4) - (i32.const 1) - ) - ) - (br $repeat|0) - ) - ) - (set_local $10 - (i32.sub - (get_local $2) - (get_local $3) ) ) (if - (i32.eqz - (i32.shr_u - (get_local $10) - (i32.const 31) - ) + (i32.ge_u + (get_local $2) + (get_local $3) ) (block (if - (i32.eqz - (get_local $10) + (i32.eq + (get_local $2) + (get_local $3) ) (return (f32.mul @@ -778,11 +757,14 @@ ) ) (set_local $2 - (get_local $10) + (i32.sub + (get_local $2) + (get_local $3) + ) ) ) ) - (set_local $11 + (set_local $10 (i32.clz (i32.shl (get_local $2) @@ -793,13 +775,13 @@ (set_local $4 (i32.sub (get_local $4) - (get_local $11) + (get_local $10) ) ) (set_local $2 (i32.shl (get_local $2) - (get_local $11) + (get_local $10) ) ) (if