Skip to content

Commit

Permalink
Merge pull request #156 from fitzgen/test-non-determinism-is-consistent
Browse files Browse the repository at this point in the history
Add a smoke test for consistent nondeterminism
  • Loading branch information
rossberg authored Jul 18, 2024
2 parents 95dc80e + e9c9a9b commit c3f9359
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/core/relaxed-simd/relaxed_madd_nmadd.wast
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,36 @@
(v128.const f64x2 -0x1.000002p+0 -0x1.000002p+0)
(v128.const f64x2 -0x1.00000204p+0 -0x1.00000204p+0))
(v128.const i64x2 -1 -1))

;; Test that the non-deterministic choice of fusing and then rounding or
;; rounding multiple times in `relaxed_madd` is consistent throughout a
;; program's execution.
;;
;; This property is impossible to test exhaustively, so this is just a simple
;; smoke test for when the operands to a `relaxed_madd` are known statically
;; versus when they are dynamically supplied. This should, at least, catch
;; illegal constant-folding and -propagation by the compiler that leads to
;; inconsistent rounding behavior at compile time versus at run time.
;;
;; FLT_MAX == 0x1.fffffep+127
;; FLT_MAX * 2 - FLT_MAX ==
;; FLT_MAX (if fma)
;; 0 (if no fma)
;; from https://www.vinc17.net/software/fma-tests.c
(module
(func (export "test-consistent-nondeterminism") (param v128 v128 v128) (result v128)
(f32x4.eq
(f32x4.relaxed_madd (v128.const f32x4 0x1.fffffep+127 0x1.fffffep+127 0x1.fffffep+127 0x1.fffffep+127 )
(v128.const f32x4 2.0 2.0 2.0 2.0)
(v128.const f32x4 -0x1.fffffep+127 -0x1.fffffep+127 -0x1.fffffep+127 -0x1.fffffep+127))
(f32x4.relaxed_madd (local.get 0)
(local.get 1)
(local.get 2))
)
)
)
(assert_return (invoke "test-consistent-nondeterminism"
(v128.const f32x4 0x1.fffffep+127 0x1.fffffep+127 0x1.fffffep+127 0x1.fffffep+127 )
(v128.const f32x4 2.0 2.0 2.0 2.0)
(v128.const f32x4 -0x1.fffffep+127 -0x1.fffffep+127 -0x1.fffffep+127 -0x1.fffffep+127))
(v128.const i32x4 -1 -1 -1 -1))

0 comments on commit c3f9359

Please sign in to comment.