Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions ml-proto/test/float_exprs.wast
Original file line number Diff line number Diff line change
Expand Up @@ -1736,3 +1736,19 @@
(assert_return (invoke "f64.no_fold_mul_sqrt_div" (f64.const 0x1.74ee531ddba38p-425) (f64.const 0x1.f370f758857f3p+560)) (f64.const 0x1.0aff34269583ep-705))
(assert_return (invoke "f64.no_fold_mul_sqrt_div" (f64.const -0x1.27f216b0da6c5p+352) (f64.const 0x1.8e0b4e0b9fd7ep-483)) (f64.const -0x1.4fa558aad514ep+593))
(assert_return (invoke "f64.no_fold_mul_sqrt_div" (f64.const 0x1.4c6955df9912bp+104) (f64.const 0x1.0cca42c9d371ep+842)) (f64.const 0x1.4468072f54294p-317))

;; Test that subnormals are not flushed even in an intermediate value in an
;; expression with a normal result.

(module
(func $f32.no_flush_intermediate_subnormal (param $x f32) (param $y f32) (param $z f32) (result f32)
(f32.mul (f32.mul (get_local $x) (get_local $y)) (get_local $z)))
(export "f32.no_flush_intermediate_subnormal" $f32.no_flush_intermediate_subnormal)

(func $f64.no_flush_intermediate_subnormal (param $x f64) (param $y f64) (param $z f64) (result f64)
(f64.mul (f64.mul (get_local $x) (get_local $y)) (get_local $z)))
(export "f64.no_flush_intermediate_subnormal" $f64.no_flush_intermediate_subnormal)
)

(assert_return (invoke "f32.no_flush_intermediate_subnormal" (f32.const 0x1p-126) (f32.const 0x1p-23) (f32.const 0x1p23)) (f32.const 0x1p-126))
(assert_return (invoke "f64.no_flush_intermediate_subnormal" (f64.const 0x1p-1022) (f64.const 0x1p-52) (f64.const 0x1p52)) (f64.const 0x1p-1022))
13 changes: 13 additions & 0 deletions ml-proto/test/float_misc.wast
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,11 @@
(assert_return (invoke "f64.mul" (f64.const 0x1.6a09e667f3bccp-538) (f64.const 0x1.6a09e667f3bccp-538)) (f64.const 0x0p+0))
(assert_return (invoke "f64.mul" (f64.const 0x1.6a09e667f3bcdp-538) (f64.const 0x1.6a09e667f3bcdp-538)) (f64.const 0x0.0000000000001p-1022))

;; Test MIN * EPSILON.
;; http://www.mpfr.org/mpfr-2.0.1/patch2
(assert_return (invoke "f32.mul" (f32.const 0x1p-126) (f32.const 0x1p-23)) (f32.const 0x1p-149))
(assert_return (invoke "f64.mul" (f64.const 0x1p-1022) (f64.const 0x1p-52)) (f64.const 0x0.0000000000001p-1022))

(assert_return (invoke "f32.div" (f32.const 1.123456789) (f32.const 100)) (f32.const 0x1.702264p-7))
(assert_return (invoke "f32.div" (f32.const 8391667.0) (f32.const 12582905.0)) (f32.const 0x1.55754p-1))
(assert_return (invoke "f32.div" (f32.const 65536.0) (f32.const 0x1p-37)) (f32.const 0x1p+53))
Expand Down Expand Up @@ -435,6 +440,11 @@
(assert_return (invoke "f64.div" (f64.const 1.0) (f64.const 0x0.4p-1022)) (f64.const infinity))
(assert_return (invoke "f64.div" (f64.const 1.0) (f64.const 0x0.4000000000001p-1022)) (f64.const 0x1.ffffffffffff8p+1023))

;; Test the minimum positive normal number divided by the minimum positive
;; subnormal number.
(assert_return (invoke "f32.div" (f32.const 0x1p-126) (f32.const 0x1p-149)) (f32.const 0x1p+23))
(assert_return (invoke "f64.div" (f64.const 0x1p-1022) (f64.const 0x0.0000000000001p-1022)) (f64.const 0x1p+52))

