upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/tests/test_f64_diff.py
diff options
context:
space:
mode:
authoriurysf <98192149+iurysf@users.noreply.github.com>2026-11-23 01:18:15 -0300
committeriurysf <98192149+iurysf@users.noreply.github.com>2026-11-23 01:18:15 -0300
commite1e81f8a24e22c71be10db1cfeaf0cdfd59cdb94 (patch)
tree22f9b72b80f8969c05c8117cbd3044a905610d12 /tests/test_f64_diff.py
parent7bd5f01dd166dfcf80f4f96bb678cccc5918a7bc (diff)
FUZZ-55: Drop div-fixup-nan-s0 from KNOWN_DIVERGENCES now that #2477 is on main
#2477 (48a1a98b) makes the translator return signed infinity for v_div_fixup_f64 with NaN(S0), as measured on RDNA2 gfx1036, which is what the reference already modelled. The case is no longer a known divergence (as TreXito's review of #4536 observed: two tests fail on main because they expect the old divergence). - Remove the div-fixup-nan-s0 entry, its reference skip and its dedicated --known program; NaN(S0) programs are compared like any other. - Add a positive test that the reference and the translator give +-inf for qNaN, -qNaN and sNaN with both output signs. - Rework the two --known tests so they no longer depend on div_fixup: the three remaining forms are excluded with a reason by default, run with --known, and a planted clamp-only translator error exits 1 and prints the shrunk program. - docs/shader_validation.md no longer lists the div_fixup case. Same change as 41525870 (prepared for #4586, which #2477 made redundant). AI-assisted (OpenBot team). Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>
Diffstat (limited to 'tests/test_f64_diff.py')
-rw-r--r--tests/test_f64_diff.py56
1 files changed, 44 insertions, 12 deletions
diff --git a/tests/test_f64_diff.py b/tests/test_f64_diff.py
index 4a02c17d7..41607eae1 100644
--- a/tests/test_f64_diff.py
+++ b/tests/test_f64_diff.py
@@ -86,16 +86,35 @@ class F64DiffTests(unittest.TestCase):
86 self.assertIn("implementation-defined", reason) 86 self.assertIn("implementation-defined", reason)
87 self.assertIsNone(actual) 87 self.assertIsNone(actual)
88 88
89 def test_div_fixup_nan_s0_is_skipped_by_default_and_runs_with_known(self): 89 def test_div_fixup_nan_s0_gives_signed_infinity_in_reference_and_translator(self):
90 setup, body, _, _ = fd.make_case(random.Random(1), "v_div_fixup_f64", known_case="div-fixup-nan-s0") 90 # Measured on RDNA2 gfx1036 (TEST-983); the translator has it since #2477 (48a1a98b). Not a known divergence any more.
91 lines = setup + body 91 self.assertNotIn("div-fixup-nan-s0", fd.KNOWN_DIVERGENCES)
92 cases = (("v_mov_b32 v13, 0x7ff80000", "1.0", "2.0", fd.EXP), # qNaN, +/+
93 ("v_mov_b32 v13, 0xfff80000", "-1.0", "2.0", fd.EXP | 0x8000000000000000), # -qNaN, sign_out negative
94 ("v_mov_b32 v13, 0x7ff00000", "1.0", "-2.0", fd.EXP | 0x8000000000000000)) # low word set below: sNaN
95 for index, (hi, s1, s2, want) in enumerate(cases):
96 lines = ["v_mov_b32 v12, 0x00000001" if index == 2 else "v_mov_b32 v12, 0x00000000", hi,
97 f"v_div_fixup_f64 v[8:9], v[12:13], {s1}, {s2}"]
98 self.assertEqual(fd.words_to_bits(*fd.ref_program(lines)[:2]), want)
99 with tempfile.TemporaryDirectory() as tmp:
100 status, reason, expected, actual = fd.run_one(lines, f"ps_f64_fixup_nan_s0_{index}", tmp)
101 self.assertEqual(status, "match", (reason, expected, actual))
102 self.assertEqual(fd.words_to_bits(*actual[:2]), want)
103
104 def test_known_divergence_forms_are_excluded_by_default_and_run_with_known(self):
105 forms = {"f64-omod": "v_add_f64 v[8:9], v[10:11], 1.0 mul:2",
106 "fclamp-nan-zero": "v_add_f64 v[8:9], 0x7ff80001, 1.0 clamp",
107 "double-neg-abs": "v_add_f64 v[8:9], -|v[8:9]|, 1.0"}
108 self.assertEqual(set(forms), set(fd.KNOWN_DIVERGENCES))
92 with tempfile.TemporaryDirectory() as tmp: 109 with tempfile.TemporaryDirectory() as tmp:
93 skipped = fd.run_one(lines, "ps_f64_fixup_default", tmp) 110 for label, line in forms.items():
94 self.assertEqual(skipped[0], "skip") 111 with self.subTest(label=label):
95 self.assertIn("div-fixup-nan-s0", skipped[1]) 112 skipped = fd.run_one([line], "ps_f64_known_default", tmp)
96 known = fd.run_one(lines, "ps_f64_fixup_known", tmp, include_known=True) 113 self.assertEqual(skipped[0], "skip")
97 self.assertEqual(known[0], "mismatch") 114 self.assertIn(f"KNOWN_DIVERGENCE {label}", skipped[1])
98 self.assertEqual(fd.words_to_bits(*known[2][:2]), fd.EXP) 115 self.assertIsNone(skipped[2])
116 executed = fd.run_one([line], "ps_f64_known_run", tmp, include_known=True)
117 self.assertIn(executed[0], ("match", "mismatch")) # really executed, not skipped
99 118
100 def test_compare_reference_does_not_write_v8_without_cndmask(self): 119 def test_compare_reference_does_not_write_v8_without_cndmask(self):
101 for op in ("v_cmp_eq_f64_e64 s20, v[12:13], 0.0", 120 for op in ("v_cmp_eq_f64_e64 s20, v[12:13], 0.0",
@@ -122,9 +141,22 @@ class F64DiffTests(unittest.TestCase):
122 normal = self.command("--ops", "v_add_f64", "--programs", "0") 141 normal = self.command("--ops", "v_add_f64", "--programs", "0")
123 known = self.command("--ops", "v_add_f64", "--programs", "0", "--no-sweep", "--known", "--all-failures") 142 known = self.command("--ops", "v_add_f64", "--programs", "0", "--no-sweep", "--known", "--all-failures")
124 self.assertNotIn("KNOWN_DIVERGENCE", normal.stdout) 143 self.assertNotIn("KNOWN_DIVERGENCE", normal.stdout)
125 self.assertEqual(known.returncode, 1) 144 self.assertIn(f"{len(fd.KNOWN_DIVERGENCES)} total", known.stdout) # one program per known divergence
126 self.assertIn("MISMATCH:", known.stdout) 145 self.assertNotIn("KNOWN_DIVERGENCE", known.stdout) # none of them is skipped
127 self.assertIn("v_div_fixup_f64", known.stdout) # the known NaN(S0) case is actually executed 146 # The CPU translator reproduces none of them any more, so the run is clean; a reproduced one exits 1.
147 self.assertEqual(known.returncode, 0, known.stdout + known.stderr)
148 stdout = io.StringIO()
149 original = fd.translate
150
151 def planted(listing, name, temp): # a translator that gets only the clamp form wrong
152 out = original(listing, name, temp)
153 if any(" clamp" in line for line in listing): out[2] ^= 1 # an exactly compared word (a NaN result is not)
154 return out
155 with mock.patch.object(fd, "translate", planted), contextlib.redirect_stdout(stdout):
156 code = fd.main(["--ops", "v_add_f64", "--programs", "0", "--no-sweep", "--known", "--all-failures"])
157 self.assertEqual(code, 1)
158 self.assertIn("MISMATCH:", stdout.getvalue())
159 self.assertIn(" clamp", stdout.getvalue()) # the shrunk program of a known form is printed
128 160
129 def test_sabotaged_translator_mismatch_and_shrinking(self): 161 def test_sabotaged_translator_mismatch_and_shrinking(self):
130 lines = ["v_mov_b32 v12, 0x00000000", "v_mov_b32 v13, 0x3ff80000", 162 lines = ["v_mov_b32 v12, 0x00000000", "v_mov_b32 v13, 0x3ff80000",