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,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