Add i64 and f32/f64 support (README updated to match) (#3)
This commit was merged in pull request #3.
This commit is contained in:
1 parent
05488c9783
commit
987cdf256b
8 files changed
+690
-128
No files matched your search
@@ -0,0 +1,78 @@
|
||||
;; f32/f64 arithmetic, comparisons, rounding, min/max, conversions, memory and globals.
|
||||
;; Exits 0 if all checks pass, otherwise with the number of the first failing check.
|
||||
(module
|
||||
(memory 1)
|
||||
(global $g (mut f64) (f64.const 1.5))
|
||||
(global $h (mut f32) (f32.const 2.5))
|
||||
(func $nan64 (result f64) (f64.div (f64.const 0) (f64.const 0)))
|
||||
(func $nan32 (result f32) (f32.div (f32.const 0) (f32.const 0)))
|
||||
(func $hyp (param $a f64) (param $b f64) (result f64)
|
||||
(f64.sqrt (f64.add (f64.mul (local.get $a) (local.get $a)) (f64.mul (local.get $b) (local.get $b)))))
|
||||
(func (export "main") (result i32)
|
||||
(local $x f32)
|
||||
;; 1-4: basic arithmetic
|
||||
(if (f64.ne (call $hyp (f64.const 3) (f64.const 4)) (f64.const 5)) (then (return (i32.const 1))))
|
||||
(if (f32.ne (f32.mul (f32.const 1.5) (f32.const 4)) (f32.const 6)) (then (return (i32.const 2))))
|
||||
(if (f64.ne (f64.div (f64.const 1) (f64.const 4)) (f64.const 0.25)) (then (return (i32.const 3))))
|
||||
(if (f32.ne (f32.sub (f32.const 0.5) (f32.const 2)) (f32.const -1.5)) (then (return (i32.const 4))))
|
||||
;; 5-8: comparisons incl. NaN
|
||||
(if (i32.eqz (f64.lt (f64.const 1) (f64.const 2))) (then (return (i32.const 5))))
|
||||
(if (i32.eqz (f64.ge (f64.const 2) (f64.const 2))) (then (return (i32.const 6))))
|
||||
(if (f64.eq (call $nan64) (call $nan64)) (then (return (i32.const 7))))
|
||||
(if (i32.eqz (f64.ne (call $nan64) (f64.const 1))) (then (return (i32.const 8))))
|
||||
(if (f64.lt (call $nan64) (f64.const 1)) (then (return (i32.const 9))))
|
||||
(if (f64.le (f64.const 1) (call $nan64)) (then (return (i32.const 10))))
|
||||
(if (f32.gt (call $nan32) (f32.const 1)) (then (return (i32.const 11))))
|
||||
(if (i32.eqz (f32.le (f32.const 1) (f32.const 1))) (then (return (i32.const 12))))
|
||||
;; 13-18: rounding
|
||||
(if (f64.ne (f64.ceil (f64.const 1.2)) (f64.const 2)) (then (return (i32.const 13))))
|
||||
(if (f64.ne (f64.floor (f64.const -1.2)) (f64.const -2)) (then (return (i32.const 14))))
|
||||
(if (f64.ne (f64.trunc (f64.const -1.7)) (f64.const -1)) (then (return (i32.const 15))))
|
||||
(if (f64.ne (f64.nearest (f64.const 2.5)) (f64.const 2)) (then (return (i32.const 16))))
|
||||
(if (f64.ne (f64.nearest (f64.const 3.5)) (f64.const 4)) (then (return (i32.const 17))))
|
||||
(if (f32.ne (f32.nearest (f32.const -0.5)) (f32.const -0)) (then (return (i32.const 18))))
|
||||
;; 19-24: abs / neg / copysign / min / max (signed zero and NaN)
|
||||
(if (f64.ne (f64.abs (f64.const -3)) (f64.const 3)) (then (return (i32.const 19))))
|
||||
(if (f32.ne (f32.neg (f32.const 3)) (f32.const -3)) (then (return (i32.const 20))))
|
||||
(if (f64.ne (f64.copysign (f64.const 2) (f64.const -0)) (f64.const -2)) (then (return (i32.const 21))))
|
||||
(if (f64.ne (f64.min (f64.const 1) (f64.const 2)) (f64.const 1)) (then (return (i32.const 22))))
|
||||
(if (f64.ne (f64.max (f64.const 1) (f64.const 2)) (f64.const 2)) (then (return (i32.const 23))))
|
||||
(if (i64.ne (i64.reinterpret_f64 (f64.min (f64.const 0) (f64.const -0))) (i64.const 0x8000000000000000)) (then (return (i32.const 24))))
|
||||
(if (i64.ne (i64.reinterpret_f64 (f64.max (f64.const -0) (f64.const 0))) (i64.const 0)) (then (return (i32.const 25))))
|
||||
(if (f64.eq (f64.min (call $nan64) (f64.const 1)) (f64.const 1)) (then (return (i32.const 26))))
|
||||
(if (f64.eq (f64.max (f64.const 1) (call $nan64)) (f64.const 1)) (then (return (i32.const 27))))
|
||||
(if (f32.ne (f32.min (f32.const 3) (f32.const -4)) (f32.const -4)) (then (return (i32.const 28))))
|
||||
;; 29-34: int -> float
|
||||
(if (f64.ne (f64.convert_i32_s (i32.const -7)) (f64.const -7)) (then (return (i32.const 29))))
|
||||
(if (f64.ne (f64.convert_i32_u (i32.const -1)) (f64.const 4294967295)) (then (return (i32.const 30))))
|
||||
(if (f64.ne (f64.convert_i64_s (i64.const -5000000000)) (f64.const -5000000000)) (then (return (i32.const 31))))
|
||||
(if (f64.ne (f64.convert_i64_u (i64.const -1)) (f64.const 18446744073709551616)) (then (return (i32.const 32))))
|
||||
(if (f32.ne (f32.convert_i32_s (i32.const 100)) (f32.const 100)) (then (return (i32.const 33))))
|
||||
(if (f32.ne (f32.convert_i64_u (i64.const 0x8000000000000000)) (f32.const 9223372036854775808)) (then (return (i32.const 34))))
|
||||
;; 35-44: float -> int (truncating)
|
||||
(if (i32.ne (i32.trunc_f64_s (f64.const -3.9)) (i32.const -3)) (then (return (i32.const 35))))
|
||||
(if (i32.ne (i32.trunc_f32_u (f32.const 4000000000)) (i32.const -294967296)) (then (return (i32.const 36))))
|
||||
(if (i32.ne (i32.trunc_f64_u (f64.const -0.5)) (i32.const 0)) (then (return (i32.const 37))))
|
||||
(if (i64.ne (i64.trunc_f64_s (f64.const -9223372036854775808)) (i64.const 0x8000000000000000)) (then (return (i32.const 38))))
|
||||
(if (i64.ne (i64.trunc_f64_s (f64.const 1e18)) (i64.const 1000000000000000000)) (then (return (i32.const 39))))
|
||||
(if (i64.ne (i64.trunc_f64_u (f64.const 1.8e19)) (i64.const 0xF9CCD8A1C5080000)) (then (return (i32.const 40))))
|
||||
(if (i64.ne (i64.trunc_f32_u (f32.const 3e9)) (i64.const 3000000000)) (then (return (i32.const 41))))
|
||||
(if (i64.ne (i64.trunc_f32_s (f32.const -2e9)) (i64.const -2000000000)) (then (return (i32.const 42))))
|
||||
;; 43-45: demote / promote / reinterpret
|
||||
(if (f32.ne (f32.demote_f64 (f64.const 0.1)) (f32.const 0.1)) (then (return (i32.const 43))))
|
||||
(if (f64.ne (f64.promote_f32 (f32.const 0.5)) (f64.const 0.5)) (then (return (i32.const 44))))
|
||||
(if (i32.ne (i32.reinterpret_f32 (f32.const 1)) (i32.const 0x3f800000)) (then (return (i32.const 45))))
|
||||
(if (f32.ne (f32.reinterpret_i32 (i32.const 0x40000000)) (f32.const 2)) (then (return (i32.const 46))))
|
||||
;; 47-49: memory
|
||||
(f64.store (i32.const 16) (f64.const 6.25))
|
||||
(if (f64.ne (f64.load (i32.const 16)) (f64.const 6.25)) (then (return (i32.const 47))))
|
||||
(f32.store (i32.const 32) (f32.const -0.75))
|
||||
(if (f32.ne (f32.load (i32.const 32)) (f32.const -0.75)) (then (return (i32.const 48))))
|
||||
(if (i32.ne (i32.load (i32.const 32)) (i32.const 0xbf400000)) (then (return (i32.const 49))))
|
||||
;; 50-52: globals, locals, select
|
||||
(global.set $g (f64.mul (global.get $g) (f64.const 2)))
|
||||
(if (f64.ne (global.get $g) (f64.const 3)) (then (return (i32.const 50))))
|
||||
(if (f32.ne (global.get $h) (f32.const 2.5)) (then (return (i32.const 51))))
|
||||
(local.set $x (select (f32.const 7) (f32.const 8) (i32.const 0)))
|
||||
(if (f32.ne (local.get $x) (f32.const 8)) (then (return (i32.const 52))))
|
||||
(i32.const 0)))
|
||||
@@ -0,0 +1,4 @@
|
||||
;; float -> int conversion of an out-of-range value traps (exit 134)
|
||||
(module
|
||||
(func (export "main") (result i32)
|
||||
(i32.trunc_f64_s (f64.const 3e9))))
|
||||
@@ -0,0 +1,50 @@
|
||||
;; i64 arithmetic, comparisons, conversions, memory and globals. Exits 0 if all checks pass,
|
||||
;; otherwise with the number of the first failing check.
|
||||
(module
|
||||
(memory 1)
|
||||
(global $g (mut i64) (i64.const 0x123456789abcdef0))
|
||||
(func $fib (param $n i64) (result i64)
|
||||
(if (result i64) (i64.lt_s (local.get $n) (i64.const 2))
|
||||
(then (local.get $n))
|
||||
(else (i64.add
|
||||
(call $fib (i64.sub (local.get $n) (i64.const 1)))
|
||||
(call $fib (i64.sub (local.get $n) (i64.const 2)))))))
|
||||
(func (export "main") (result i32)
|
||||
(local $x i64)
|
||||
;; 1: fib(40) needs more than 32 bits of intermediate range
|
||||
(if (i64.ne (call $fib (i64.const 40)) (i64.const 102334155)) (then (return (i32.const 1))))
|
||||
;; 2: 64-bit multiply overflows i32
|
||||
(if (i64.ne (i64.mul (i64.const 4294967296) (i64.const 3)) (i64.const 12884901888)) (then (return (i32.const 2))))
|
||||
;; 3: signed division / remainder
|
||||
(if (i64.ne (i64.div_s (i64.const -9000000000) (i64.const 7)) (i64.const -1285714285)) (then (return (i32.const 3))))
|
||||
(if (i64.ne (i64.rem_s (i64.const -9000000000) (i64.const 7)) (i64.const -5)) (then (return (i32.const 4))))
|
||||
;; 5: unsigned division treats -1 as 2^64-1
|
||||
(if (i64.ne (i64.div_u (i64.const -1) (i64.const 2)) (i64.const 0x7fffffffffffffff)) (then (return (i32.const 5))))
|
||||
;; 6: INT64_MIN rem_s -1 is 0 (no trap)
|
||||
(if (i64.ne (i64.rem_s (i64.const 0x8000000000000000) (i64.const -1)) (i64.const 0)) (then (return (i32.const 6))))
|
||||
;; 7: unsigned vs signed comparison
|
||||
(if (i32.eqz (i64.lt_u (i64.const 1) (i64.const -1))) (then (return (i32.const 7))))
|
||||
(if (i32.eqz (i64.gt_s (i64.const 1) (i64.const -1))) (then (return (i32.const 8))))
|
||||
;; 9: shifts / rotates use 6-bit counts
|
||||
(if (i64.ne (i64.shl (i64.const 1) (i64.const 40)) (i64.const 1099511627776)) (then (return (i32.const 9))))
|
||||
(if (i64.ne (i64.shr_s (i64.const -1099511627776) (i64.const 40)) (i64.const -1)) (then (return (i32.const 10))))
|
||||
(if (i64.ne (i64.shr_u (i64.const -1) (i64.const 60)) (i64.const 15)) (then (return (i32.const 11))))
|
||||
(if (i64.ne (i64.rotl (i64.const 0x8000000000000001) (i64.const 1)) (i64.const 3)) (then (return (i32.const 12))))
|
||||
;; 13: conversions
|
||||
(if (i64.ne (i64.extend_i32_s (i32.const -1)) (i64.const -1)) (then (return (i32.const 13))))
|
||||
(if (i64.ne (i64.extend_i32_u (i32.const -1)) (i64.const 0xffffffff)) (then (return (i32.const 14))))
|
||||
(if (i32.ne (i32.wrap_i64 (i64.const 0x1ffffffff)) (i32.const -1)) (then (return (i32.const 15))))
|
||||
;; 16: memory round trip, plus narrow loads
|
||||
(i64.store (i32.const 8) (i64.const 0x8877665544332211))
|
||||
(if (i64.ne (i64.load (i32.const 8)) (i64.const 0x8877665544332211)) (then (return (i32.const 16))))
|
||||
(if (i64.ne (i64.load8_s (i32.const 15)) (i64.const -0x78)) (then (return (i32.const 17))))
|
||||
(if (i64.ne (i64.load32_u (i32.const 12)) (i64.const 0x88776655)) (then (return (i32.const 18))))
|
||||
(if (i64.ne (i64.load32_s (i32.const 12)) (i64.const -0x778899ab)) (then (return (i32.const 19))))
|
||||
;; 20: i64 global
|
||||
(global.set $g (i64.add (global.get $g) (i64.const 1)))
|
||||
(if (i64.ne (global.get $g) (i64.const 0x123456789abcdef1)) (then (return (i32.const 20))))
|
||||
;; 21: i64 local, select, eqz
|
||||
(local.set $x (select (i64.const 5000000000) (i64.const 1) (i32.const 1)))
|
||||
(if (i64.ne (local.get $x) (i64.const 5000000000)) (then (return (i32.const 21))))
|
||||
(if (i32.eqz (i64.eqz (i64.const 0))) (then (return (i32.const 22))))
|
||||
(i32.const 0)))
|
||||
Reference in new issue
Block a user