From 5e56dca2bd6247a8b06b16979d0ec307f50eed7f Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 6 May 2016 11:18:46 -0700 Subject: [PATCH 1/7] Add some interesting boundary cases for `nearest`. --- ml-proto/test/float_misc.wast | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ml-proto/test/float_misc.wast b/ml-proto/test/float_misc.wast index 3ea32a0c7b..7e6df29bc3 100644 --- a/ml-proto/test/float_misc.wast +++ b/ml-proto/test/float_misc.wast @@ -561,9 +561,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). From cb1c506beb0f1bb04eeb35de90ce97f11f96a3a9 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 12 May 2016 07:35:44 -0700 Subject: [PATCH 2/7] Test integer x/0 where the denominator is a constant. --- ml-proto/test/int_exprs.wast | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/ml-proto/test/int_exprs.wast b/ml-proto/test/int_exprs.wast index 88324d11ce..ac05baf984 100644 --- a/ml-proto/test/int_exprs.wast +++ b/ml-proto/test/int_exprs.wast @@ -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 From b148445cf16eb6173d49494e77a32e9dc5c4e1c8 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 12 May 2016 09:33:47 -0700 Subject: [PATCH 3/7] Test MIN * EPSILON. --- ml-proto/test/float_misc.wast | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ml-proto/test/float_misc.wast b/ml-proto/test/float_misc.wast index 7e6df29bc3..51a63f16c9 100644 --- a/ml-proto/test/float_misc.wast +++ b/ml-proto/test/float_misc.wast @@ -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)) From 2743a827bddaca820e2409a312a97878d7f5b524 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 12 May 2016 09:33:58 -0700 Subject: [PATCH 4/7] Test the minimum positive normal number divided by the minimum positive subnormal number. --- ml-proto/test/float_misc.wast | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ml-proto/test/float_misc.wast b/ml-proto/test/float_misc.wast index 51a63f16c9..45c529c84c 100644 --- a/ml-proto/test/float_misc.wast +++ b/ml-proto/test/float_misc.wast @@ -440,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)) From 377adc1c328285b38600a8f849805ea901b0acb0 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 13 May 2016 09:58:14 -0700 Subject: [PATCH 5/7] Test memory maximum size range and overflow. --- ml-proto/test/memory.wast | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ml-proto/test/memory.wast b/ml-proto/test/memory.wast index 40d6f37588..b508242216 100644 --- a/ml-proto/test/memory.wast +++ b/ml-proto/test/memory.wast @@ -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"))) @@ -31,6 +32,10 @@ (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)) + "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)))) From b394e69534307cf1a317e2710109f145385811b2 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 13 May 2016 10:08:32 -0700 Subject: [PATCH 6/7] Test that subnormals are not flushed in intermediate values. --- ml-proto/test/float_exprs.wast | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ml-proto/test/float_exprs.wast b/ml-proto/test/float_exprs.wast index 322a1960d5..2258d02ed1 100644 --- a/ml-proto/test/float_exprs.wast +++ b/ml-proto/test/float_exprs.wast @@ -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)) From 646a8d9cb1c841701d7e6e33bb794e9c83e4261d Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 13 May 2016 12:32:31 -0700 Subject: [PATCH 7/7] Add tests for invalid memory sizes that try to catch 32-bit wraparound. --- ml-proto/test/memory.wast | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ml-proto/test/memory.wast b/ml-proto/test/memory.wast index b508242216..390717e4cd 100644 --- a/ml-proto/test/memory.wast +++ b/ml-proto/test/memory.wast @@ -36,6 +36,14 @@ (module (memory 0 65536)) "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))))