;; Test for bugs found in an early RISC-V implementation.
;; https://github.com/riscv/riscv-tests/pull/8
(assert_return (invoke "f32.sqrt" (f32.const 0x1.56p+7)) (f32.const 0x1.a2744cp+3))
Expand Down Expand Up @@ -561,9 +571,12 @@
(assert_return (invoke "f32.nearest" (f32.const 0x1.000002p+23)) (f32.const 0x1.000002p+23))
(assert_return (invoke "f32.nearest" (f32.const 0x1.000004p+23)) (f32.const 0x1.000004p+23))
(assert_return (invoke "f32.nearest" (f32.const 0x1.fffffep-2)) (f32.const 0.0))
(assert_return (invoke "f32.nearest" (f32.const 0x1.fffffep+47)) (f32.const 0x1.fffffep+47))

(assert_return (invoke "f64.nearest" (f64.const 0x1.0000000000001p+52)) (f64.const 0x1.0000000000001p+52))
(assert_return (invoke "f64.nearest" (f64.const 0x1.0000000000002p+52)) (f64.const 0x1.0000000000002p+52))
(assert_return (invoke "f64.nearest" (f64.const 0x1.fffffffffffffp-2)) (f64.const 0.0))
(assert_return (invoke "f64.nearest" (f64.const 0x1.fffffffffffffp+105)) (f64.const 0x1.fffffffffffffp+105))

;; Nearest should not round halfway cases away from zero (as C's round(3) does)
;; or up (as JS's Math.round does).
Expand Down
23 changes: 23 additions & 0 deletions ml-proto/test/int_exprs.wast
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,29 @@
(assert_return (invoke "i32.no_fold_rem_s_2" (i32.const -11)) (i32.const -1))
(assert_return (invoke "i64.no_fold_rem_s_2" (i64.const -11)) (i64.const -1))

;; Test that x/0 works

(module
(func $i32.div_s_3 (param $x i32) (result i32)
(i32.div_s (get_local $x) (i32.const 0)))
(export "i32.div_s_3" $i32.div_s_3)
(func $i32.div_u_3 (param $x i32) (result i32)
(i32.div_u (get_local $x) (i32.const 0)))
(export "i32.div_u_3" $i32.div_u_3)

(func $i64.div_s_3 (param $x i64) (result i64)
(i64.div_s (get_local $x) (i64.const 0)))
(export "i64.div_s_3" $i64.div_s_3)
(func $i64.div_u_3 (param $x i64) (result i64)
(i64.div_u (get_local $x) (i64.const 0)))
(export "i64.div_u_3" $i64.div_u_3)
)

(assert_trap (invoke "i32.div_s_3" (i32.const 71)) "integer divide by zero")
(assert_trap (invoke "i32.div_u_3" (i32.const 71)) "integer divide by zero")
(assert_trap (invoke "i64.div_s_3" (i64.const 71)) "integer divide by zero")
(assert_trap (invoke "i64.div_u_3" (i64.const 71)) "integer divide by zero")

;; Test that x/3 works

(module
Expand Down
13 changes: 13 additions & 0 deletions ml-proto/test/memory.wast
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
(module (memory 0 0))
(module (memory 0 1))
(module (memory 1 256))
(module (memory 0 65535))
(module (memory 0 0 (segment 0 "")))
(module (memory 1 1 (segment 0 "a")))
(module (memory 1 2 (segment 0 "a") (segment 65535 "b")))
Expand Down Expand Up @@ -31,6 +32,18 @@
(module (memory 1 2 (segment 0 "a") (segment 2 "b") (segment 1 "c")))
"data segment not disjoint and ordered"
)
(assert_invalid
(module (memory 0 65536))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about also adding a test with a value that overflows the 32-bit (resp 64-bit range), to check that there is no accidental wrap-around?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok; tests added.

"linear memory pages must be less or equal to 65535 (4GiB)"
)
(assert_invalid
(module (memory 0 2147483648))
"linear memory pages must be less or equal to 65535 (4GiB)"
)
(assert_invalid
(module (memory 0 4294967296))
"linear memory pages must be less or equal to 65535 (4GiB)"
)

;; Test alignment annotation rules
(module (memory 0) (func (i32.load8_u align=2 (i32.const 0))))
Expand Down