diff --git a/std/assembly/math.ts b/std/assembly/math.ts index 62bc20fdd6..9e4dfd9573 100644 --- a/std/assembly/math.ts +++ b/std/assembly/math.ts @@ -42,6 +42,7 @@ function R(z: f64): f64 { // Rational approximation of (asin(x)-x)/x^3 return p / q; } +/** @internal */ // @ts-ignore: decorator @inline function expo2(x: f64): f64 { // exp(x)/2 for x >= log(DBL_MAX) @@ -52,6 +53,27 @@ function expo2(x: f64): f64 { // exp(x)/2 for x >= log(DBL_MAX) return NativeMath.exp(x - kln2) * scale * scale; } +/** @internal */ +function dtoi32(x: f64): i32 { + if (ASC_SHRINK_LEVEL > 0) { + const inv32 = 1.0 / 4294967296; + return (x - 4294967296 * floor(x * inv32)); + } else { + let result = 0; + let u = reinterpret(x); + let e = (u >> 52) & 0x7ff; + if (e <= 1023 + 30) { + result = x; + } else if (e <= 1023 + 30 + 53) { + let v = (u & ((1 << 52) - 1)) | (1 << 52); + v = v << e - 1023 - 52 + 32; + result = (v >> 32); + result = select(-result, result, u >> 63); + } + return result; + } +} + // @ts-ignore: decorator @lazy var random_seeded = false; @@ -398,9 +420,7 @@ export namespace NativeMath { * For emulate JS conversion behavior and avoid trapping from wasm we should modulate by MAX_INT * our float-point arguments before actual convertion to integers. */ - return builtin_clz( - (x - 4294967296 * builtin_floor(x * (1.0 / 4294967296))) - ); + return builtin_clz(dtoi32(x)); } export function cos(x: f64): f64 { // TODO @@ -599,11 +619,7 @@ export namespace NativeMath { * our float-point arguments before actual convertion to integers. */ if (!isFinite(x + y)) return 0; - const inv32 = 1.0 / 4294967296; - return ( - (x - 4294967296 * builtin_floor(x * inv32)) * - (y - 4294967296 * builtin_floor(y * inv32)) - ); + return dtoi32(x) * dtoi32(y); } export function log(x: f64): f64 { // see: musl/src/math/log.c and SUN COPYRIGHT NOTICE above @@ -1700,9 +1716,7 @@ export namespace NativeMathf { export function clz32(x: f32): f32 { if (!isFinite(x)) return 32; - return builtin_clz( - (x - 4294967296 * builtin_floor(x * (1.0 / 4294967296))) - ); + return builtin_clz(dtoi32(x)); } export function cos(x: f32): f32 { // see: musl/src/math/cosf.c @@ -1927,11 +1941,7 @@ export namespace NativeMathf { * our float-point arguments before actual convertion to integers. */ if (!isFinite(x + y)) return 0; - const inv32 = 1.0 / 4294967296; - return ( - (x - 4294967296 * builtin_floor(x * inv32)) * - (y - 4294967296 * builtin_floor(y * inv32)) - ); + return (dtoi32(x) * dtoi32(y)); } export function log(x: f32): f32 { // see: musl/src/math/logf.c and SUN COPYRIGHT NOTICE above diff --git a/tests/compiler/std/array.optimized.wat b/tests/compiler/std/array.optimized.wat index 6881bb0567..98dd148e80 100644 --- a/tests/compiler/std/array.optimized.wat +++ b/tests/compiler/std/array.optimized.wat @@ -4156,7 +4156,7 @@ if i32.const 0 i32.const 3160 - i32.const 1020 + i32.const 1036 i32.const 4 call $~lib/builtins/abort unreachable @@ -5709,7 +5709,7 @@ if i32.const 3936 i32.const 3160 - i32.const 1029 + i32.const 1045 i32.const 24 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/array.untouched.wat b/tests/compiler/std/array.untouched.wat index c99857cfe3..1c885b2079 100644 --- a/tests/compiler/std/array.untouched.wat +++ b/tests/compiler/std/array.untouched.wat @@ -6534,7 +6534,7 @@ if i32.const 0 i32.const 3160 - i32.const 1020 + i32.const 1036 i32.const 4 call $~lib/builtins/abort unreachable @@ -8842,7 +8842,7 @@ if i32.const 3936 i32.const 3160 - i32.const 1029 + i32.const 1045 i32.const 24 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/libm.optimized.wat b/tests/compiler/std/libm.optimized.wat index 674c46355b..33ec020d05 100644 --- a/tests/compiler/std/libm.optimized.wat +++ b/tests/compiler/std/libm.optimized.wat @@ -1621,14 +1621,7 @@ f64.const 0 f64.eq ) - (func $~lib/math/NativeMath.clz32 (; 26 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) - local.get $0 - call $~lib/number/isFinite - i32.eqz - if - f64.const 32 - return - end + (func $~lib/math/dtoi32 (; 26 ;) (type $FUNCSIG$id) (param $0 f64) (result i32) local.get $0 f64.const 4294967296 local.get $0 @@ -1639,12 +1632,20 @@ f64.sub i64.trunc_f64_s i32.wrap_i64 - i32.clz - f64.convert_i32_s ) (func $../../lib/libm/assembly/libm/clz32 (; 27 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) - local.get $0 - call $~lib/math/NativeMath.clz32 + block $__inlined_func$~lib/math/NativeMath.clz32 (result f64) + f64.const 32 + local.get $0 + call $~lib/number/isFinite + i32.eqz + br_if $__inlined_func$~lib/math/NativeMath.clz32 + drop + local.get $0 + call $~lib/math/dtoi32 + i32.clz + f64.convert_i32_s + end ) (func $../../lib/libm/assembly/libm/cos (; 28 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) local.get $0 @@ -2412,49 +2413,29 @@ local.get $1 call $~lib/math/NativeMath.hypot ) - (func $~lib/math/NativeMath.imul (; 40 ;) (type $FUNCSIG$ddd) (param $0 f64) (param $1 f64) (result f64) - local.get $0 - local.get $1 - f64.add - call $~lib/number/isFinite - i32.eqz - if + (func $../../lib/libm/assembly/libm/imul (; 40 ;) (type $FUNCSIG$ddd) (param $0 f64) (param $1 f64) (result f64) + block $__inlined_func$~lib/math/NativeMath.imul (result f64) f64.const 0 - return + local.get $0 + local.get $1 + f64.add + call $~lib/number/isFinite + i32.eqz + br_if $__inlined_func$~lib/math/NativeMath.imul + drop + local.get $0 + call $~lib/math/dtoi32 + local.get $1 + call $~lib/math/dtoi32 + i32.mul + f64.convert_i32_s end - local.get $0 - f64.const 4294967296 - local.get $0 - f64.const 2.3283064365386963e-10 - f64.mul - f64.floor - f64.mul - f64.sub - i64.trunc_f64_s - i32.wrap_i64 - local.get $1 - f64.const 4294967296 - local.get $1 - f64.const 2.3283064365386963e-10 - f64.mul - f64.floor - f64.mul - f64.sub - i64.trunc_f64_s - i32.wrap_i64 - i32.mul - f64.convert_i32_s ) - (func $../../lib/libm/assembly/libm/imul (; 41 ;) (type $FUNCSIG$ddd) (param $0 f64) (param $1 f64) (result f64) - local.get $0 - local.get $1 - call $~lib/math/NativeMath.imul - ) - (func $../../lib/libm/assembly/libm/log (; 42 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $../../lib/libm/assembly/libm/log (; 41 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.log ) - (func $~lib/math/NativeMath.log10 (; 43 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.log10 (; 42 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) (local $1 f64) (local $2 i32) (local $3 i64) @@ -2658,15 +2639,15 @@ local.get $1 f64.add ) - (func $../../lib/libm/assembly/libm/log10 (; 44 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $../../lib/libm/assembly/libm/log10 (; 43 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.log10 ) - (func $../../lib/libm/assembly/libm/log1p (; 45 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $../../lib/libm/assembly/libm/log1p (; 44 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.log1p ) - (func $~lib/math/NativeMath.log2 (; 46 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.log2 (; 45 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) (local $1 f64) (local $2 i32) (local $3 i64) @@ -2863,21 +2844,21 @@ local.get $1 f64.add ) - (func $../../lib/libm/assembly/libm/log2 (; 47 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $../../lib/libm/assembly/libm/log2 (; 46 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.log2 ) - (func $../../lib/libm/assembly/libm/max (; 48 ;) (type $FUNCSIG$ddd) (param $0 f64) (param $1 f64) (result f64) + (func $../../lib/libm/assembly/libm/max (; 47 ;) (type $FUNCSIG$ddd) (param $0 f64) (param $1 f64) (result f64) local.get $0 local.get $1 f64.max ) - (func $../../lib/libm/assembly/libm/min (; 49 ;) (type $FUNCSIG$ddd) (param $0 f64) (param $1 f64) (result f64) + (func $../../lib/libm/assembly/libm/min (; 48 ;) (type $FUNCSIG$ddd) (param $0 f64) (param $1 f64) (result f64) local.get $0 local.get $1 f64.min ) - (func $~lib/math/NativeMath.pow (; 50 ;) (type $FUNCSIG$ddd) (param $0 f64) (param $1 f64) (result f64) + (func $~lib/math/NativeMath.pow (; 49 ;) (type $FUNCSIG$ddd) (param $0 f64) (param $1 f64) (result f64) (local $2 f64) (local $3 f64) (local $4 i32) @@ -3785,12 +3766,12 @@ f64.const 1e-300 f64.mul ) - (func $../../lib/libm/assembly/libm/pow (; 51 ;) (type $FUNCSIG$ddd) (param $0 f64) (param $1 f64) (result f64) + (func $../../lib/libm/assembly/libm/pow (; 50 ;) (type $FUNCSIG$ddd) (param $0 f64) (param $1 f64) (result f64) local.get $0 local.get $1 call $~lib/math/NativeMath.pow ) - (func $../../lib/libm/assembly/libm/round (; 52 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $../../lib/libm/assembly/libm/round (; 51 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) local.get $0 f64.const 0.5 f64.add @@ -3798,7 +3779,7 @@ local.get $0 f64.copysign ) - (func $../../lib/libm/assembly/libm/sign (; 53 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $../../lib/libm/assembly/libm/sign (; 52 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) local.get $0 f64.abs f64.const 0 @@ -3811,11 +3792,11 @@ end local.get $0 ) - (func $../../lib/libm/assembly/libm/sin (; 54 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $../../lib/libm/assembly/libm/sin (; 53 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) local.get $0 call $~lib/bindings/Math/sin ) - (func $~lib/math/NativeMath.sinh (; 55 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.sinh (; 54 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) (local $1 f64) (local $2 f64) (local $3 i32) @@ -3892,19 +3873,19 @@ f64.mul f64.mul ) - (func $../../lib/libm/assembly/libm/sinh (; 56 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $../../lib/libm/assembly/libm/sinh (; 55 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.sinh ) - (func $../../lib/libm/assembly/libm/sqrt (; 57 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $../../lib/libm/assembly/libm/sqrt (; 56 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) local.get $0 f64.sqrt ) - (func $../../lib/libm/assembly/libm/tan (; 58 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $../../lib/libm/assembly/libm/tan (; 57 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) local.get $0 call $~lib/bindings/Math/tan ) - (func $~lib/math/NativeMath.tanh (; 59 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.tanh (; 58 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) (local $1 f64) (local $2 i32) (local $3 i64) @@ -3983,19 +3964,19 @@ local.get $0 f64.copysign ) - (func $../../lib/libm/assembly/libm/tanh (; 60 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $../../lib/libm/assembly/libm/tanh (; 59 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.tanh ) - (func $../../lib/libm/assembly/libm/trunc (; 61 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $../../lib/libm/assembly/libm/trunc (; 60 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) local.get $0 f64.trunc ) - (func $../../lib/libm/assembly/libmf/abs (; 62 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/abs (; 61 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 f32.abs ) - (func $~lib/math/Rf (; 63 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/Rf (; 62 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 f32.const 0.16666586697101593 local.get $0 @@ -4014,7 +3995,7 @@ f32.add f32.div ) - (func $~lib/math/NativeMathf.acos (; 64 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.acos (; 63 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 f32) (local $2 i32) (local $3 i32) @@ -4130,11 +4111,11 @@ f32.add f32.mul ) - (func $../../lib/libm/assembly/libmf/acos (; 65 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/acos (; 64 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.acos ) - (func $~lib/math/NativeMathf.log1p (; 66 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.log1p (; 65 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 f32) (local $2 i32) (local $3 i32) @@ -4304,7 +4285,7 @@ f32.mul f32.add ) - (func $~lib/math/NativeMathf.log (; 67 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.log (; 66 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 i32) (local $2 f32) (local $3 f32) @@ -4438,7 +4419,7 @@ f32.mul f32.add ) - (func $~lib/math/NativeMathf.acosh (; 68 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.acosh (; 67 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 i32) local.get $0 i32.reinterpret_f32 @@ -4488,11 +4469,11 @@ f32.const 0.6931471824645996 f32.add ) - (func $../../lib/libm/assembly/libmf/acosh (; 69 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/acosh (; 68 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.acosh ) - (func $~lib/math/NativeMathf.asin (; 70 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.asin (; 69 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 i32) (local $2 f32) (local $3 f64) @@ -4572,11 +4553,11 @@ local.get $0 f32.copysign ) - (func $../../lib/libm/assembly/libmf/asin (; 71 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/asin (; 70 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.asin ) - (func $~lib/math/NativeMathf.asinh (; 72 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.asinh (; 71 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 f32) (local $2 i32) local.get $0 @@ -4641,16 +4622,16 @@ local.get $0 f32.copysign ) - (func $../../lib/libm/assembly/libmf/asinh (; 73 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/asinh (; 72 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.asinh ) - (func $~lib/number/isNaN (; 74 ;) (type $FUNCSIG$if) (param $0 f32) (result i32) + (func $~lib/number/isNaN (; 73 ;) (type $FUNCSIG$if) (param $0 f32) (result i32) local.get $0 local.get $0 f32.ne ) - (func $~lib/math/NativeMathf.atan (; 75 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.atan (; 74 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 i32) (local $2 f32) (local $3 f32) @@ -4848,11 +4829,11 @@ local.get $4 f32.copysign ) - (func $../../lib/libm/assembly/libmf/atan (; 76 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/atan (; 75 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.atan ) - (func $~lib/math/NativeMathf.atanh (; 77 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.atanh (; 76 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 f32) (local $2 i32) local.get $0 @@ -4902,11 +4883,11 @@ local.get $0 f32.copysign ) - (func $../../lib/libm/assembly/libmf/atanh (; 78 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/atanh (; 77 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.atanh ) - (func $~lib/math/NativeMathf.atan2 (; 79 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) + (func $~lib/math/NativeMathf.atan2 (; 78 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -5130,12 +5111,12 @@ i32.and select ) - (func $../../lib/libm/assembly/libmf/atan2 (; 80 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) + (func $../../lib/libm/assembly/libmf/atan2 (; 79 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) local.get $0 local.get $1 call $~lib/math/NativeMathf.atan2 ) - (func $~lib/math/NativeMathf.cbrt (; 81 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.cbrt (; 80 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 f64) (local $2 f64) (local $3 i32) @@ -5234,47 +5215,37 @@ f64.div f32.demote_f64 ) - (func $../../lib/libm/assembly/libmf/cbrt (; 82 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/cbrt (; 81 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.cbrt ) - (func $../../lib/libm/assembly/libmf/ceil (; 83 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/ceil (; 82 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 f32.ceil ) - (func $~lib/number/isFinite (; 84 ;) (type $FUNCSIG$if) (param $0 f32) (result i32) + (func $~lib/number/isFinite (; 83 ;) (type $FUNCSIG$if) (param $0 f32) (result i32) local.get $0 local.get $0 f32.sub f32.const 0 f32.eq ) - (func $~lib/math/NativeMathf.clz32 (; 85 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) - local.get $0 - call $~lib/number/isFinite - i32.eqz - if + (func $../../lib/libm/assembly/libmf/clz32 (; 84 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + block $__inlined_func$~lib/math/NativeMathf.clz32 (result f32) f32.const 32 - return + local.get $0 + call $~lib/number/isFinite + i32.eqz + br_if $__inlined_func$~lib/math/NativeMathf.clz32 + drop + local.get $0 + f64.promote_f32 + call $~lib/math/dtoi32 + i32.clz + f32.convert_i32_s end - local.get $0 - f32.const 4294967296 - local.get $0 - f32.const 2.3283064365386963e-10 - f32.mul - f32.floor - f32.mul - f32.sub - i64.trunc_f32_s - i32.wrap_i64 - i32.clz - f32.convert_i32_s - ) - (func $../../lib/libm/assembly/libmf/clz32 (; 86 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) - local.get $0 - call $~lib/math/NativeMathf.clz32 ) - (func $~lib/array/Array#__unchecked_get (; 87 ;) (type $FUNCSIG$ji) (param $0 i32) (result i64) + (func $~lib/array/Array#__unchecked_get (; 85 ;) (type $FUNCSIG$ji) (param $0 i32) (result i64) i32.const 76 i32.load local.get $0 @@ -5283,7 +5254,7 @@ i32.add i64.load ) - (func $~lib/math/NativeMathf.cos (; 88 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.cos (; 86 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 f64) (local $2 i32) (local $3 f64) @@ -5555,11 +5526,11 @@ end local.get $0 ) - (func $../../lib/libm/assembly/libmf/cos (; 89 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/cos (; 87 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.cos ) - (func $~lib/math/NativeMathf.expm1 (; 90 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.expm1 (; 88 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 i32) (local $2 f32) (local $3 f32) @@ -5811,7 +5782,7 @@ local.get $4 f32.mul ) - (func $~lib/math/NativeMathf.scalbn (; 91 ;) (type $FUNCSIG$ffi) (param $0 f32) (param $1 i32) (result f32) + (func $~lib/math/NativeMathf.scalbn (; 89 ;) (type $FUNCSIG$ffi) (param $0 f32) (param $1 i32) (result f32) local.get $1 i32.const 127 i32.gt_s @@ -5887,7 +5858,7 @@ f32.reinterpret_i32 f32.mul ) - (func $~lib/math/NativeMathf.exp (; 92 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.exp (; 90 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 i32) (local $2 i32) (local $3 f32) @@ -6015,7 +5986,7 @@ local.get $1 call $~lib/math/NativeMathf.scalbn ) - (func $~lib/math/NativeMathf.cosh (; 93 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.cosh (; 91 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 i32) local.get $0 i32.reinterpret_f32 @@ -6074,26 +6045,26 @@ f32.const 1661534994731144841129758e11 f32.mul ) - (func $../../lib/libm/assembly/libmf/cosh (; 94 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/cosh (; 92 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.cosh ) - (func $../../lib/libm/assembly/libmf/exp (; 95 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/exp (; 93 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.exp ) - (func $../../lib/libm/assembly/libmf/expm1 (; 96 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/expm1 (; 94 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.expm1 ) - (func $../../lib/libm/assembly/libmf/floor (; 97 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/floor (; 95 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 f32.floor ) - (func $../../lib/libm/assembly/libmf/fround (; 98 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/fround (; 96 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 ) - (func $~lib/math/NativeMathf.hypot (; 99 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) + (func $~lib/math/NativeMathf.hypot (; 97 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) (local $2 i32) (local $3 i32) (local $4 f32) @@ -6198,12 +6169,12 @@ f32.sqrt f32.mul ) - (func $../../lib/libm/assembly/libmf/hypot (; 100 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) + (func $../../lib/libm/assembly/libmf/hypot (; 98 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) local.get $0 local.get $1 call $~lib/math/NativeMathf.hypot ) - (func $../../lib/libm/assembly/libmf/imul (; 101 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) + (func $../../lib/libm/assembly/libmf/imul (; 99 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) block $~lib/math/NativeMathf.imul|inlined.0 (result f32) f32.const 0 local.get $0 @@ -6215,37 +6186,19 @@ drop local.get $0 f64.promote_f32 - f64.const 4294967296 - local.get $0 - f64.promote_f32 - f64.const 2.3283064365386963e-10 - f64.mul - f64.floor - f64.mul - f64.sub - i64.trunc_f64_s - i32.wrap_i64 - local.get $1 - f64.promote_f32 - f64.const 4294967296 + call $~lib/math/dtoi32 local.get $1 f64.promote_f32 - f64.const 2.3283064365386963e-10 - f64.mul - f64.floor - f64.mul - f64.sub - i64.trunc_f64_s - i32.wrap_i64 + call $~lib/math/dtoi32 i32.mul f32.convert_i32_s end ) - (func $../../lib/libm/assembly/libmf/log (; 102 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/log (; 100 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.log ) - (func $~lib/math/NativeMathf.log10 (; 103 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.log10 (; 101 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 i32) (local $2 f32) (local $3 i32) @@ -6403,15 +6356,15 @@ f32.mul f32.add ) - (func $../../lib/libm/assembly/libmf/log10 (; 104 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/log10 (; 102 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.log10 ) - (func $../../lib/libm/assembly/libmf/log1p (; 105 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/log1p (; 103 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.log1p ) - (func $~lib/math/NativeMathf.log2 (; 106 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.log2 (; 104 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 i32) (local $2 f32) (local $3 i32) @@ -6561,21 +6514,21 @@ f32.convert_i32_s f32.add ) - (func $../../lib/libm/assembly/libmf/log2 (; 107 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/log2 (; 105 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.log2 ) - (func $../../lib/libm/assembly/libmf/max (; 108 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) + (func $../../lib/libm/assembly/libmf/max (; 106 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) local.get $0 local.get $1 f32.max ) - (func $../../lib/libm/assembly/libmf/min (; 109 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) + (func $../../lib/libm/assembly/libmf/min (; 107 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) local.get $0 local.get $1 f32.min ) - (func $~lib/math/NativeMathf.pow (; 110 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) + (func $~lib/math/NativeMathf.pow (; 108 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) (local $2 f32) (local $3 f32) (local $4 i32) @@ -7361,12 +7314,12 @@ f32.const 1.0000000031710769e-30 f32.mul ) - (func $../../lib/libm/assembly/libmf/pow (; 111 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) + (func $../../lib/libm/assembly/libmf/pow (; 109 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) local.get $0 local.get $1 call $~lib/math/NativeMathf.pow ) - (func $../../lib/libm/assembly/libmf/round (; 112 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/round (; 110 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 f32.const 0.5 f32.add @@ -7374,7 +7327,7 @@ local.get $0 f32.copysign ) - (func $../../lib/libm/assembly/libmf/sign (; 113 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/sign (; 111 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 f32.abs f32.const 0 @@ -7387,7 +7340,7 @@ end local.get $0 ) - (func $~lib/math/NativeMathf.sin (; 114 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.sin (; 112 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 f64) (local $2 i32) (local $3 f64) @@ -7660,11 +7613,11 @@ end local.get $0 ) - (func $../../lib/libm/assembly/libmf/sin (; 115 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/sin (; 113 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.sin ) - (func $~lib/math/NativeMathf.sinh (; 116 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.sinh (; 114 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 f32) (local $2 i32) (local $3 f32) @@ -7736,15 +7689,15 @@ f32.mul f32.mul ) - (func $../../lib/libm/assembly/libmf/sinh (; 117 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/sinh (; 115 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.sinh ) - (func $../../lib/libm/assembly/libmf/sqrt (; 118 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/sqrt (; 116 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 f32.sqrt ) - (func $~lib/math/NativeMathf.tan (; 119 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.tan (; 117 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 f64) (local $2 i32) (local $3 f64) @@ -8001,11 +7954,11 @@ local.get $1 f32.demote_f64 ) - (func $../../lib/libm/assembly/libmf/tan (; 120 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/tan (; 118 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.tan ) - (func $~lib/math/NativeMathf.tanh (; 121 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.tanh (; 119 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 f32) (local $2 i32) local.get $0 @@ -8079,15 +8032,15 @@ local.get $0 f32.copysign ) - (func $../../lib/libm/assembly/libmf/tanh (; 122 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/tanh (; 120 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.tanh ) - (func $../../lib/libm/assembly/libmf/trunc (; 123 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/trunc (; 121 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 f32.trunc ) - (func $null (; 124 ;) (type $FUNCSIG$v) + (func $null (; 122 ;) (type $FUNCSIG$v) nop ) ) diff --git a/tests/compiler/std/libm.untouched.wat b/tests/compiler/std/libm.untouched.wat index d09a870ca6..8cf4b64a0b 100644 --- a/tests/compiler/std/libm.untouched.wat +++ b/tests/compiler/std/libm.untouched.wat @@ -1952,7 +1952,78 @@ f64.const 0 f64.eq ) - (func $~lib/math/NativeMath.clz32 (; 26 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $~lib/math/dtoi32 (; 26 ;) (type $FUNCSIG$id) (param $0 f64) (result i32) + (local $1 i32) + (local $2 i64) + (local $3 i64) + (local $4 i64) + i32.const 0 + local.set $1 + local.get $0 + i64.reinterpret_f64 + local.set $2 + local.get $2 + i64.const 52 + i64.shr_u + i64.const 2047 + i64.and + local.set $3 + local.get $3 + i64.const 1053 + i64.le_u + if + local.get $0 + i32.trunc_f64_s + local.set $1 + else + local.get $3 + i64.const 1106 + i64.le_u + if + local.get $2 + i64.const 1 + i64.const 52 + i64.shl + i64.const 1 + i64.sub + i64.and + i64.const 1 + i64.const 52 + i64.shl + i64.or + local.set $4 + local.get $4 + local.get $3 + i64.const 1023 + i64.sub + i64.const 52 + i64.sub + i64.const 32 + i64.add + i64.shl + local.set $4 + local.get $4 + i64.const 32 + i64.shr_u + i32.wrap_i64 + local.set $1 + i32.const 0 + local.get $1 + i32.sub + local.get $1 + local.get $2 + i64.const 63 + i64.shr_u + i64.const 0 + i64.ne + select + local.set $1 + end + end + local.get $1 + return + ) + (func $~lib/math/NativeMath.clz32 (; 27 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) local.get $0 call $~lib/number/isFinite i32.eqz @@ -1961,33 +2032,23 @@ return end local.get $0 - f64.const 4294967296 - local.get $0 - f64.const 1 - f64.const 4294967296 - f64.div - f64.mul - f64.floor - f64.mul - f64.sub - i64.trunc_f64_s - i32.wrap_i64 + call $~lib/math/dtoi32 i32.clz f64.convert_i32_s ) - (func $../../lib/libm/assembly/libm/clz32 (; 27 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $../../lib/libm/assembly/libm/clz32 (; 28 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.clz32 ) - (func $~lib/math/NativeMath.cos (; 28 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.cos (; 29 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) local.get $0 call $~lib/bindings/Math/cos ) - (func $../../lib/libm/assembly/libm/cos (; 29 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $../../lib/libm/assembly/libm/cos (; 30 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.cos ) - (func $~lib/math/NativeMath.expm1 (; 30 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.expm1 (; 31 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) (local $1 i64) (local $2 i32) (local $3 i32) @@ -2299,7 +2360,7 @@ local.get $14 f64.mul ) - (func $~lib/math/NativeMath.scalbn (; 31 ;) (type $FUNCSIG$ddi) (param $0 f64) (param $1 i32) (result f64) + (func $~lib/math/NativeMath.scalbn (; 32 ;) (type $FUNCSIG$ddi) (param $0 f64) (param $1 i32) (result f64) (local $2 f64) (local $3 i32) (local $4 i32) @@ -2390,7 +2451,7 @@ f64.reinterpret_i64 f64.mul ) - (func $~lib/math/NativeMath.exp (; 32 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.exp (; 33 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) (local $1 i32) (local $2 i32) (local $3 f64) @@ -2555,7 +2616,7 @@ local.get $5 call $~lib/math/NativeMath.scalbn ) - (func $~lib/math/NativeMath.cosh (; 33 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.cosh (; 34 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) (local $1 i64) (local $2 i32) (local $3 f64) @@ -2644,26 +2705,26 @@ local.set $3 local.get $3 ) - (func $../../lib/libm/assembly/libm/cosh (; 34 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $../../lib/libm/assembly/libm/cosh (; 35 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.cosh ) - (func $../../lib/libm/assembly/libm/exp (; 35 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $../../lib/libm/assembly/libm/exp (; 36 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.exp ) - (func $../../lib/libm/assembly/libm/expm1 (; 36 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $../../lib/libm/assembly/libm/expm1 (; 37 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.expm1 ) - (func $../../lib/libm/assembly/libm/floor (; 37 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $../../lib/libm/assembly/libm/floor (; 38 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) (local $1 f64) local.get $0 local.set $1 local.get $1 f64.floor ) - (func $../../lib/libm/assembly/libm/fround (; 38 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $../../lib/libm/assembly/libm/fround (; 39 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) (local $1 f64) local.get $0 local.set $1 @@ -2671,7 +2732,7 @@ f32.demote_f64 f64.promote_f32 ) - (func $~lib/math/NativeMath.hypot (; 39 ;) (type $FUNCSIG$ddd) (param $0 f64) (param $1 f64) (result f64) + (func $~lib/math/NativeMath.hypot (; 40 ;) (type $FUNCSIG$ddd) (param $0 f64) (param $1 f64) (result f64) (local $2 i64) (local $3 i64) (local $4 i64) @@ -2866,12 +2927,12 @@ f64.sqrt f64.mul ) - (func $../../lib/libm/assembly/libm/hypot (; 40 ;) (type $FUNCSIG$ddd) (param $0 f64) (param $1 f64) (result f64) + (func $../../lib/libm/assembly/libm/hypot (; 41 ;) (type $FUNCSIG$ddd) (param $0 f64) (param $1 f64) (result f64) local.get $0 local.get $1 call $~lib/math/NativeMath.hypot ) - (func $~lib/math/NativeMath.imul (; 41 ;) (type $FUNCSIG$ddd) (param $0 f64) (param $1 f64) (result f64) + (func $~lib/math/NativeMath.imul (; 42 ;) (type $FUNCSIG$ddd) (param $0 f64) (param $1 f64) (result f64) local.get $0 local.get $1 f64.add @@ -2882,38 +2943,22 @@ return end local.get $0 - f64.const 4294967296 - local.get $0 - f64.const 2.3283064365386963e-10 - f64.mul - f64.floor - f64.mul - f64.sub - i64.trunc_f64_s - i32.wrap_i64 - local.get $1 - f64.const 4294967296 + call $~lib/math/dtoi32 local.get $1 - f64.const 2.3283064365386963e-10 - f64.mul - f64.floor - f64.mul - f64.sub - i64.trunc_f64_s - i32.wrap_i64 + call $~lib/math/dtoi32 i32.mul f64.convert_i32_s ) - (func $../../lib/libm/assembly/libm/imul (; 42 ;) (type $FUNCSIG$ddd) (param $0 f64) (param $1 f64) (result f64) + (func $../../lib/libm/assembly/libm/imul (; 43 ;) (type $FUNCSIG$ddd) (param $0 f64) (param $1 f64) (result f64) local.get $0 local.get $1 call $~lib/math/NativeMath.imul ) - (func $../../lib/libm/assembly/libm/log (; 43 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $../../lib/libm/assembly/libm/log (; 44 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.log ) - (func $~lib/math/NativeMath.log10 (; 44 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.log10 (; 45 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) (local $1 i64) (local $2 i32) (local $3 i32) @@ -3173,15 +3218,15 @@ local.get $8 f64.add ) - (func $../../lib/libm/assembly/libm/log10 (; 45 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $../../lib/libm/assembly/libm/log10 (; 46 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.log10 ) - (func $../../lib/libm/assembly/libm/log1p (; 46 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $../../lib/libm/assembly/libm/log1p (; 47 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.log1p ) - (func $~lib/math/NativeMath.log2 (; 47 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.log2 (; 48 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) (local $1 i64) (local $2 i32) (local $3 i32) @@ -3434,11 +3479,11 @@ local.get $14 f64.add ) - (func $../../lib/libm/assembly/libm/log2 (; 48 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $../../lib/libm/assembly/libm/log2 (; 49 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.log2 ) - (func $../../lib/libm/assembly/libm/max (; 49 ;) (type $FUNCSIG$ddd) (param $0 f64) (param $1 f64) (result f64) + (func $../../lib/libm/assembly/libm/max (; 50 ;) (type $FUNCSIG$ddd) (param $0 f64) (param $1 f64) (result f64) (local $2 f64) (local $3 f64) local.get $0 @@ -3449,7 +3494,7 @@ local.get $2 f64.max ) - (func $../../lib/libm/assembly/libm/min (; 50 ;) (type $FUNCSIG$ddd) (param $0 f64) (param $1 f64) (result f64) + (func $../../lib/libm/assembly/libm/min (; 51 ;) (type $FUNCSIG$ddd) (param $0 f64) (param $1 f64) (result f64) (local $2 f64) (local $3 f64) local.get $0 @@ -3460,7 +3505,7 @@ local.get $2 f64.min ) - (func $~lib/math/NativeMath.pow (; 51 ;) (type $FUNCSIG$ddd) (param $0 f64) (param $1 f64) (result f64) + (func $~lib/math/NativeMath.pow (; 52 ;) (type $FUNCSIG$ddd) (param $0 f64) (param $1 f64) (result f64) (local $2 i64) (local $3 i32) (local $4 i32) @@ -4540,12 +4585,12 @@ local.get $16 f64.mul ) - (func $../../lib/libm/assembly/libm/pow (; 52 ;) (type $FUNCSIG$ddd) (param $0 f64) (param $1 f64) (result f64) + (func $../../lib/libm/assembly/libm/pow (; 53 ;) (type $FUNCSIG$ddd) (param $0 f64) (param $1 f64) (result f64) local.get $0 local.get $1 call $~lib/math/NativeMath.pow ) - (func $../../lib/libm/assembly/libm/round (; 53 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $../../lib/libm/assembly/libm/round (; 54 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) (local $1 f64) local.get $0 local.set $1 @@ -4556,7 +4601,7 @@ local.get $1 f64.copysign ) - (func $../../lib/libm/assembly/libm/sign (; 54 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $../../lib/libm/assembly/libm/sign (; 55 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) (local $1 f64) block $~lib/math/NativeMath.sign|inlined.0 (result f64) local.get $0 @@ -4579,15 +4624,15 @@ br $~lib/math/NativeMath.sign|inlined.0 end ) - (func $~lib/math/NativeMath.sin (; 55 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.sin (; 56 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) local.get $0 call $~lib/bindings/Math/sin ) - (func $../../lib/libm/assembly/libm/sin (; 56 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $../../lib/libm/assembly/libm/sin (; 57 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.sin ) - (func $~lib/math/NativeMath.sinh (; 57 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.sinh (; 58 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) (local $1 i64) (local $2 f64) (local $3 i32) @@ -4685,26 +4730,26 @@ local.set $4 local.get $4 ) - (func $../../lib/libm/assembly/libm/sinh (; 58 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $../../lib/libm/assembly/libm/sinh (; 59 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.sinh ) - (func $../../lib/libm/assembly/libm/sqrt (; 59 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $../../lib/libm/assembly/libm/sqrt (; 60 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) (local $1 f64) local.get $0 local.set $1 local.get $1 f64.sqrt ) - (func $~lib/math/NativeMath.tan (; 60 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.tan (; 61 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) local.get $0 call $~lib/bindings/Math/tan ) - (func $../../lib/libm/assembly/libm/tan (; 61 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $../../lib/libm/assembly/libm/tan (; 62 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.tan ) - (func $~lib/math/NativeMath.tanh (; 62 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.tanh (; 63 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) (local $1 i64) (local $2 f64) (local $3 i32) @@ -4796,25 +4841,25 @@ local.get $0 f64.copysign ) - (func $../../lib/libm/assembly/libm/tanh (; 63 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $../../lib/libm/assembly/libm/tanh (; 64 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.tanh ) - (func $../../lib/libm/assembly/libm/trunc (; 64 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $../../lib/libm/assembly/libm/trunc (; 65 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) (local $1 f64) local.get $0 local.set $1 local.get $1 f64.trunc ) - (func $../../lib/libm/assembly/libmf/abs (; 65 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/abs (; 66 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 f32) local.get $0 local.set $1 local.get $1 f32.abs ) - (func $~lib/math/Rf (; 66 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/Rf (; 67 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 f32) (local $2 f32) local.get $0 @@ -4839,7 +4884,7 @@ local.get $2 f32.div ) - (func $~lib/math/NativeMathf.acos (; 67 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.acos (; 68 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 i32) (local $2 i32) (local $3 f32) @@ -4979,11 +5024,11 @@ f32.add f32.mul ) - (func $../../lib/libm/assembly/libmf/acos (; 68 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/acos (; 69 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.acos ) - (func $~lib/math/NativeMathf.log1p (; 69 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.log1p (; 70 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 i32) (local $2 f32) (local $3 f32) @@ -5192,7 +5237,7 @@ f32.mul f32.add ) - (func $~lib/math/NativeMathf.log (; 70 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.log (; 71 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 i32) (local $2 i32) (local $3 f32) @@ -5360,7 +5405,7 @@ f32.mul f32.add ) - (func $~lib/math/NativeMathf.acosh (; 71 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.acosh (; 72 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 i32) (local $2 i32) (local $3 f32) @@ -5416,11 +5461,11 @@ f32.const 0.6931471824645996 f32.add ) - (func $../../lib/libm/assembly/libmf/acosh (; 72 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/acosh (; 73 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.acosh ) - (func $~lib/math/NativeMathf.asin (; 73 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.asin (; 74 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 f32) (local $2 i32) (local $3 f32) @@ -5512,11 +5557,11 @@ local.get $1 f32.copysign ) - (func $../../lib/libm/assembly/libmf/asin (; 74 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/asin (; 75 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.asin ) - (func $~lib/math/NativeMathf.asinh (; 75 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.asinh (; 76 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 i32) (local $2 f32) local.get $0 @@ -5585,16 +5630,16 @@ local.get $0 f32.copysign ) - (func $../../lib/libm/assembly/libmf/asinh (; 76 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/asinh (; 77 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.asinh ) - (func $~lib/number/isNaN (; 77 ;) (type $FUNCSIG$if) (param $0 f32) (result i32) + (func $~lib/number/isNaN (; 78 ;) (type $FUNCSIG$if) (param $0 f32) (result i32) local.get $0 local.get $0 f32.ne ) - (func $~lib/math/NativeMathf.atan (; 78 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.atan (; 79 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 i32) (local $2 f32) (local $3 f32) @@ -5823,11 +5868,11 @@ local.get $2 f32.copysign ) - (func $../../lib/libm/assembly/libmf/atan (; 79 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/atan (; 80 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.atan ) - (func $~lib/math/NativeMathf.atanh (; 80 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.atanh (; 81 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 i32) (local $2 f32) local.get $0 @@ -5881,11 +5926,11 @@ local.get $0 f32.copysign ) - (func $../../lib/libm/assembly/libmf/atanh (; 81 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/atanh (; 82 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.atanh ) - (func $~lib/math/NativeMathf.atan2 (; 82 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) + (func $~lib/math/NativeMathf.atan2 (; 83 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -6197,12 +6242,12 @@ end unreachable ) - (func $../../lib/libm/assembly/libmf/atan2 (; 83 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) + (func $../../lib/libm/assembly/libmf/atan2 (; 84 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) local.get $0 local.get $1 call $~lib/math/NativeMathf.atan2 ) - (func $~lib/math/NativeMathf.cbrt (; 84 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.cbrt (; 85 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 i32) (local $2 i32) (local $3 f64) @@ -6318,25 +6363,25 @@ local.get $3 f32.demote_f64 ) - (func $../../lib/libm/assembly/libmf/cbrt (; 85 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/cbrt (; 86 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.cbrt ) - (func $../../lib/libm/assembly/libmf/ceil (; 86 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/ceil (; 87 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 f32) local.get $0 local.set $1 local.get $1 f32.ceil ) - (func $~lib/number/isFinite (; 87 ;) (type $FUNCSIG$if) (param $0 f32) (result i32) + (func $~lib/number/isFinite (; 88 ;) (type $FUNCSIG$if) (param $0 f32) (result i32) local.get $0 local.get $0 f32.sub f32.const 0 f32.eq ) - (func $~lib/math/NativeMathf.clz32 (; 88 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.clz32 (; 89 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/number/isFinite i32.eqz @@ -6345,25 +6390,16 @@ return end local.get $0 - f32.const 4294967296 - local.get $0 - f32.const 1 - f32.const 4294967296 - f32.div - f32.mul - f32.floor - f32.mul - f32.sub - i64.trunc_f32_s - i32.wrap_i64 + f64.promote_f32 + call $~lib/math/dtoi32 i32.clz f32.convert_i32_s ) - (func $../../lib/libm/assembly/libmf/clz32 (; 89 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/clz32 (; 90 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.clz32 ) - (func $~lib/array/Array#__unchecked_get (; 90 ;) (type $FUNCSIG$jii) (param $0 i32) (param $1 i32) (result i64) + (func $~lib/array/Array#__unchecked_get (; 91 ;) (type $FUNCSIG$jii) (param $0 i32) (param $1 i32) (result i64) local.get $0 i32.load offset=4 local.get $1 @@ -6372,7 +6408,7 @@ i32.add i64.load ) - (func $~lib/math/NativeMathf.cos (; 91 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.cos (; 92 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 i32) (local $2 i32) (local $3 f64) @@ -6995,11 +7031,11 @@ local.get $26 end ) - (func $../../lib/libm/assembly/libmf/cos (; 92 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/cos (; 93 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.cos ) - (func $~lib/math/NativeMathf.expm1 (; 93 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.expm1 (; 94 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -7292,7 +7328,7 @@ local.get $13 f32.mul ) - (func $~lib/math/NativeMathf.scalbn (; 94 ;) (type $FUNCSIG$ffi) (param $0 f32) (param $1 i32) (result f32) + (func $~lib/math/NativeMathf.scalbn (; 95 ;) (type $FUNCSIG$ffi) (param $0 f32) (param $1 i32) (result f32) (local $2 f32) (local $3 i32) (local $4 i32) @@ -7382,7 +7418,7 @@ f32.reinterpret_i32 f32.mul ) - (func $~lib/math/NativeMathf.exp (; 95 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.exp (; 96 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 i32) (local $2 i32) (local $3 f32) @@ -7526,7 +7562,7 @@ local.get $5 call $~lib/math/NativeMathf.scalbn ) - (func $~lib/math/NativeMathf.cosh (; 96 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.cosh (; 97 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 i32) (local $2 f32) (local $3 f32) @@ -7603,32 +7639,32 @@ local.get $3 f32.mul ) - (func $../../lib/libm/assembly/libmf/cosh (; 97 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/cosh (; 98 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.cosh ) - (func $../../lib/libm/assembly/libmf/exp (; 98 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/exp (; 99 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.exp ) - (func $../../lib/libm/assembly/libmf/expm1 (; 99 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/expm1 (; 100 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.expm1 ) - (func $../../lib/libm/assembly/libmf/floor (; 100 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/floor (; 101 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 f32) local.get $0 local.set $1 local.get $1 f32.floor ) - (func $../../lib/libm/assembly/libmf/fround (; 101 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/fround (; 102 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 f32) local.get $0 local.set $1 local.get $1 ) - (func $~lib/math/NativeMathf.hypot (; 102 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) + (func $~lib/math/NativeMathf.hypot (; 103 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -7745,12 +7781,12 @@ f32.sqrt f32.mul ) - (func $../../lib/libm/assembly/libmf/hypot (; 103 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) + (func $../../lib/libm/assembly/libmf/hypot (; 104 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) local.get $0 local.get $1 call $~lib/math/NativeMathf.hypot ) - (func $../../lib/libm/assembly/libmf/imul (; 104 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) + (func $../../lib/libm/assembly/libmf/imul (; 105 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) (local $2 f32) (local $3 f32) block $~lib/math/NativeMathf.imul|inlined.0 (result f32) @@ -7769,39 +7805,19 @@ end local.get $3 f64.promote_f32 - f32.const 4294967296 - f64.promote_f32 - local.get $3 - f64.promote_f32 - f64.const 2.3283064365386963e-10 - f64.mul - f64.floor - f64.mul - f64.sub - i64.trunc_f64_s - i32.wrap_i64 - local.get $2 - f64.promote_f32 - f32.const 4294967296 - f64.promote_f32 + call $~lib/math/dtoi32 local.get $2 f64.promote_f32 - f64.const 2.3283064365386963e-10 - f64.mul - f64.floor - f64.mul - f64.sub - i64.trunc_f64_s - i32.wrap_i64 + call $~lib/math/dtoi32 i32.mul f32.convert_i32_s end ) - (func $../../lib/libm/assembly/libmf/log (; 105 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/log (; 106 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.log ) - (func $~lib/math/NativeMathf.log10 (; 106 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.log10 (; 107 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 i32) (local $2 i32) (local $3 f32) @@ -8001,15 +8017,15 @@ f32.mul f32.add ) - (func $../../lib/libm/assembly/libmf/log10 (; 107 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/log10 (; 108 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.log10 ) - (func $../../lib/libm/assembly/libmf/log1p (; 108 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/log1p (; 109 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.log1p ) - (func $~lib/math/NativeMathf.log2 (; 109 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.log2 (; 110 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 i32) (local $2 i32) (local $3 f32) @@ -8204,11 +8220,11 @@ local.get $14 f32.add ) - (func $../../lib/libm/assembly/libmf/log2 (; 110 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/log2 (; 111 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.log2 ) - (func $../../lib/libm/assembly/libmf/max (; 111 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) + (func $../../lib/libm/assembly/libmf/max (; 112 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) (local $2 f32) (local $3 f32) local.get $0 @@ -8219,7 +8235,7 @@ local.get $2 f32.max ) - (func $../../lib/libm/assembly/libmf/min (; 112 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) + (func $../../lib/libm/assembly/libmf/min (; 113 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) (local $2 f32) (local $3 f32) local.get $0 @@ -8230,7 +8246,7 @@ local.get $2 f32.min ) - (func $~lib/math/NativeMathf.pow (; 113 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) + (func $~lib/math/NativeMathf.pow (; 114 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -9164,12 +9180,12 @@ local.get $11 f32.mul ) - (func $../../lib/libm/assembly/libmf/pow (; 114 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) + (func $../../lib/libm/assembly/libmf/pow (; 115 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) local.get $0 local.get $1 call $~lib/math/NativeMathf.pow ) - (func $../../lib/libm/assembly/libmf/round (; 115 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/round (; 116 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 f32) local.get $0 local.set $1 @@ -9180,7 +9196,7 @@ local.get $1 f32.copysign ) - (func $../../lib/libm/assembly/libmf/sign (; 116 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/sign (; 117 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 f32) block $~lib/math/NativeMathf.sign|inlined.0 (result f32) local.get $0 @@ -9203,7 +9219,7 @@ br $~lib/math/NativeMathf.sign|inlined.0 end ) - (func $~lib/math/NativeMathf.sin (; 117 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.sin (; 118 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 i32) (local $2 i32) (local $3 f64) @@ -9818,11 +9834,11 @@ local.get $26 end ) - (func $../../lib/libm/assembly/libmf/sin (; 118 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/sin (; 119 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.sin ) - (func $~lib/math/NativeMathf.sinh (; 119 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.sinh (; 120 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 i32) (local $2 f32) (local $3 f32) @@ -9911,18 +9927,18 @@ local.set $3 local.get $3 ) - (func $../../lib/libm/assembly/libmf/sinh (; 120 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/sinh (; 121 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.sinh ) - (func $../../lib/libm/assembly/libmf/sqrt (; 121 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/sqrt (; 122 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 f32) local.get $0 local.set $1 local.get $1 f32.sqrt ) - (func $~lib/math/NativeMathf.tan (; 122 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.tan (; 123 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -10578,11 +10594,11 @@ end f32.demote_f64 ) - (func $../../lib/libm/assembly/libmf/tan (; 123 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/tan (; 124 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.tan ) - (func $~lib/math/NativeMathf.tanh (; 124 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.tanh (; 125 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 i32) (local $2 f32) (local $3 f32) @@ -10668,17 +10684,17 @@ local.get $0 f32.copysign ) - (func $../../lib/libm/assembly/libmf/tanh (; 125 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/tanh (; 126 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) local.get $0 call $~lib/math/NativeMathf.tanh ) - (func $../../lib/libm/assembly/libmf/trunc (; 126 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $../../lib/libm/assembly/libmf/trunc (; 127 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) (local $1 f32) local.get $0 local.set $1 local.get $1 f32.trunc ) - (func $null (; 127 ;) (type $FUNCSIG$v) + (func $null (; 128 ;) (type $FUNCSIG$v) ) ) diff --git a/tests/compiler/std/math.optimized.wat b/tests/compiler/std/math.optimized.wat index 583c4b84a0..5d2a19a59a 100644 --- a/tests/compiler/std/math.optimized.wat +++ b/tests/compiler/std/math.optimized.wat @@ -8044,7 +8044,7 @@ if i32.const 0 i32.const 144 - i32.const 1020 + i32.const 1036 i32.const 4 call $~lib/builtins/abort unreachable @@ -8075,7 +8075,7 @@ if i32.const 184 i32.const 144 - i32.const 1029 + i32.const 1045 i32.const 24 call $~lib/builtins/abort unreachable @@ -8122,7 +8122,7 @@ if i32.const 184 i32.const 144 - i32.const 2309 + i32.const 2319 i32.const 24 call $~lib/builtins/abort unreachable @@ -9677,16 +9677,7 @@ f32.const 0 call $std/math/check ) - (func $~lib/math/NativeMath.imul (; 157 ;) (type $FUNCSIG$ddd) (param $0 f64) (param $1 f64) (result f64) - local.get $0 - local.get $1 - f64.add - call $~lib/number/isFinite - i32.eqz - if - f64.const 0 - return - end + (func $~lib/math/dtoi32 (; 157 ;) (type $FUNCSIG$id) (param $0 f64) (result i32) local.get $0 f64.const 4294967296 local.get $0 @@ -9697,20 +9688,25 @@ f64.sub i64.trunc_f64_s i32.wrap_i64 + ) + (func $~lib/math/NativeMath.imul (; 158 ;) (type $FUNCSIG$ddd) (param $0 f64) (param $1 f64) (result f64) + local.get $0 local.get $1 - f64.const 4294967296 + f64.add + call $~lib/number/isFinite + i32.eqz + if + f64.const 0 + return + end + local.get $0 + call $~lib/math/dtoi32 local.get $1 - f64.const 2.3283064365386963e-10 - f64.mul - f64.floor - f64.mul - f64.sub - i64.trunc_f64_s - i32.wrap_i64 + call $~lib/math/dtoi32 i32.mul f64.convert_i32_s ) - (func $~lib/math/NativeMath.clz32 (; 158 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.clz32 (; 159 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) local.get $0 call $~lib/number/isFinite i32.eqz @@ -9719,19 +9715,11 @@ return end local.get $0 - f64.const 4294967296 - local.get $0 - f64.const 2.3283064365386963e-10 - f64.mul - f64.floor - f64.mul - f64.sub - i64.trunc_f64_s - i32.wrap_i64 + call $~lib/math/dtoi32 i32.clz f64.convert_i32_s ) - (func $~lib/math/ipow64 (; 159 ;) (type $FUNCSIG$jji) (param $0 i64) (param $1 i32) (result i64) + (func $~lib/math/ipow64 (; 160 ;) (type $FUNCSIG$jji) (param $0 i64) (param $1 i32) (result i64) (local $2 i64) i64.const 1 local.set $2 @@ -9763,7 +9751,7 @@ end local.get $2 ) - (func $~lib/math/ipow32f (; 160 ;) (type $FUNCSIG$ffi) (param $0 f32) (param $1 i32) (result f32) + (func $~lib/math/ipow32f (; 161 ;) (type $FUNCSIG$ffi) (param $0 f32) (param $1 i32) (result f32) (local $2 f32) (local $3 i32) local.get $1 @@ -9809,7 +9797,7 @@ end local.get $2 ) - (func $~lib/math/ipow64f (; 161 ;) (type $FUNCSIG$ddi) (param $0 f64) (param $1 i32) (result f64) + (func $~lib/math/ipow64f (; 162 ;) (type $FUNCSIG$ddi) (param $0 f64) (param $1 i32) (result f64) (local $2 f64) (local $3 i32) local.get $1 @@ -9855,7 +9843,7 @@ end local.get $2 ) - (func $start:std/math (; 162 ;) (type $FUNCSIG$v) + (func $start:std/math (; 163 ;) (type $FUNCSIG$v) (local $0 i32) (local $1 f64) (local $2 f32) @@ -39882,10 +39870,10 @@ unreachable end ) - (func $start (; 163 ;) (type $FUNCSIG$v) + (func $start (; 164 ;) (type $FUNCSIG$v) call $start:std/math ) - (func $null (; 164 ;) (type $FUNCSIG$v) + (func $null (; 165 ;) (type $FUNCSIG$v) nop ) ) diff --git a/tests/compiler/std/math.untouched.wat b/tests/compiler/std/math.untouched.wat index b86637b3b6..900f3c105d 100644 --- a/tests/compiler/std/math.untouched.wat +++ b/tests/compiler/std/math.untouched.wat @@ -10135,7 +10135,7 @@ if i32.const 0 i32.const 144 - i32.const 1020 + i32.const 1036 i32.const 4 call $~lib/builtins/abort unreachable @@ -10167,7 +10167,7 @@ if i32.const 184 i32.const 144 - i32.const 1029 + i32.const 1045 i32.const 24 call $~lib/builtins/abort unreachable @@ -10224,7 +10224,7 @@ if i32.const 184 i32.const 144 - i32.const 2309 + i32.const 2319 i32.const 24 call $~lib/builtins/abort unreachable @@ -12798,7 +12798,78 @@ local.get $3 call $std/math/check ) - (func $~lib/math/NativeMath.imul (; 160 ;) (type $FUNCSIG$ddd) (param $0 f64) (param $1 f64) (result f64) + (func $~lib/math/dtoi32 (; 160 ;) (type $FUNCSIG$id) (param $0 f64) (result i32) + (local $1 i32) + (local $2 i64) + (local $3 i64) + (local $4 i64) + i32.const 0 + local.set $1 + local.get $0 + i64.reinterpret_f64 + local.set $2 + local.get $2 + i64.const 52 + i64.shr_u + i64.const 2047 + i64.and + local.set $3 + local.get $3 + i64.const 1053 + i64.le_u + if + local.get $0 + i32.trunc_f64_s + local.set $1 + else + local.get $3 + i64.const 1106 + i64.le_u + if + local.get $2 + i64.const 1 + i64.const 52 + i64.shl + i64.const 1 + i64.sub + i64.and + i64.const 1 + i64.const 52 + i64.shl + i64.or + local.set $4 + local.get $4 + local.get $3 + i64.const 1023 + i64.sub + i64.const 52 + i64.sub + i64.const 32 + i64.add + i64.shl + local.set $4 + local.get $4 + i64.const 32 + i64.shr_u + i32.wrap_i64 + local.set $1 + i32.const 0 + local.get $1 + i32.sub + local.get $1 + local.get $2 + i64.const 63 + i64.shr_u + i64.const 0 + i64.ne + select + local.set $1 + end + end + local.get $1 + return + ) + (func $~lib/math/NativeMath.imul (; 161 ;) (type $FUNCSIG$ddd) (param $0 f64) (param $1 f64) (result f64) local.get $0 local.get $1 f64.add @@ -12809,29 +12880,13 @@ return end local.get $0 - f64.const 4294967296 - local.get $0 - f64.const 2.3283064365386963e-10 - f64.mul - f64.floor - f64.mul - f64.sub - i64.trunc_f64_s - i32.wrap_i64 - local.get $1 - f64.const 4294967296 + call $~lib/math/dtoi32 local.get $1 - f64.const 2.3283064365386963e-10 - f64.mul - f64.floor - f64.mul - f64.sub - i64.trunc_f64_s - i32.wrap_i64 + call $~lib/math/dtoi32 i32.mul f64.convert_i32_s ) - (func $~lib/math/NativeMath.clz32 (; 161 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.clz32 (; 162 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) local.get $0 call $~lib/number/isFinite i32.eqz @@ -12840,21 +12895,11 @@ return end local.get $0 - f64.const 4294967296 - local.get $0 - f64.const 1 - f64.const 4294967296 - f64.div - f64.mul - f64.floor - f64.mul - f64.sub - i64.trunc_f64_s - i32.wrap_i64 + call $~lib/math/dtoi32 i32.clz f64.convert_i32_s ) - (func $~lib/math/ipow64 (; 162 ;) (type $FUNCSIG$jji) (param $0 i64) (param $1 i32) (result i64) + (func $~lib/math/ipow64 (; 163 ;) (type $FUNCSIG$jji) (param $0 i64) (param $1 i32) (result i64) (local $2 i64) (local $3 i32) (local $4 i32) @@ -13075,7 +13120,7 @@ end local.get $2 ) - (func $~lib/math/ipow32f (; 163 ;) (type $FUNCSIG$ffi) (param $0 f32) (param $1 i32) (result f32) + (func $~lib/math/ipow32f (; 164 ;) (type $FUNCSIG$ffi) (param $0 f32) (param $1 i32) (result f32) (local $2 i32) (local $3 f32) local.get $1 @@ -13125,7 +13170,7 @@ local.get $3 end ) - (func $~lib/math/ipow64f (; 164 ;) (type $FUNCSIG$ddi) (param $0 f64) (param $1 i32) (result f64) + (func $~lib/math/ipow64f (; 165 ;) (type $FUNCSIG$ddi) (param $0 f64) (param $1 i32) (result f64) (local $2 i32) (local $3 f64) local.get $1 @@ -13175,7 +13220,7 @@ local.get $3 end ) - (func $start:std/math (; 165 ;) (type $FUNCSIG$v) + (func $start:std/math (; 166 ;) (type $FUNCSIG$v) (local $0 i32) (local $1 f64) (local $2 i64) @@ -46850,9 +46895,9 @@ unreachable end ) - (func $start (; 166 ;) (type $FUNCSIG$v) + (func $start (; 167 ;) (type $FUNCSIG$v) call $start:std/math ) - (func $null (; 167 ;) (type $FUNCSIG$v) + (func $null (; 168 ;) (type $FUNCSIG$v) ) )