diff --git a/std/assembly/math.ts b/std/assembly/math.ts index 13a95637..575b9071 100644 --- a/std/assembly/math.ts +++ b/std/assembly/math.ts @@ -349,9 +349,17 @@ export namespace NativeMath { return builtin_ceil(x); } - @inline export function clz32(x: f64): f64 { - return builtin_clz(x); + if (!isFinite(x)) return 32; + /* + * Wasm (MVP) and JS have different approaches for double->int conversions. + * + * 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))) + ); } export function cos(x: f64): f64 { // TODO @@ -543,7 +551,7 @@ export namespace NativeMath { export function imul(x: f64, y: f64): f64 { /* - * Wasm (MVP) and JS have different approachas for double->int conversions. + * Wasm (MVP) and JS have different approaches for double->int conversions. * * 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. @@ -1493,9 +1501,11 @@ export namespace NativeMathf { return builtin_ceil(x); } - @inline export function clz32(x: f32): f32 { - return builtin_clz(x); + if (!isFinite(x)) return 32; + return builtin_clz( + (x - 4294967296 * builtin_floor(x * (1.0 / 4294967296))) + ); } export function cos(x: f32): f32 { // TODO @@ -1669,7 +1679,18 @@ export namespace NativeMathf { @inline export function imul(x: f32, y: f32): f32 { - return (x * y); + /* + * Wasm (MVP) and JS have different approaches for double->int conversions. + * + * 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. + */ + if (!isFinite(x + y)) return 0; + const inv32 = 1.0 / 4294967296; + return ( + (x - 4294967296 * builtin_floor(x * inv32)) * + (y - 4294967296 * builtin_floor(y * inv32)) + ); } 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 cc1becf9..5dc3bec2 100644 --- a/tests/compiler/std/array.optimized.wat +++ b/tests/compiler/std/array.optimized.wat @@ -3876,7 +3876,7 @@ if i32.const 0 i32.const 2896 - i32.const 968 + i32.const 976 i32.const 4 call $~lib/env/abort unreachable @@ -5552,7 +5552,7 @@ if i32.const 0 i32.const 2896 - i32.const 977 + i32.const 985 i32.const 24 call $~lib/env/abort unreachable diff --git a/tests/compiler/std/array.untouched.wat b/tests/compiler/std/array.untouched.wat index 8dd7b014..d29923f2 100644 --- a/tests/compiler/std/array.untouched.wat +++ b/tests/compiler/std/array.untouched.wat @@ -5505,7 +5505,7 @@ if i32.const 0 i32.const 2896 - i32.const 968 + i32.const 976 i32.const 4 call $~lib/env/abort unreachable @@ -9230,7 +9230,7 @@ if i32.const 0 i32.const 2896 - i32.const 977 + i32.const 985 i32.const 24 call $~lib/env/abort unreachable diff --git a/tests/compiler/std/libm.optimized.wat b/tests/compiler/std/libm.optimized.wat index 23da4d1f..3b1c4006 100644 --- a/tests/compiler/std/libm.optimized.wat +++ b/tests/compiler/std/libm.optimized.wat @@ -1563,16 +1563,37 @@ local.get $0 f64.ceil ) - (func $std/libm/clz32 (; 21 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.clz32 (; 21 ;) (type $FF) (param $0 f64) (result f64) local.get $0 - i32.trunc_f64_s + local.get $0 + f64.sub + f64.const 0 + f64.ne + if + f64.const 32 + 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 i32.clz f64.convert_i32_s ) - (func $std/libm/cos (; 22 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/clz32 (; 22 ;) (type $FF) (param $0 f64) (result f64) + local.get $0 + call $~lib/math/NativeMath.clz32 + ) + (func $std/libm/cos (; 23 ;) (type $FF) (param $0 f64) (result f64) unreachable ) - (func $~lib/math/NativeMath.expm1 (; 23 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.expm1 (; 24 ;) (type $FF) (param $0 f64) (result f64) (local $1 f64) (local $2 f64) (local $3 i32) @@ -1851,7 +1872,7 @@ local.get $5 f64.mul ) - (func $~lib/math/NativeMath.scalbn (; 24 ;) (type $FiF) (param $0 f64) (param $1 i32) (result f64) + (func $~lib/math/NativeMath.scalbn (; 25 ;) (type $FiF) (param $0 f64) (param $1 i32) (result f64) local.get $1 i32.const 1023 i32.gt_s @@ -1928,7 +1949,7 @@ f64.reinterpret_i64 f64.mul ) - (func $~lib/math/NativeMath.exp (; 25 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.exp (; 26 ;) (type $FF) (param $0 f64) (result f64) (local $1 i32) (local $2 f64) (local $3 i32) @@ -2078,7 +2099,7 @@ local.get $3 call $~lib/math/NativeMath.scalbn ) - (func $~lib/math/NativeMath.cosh (; 26 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.cosh (; 27 ;) (type $FF) (param $0 f64) (result f64) (local $1 i32) (local $2 i64) local.get $0 @@ -2142,27 +2163,27 @@ f64.const 2247116418577894884661631e283 f64.mul ) - (func $std/libm/cosh (; 27 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/cosh (; 28 ;) (type $FF) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.cosh ) - (func $std/libm/exp (; 28 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/exp (; 29 ;) (type $FF) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.exp ) - (func $std/libm/expm1 (; 29 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/expm1 (; 30 ;) (type $FF) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.expm1 ) - (func $std/libm/floor (; 30 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/floor (; 31 ;) (type $FF) (param $0 f64) (result f64) local.get $0 f64.floor ) - (func $std/libm/fround (; 31 ;) (type $Ff) (param $0 f64) (result f32) + (func $std/libm/fround (; 32 ;) (type $Ff) (param $0 f64) (result f32) local.get $0 f32.demote_f64 ) - (func $~lib/math/NativeMath.hypot (; 32 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (func $~lib/math/NativeMath.hypot (; 33 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) (local $2 f64) (local $3 i64) (local $4 f64) @@ -2341,12 +2362,12 @@ f64.sqrt f64.mul ) - (func $std/libm/hypot (; 33 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (func $std/libm/hypot (; 34 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) local.get $0 local.get $1 call $~lib/math/NativeMath.hypot ) - (func $~lib/math/NativeMath.imul (; 34 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (func $~lib/math/NativeMath.imul (; 35 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) (local $2 f64) local.get $0 local.get $1 @@ -2383,16 +2404,16 @@ i32.mul f64.convert_i32_s ) - (func $std/libm/imul (; 35 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (func $std/libm/imul (; 36 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) local.get $0 local.get $1 call $~lib/math/NativeMath.imul ) - (func $std/libm/log (; 36 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/log (; 37 ;) (type $FF) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.log ) - (func $~lib/math/NativeMath.log10 (; 37 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.log10 (; 38 ;) (type $FF) (param $0 f64) (result f64) (local $1 f64) (local $2 i32) (local $3 i32) @@ -2604,15 +2625,15 @@ local.get $0 f64.add ) - (func $std/libm/log10 (; 38 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/log10 (; 39 ;) (type $FF) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.log10 ) - (func $std/libm/log1p (; 39 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/log1p (; 40 ;) (type $FF) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.log1p ) - (func $~lib/math/NativeMath.log2 (; 40 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.log2 (; 41 ;) (type $FF) (param $0 f64) (result f64) (local $1 f64) (local $2 i32) (local $3 i32) @@ -2818,21 +2839,21 @@ local.get $0 f64.add ) - (func $std/libm/log2 (; 41 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/log2 (; 42 ;) (type $FF) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.log2 ) - (func $std/libm/max (; 42 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (func $std/libm/max (; 43 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) local.get $0 local.get $1 f64.max ) - (func $std/libm/min (; 43 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (func $std/libm/min (; 44 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) local.get $0 local.get $1 f64.min ) - (func $~lib/math/NativeMath.pow (; 44 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (func $~lib/math/NativeMath.pow (; 45 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) (local $2 f64) (local $3 f64) (local $4 i32) @@ -3782,12 +3803,12 @@ f64.const 1e-300 f64.mul ) - (func $std/libm/pow (; 45 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (func $std/libm/pow (; 46 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) local.get $0 local.get $1 call $~lib/math/NativeMath.pow ) - (func $std/libm/round (; 46 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/round (; 47 ;) (type $FF) (param $0 f64) (result f64) local.get $0 f64.const 0.5 f64.add @@ -3795,7 +3816,7 @@ local.get $0 f64.copysign ) - (func $std/libm/sign (; 47 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/sign (; 48 ;) (type $FF) (param $0 f64) (result f64) local.get $0 f64.const 0 f64.gt @@ -3813,7 +3834,7 @@ end local.get $0 ) - (func $~lib/math/NativeMath.sinh (; 48 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.sinh (; 49 ;) (type $FF) (param $0 f64) (result f64) (local $1 f64) (local $2 f64) (local $3 i32) @@ -3890,15 +3911,15 @@ f64.mul f64.mul ) - (func $std/libm/sinh (; 49 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/sinh (; 50 ;) (type $FF) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.sinh ) - (func $std/libm/sqrt (; 50 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/sqrt (; 51 ;) (type $FF) (param $0 f64) (result f64) local.get $0 f64.sqrt ) - (func $~lib/math/NativeMath.tanh (; 51 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.tanh (; 52 ;) (type $FF) (param $0 f64) (result f64) (local $1 f64) (local $2 i32) (local $3 i64) @@ -3977,15 +3998,15 @@ local.get $0 f64.copysign ) - (func $std/libm/tanh (; 52 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/tanh (; 53 ;) (type $FF) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.tanh ) - (func $std/libm/trunc (; 53 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/trunc (; 54 ;) (type $FF) (param $0 f64) (result f64) local.get $0 f64.trunc ) - (func $null (; 54 ;) (type $_) + (func $null (; 55 ;) (type $_) nop ) ) diff --git a/tests/compiler/std/libm.untouched.wat b/tests/compiler/std/libm.untouched.wat index 3c0dc866..fc59d714 100644 --- a/tests/compiler/std/libm.untouched.wat +++ b/tests/compiler/std/libm.untouched.wat @@ -1923,24 +1923,49 @@ local.get $1 f64.ceil ) - (func $std/libm/clz32 (; 22 ;) (type $FF) (param $0 f64) (result f64) - (local $1 f64) + (func $~lib/builtins/isFinite (; 22 ;) (type $Fi) (param $0 f64) (result i32) local.get $0 - local.set $1 - local.get $1 - i32.trunc_f64_s + local.get $0 + f64.sub + f64.const 0 + f64.eq + ) + (func $~lib/math/NativeMath.clz32 (; 23 ;) (type $FF) (param $0 f64) (result f64) + local.get $0 + call $~lib/builtins/isFinite + i32.eqz + if + f64.const 32 + 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 i32.clz f64.convert_i32_s ) - (func $~lib/math/NativeMath.cos (; 23 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/clz32 (; 24 ;) (type $FF) (param $0 f64) (result f64) + local.get $0 + call $~lib/math/NativeMath.clz32 + ) + (func $~lib/math/NativeMath.cos (; 25 ;) (type $FF) (param $0 f64) (result f64) unreachable f64.const 0 ) - (func $std/libm/cos (; 24 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/cos (; 26 ;) (type $FF) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.cos ) - (func $~lib/math/NativeMath.expm1 (; 25 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.expm1 (; 27 ;) (type $FF) (param $0 f64) (result f64) (local $1 i64) (local $2 i32) (local $3 i32) @@ -2254,7 +2279,7 @@ local.get $14 f64.mul ) - (func $~lib/math/NativeMath.scalbn (; 26 ;) (type $FiF) (param $0 f64) (param $1 i32) (result f64) + (func $~lib/math/NativeMath.scalbn (; 28 ;) (type $FiF) (param $0 f64) (param $1 i32) (result f64) (local $2 f64) (local $3 i32) (local $4 i32) @@ -2345,7 +2370,7 @@ f64.reinterpret_i64 f64.mul ) - (func $~lib/math/NativeMath.exp (; 27 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.exp (; 29 ;) (type $FF) (param $0 f64) (result f64) (local $1 i32) (local $2 i32) (local $3 f64) @@ -2510,7 +2535,7 @@ local.get $5 call $~lib/math/NativeMath.scalbn ) - (func $~lib/math/NativeMath.cosh (; 28 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.cosh (; 30 ;) (type $FF) (param $0 f64) (result f64) (local $1 i64) (local $2 i32) (local $3 f64) @@ -2605,33 +2630,33 @@ local.set $3 local.get $3 ) - (func $std/libm/cosh (; 29 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/cosh (; 31 ;) (type $FF) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.cosh ) - (func $std/libm/exp (; 30 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/exp (; 32 ;) (type $FF) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.exp ) - (func $std/libm/expm1 (; 31 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/expm1 (; 33 ;) (type $FF) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.expm1 ) - (func $std/libm/floor (; 32 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/floor (; 34 ;) (type $FF) (param $0 f64) (result f64) (local $1 f64) local.get $0 local.set $1 local.get $1 f64.floor ) - (func $std/libm/fround (; 33 ;) (type $Ff) (param $0 f64) (result f32) + (func $std/libm/fround (; 35 ;) (type $Ff) (param $0 f64) (result f32) (local $1 f64) local.get $0 local.set $1 local.get $1 f32.demote_f64 ) - (func $~lib/math/NativeMath.hypot (; 34 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (func $~lib/math/NativeMath.hypot (; 36 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) (local $2 i64) (local $3 i64) (local $4 i64) @@ -2832,19 +2857,12 @@ f64.sqrt f64.mul ) - (func $std/libm/hypot (; 35 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (func $std/libm/hypot (; 37 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) local.get $0 local.get $1 call $~lib/math/NativeMath.hypot ) - (func $~lib/builtins/isFinite (; 36 ;) (type $Fi) (param $0 f64) (result i32) - local.get $0 - local.get $0 - f64.sub - f64.const 0 - f64.eq - ) - (func $~lib/math/NativeMath.imul (; 37 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (func $~lib/math/NativeMath.imul (; 38 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) local.get $0 local.get $1 f64.add @@ -2877,16 +2895,16 @@ i32.mul f64.convert_i32_s ) - (func $std/libm/imul (; 38 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (func $std/libm/imul (; 39 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) local.get $0 local.get $1 call $~lib/math/NativeMath.imul ) - (func $std/libm/log (; 39 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/log (; 40 ;) (type $FF) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.log ) - (func $~lib/math/NativeMath.log10 (; 40 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.log10 (; 41 ;) (type $FF) (param $0 f64) (result f64) (local $1 i64) (local $2 i32) (local $3 i32) @@ -3149,15 +3167,15 @@ local.get $9 f64.add ) - (func $std/libm/log10 (; 41 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/log10 (; 42 ;) (type $FF) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.log10 ) - (func $std/libm/log1p (; 42 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/log1p (; 43 ;) (type $FF) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.log1p ) - (func $~lib/math/NativeMath.log2 (; 43 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.log2 (; 44 ;) (type $FF) (param $0 f64) (result f64) (local $1 i64) (local $2 i32) (local $3 i32) @@ -3413,11 +3431,11 @@ local.get $15 f64.add ) - (func $std/libm/log2 (; 44 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/log2 (; 45 ;) (type $FF) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.log2 ) - (func $std/libm/max (; 45 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (func $std/libm/max (; 46 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) (local $2 f64) (local $3 f64) local.get $0 @@ -3428,7 +3446,7 @@ local.get $3 f64.max ) - (func $std/libm/min (; 46 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (func $std/libm/min (; 47 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) (local $2 f64) (local $3 f64) local.get $0 @@ -3439,7 +3457,7 @@ local.get $3 f64.min ) - (func $~lib/math/NativeMath.pow (; 47 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (func $~lib/math/NativeMath.pow (; 48 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) (local $2 i64) (local $3 i32) (local $4 i32) @@ -4527,12 +4545,12 @@ local.get $16 f64.mul ) - (func $std/libm/pow (; 48 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (func $std/libm/pow (; 49 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) local.get $0 local.get $1 call $~lib/math/NativeMath.pow ) - (func $std/libm/round (; 49 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/round (; 50 ;) (type $FF) (param $0 f64) (result f64) (local $1 f64) local.get $0 local.set $1 @@ -4543,7 +4561,7 @@ local.get $1 f64.copysign ) - (func $std/libm/sign (; 50 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/sign (; 51 ;) (type $FF) (param $0 f64) (result f64) (local $1 f64) block $~lib/math/NativeMath.sign|inlined.0 (result f64) local.get $0 @@ -4566,15 +4584,15 @@ br $~lib/math/NativeMath.sign|inlined.0 end ) - (func $~lib/math/NativeMath.sin (; 51 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.sin (; 52 ;) (type $FF) (param $0 f64) (result f64) unreachable f64.const 0 ) - (func $std/libm/sin (; 52 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/sin (; 53 ;) (type $FF) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.sin ) - (func $~lib/math/NativeMath.sinh (; 53 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.sinh (; 54 ;) (type $FF) (param $0 f64) (result f64) (local $1 i64) (local $2 f64) (local $3 i32) @@ -4678,26 +4696,26 @@ local.set $4 local.get $4 ) - (func $std/libm/sinh (; 54 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/sinh (; 55 ;) (type $FF) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.sinh ) - (func $std/libm/sqrt (; 55 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/sqrt (; 56 ;) (type $FF) (param $0 f64) (result f64) (local $1 f64) local.get $0 local.set $1 local.get $1 f64.sqrt ) - (func $~lib/math/NativeMath.tan (; 56 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.tan (; 57 ;) (type $FF) (param $0 f64) (result f64) unreachable f64.const 0 ) - (func $std/libm/tan (; 57 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/tan (; 58 ;) (type $FF) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.tan ) - (func $~lib/math/NativeMath.tanh (; 58 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.tanh (; 59 ;) (type $FF) (param $0 f64) (result f64) (local $1 i64) (local $2 f64) (local $3 i32) @@ -4789,17 +4807,17 @@ local.get $0 f64.copysign ) - (func $std/libm/tanh (; 59 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/tanh (; 60 ;) (type $FF) (param $0 f64) (result f64) local.get $0 call $~lib/math/NativeMath.tanh ) - (func $std/libm/trunc (; 60 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/trunc (; 61 ;) (type $FF) (param $0 f64) (result f64) (local $1 f64) local.get $0 local.set $1 local.get $1 f64.trunc ) - (func $null (; 61 ;) (type $_) + (func $null (; 62 ;) (type $_) ) ) diff --git a/tests/compiler/std/math.optimized.wat b/tests/compiler/std/math.optimized.wat index b0fb306a..50c031b6 100644 --- a/tests/compiler/std/math.optimized.wat +++ b/tests/compiler/std/math.optimized.wat @@ -8001,7 +8001,7 @@ if i32.const 0 i32.const 40 - i32.const 968 + i32.const 976 i32.const 4 call $~lib/env/abort unreachable @@ -8067,7 +8067,7 @@ if i32.const 0 i32.const 40 - i32.const 977 + i32.const 985 i32.const 24 call $~lib/env/abort unreachable @@ -8114,7 +8114,7 @@ if i32.const 0 i32.const 40 - i32.const 2044 + i32.const 2065 i32.const 24 call $~lib/env/abort unreachable @@ -9222,7 +9222,30 @@ i32.mul f64.convert_i32_s ) - (func $~lib/math/ipow64 (; 146 ;) (type $IiI) (param $0 i64) (param $1 i32) (result i64) + (func $~lib/math/NativeMath.clz32 (; 146 ;) (type $FF) (param $0 f64) (result f64) + local.get $0 + local.get $0 + f64.sub + f64.const 0 + f64.ne + if + f64.const 32 + 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 + i32.clz + f64.convert_i32_s + ) + (func $~lib/math/ipow64 (; 147 ;) (type $IiI) (param $0 i64) (param $1 i32) (result i64) (local $2 i64) (local $3 i32) i64.const 1 @@ -9418,7 +9441,7 @@ end local.get $2 ) - (func $~lib/math/ipow32f (; 147 ;) (type $fif) (param $0 f32) (param $1 i32) (result f32) + (func $~lib/math/ipow32f (; 148 ;) (type $fif) (param $0 f32) (param $1 i32) (result f32) (local $2 f32) (local $3 i32) local.get $1 @@ -9464,7 +9487,7 @@ end local.get $2 ) - (func $~lib/math/ipow64f (; 148 ;) (type $FiF) (param $0 f64) (param $1 i32) (result f64) + (func $~lib/math/ipow64f (; 149 ;) (type $FiF) (param $0 f64) (param $1 i32) (result f64) (local $2 f64) (local $3 i32) local.get $1 @@ -9510,7 +9533,7 @@ end local.get $2 ) - (func $start:std/math (; 149 ;) (type $_) + (func $start:std/math (; 150 ;) (type $_) (local $0 f64) (local $1 f32) (local $2 i32) @@ -37846,11 +37869,10 @@ call $~lib/env/abort unreachable end - i64.const 0 - i32.const 0 - call $~lib/math/ipow64 - i64.const 1 - i64.ne + f64.const 0 + call $~lib/math/NativeMath.clz32 + f64.const 32 + f64.ne if i32.const 0 i32.const 8 @@ -37859,11 +37881,10 @@ call $~lib/env/abort unreachable end - i64.const 0 - i32.const 1 - call $~lib/math/ipow64 - i64.const 0 - i64.ne + f64.const 1 + call $~lib/math/NativeMath.clz32 + f64.const 31 + f64.ne if i32.const 0 i32.const 8 @@ -37872,11 +37893,10 @@ call $~lib/env/abort unreachable end - i64.const 0 - i32.const 2 - call $~lib/math/ipow64 - i64.const 0 - i64.ne + f64.const -1 + call $~lib/math/NativeMath.clz32 + f64.const 0 + f64.ne if i32.const 0 i32.const 8 @@ -37885,6 +37905,201 @@ call $~lib/env/abort unreachable end + f64.const -128 + call $~lib/math/NativeMath.clz32 + f64.const 0 + f64.ne + if + i32.const 0 + i32.const 8 + i32.const 3292 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const 4294967295 + call $~lib/math/NativeMath.clz32 + f64.const 0 + f64.ne + if + i32.const 0 + i32.const 8 + i32.const 3293 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const 4294967295.5 + call $~lib/math/NativeMath.clz32 + f64.const 0 + f64.ne + if + i32.const 0 + i32.const 8 + i32.const 3294 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const 4294967296 + call $~lib/math/NativeMath.clz32 + f64.const 32 + f64.ne + if + i32.const 0 + i32.const 8 + i32.const 3295 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const 4294967297 + call $~lib/math/NativeMath.clz32 + f64.const 31 + f64.ne + if + i32.const 0 + i32.const 8 + i32.const 3296 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const nan:0x8000000000000 + call $~lib/math/NativeMath.clz32 + f64.const 32 + f64.ne + if + i32.const 0 + i32.const 8 + i32.const 3297 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const inf + call $~lib/math/NativeMath.clz32 + f64.const 32 + f64.ne + if + i32.const 0 + i32.const 8 + i32.const 3298 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const 9007199254740991 + call $~lib/math/NativeMath.clz32 + f64.const 0 + f64.ne + if + i32.const 0 + i32.const 8 + i32.const 3299 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const -9007199254740991 + call $~lib/math/NativeMath.clz32 + f64.const 31 + f64.ne + if + i32.const 0 + i32.const 8 + i32.const 3300 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const 1797693134862315708145274e284 + call $~lib/math/NativeMath.clz32 + f64.const 32 + f64.ne + if + i32.const 0 + i32.const 8 + i32.const 3301 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const 5e-324 + call $~lib/math/NativeMath.clz32 + f64.const 32 + f64.ne + if + i32.const 0 + i32.const 8 + i32.const 3302 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const -1797693134862315708145274e284 + call $~lib/math/NativeMath.clz32 + f64.const 32 + f64.ne + if + i32.const 0 + i32.const 8 + i32.const 3303 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const 2.220446049250313e-16 + call $~lib/math/NativeMath.clz32 + f64.const 32 + f64.ne + if + i32.const 0 + i32.const 8 + i32.const 3304 + i32.const 0 + call $~lib/env/abort + unreachable + end + i64.const 0 + i32.const 0 + call $~lib/math/ipow64 + i64.const 1 + i64.ne + if + i32.const 0 + i32.const 8 + i32.const 3308 + i32.const 0 + call $~lib/env/abort + unreachable + end + i64.const 0 + i32.const 1 + call $~lib/math/ipow64 + i64.const 0 + i64.ne + if + i32.const 0 + i32.const 8 + i32.const 3309 + i32.const 0 + call $~lib/env/abort + unreachable + end + i64.const 0 + i32.const 2 + call $~lib/math/ipow64 + i64.const 0 + i64.ne + if + i32.const 0 + i32.const 8 + i32.const 3310 + i32.const 0 + call $~lib/env/abort + unreachable + end i64.const 0 i32.const 3 call $~lib/math/ipow64 @@ -37893,7 +38108,7 @@ if i32.const 0 i32.const 8 - i32.const 3292 + i32.const 3311 i32.const 0 call $~lib/env/abort unreachable @@ -37906,7 +38121,7 @@ if i32.const 0 i32.const 8 - i32.const 3294 + i32.const 3313 i32.const 0 call $~lib/env/abort unreachable @@ -37919,7 +38134,7 @@ if i32.const 0 i32.const 8 - i32.const 3295 + i32.const 3314 i32.const 0 call $~lib/env/abort unreachable @@ -37932,7 +38147,7 @@ if i32.const 0 i32.const 8 - i32.const 3296 + i32.const 3315 i32.const 0 call $~lib/env/abort unreachable @@ -37945,7 +38160,7 @@ if i32.const 0 i32.const 8 - i32.const 3297 + i32.const 3316 i32.const 0 call $~lib/env/abort unreachable @@ -37958,7 +38173,7 @@ if i32.const 0 i32.const 8 - i32.const 3299 + i32.const 3318 i32.const 0 call $~lib/env/abort unreachable @@ -37971,7 +38186,7 @@ if i32.const 0 i32.const 8 - i32.const 3300 + i32.const 3319 i32.const 0 call $~lib/env/abort unreachable @@ -37984,7 +38199,7 @@ if i32.const 0 i32.const 8 - i32.const 3301 + i32.const 3320 i32.const 0 call $~lib/env/abort unreachable @@ -37997,7 +38212,7 @@ if i32.const 0 i32.const 8 - i32.const 3302 + i32.const 3321 i32.const 0 call $~lib/env/abort unreachable @@ -38010,7 +38225,7 @@ if i32.const 0 i32.const 8 - i32.const 3304 + i32.const 3323 i32.const 0 call $~lib/env/abort unreachable @@ -38023,7 +38238,7 @@ if i32.const 0 i32.const 8 - i32.const 3305 + i32.const 3324 i32.const 0 call $~lib/env/abort unreachable @@ -38036,7 +38251,7 @@ if i32.const 0 i32.const 8 - i32.const 3306 + i32.const 3325 i32.const 0 call $~lib/env/abort unreachable @@ -38049,7 +38264,7 @@ if i32.const 0 i32.const 8 - i32.const 3307 + i32.const 3326 i32.const 0 call $~lib/env/abort unreachable @@ -38062,7 +38277,7 @@ if i32.const 0 i32.const 8 - i32.const 3309 + i32.const 3328 i32.const 0 call $~lib/env/abort unreachable @@ -38075,7 +38290,7 @@ if i32.const 0 i32.const 8 - i32.const 3310 + i32.const 3329 i32.const 0 call $~lib/env/abort unreachable @@ -38088,7 +38303,7 @@ if i32.const 0 i32.const 8 - i32.const 3311 + i32.const 3330 i32.const 0 call $~lib/env/abort unreachable @@ -38101,7 +38316,7 @@ if i32.const 0 i32.const 8 - i32.const 3312 + i32.const 3331 i32.const 0 call $~lib/env/abort unreachable @@ -38114,7 +38329,7 @@ if i32.const 0 i32.const 8 - i32.const 3314 + i32.const 3333 i32.const 0 call $~lib/env/abort unreachable @@ -38127,7 +38342,7 @@ if i32.const 0 i32.const 8 - i32.const 3315 + i32.const 3334 i32.const 0 call $~lib/env/abort unreachable @@ -38140,7 +38355,7 @@ if i32.const 0 i32.const 8 - i32.const 3316 + i32.const 3335 i32.const 0 call $~lib/env/abort unreachable @@ -38153,7 +38368,7 @@ if i32.const 0 i32.const 8 - i32.const 3317 + i32.const 3336 i32.const 0 call $~lib/env/abort unreachable @@ -38166,7 +38381,7 @@ if i32.const 0 i32.const 8 - i32.const 3318 + i32.const 3337 i32.const 0 call $~lib/env/abort unreachable @@ -38179,7 +38394,7 @@ if i32.const 0 i32.const 8 - i32.const 3319 + i32.const 3338 i32.const 0 call $~lib/env/abort unreachable @@ -38192,7 +38407,7 @@ if i32.const 0 i32.const 8 - i32.const 3320 + i32.const 3339 i32.const 0 call $~lib/env/abort unreachable @@ -38209,7 +38424,7 @@ if i32.const 0 i32.const 8 - i32.const 3322 + i32.const 3341 i32.const 0 call $~lib/env/abort unreachable @@ -38222,7 +38437,7 @@ if i32.const 0 i32.const 8 - i32.const 3326 + i32.const 3345 i32.const 0 call $~lib/env/abort unreachable @@ -38235,7 +38450,7 @@ if i32.const 0 i32.const 8 - i32.const 3327 + i32.const 3346 i32.const 0 call $~lib/env/abort unreachable @@ -38249,7 +38464,7 @@ if i32.const 0 i32.const 8 - i32.const 3328 + i32.const 3347 i32.const 0 call $~lib/env/abort unreachable @@ -38263,7 +38478,7 @@ if i32.const 0 i32.const 8 - i32.const 3329 + i32.const 3348 i32.const 0 call $~lib/env/abort unreachable @@ -38277,7 +38492,7 @@ if i32.const 0 i32.const 8 - i32.const 3330 + i32.const 3349 i32.const 0 call $~lib/env/abort unreachable @@ -38290,7 +38505,7 @@ if i32.const 0 i32.const 8 - i32.const 3331 + i32.const 3350 i32.const 0 call $~lib/env/abort unreachable @@ -38303,7 +38518,7 @@ if i32.const 0 i32.const 8 - i32.const 3332 + i32.const 3351 i32.const 0 call $~lib/env/abort unreachable @@ -38316,7 +38531,7 @@ if i32.const 0 i32.const 8 - i32.const 3333 + i32.const 3352 i32.const 0 call $~lib/env/abort unreachable @@ -38329,7 +38544,7 @@ if i32.const 0 i32.const 8 - i32.const 3334 + i32.const 3353 i32.const 0 call $~lib/env/abort unreachable @@ -38342,7 +38557,7 @@ if i32.const 0 i32.const 8 - i32.const 3335 + i32.const 3354 i32.const 0 call $~lib/env/abort unreachable @@ -38355,7 +38570,7 @@ if i32.const 0 i32.const 8 - i32.const 3336 + i32.const 3355 i32.const 0 call $~lib/env/abort unreachable @@ -38368,7 +38583,7 @@ if i32.const 0 i32.const 8 - i32.const 3337 + i32.const 3356 i32.const 0 call $~lib/env/abort unreachable @@ -38381,7 +38596,7 @@ if i32.const 0 i32.const 8 - i32.const 3338 + i32.const 3357 i32.const 0 call $~lib/env/abort unreachable @@ -38394,7 +38609,7 @@ if i32.const 0 i32.const 8 - i32.const 3339 + i32.const 3358 i32.const 0 call $~lib/env/abort unreachable @@ -38407,7 +38622,7 @@ if i32.const 0 i32.const 8 - i32.const 3340 + i32.const 3359 i32.const 0 call $~lib/env/abort unreachable @@ -38420,7 +38635,7 @@ if i32.const 0 i32.const 8 - i32.const 3341 + i32.const 3360 i32.const 0 call $~lib/env/abort unreachable @@ -38433,7 +38648,7 @@ if i32.const 0 i32.const 8 - i32.const 3345 + i32.const 3364 i32.const 0 call $~lib/env/abort unreachable @@ -38446,7 +38661,7 @@ if i32.const 0 i32.const 8 - i32.const 3346 + i32.const 3365 i32.const 0 call $~lib/env/abort unreachable @@ -38460,7 +38675,7 @@ if i32.const 0 i32.const 8 - i32.const 3347 + i32.const 3366 i32.const 0 call $~lib/env/abort unreachable @@ -38474,7 +38689,7 @@ if i32.const 0 i32.const 8 - i32.const 3348 + i32.const 3367 i32.const 0 call $~lib/env/abort unreachable @@ -38488,7 +38703,7 @@ if i32.const 0 i32.const 8 - i32.const 3349 + i32.const 3368 i32.const 0 call $~lib/env/abort unreachable @@ -38501,7 +38716,7 @@ if i32.const 0 i32.const 8 - i32.const 3350 + i32.const 3369 i32.const 0 call $~lib/env/abort unreachable @@ -38514,7 +38729,7 @@ if i32.const 0 i32.const 8 - i32.const 3351 + i32.const 3370 i32.const 0 call $~lib/env/abort unreachable @@ -38527,7 +38742,7 @@ if i32.const 0 i32.const 8 - i32.const 3352 + i32.const 3371 i32.const 0 call $~lib/env/abort unreachable @@ -38540,7 +38755,7 @@ if i32.const 0 i32.const 8 - i32.const 3353 + i32.const 3372 i32.const 0 call $~lib/env/abort unreachable @@ -38553,7 +38768,7 @@ if i32.const 0 i32.const 8 - i32.const 3354 + i32.const 3373 i32.const 0 call $~lib/env/abort unreachable @@ -38566,7 +38781,7 @@ if i32.const 0 i32.const 8 - i32.const 3355 + i32.const 3374 i32.const 0 call $~lib/env/abort unreachable @@ -38579,7 +38794,7 @@ if i32.const 0 i32.const 8 - i32.const 3356 + i32.const 3375 i32.const 0 call $~lib/env/abort unreachable @@ -38592,7 +38807,7 @@ if i32.const 0 i32.const 8 - i32.const 3357 + i32.const 3376 i32.const 0 call $~lib/env/abort unreachable @@ -38605,7 +38820,7 @@ if i32.const 0 i32.const 8 - i32.const 3358 + i32.const 3377 i32.const 0 call $~lib/env/abort unreachable @@ -38618,7 +38833,7 @@ if i32.const 0 i32.const 8 - i32.const 3359 + i32.const 3378 i32.const 0 call $~lib/env/abort unreachable @@ -38631,16 +38846,16 @@ if i32.const 0 i32.const 8 - i32.const 3360 + i32.const 3379 i32.const 0 call $~lib/env/abort unreachable end ) - (func $start (; 150 ;) (type $_) + (func $start (; 151 ;) (type $_) call $start:std/math ) - (func $null (; 151 ;) (type $_) + (func $null (; 152 ;) (type $_) nop ) ) diff --git a/tests/compiler/std/math.ts b/tests/compiler/std/math.ts index 5d10bbbd..d26a6848 100644 --- a/tests/compiler/std/math.ts +++ b/tests/compiler/std/math.ts @@ -3284,6 +3284,25 @@ assert(NativeMath.imul(NaN, 1) == 0); assert(NativeMath.imul(1, Infinity) == 0); assert(NativeMath.imul(f64.MAX_VALUE, f64.MAX_VALUE) == 0); +// Math.clz32 ///////////////////////////////////////////////////////////////////////////////// + +assert(NativeMath.clz32(0) == 32); +assert(NativeMath.clz32(1) == 31); +assert(NativeMath.clz32(-1) == 0); +assert(NativeMath.clz32(-128) == 0); +assert(NativeMath.clz32(4294967295.) == 0); +assert(NativeMath.clz32(4294967295.5) == 0); +assert(NativeMath.clz32(4294967296) == 32); +assert(NativeMath.clz32(4294967297) == 31); +assert(NativeMath.clz32(NaN) == 32); +assert(NativeMath.clz32(Infinity) == 32); +assert(NativeMath.clz32(f64.MAX_SAFE_INTEGER) == 0); +assert(NativeMath.clz32(-f64.MAX_SAFE_INTEGER) == 31); +assert(NativeMath.clz32(f64.MAX_VALUE) == 32); +assert(NativeMath.clz32(f64.MIN_VALUE) == 32); +assert(NativeMath.clz32(-f64.MAX_VALUE) == 32); +assert(NativeMath.clz32(f64.EPSILON) == 32); + // ipow64 ///////////////////////////////////////////////////////////////////////////////////// assert(ipow64(0, 0) == 1); diff --git a/tests/compiler/std/math.untouched.wat b/tests/compiler/std/math.untouched.wat index cdffcb64..9a2dbea8 100644 --- a/tests/compiler/std/math.untouched.wat +++ b/tests/compiler/std/math.untouched.wat @@ -93,6 +93,8 @@ (global $~lib/math/random_state1_32 (mut i32) (i32.const 0)) (global $~lib/ASC_SHRINK_LEVEL i32 (i32.const 0)) (global $~lib/builtins/f64.MAX_VALUE f64 (f64.const 1797693134862315708145274e284)) + (global $~lib/builtins/f64.MAX_SAFE_INTEGER f64 (f64.const 9007199254740991)) + (global $~lib/builtins/f64.EPSILON f64 (f64.const 2.220446049250313e-16)) (global $~lib/builtins/f32.MAX_VALUE f32 (f32.const 3402823466385288598117041e14)) (global $~lib/builtins/f32.MIN_VALUE f32 (f32.const 1.401298464324817e-45)) (global $~lib/memory/HEAP_BASE i32 (i32.const 68)) @@ -9772,7 +9774,7 @@ if i32.const 0 i32.const 40 - i32.const 968 + i32.const 976 i32.const 4 call $~lib/env/abort unreachable @@ -9804,7 +9806,7 @@ if i32.const 0 i32.const 40 - i32.const 977 + i32.const 985 i32.const 24 call $~lib/env/abort unreachable @@ -9861,7 +9863,7 @@ if i32.const 0 i32.const 40 - i32.const 2044 + i32.const 2065 i32.const 24 call $~lib/env/abort unreachable @@ -11245,7 +11247,30 @@ i32.mul f64.convert_i32_s ) - (func $~lib/math/ipow64 (; 154 ;) (type $IiI) (param $0 i64) (param $1 i32) (result i64) + (func $~lib/math/NativeMath.clz32 (; 154 ;) (type $FF) (param $0 f64) (result f64) + local.get $0 + call $~lib/builtins/isFinite + i32.eqz + if + f64.const 32 + 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 + i32.clz + f64.convert_i32_s + ) + (func $~lib/math/ipow64 (; 155 ;) (type $IiI) (param $0 i64) (param $1 i32) (result i64) (local $2 i64) (local $3 i32) (local $4 i32) @@ -11477,7 +11502,7 @@ end local.get $2 ) - (func $~lib/math/ipow32f (; 155 ;) (type $fif) (param $0 f32) (param $1 i32) (result f32) + (func $~lib/math/ipow32f (; 156 ;) (type $fif) (param $0 f32) (param $1 i32) (result f32) (local $2 i32) (local $3 f32) local.get $1 @@ -11528,7 +11553,7 @@ local.get $3 end ) - (func $~lib/math/ipow64f (; 156 ;) (type $FiF) (param $0 f64) (param $1 i32) (result f64) + (func $~lib/math/ipow64f (; 157 ;) (type $FiF) (param $0 f64) (param $1 i32) (result f64) (local $2 i32) (local $3 f64) local.get $1 @@ -11579,7 +11604,7 @@ local.get $3 end ) - (func $start:std/math (; 157 ;) (type $_) + (func $start:std/math (; 158 ;) (type $_) (local $0 i32) (local $1 f64) (local $2 i32) @@ -42118,11 +42143,10 @@ call $~lib/env/abort unreachable end - i64.const 0 - i32.const 0 - call $~lib/math/ipow64 - i64.const 1 - i64.eq + f64.const 0 + call $~lib/math/NativeMath.clz32 + f64.const 32 + f64.eq i32.eqz if i32.const 0 @@ -42132,11 +42156,10 @@ call $~lib/env/abort unreachable end - i64.const 0 - i32.const 1 - call $~lib/math/ipow64 - i64.const 0 - i64.eq + f64.const 1 + call $~lib/math/NativeMath.clz32 + f64.const 31 + f64.eq i32.eqz if i32.const 0 @@ -42146,11 +42169,10 @@ call $~lib/env/abort unreachable end - i64.const 0 - i32.const 2 - call $~lib/math/ipow64 - i64.const 0 - i64.eq + f64.const -1 + call $~lib/math/NativeMath.clz32 + f64.const 0 + f64.eq i32.eqz if i32.const 0 @@ -42160,6 +42182,219 @@ call $~lib/env/abort unreachable end + f64.const -128 + call $~lib/math/NativeMath.clz32 + f64.const 0 + f64.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3292 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const 4294967295 + call $~lib/math/NativeMath.clz32 + f64.const 0 + f64.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3293 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const 4294967295.5 + call $~lib/math/NativeMath.clz32 + f64.const 0 + f64.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3294 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const 4294967296 + call $~lib/math/NativeMath.clz32 + f64.const 32 + f64.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3295 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const 4294967297 + call $~lib/math/NativeMath.clz32 + f64.const 31 + f64.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3296 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const nan:0x8000000000000 + call $~lib/math/NativeMath.clz32 + f64.const 32 + f64.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3297 + i32.const 0 + call $~lib/env/abort + unreachable + end + f64.const inf + call $~lib/math/NativeMath.clz32 + f64.const 32 + f64.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3298 + i32.const 0 + call $~lib/env/abort + unreachable + end + global.get $~lib/builtins/f64.MAX_SAFE_INTEGER + call $~lib/math/NativeMath.clz32 + f64.const 0 + f64.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3299 + i32.const 0 + call $~lib/env/abort + unreachable + end + global.get $~lib/builtins/f64.MAX_SAFE_INTEGER + f64.neg + call $~lib/math/NativeMath.clz32 + f64.const 31 + f64.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3300 + i32.const 0 + call $~lib/env/abort + unreachable + end + global.get $~lib/builtins/f64.MAX_VALUE + call $~lib/math/NativeMath.clz32 + f64.const 32 + f64.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3301 + i32.const 0 + call $~lib/env/abort + unreachable + end + global.get $~lib/builtins/f64.MIN_VALUE + call $~lib/math/NativeMath.clz32 + f64.const 32 + f64.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3302 + i32.const 0 + call $~lib/env/abort + unreachable + end + global.get $~lib/builtins/f64.MAX_VALUE + f64.neg + call $~lib/math/NativeMath.clz32 + f64.const 32 + f64.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3303 + i32.const 0 + call $~lib/env/abort + unreachable + end + global.get $~lib/builtins/f64.EPSILON + call $~lib/math/NativeMath.clz32 + f64.const 32 + f64.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3304 + i32.const 0 + call $~lib/env/abort + unreachable + end + i64.const 0 + i32.const 0 + call $~lib/math/ipow64 + i64.const 1 + i64.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3308 + i32.const 0 + call $~lib/env/abort + unreachable + end + i64.const 0 + i32.const 1 + call $~lib/math/ipow64 + i64.const 0 + i64.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3309 + i32.const 0 + call $~lib/env/abort + unreachable + end + i64.const 0 + i32.const 2 + call $~lib/math/ipow64 + i64.const 0 + i64.eq + i32.eqz + if + i32.const 0 + i32.const 8 + i32.const 3310 + i32.const 0 + call $~lib/env/abort + unreachable + end i64.const 0 i32.const 3 call $~lib/math/ipow64 @@ -42169,7 +42404,7 @@ if i32.const 0 i32.const 8 - i32.const 3292 + i32.const 3311 i32.const 0 call $~lib/env/abort unreachable @@ -42183,7 +42418,7 @@ if i32.const 0 i32.const 8 - i32.const 3294 + i32.const 3313 i32.const 0 call $~lib/env/abort unreachable @@ -42197,7 +42432,7 @@ if i32.const 0 i32.const 8 - i32.const 3295 + i32.const 3314 i32.const 0 call $~lib/env/abort unreachable @@ -42211,7 +42446,7 @@ if i32.const 0 i32.const 8 - i32.const 3296 + i32.const 3315 i32.const 0 call $~lib/env/abort unreachable @@ -42225,7 +42460,7 @@ if i32.const 0 i32.const 8 - i32.const 3297 + i32.const 3316 i32.const 0 call $~lib/env/abort unreachable @@ -42239,7 +42474,7 @@ if i32.const 0 i32.const 8 - i32.const 3299 + i32.const 3318 i32.const 0 call $~lib/env/abort unreachable @@ -42253,7 +42488,7 @@ if i32.const 0 i32.const 8 - i32.const 3300 + i32.const 3319 i32.const 0 call $~lib/env/abort unreachable @@ -42267,7 +42502,7 @@ if i32.const 0 i32.const 8 - i32.const 3301 + i32.const 3320 i32.const 0 call $~lib/env/abort unreachable @@ -42281,7 +42516,7 @@ if i32.const 0 i32.const 8 - i32.const 3302 + i32.const 3321 i32.const 0 call $~lib/env/abort unreachable @@ -42295,7 +42530,7 @@ if i32.const 0 i32.const 8 - i32.const 3304 + i32.const 3323 i32.const 0 call $~lib/env/abort unreachable @@ -42309,7 +42544,7 @@ if i32.const 0 i32.const 8 - i32.const 3305 + i32.const 3324 i32.const 0 call $~lib/env/abort unreachable @@ -42323,7 +42558,7 @@ if i32.const 0 i32.const 8 - i32.const 3306 + i32.const 3325 i32.const 0 call $~lib/env/abort unreachable @@ -42337,7 +42572,7 @@ if i32.const 0 i32.const 8 - i32.const 3307 + i32.const 3326 i32.const 0 call $~lib/env/abort unreachable @@ -42351,7 +42586,7 @@ if i32.const 0 i32.const 8 - i32.const 3309 + i32.const 3328 i32.const 0 call $~lib/env/abort unreachable @@ -42365,7 +42600,7 @@ if i32.const 0 i32.const 8 - i32.const 3310 + i32.const 3329 i32.const 0 call $~lib/env/abort unreachable @@ -42379,7 +42614,7 @@ if i32.const 0 i32.const 8 - i32.const 3311 + i32.const 3330 i32.const 0 call $~lib/env/abort unreachable @@ -42393,7 +42628,7 @@ if i32.const 0 i32.const 8 - i32.const 3312 + i32.const 3331 i32.const 0 call $~lib/env/abort unreachable @@ -42407,7 +42642,7 @@ if i32.const 0 i32.const 8 - i32.const 3314 + i32.const 3333 i32.const 0 call $~lib/env/abort unreachable @@ -42421,7 +42656,7 @@ if i32.const 0 i32.const 8 - i32.const 3315 + i32.const 3334 i32.const 0 call $~lib/env/abort unreachable @@ -42435,7 +42670,7 @@ if i32.const 0 i32.const 8 - i32.const 3316 + i32.const 3335 i32.const 0 call $~lib/env/abort unreachable @@ -42449,7 +42684,7 @@ if i32.const 0 i32.const 8 - i32.const 3317 + i32.const 3336 i32.const 0 call $~lib/env/abort unreachable @@ -42463,7 +42698,7 @@ if i32.const 0 i32.const 8 - i32.const 3318 + i32.const 3337 i32.const 0 call $~lib/env/abort unreachable @@ -42477,7 +42712,7 @@ if i32.const 0 i32.const 8 - i32.const 3319 + i32.const 3338 i32.const 0 call $~lib/env/abort unreachable @@ -42491,7 +42726,7 @@ if i32.const 0 i32.const 8 - i32.const 3320 + i32.const 3339 i32.const 0 call $~lib/env/abort unreachable @@ -42509,7 +42744,7 @@ if i32.const 0 i32.const 8 - i32.const 3322 + i32.const 3341 i32.const 0 call $~lib/env/abort unreachable @@ -42523,7 +42758,7 @@ if i32.const 0 i32.const 8 - i32.const 3326 + i32.const 3345 i32.const 0 call $~lib/env/abort unreachable @@ -42537,7 +42772,7 @@ if i32.const 0 i32.const 8 - i32.const 3327 + i32.const 3346 i32.const 0 call $~lib/env/abort unreachable @@ -42557,7 +42792,7 @@ if i32.const 0 i32.const 8 - i32.const 3328 + i32.const 3347 i32.const 0 call $~lib/env/abort unreachable @@ -42577,7 +42812,7 @@ if i32.const 0 i32.const 8 - i32.const 3329 + i32.const 3348 i32.const 0 call $~lib/env/abort unreachable @@ -42597,7 +42832,7 @@ if i32.const 0 i32.const 8 - i32.const 3330 + i32.const 3349 i32.const 0 call $~lib/env/abort unreachable @@ -42611,7 +42846,7 @@ if i32.const 0 i32.const 8 - i32.const 3331 + i32.const 3350 i32.const 0 call $~lib/env/abort unreachable @@ -42625,7 +42860,7 @@ if i32.const 0 i32.const 8 - i32.const 3332 + i32.const 3351 i32.const 0 call $~lib/env/abort unreachable @@ -42640,7 +42875,7 @@ if i32.const 0 i32.const 8 - i32.const 3333 + i32.const 3352 i32.const 0 call $~lib/env/abort unreachable @@ -42656,7 +42891,7 @@ if i32.const 0 i32.const 8 - i32.const 3334 + i32.const 3353 i32.const 0 call $~lib/env/abort unreachable @@ -42671,7 +42906,7 @@ if i32.const 0 i32.const 8 - i32.const 3335 + i32.const 3354 i32.const 0 call $~lib/env/abort unreachable @@ -42685,7 +42920,7 @@ if i32.const 0 i32.const 8 - i32.const 3336 + i32.const 3355 i32.const 0 call $~lib/env/abort unreachable @@ -42699,7 +42934,7 @@ if i32.const 0 i32.const 8 - i32.const 3337 + i32.const 3356 i32.const 0 call $~lib/env/abort unreachable @@ -42713,7 +42948,7 @@ if i32.const 0 i32.const 8 - i32.const 3338 + i32.const 3357 i32.const 0 call $~lib/env/abort unreachable @@ -42727,7 +42962,7 @@ if i32.const 0 i32.const 8 - i32.const 3339 + i32.const 3358 i32.const 0 call $~lib/env/abort unreachable @@ -42741,7 +42976,7 @@ if i32.const 0 i32.const 8 - i32.const 3340 + i32.const 3359 i32.const 0 call $~lib/env/abort unreachable @@ -42755,7 +42990,7 @@ if i32.const 0 i32.const 8 - i32.const 3341 + i32.const 3360 i32.const 0 call $~lib/env/abort unreachable @@ -42769,7 +43004,7 @@ if i32.const 0 i32.const 8 - i32.const 3345 + i32.const 3364 i32.const 0 call $~lib/env/abort unreachable @@ -42783,7 +43018,7 @@ if i32.const 0 i32.const 8 - i32.const 3346 + i32.const 3365 i32.const 0 call $~lib/env/abort unreachable @@ -42796,7 +43031,7 @@ if i32.const 0 i32.const 8 - i32.const 3347 + i32.const 3366 i32.const 0 call $~lib/env/abort unreachable @@ -42809,7 +43044,7 @@ if i32.const 0 i32.const 8 - i32.const 3348 + i32.const 3367 i32.const 0 call $~lib/env/abort unreachable @@ -42822,7 +43057,7 @@ if i32.const 0 i32.const 8 - i32.const 3349 + i32.const 3368 i32.const 0 call $~lib/env/abort unreachable @@ -42836,7 +43071,7 @@ if i32.const 0 i32.const 8 - i32.const 3350 + i32.const 3369 i32.const 0 call $~lib/env/abort unreachable @@ -42850,7 +43085,7 @@ if i32.const 0 i32.const 8 - i32.const 3351 + i32.const 3370 i32.const 0 call $~lib/env/abort unreachable @@ -42865,7 +43100,7 @@ if i32.const 0 i32.const 8 - i32.const 3352 + i32.const 3371 i32.const 0 call $~lib/env/abort unreachable @@ -42881,7 +43116,7 @@ if i32.const 0 i32.const 8 - i32.const 3353 + i32.const 3372 i32.const 0 call $~lib/env/abort unreachable @@ -42896,7 +43131,7 @@ if i32.const 0 i32.const 8 - i32.const 3354 + i32.const 3373 i32.const 0 call $~lib/env/abort unreachable @@ -42910,7 +43145,7 @@ if i32.const 0 i32.const 8 - i32.const 3355 + i32.const 3374 i32.const 0 call $~lib/env/abort unreachable @@ -42924,7 +43159,7 @@ if i32.const 0 i32.const 8 - i32.const 3356 + i32.const 3375 i32.const 0 call $~lib/env/abort unreachable @@ -42938,7 +43173,7 @@ if i32.const 0 i32.const 8 - i32.const 3357 + i32.const 3376 i32.const 0 call $~lib/env/abort unreachable @@ -42952,7 +43187,7 @@ if i32.const 0 i32.const 8 - i32.const 3358 + i32.const 3377 i32.const 0 call $~lib/env/abort unreachable @@ -42966,7 +43201,7 @@ if i32.const 0 i32.const 8 - i32.const 3359 + i32.const 3378 i32.const 0 call $~lib/env/abort unreachable @@ -42980,15 +43215,15 @@ if i32.const 0 i32.const 8 - i32.const 3360 + i32.const 3379 i32.const 0 call $~lib/env/abort unreachable end ) - (func $start (; 158 ;) (type $_) + (func $start (; 159 ;) (type $_) call $start:std/math ) - (func $null (; 159 ;) (type $_) + (func $null (; 160 ;) (type $_) ) )