Skip to content

Commit c3f9359

Browse files
authored
Merge pull request #156 from fitzgen/test-non-determinism-is-consistent
Add a smoke test for consistent nondeterminism
2 parents 95dc80e + e9c9a9b commit c3f9359

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

test/core/relaxed-simd/relaxed_madd_nmadd.wast

+33
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,36 @@
189189
(v128.const f64x2 -0x1.000002p+0 -0x1.000002p+0)
190190
(v128.const f64x2 -0x1.00000204p+0 -0x1.00000204p+0))
191191
(v128.const i64x2 -1 -1))
192+
193+
;; Test that the non-deterministic choice of fusing and then rounding or
194+
;; rounding multiple times in `relaxed_madd` is consistent throughout a
195+
;; program's execution.
196+
;;
197+
;; This property is impossible to test exhaustively, so this is just a simple
198+
;; smoke test for when the operands to a `relaxed_madd` are known statically
199+
;; versus when they are dynamically supplied. This should, at least, catch
200+
;; illegal constant-folding and -propagation by the compiler that leads to
201+
;; inconsistent rounding behavior at compile time versus at run time.
202+
;;
203+
;; FLT_MAX == 0x1.fffffep+127
204+
;; FLT_MAX * 2 - FLT_MAX ==
205+
;; FLT_MAX (if fma)
206+
;; 0 (if no fma)
207+
;; from https://www.vinc17.net/software/fma-tests.c
208+
(module
209+
(func (export "test-consistent-nondeterminism") (param v128 v128 v128) (result v128)
210+
(f32x4.eq
211+
(f32x4.relaxed_madd (v128.const f32x4 0x1.fffffep+127 0x1.fffffep+127 0x1.fffffep+127 0x1.fffffep+127 )
212+
(v128.const f32x4 2.0 2.0 2.0 2.0)
213+
(v128.const f32x4 -0x1.fffffep+127 -0x1.fffffep+127 -0x1.fffffep+127 -0x1.fffffep+127))
214+
(f32x4.relaxed_madd (local.get 0)
215+
(local.get 1)
216+
(local.get 2))
217+
)
218+
)
219+
)
220+
(assert_return (invoke "test-consistent-nondeterminism"
221+
(v128.const f32x4 0x1.fffffep+127 0x1.fffffep+127 0x1.fffffep+127 0x1.fffffep+127 )
222+
(v128.const f32x4 2.0 2.0 2.0 2.0)
223+
(v128.const f32x4 -0x1.fffffep+127 -0x1.fffffep+127 -0x1.fffffep+127 -0x1.fffffep+127))
224+
(v128.const i32x4 -1 -1 -1 -1))

0 commit comments

Comments
 (0)