diff --git a/std/assembly/builtins.ts b/std/assembly/builtins.ts index 74f4d7fe..12e88c5e 100644 --- a/std/assembly/builtins.ts +++ b/std/assembly/builtins.ts @@ -13,19 +13,11 @@ export const NaN: f64 = 0 / 0; export const Infinity: f64 = 1 / 0; export function isNaN(value: T): bool { - return isFloat(value) - ? sizeof() == 32 - ? (reinterpret(value) & -1 >>> 1) > 0xFF << 23 - : (reinterpret(value) & -1 >>> 1) > 0x7FF << 52 - : false; + return value != value; } export function isFinite(value: T): bool { - return isFloat(value) - ? sizeof() == 32 - ? (reinterpret(value) & -1 >>> 1) < 0xFF << 23 - : (reinterpret(value) & -1 >>> 1) < 0x7FF << 52 - : true; + return value - value == 0; } export declare function clz(value: T): T; diff --git a/tests/compiler/binary.optimized.wat b/tests/compiler/binary.optimized.wat index c436e26f..c66393ed 100644 --- a/tests/compiler/binary.optimized.wat +++ b/tests/compiler/binary.optimized.wat @@ -1528,16 +1528,9 @@ ) ) (func $isNaN (; 2 ;) (type $fi) (param $0 f32) (result i32) - (i64.gt_u - (i64.and - (i64.reinterpret/f64 - (f64.promote/f32 - (get_local $0) - ) - ) - (i64.const 9223372036854775807) - ) - (i64.const 9218868437227405312) + (f32.ne + (get_local $0) + (get_local $0) ) ) (func $~lib/math/NativeMathf.mod (; 3 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32) @@ -3166,14 +3159,9 @@ ) ) (func $isNaN (; 6 ;) (type $Fi) (param $0 f64) (result i32) - (i64.gt_u - (i64.and - (i64.reinterpret/f64 - (get_local $0) - ) - (i64.const 9223372036854775807) - ) - (i64.const 9218868437227405312) + (f64.ne + (get_local $0) + (get_local $0) ) ) (func $~lib/math/NativeMath.mod (; 7 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) diff --git a/tests/compiler/binary.untouched.wat b/tests/compiler/binary.untouched.wat index dfb4d404..e911b771 100644 --- a/tests/compiler/binary.untouched.wat +++ b/tests/compiler/binary.untouched.wat @@ -4,7 +4,6 @@ (type $FiF (func (param f64 i32) (result f64))) (type $fff (func (param f32 f32) (result f32))) (type $fi (func (param f32) (result i32))) - (type $i (func (result i32))) (type $f (func (result f32))) (type $fif (func (param f32 i32) (result f32))) (type $Fi (func (param f64) (result i32))) @@ -1721,22 +1720,9 @@ ) (func $isNaN (; 2 ;) (type $fi) (param $0 f32) (result i32) (return - (i64.gt_u - (i64.and - (i64.reinterpret/f64 - (f64.promote/f32 - (get_local $0) - ) - ) - (i64.shr_u - (i64.const -1) - (i64.const 1) - ) - ) - (i64.shl - (i64.const 2047) - (i64.const 52) - ) + (f32.ne + (get_local $0) + (get_local $0) ) ) ) @@ -3624,20 +3610,9 @@ ) (func $isNaN (; 6 ;) (type $Fi) (param $0 f64) (result i32) (return - (i64.gt_u - (i64.and - (i64.reinterpret/f64 - (get_local $0) - ) - (i64.shr_u - (i64.const -1) - (i64.const 1) - ) - ) - (i64.shl - (i64.const 2047) - (i64.const 52) - ) + (f64.ne + (get_local $0) + (get_local $0) ) ) ) diff --git a/tests/compiler/builtins.optimized.wat b/tests/compiler/builtins.optimized.wat index 01208204..56b5d946 100644 --- a/tests/compiler/builtins.optimized.wat +++ b/tests/compiler/builtins.optimized.wat @@ -19,51 +19,33 @@ (export "memory" (memory $0)) (start $start) (func $isNaN (; 1 ;) (type $fi) (param $0 f32) (result i32) - (i64.gt_u - (i64.and - (i64.reinterpret/f64 - (f64.promote/f32 - (get_local $0) - ) - ) - (i64.const 9223372036854775807) - ) - (i64.const 9218868437227405312) + (f32.ne + (get_local $0) + (get_local $0) ) ) (func $isFinite (; 2 ;) (type $fi) (param $0 f32) (result i32) - (i64.lt_u - (i64.and - (i64.reinterpret/f64 - (f64.promote/f32 - (get_local $0) - ) - ) - (i64.const 9223372036854775807) + (f32.eq + (f32.sub + (get_local $0) + (get_local $0) ) - (i64.const 9218868437227405312) + (f32.const 0) ) ) (func $isNaN (; 3 ;) (type $Fi) (param $0 f64) (result i32) - (i64.gt_u - (i64.and - (i64.reinterpret/f64 - (get_local $0) - ) - (i64.const 9223372036854775807) - ) - (i64.const 9218868437227405312) + (f64.ne + (get_local $0) + (get_local $0) ) ) (func $isFinite (; 4 ;) (type $Fi) (param $0 f64) (result i32) - (i64.lt_u - (i64.and - (i64.reinterpret/f64 - (get_local $0) - ) - (i64.const 9223372036854775807) + (f64.eq + (f64.sub + (get_local $0) + (get_local $0) ) - (i64.const 9218868437227405312) + (f64.const 0) ) ) (func $builtins/test (; 5 ;) (type $v) diff --git a/tests/compiler/builtins.untouched.wat b/tests/compiler/builtins.untouched.wat index 6635cde9..34e3cf48 100644 --- a/tests/compiler/builtins.untouched.wat +++ b/tests/compiler/builtins.untouched.wat @@ -2,8 +2,8 @@ (type $iiiiv (func (param i32 i32 i32 i32))) (type $F (func (result f64))) (type $fi (func (param f32) (result i32))) - (type $i (func (result i32))) (type $Fi (func (param f64) (result i32))) + (type $i (func (result i32))) (type $v (func)) (type $f (func (result f32))) (import "env" "abort" (func $abort (param i32 i32 i32 i32))) @@ -27,81 +27,39 @@ (start $start) (func $isNaN (; 1 ;) (type $fi) (param $0 f32) (result i32) (return - (i64.gt_u - (i64.and - (i64.reinterpret/f64 - (f64.promote/f32 - (get_local $0) - ) - ) - (i64.shr_u - (i64.const -1) - (i64.const 1) - ) - ) - (i64.shl - (i64.const 2047) - (i64.const 52) - ) + (f32.ne + (get_local $0) + (get_local $0) ) ) ) (func $isFinite (; 2 ;) (type $fi) (param $0 f32) (result i32) (return - (i64.lt_u - (i64.and - (i64.reinterpret/f64 - (f64.promote/f32 - (get_local $0) - ) - ) - (i64.shr_u - (i64.const -1) - (i64.const 1) - ) - ) - (i64.shl - (i64.const 2047) - (i64.const 52) + (f32.eq + (f32.sub + (get_local $0) + (get_local $0) ) + (f32.const 0) ) ) ) (func $isNaN (; 3 ;) (type $Fi) (param $0 f64) (result i32) (return - (i64.gt_u - (i64.and - (i64.reinterpret/f64 - (get_local $0) - ) - (i64.shr_u - (i64.const -1) - (i64.const 1) - ) - ) - (i64.shl - (i64.const 2047) - (i64.const 52) - ) + (f64.ne + (get_local $0) + (get_local $0) ) ) ) (func $isFinite (; 4 ;) (type $Fi) (param $0 f64) (result i32) (return - (i64.lt_u - (i64.and - (i64.reinterpret/f64 - (get_local $0) - ) - (i64.shr_u - (i64.const -1) - (i64.const 1) - ) - ) - (i64.shl - (i64.const 2047) - (i64.const 52) + (f64.eq + (f64.sub + (get_local $0) + (get_local $0) ) + (f64.const 0) ) ) ) diff --git a/tests/compiler/showcase.optimized.wat b/tests/compiler/showcase.optimized.wat index e5e40f00..0ac4ddd7 100644 --- a/tests/compiler/showcase.optimized.wat +++ b/tests/compiler/showcase.optimized.wat @@ -1577,16 +1577,9 @@ ) ) (func $isNaN (; 3 ;) (type $fi) (param $0 f32) (result i32) - (i64.gt_u - (i64.and - (i64.reinterpret/f64 - (f64.promote/f32 - (get_local $0) - ) - ) - (i64.const 9223372036854775807) - ) - (i64.const 9218868437227405312) + (f32.ne + (get_local $0) + (get_local $0) ) ) (func $~lib/math/NativeMathf.mod (; 4 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32) @@ -3215,14 +3208,9 @@ ) ) (func $isNaN (; 7 ;) (type $Fi) (param $0 f64) (result i32) - (i64.gt_u - (i64.and - (i64.reinterpret/f64 - (get_local $0) - ) - (i64.const 9223372036854775807) - ) - (i64.const 9218868437227405312) + (f64.ne + (get_local $0) + (get_local $0) ) ) (func $~lib/math/NativeMath.mod (; 8 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) @@ -3594,27 +3582,21 @@ ) ) (func $isFinite (; 9 ;) (type $fi) (param $0 f32) (result i32) - (i64.lt_u - (i64.and - (i64.reinterpret/f64 - (f64.promote/f32 - (get_local $0) - ) - ) - (i64.const 9223372036854775807) + (f32.eq + (f32.sub + (get_local $0) + (get_local $0) ) - (i64.const 9218868437227405312) + (f32.const 0) ) ) (func $isFinite (; 10 ;) (type $Fi) (param $0 f64) (result i32) - (i64.lt_u - (i64.and - (i64.reinterpret/f64 - (get_local $0) - ) - (i64.const 9223372036854775807) + (f64.eq + (f64.sub + (get_local $0) + (get_local $0) ) - (i64.const 9218868437227405312) + (f64.const 0) ) ) (func $showcase/ANamespace.aNamespacedFunction (; 11 ;) (type $ii) (param $0 i32) (result i32) diff --git a/tests/compiler/showcase.untouched.wat b/tests/compiler/showcase.untouched.wat index dde711ab..40f2ede4 100644 --- a/tests/compiler/showcase.untouched.wat +++ b/tests/compiler/showcase.untouched.wat @@ -4,11 +4,11 @@ (type $FiF (func (param f64 i32) (result f64))) (type $fff (func (param f32 f32) (result f32))) (type $fi (func (param f32) (result i32))) - (type $i (func (result i32))) (type $f (func (result f32))) (type $fif (func (param f32 i32) (result f32))) (type $Fi (func (param f64) (result i32))) (type $iiiiv (func (param i32 i32 i32 i32))) + (type $i (func (result i32))) (type $ii (func (param i32) (result i32))) (type $iii (func (param i32 i32) (result i32))) (type $v (func)) @@ -1777,22 +1777,9 @@ ) (func $isNaN (; 3 ;) (type $fi) (param $0 f32) (result i32) (return - (i64.gt_u - (i64.and - (i64.reinterpret/f64 - (f64.promote/f32 - (get_local $0) - ) - ) - (i64.shr_u - (i64.const -1) - (i64.const 1) - ) - ) - (i64.shl - (i64.const 2047) - (i64.const 52) - ) + (f32.ne + (get_local $0) + (get_local $0) ) ) ) @@ -3680,20 +3667,9 @@ ) (func $isNaN (; 7 ;) (type $Fi) (param $0 f64) (result i32) (return - (i64.gt_u - (i64.and - (i64.reinterpret/f64 - (get_local $0) - ) - (i64.shr_u - (i64.const -1) - (i64.const 1) - ) - ) - (i64.shl - (i64.const 2047) - (i64.const 52) - ) + (f64.ne + (get_local $0) + (get_local $0) ) ) ) @@ -4150,41 +4126,23 @@ ) (func $isFinite (; 9 ;) (type $fi) (param $0 f32) (result i32) (return - (i64.lt_u - (i64.and - (i64.reinterpret/f64 - (f64.promote/f32 - (get_local $0) - ) - ) - (i64.shr_u - (i64.const -1) - (i64.const 1) - ) - ) - (i64.shl - (i64.const 2047) - (i64.const 52) + (f32.eq + (f32.sub + (get_local $0) + (get_local $0) ) + (f32.const 0) ) ) ) (func $isFinite (; 10 ;) (type $Fi) (param $0 f64) (result i32) (return - (i64.lt_u - (i64.and - (i64.reinterpret/f64 - (get_local $0) - ) - (i64.shr_u - (i64.const -1) - (i64.const 1) - ) - ) - (i64.shl - (i64.const 2047) - (i64.const 52) + (f64.eq + (f64.sub + (get_local $0) + (get_local $0) ) + (f64.const 0) ) ) ) diff --git a/tests/compiler/std/libm.optimized.wat b/tests/compiler/std/libm.optimized.wat index 1d546330..ef3f8245 100644 --- a/tests/compiler/std/libm.optimized.wat +++ b/tests/compiler/std/libm.optimized.wat @@ -1308,14 +1308,9 @@ ) ) (func $isNaN (; 12 ;) (type $Fi) (param $0 f64) (result i32) - (i64.gt_u - (i64.and - (i64.reinterpret/f64 - (get_local $0) - ) - (i64.const 9223372036854775807) - ) - (i64.const 9218868437227405312) + (f64.ne + (get_local $0) + (get_local $0) ) ) (func $~lib/math/NativeMath.atan (; 13 ;) (type $FF) (param $0 f64) (result f64) diff --git a/tests/compiler/std/libm.untouched.wat b/tests/compiler/std/libm.untouched.wat index 826d34fd..3f2239bb 100644 --- a/tests/compiler/std/libm.untouched.wat +++ b/tests/compiler/std/libm.untouched.wat @@ -3,8 +3,8 @@ (type $FF (func (param f64) (result f64))) (type $f (func (result f32))) (type $Fi (func (param f64) (result i32))) - (type $i (func (result i32))) (type $FFF (func (param f64 f64) (result f64))) + (type $i (func (result i32))) (type $FiF (func (param f64 i32) (result f64))) (type $Ff (func (param f64) (result f32))) (global $std/libm/E f64 (f64.const 2.718281828459045)) @@ -1557,20 +1557,9 @@ ) (func $isNaN (; 12 ;) (type $Fi) (param $0 f64) (result i32) (return - (i64.gt_u - (i64.and - (i64.reinterpret/f64 - (get_local $0) - ) - (i64.shr_u - (i64.const -1) - (i64.const 1) - ) - ) - (i64.shl - (i64.const 2047) - (i64.const 52) - ) + (f64.ne + (get_local $0) + (get_local $0) ) ) ) diff --git a/tests/compiler/std/math.optimized.wat b/tests/compiler/std/math.optimized.wat index 3032585e..9979ded8 100644 --- a/tests/compiler/std/math.optimized.wat +++ b/tests/compiler/std/math.optimized.wat @@ -69,14 +69,9 @@ (export "memory" (memory $0)) (start $start) (func $isNaN (; 31 ;) (type $Fi) (param $0 f64) (result i32) - (i64.gt_u - (i64.and - (i64.reinterpret/f64 - (get_local $0) - ) - (i64.const 9223372036854775807) - ) - (i64.const 9218868437227405312) + (f64.ne + (get_local $0) + (get_local $0) ) ) (func $std/math/signbit (; 32 ;) (type $Fi) (param $0 f64) (result i32) @@ -90,14 +85,12 @@ ) ) (func $isFinite (; 33 ;) (type $Fi) (param $0 f64) (result i32) - (i64.lt_u - (i64.and - (i64.reinterpret/f64 - (get_local $0) - ) - (i64.const 9223372036854775807) + (f64.eq + (f64.sub + (get_local $0) + (get_local $0) ) - (i64.const 9218868437227405312) + (f64.const 0) ) ) (func $std/math/eulp (; 34 ;) (type $Fi) (param $0 f64) (result i32) @@ -374,16 +367,9 @@ (i32.const 1) ) (func $isNaN (; 38 ;) (type $fi) (param $0 f32) (result i32) - (i64.gt_u - (i64.and - (i64.reinterpret/f64 - (f64.promote/f32 - (get_local $0) - ) - ) - (i64.const 9223372036854775807) - ) - (i64.const 9218868437227405312) + (f32.ne + (get_local $0) + (get_local $0) ) ) (func $std/math/signbitf (; 39 ;) (type $fi) (param $0 f32) (result i32) @@ -395,16 +381,12 @@ ) ) (func $isFinite (; 40 ;) (type $fi) (param $0 f32) (result i32) - (i64.lt_u - (i64.and - (i64.reinterpret/f64 - (f64.promote/f32 - (get_local $0) - ) - ) - (i64.const 9223372036854775807) + (f32.eq + (f32.sub + (get_local $0) + (get_local $0) ) - (i64.const 9218868437227405312) + (f32.const 0) ) ) (func $std/math/eulpf (; 41 ;) (type $fi) (param $0 f32) (result i32) diff --git a/tests/compiler/std/math.untouched.wat b/tests/compiler/std/math.untouched.wat index 571e0e6f..6cdc40a5 100644 --- a/tests/compiler/std/math.untouched.wat +++ b/tests/compiler/std/math.untouched.wat @@ -80,20 +80,9 @@ (start $start) (func $isNaN (; 31 ;) (type $Fi) (param $0 f64) (result i32) (return - (i64.gt_u - (i64.and - (i64.reinterpret/f64 - (get_local $0) - ) - (i64.shr_u - (i64.const -1) - (i64.const 1) - ) - ) - (i64.shl - (i64.const 2047) - (i64.const 52) - ) + (f64.ne + (get_local $0) + (get_local $0) ) ) ) @@ -111,20 +100,12 @@ ) (func $isFinite (; 33 ;) (type $Fi) (param $0 f64) (result i32) (return - (i64.lt_u - (i64.and - (i64.reinterpret/f64 - (get_local $0) - ) - (i64.shr_u - (i64.const -1) - (i64.const 1) - ) - ) - (i64.shl - (i64.const 2047) - (i64.const 52) + (f64.eq + (f64.sub + (get_local $0) + (get_local $0) ) + (f64.const 0) ) ) ) @@ -427,22 +408,9 @@ ) (func $isNaN (; 38 ;) (type $fi) (param $0 f32) (result i32) (return - (i64.gt_u - (i64.and - (i64.reinterpret/f64 - (f64.promote/f32 - (get_local $0) - ) - ) - (i64.shr_u - (i64.const -1) - (i64.const 1) - ) - ) - (i64.shl - (i64.const 2047) - (i64.const 52) - ) + (f32.ne + (get_local $0) + (get_local $0) ) ) ) @@ -458,22 +426,12 @@ ) (func $isFinite (; 40 ;) (type $fi) (param $0 f32) (result i32) (return - (i64.lt_u - (i64.and - (i64.reinterpret/f64 - (f64.promote/f32 - (get_local $0) - ) - ) - (i64.shr_u - (i64.const -1) - (i64.const 1) - ) - ) - (i64.shl - (i64.const 2047) - (i64.const 52) + (f32.eq + (f32.sub + (get_local $0) + (get_local $0) ) + (f32.const 0) ) ) ) diff --git a/tests/compiler/std/mod.optimized.wat b/tests/compiler/std/mod.optimized.wat index 0045c9de..dde4a35f 100644 --- a/tests/compiler/std/mod.optimized.wat +++ b/tests/compiler/std/mod.optimized.wat @@ -16,14 +16,9 @@ (export "memory" (memory $0)) (start $start) (func $isNaN (; 2 ;) (type $Fi) (param $0 f64) (result i32) - (i64.gt_u - (i64.and - (i64.reinterpret/f64 - (get_local $0) - ) - (i64.const 9223372036854775807) - ) - (i64.const 9218868437227405312) + (f64.ne + (get_local $0) + (get_local $0) ) ) (func $~lib/math/NativeMath.mod (; 3 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) @@ -460,16 +455,9 @@ ) ) (func $isNaN (; 6 ;) (type $fi) (param $0 f32) (result i32) - (i64.gt_u - (i64.and - (i64.reinterpret/f64 - (f64.promote/f32 - (get_local $0) - ) - ) - (i64.const 9223372036854775807) - ) - (i64.const 9218868437227405312) + (f32.ne + (get_local $0) + (get_local $0) ) ) (func $~lib/math/NativeMathf.mod (; 7 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32) diff --git a/tests/compiler/std/mod.untouched.wat b/tests/compiler/std/mod.untouched.wat index c62c572f..0db365b8 100644 --- a/tests/compiler/std/mod.untouched.wat +++ b/tests/compiler/std/mod.untouched.wat @@ -2,8 +2,8 @@ (type $FFFi (func (param f64 f64 f64) (result i32))) (type $FFF (func (param f64 f64) (result f64))) (type $Fi (func (param f64) (result i32))) - (type $i (func (result i32))) (type $FFi (func (param f64 f64) (result i32))) + (type $i (func (result i32))) (type $iiiiv (func (param i32 i32 i32 i32))) (type $F (func (result f64))) (type $fffi (func (param f32 f32 f32) (result i32))) @@ -23,20 +23,9 @@ (start $start) (func $isNaN (; 2 ;) (type $Fi) (param $0 f64) (result i32) (return - (i64.gt_u - (i64.and - (i64.reinterpret/f64 - (get_local $0) - ) - (i64.shr_u - (i64.const -1) - (i64.const 1) - ) - ) - (i64.shl - (i64.const 2047) - (i64.const 52) - ) + (f64.ne + (get_local $0) + (get_local $0) ) ) ) @@ -566,22 +555,9 @@ ) (func $isNaN (; 6 ;) (type $fi) (param $0 f32) (result i32) (return - (i64.gt_u - (i64.and - (i64.reinterpret/f64 - (f64.promote/f32 - (get_local $0) - ) - ) - (i64.shr_u - (i64.const -1) - (i64.const 1) - ) - ) - (i64.shl - (i64.const 2047) - (i64.const 52) - ) + (f32.ne + (get_local $0) + (get_local $0) ) ) )