diff options
| author | Spaghetih <191181391+Spaghetih@users.noreply.github.com> | 2026-11-22 01:37:53 +0100 |
|---|---|---|
| committer | Spaghetih <191181391+Spaghetih@users.noreply.github.com> | 2026-11-22 01:37:53 +0100 |
| commit | 3f4cf2e40d6be28d665fef090bcaa8668b9e8481 (patch) | |
| tree | 1cdba1d1b3539659c34e407fda42a018afd4db9a /tests/test_mem_diff.py | |
| parent | 91b36cf86cb92a95836eed8af73abc0671a61e31 (diff) | |
FUZZ-5: typed buffer loads in tools/mem_diff.py (buffer_load_format, tbuffer_load_format)
A buffer_format family: buffer_load_format_* on every format the translator decodes (random DST_SEL 0/X/Y/Z/W) and tbuffer_load_format_* on the five formats the 1.0.2.1 corpus uses. The reference decodes each element from the GFX10 format name (tools/gfx10_formats.json), not from the translator's table.
Two outcomes await a gfx10 hardware measurement (posted in #374) and are counted apart: UNORM/SNORM results 1 ULP from the correctly rounded value (the translator multiplies by a rounded reciprocal), and the missing W of a 32-bit format (0 in the translator, 1 / 1.0 for every other format). 5,000 programs: no other difference. Mutations of the 16_16_SNORM kind, the 8_8_8_8_UINT widths and the DST_SEL order make 33, 37 and 191 of 300 programs fail.
AI-assisted.
Diffstat (limited to 'tests/test_mem_diff.py')
| -rw-r--r-- | tests/test_mem_diff.py | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/tests/test_mem_diff.py b/tests/test_mem_diff.py index 4455281a0..4a1ded18e 100644 --- a/tests/test_mem_diff.py +++ b/tests/test_mem_diff.py | |||
| @@ -7,6 +7,7 @@ import os | |||
| 7 | import random | 7 | import random |
| 8 | import sys | 8 | import sys |
| 9 | import unittest | 9 | import unittest |
| 10 | from fractions import Fraction | ||
| 10 | 11 | ||
| 11 | ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 12 | ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 12 | sys.path.insert(0, os.path.join(ROOT, "tools")) | 13 | sys.path.insert(0, os.path.join(ROOT, "tools")) |
| @@ -38,7 +39,10 @@ class Harness(unittest.TestCase): | |||
| 38 | self.assertEqual(counts["mismatch"], 0, first) | 39 | self.assertEqual(counts["mismatch"], 0, first) |
| 39 | self.assertEqual(counts["harness-error"], 0, first) | 40 | self.assertEqual(counts["harness-error"], 0, first) |
| 40 | self.assertEqual(counts["skip"], {}, counts["skip"]) | 41 | self.assertEqual(counts["skip"], {}, counts["skip"]) |
| 41 | self.assertEqual(counts["pass"], 60) | 42 | # Two typed-buffer questions await a hardware measurement and are counted apart (see mem_diff.py). |
| 43 | self.assertEqual(counts["pass"] + counts["norm-ulp1"] + counts["missing-w32"], 60) | ||
| 44 | if family != "buffer_format": | ||
| 45 | self.assertEqual(counts["pass"], 60) | ||
| 42 | 46 | ||
| 43 | 47 | ||
| 44 | class Reference(unittest.TestCase): | 48 | class Reference(unittest.TestCase): |
| @@ -75,6 +79,47 @@ class Reference(unittest.TestCase): | |||
| 75 | self.assertEqual((ref.mem[0x6000], ref.v[4]), (9, 7)) | 79 | self.assertEqual((ref.mem[0x6000], ref.v[4]), (9, 7)) |
| 76 | 80 | ||
| 77 | 81 | ||
| 82 | class FormatDecode(unittest.TestCase): | ||
| 83 | """The reference decode of typed-buffer formats, from the GFX10 names (expected words worked out by hand).""" | ||
| 84 | |||
| 85 | def test_names_list_widths_from_the_top_bit(self): | ||
| 86 | self.assertEqual(md.parse_format("GFX10_FORMAT_2_10_10_10_UNORM"), ([10, 10, 10, 2], "UNORM")) | ||
| 87 | self.assertEqual(md.parse_format("GFX10_FORMAT_16_16_SNORM"), ([16, 16], "SNORM")) | ||
| 88 | self.assertIsNone(md.parse_format("GFX10_FORMAT_10_11_11_FLOAT")) # packed float: not modelled | ||
| 89 | |||
| 90 | def test_correct_rounding(self): | ||
| 91 | self.assertEqual(md.f32_round(Fraction(3, 255)), 0x3C40C0C1) # the multiply-by-reciprocal gives ...C2 | ||
| 92 | self.assertEqual(md.f32_round(Fraction(1, 1)), 0x3F800000) | ||
| 93 | self.assertEqual(md.f32_round(Fraction(1, 3)), 0x3EAAAAAB) | ||
| 94 | |||
| 95 | def test_decode_examples(self): | ||
| 96 | # 8_8_8_8_UINT: X in the low byte; four channels, nothing missing. | ||
| 97 | self.assertEqual(md.decode_element(0xDDCCBBAA, [8, 8, 8, 8], "UINT"), [0xAA, 0xBB, 0xCC, 0xDD]) | ||
| 98 | # 16_16_SNORM: X = 0x8000 clamps to -1.0, Y = 0x7FFF is 1.0; Z/W missing -> 0, 1.0. | ||
| 99 | self.assertEqual(md.decode_element(0x7FFF8000, [16, 16], "SNORM"), [0xBF800000, 0x3F800000, 0, 0x3F800000]) | ||
| 100 | # 2_10_10_10_UNORM: X10 at bit 0 ... W2 at bit 30. All ones in X, W = 3 -> 1.0, Y = Z = 0. | ||
| 101 | self.assertEqual(md.decode_element(0xC00003FF, [10, 10, 10, 2], "UNORM"), | ||
| 102 | [0x3F800000, 0, 0, 0x3F800000]) | ||
| 103 | # 32_UINT: missing Y, Z, W -> 0, 0, 1 (integer one). | ||
| 104 | self.assertEqual(md.decode_element(7, [32], "UINT"), [7, 0, 0, 1]) | ||
| 105 | |||
| 106 | def test_open_questions_are_counted_apart(self): | ||
| 107 | """A 32-bit format's missing W (translator 0) and a UNORM 1-ULP difference are their own statuses.""" | ||
| 108 | base = ["s_mov_b32 s0, 0x7000", "s_mov_b32 s1, 0", "s_mov_b32 s2, 0x100"] | ||
| 109 | w32 = program(base + [f"s_mov_b32 s3, {22 << 12 | md.XYZW:#x}", "v_mov_b32 v2, 0", | ||
| 110 | "buffer_load_format_xyzw v[4:7], v2, s[0:3], 0 offen", "s_waitcnt vmcnt(0)", | ||
| 111 | "v_mov_b32 v8, v4", "v_mov_b32 v9, v5", "v_mov_b32 v10, v6", "v_mov_b32 v11, v7"], | ||
| 112 | {0x7000: 0x40000000}) | ||
| 113 | w32.missing_w32_regs, w32.export_sources = {7}, {0: 4, 1: 5, 2: 6, 3: 7} | ||
| 114 | self.assertEqual(md.run_one("ps_mem_w32", w32)[0], "missing-w32") | ||
| 115 | unorm = program(base + [f"s_mov_b32 s3, {56 << 12 | md.XYZW:#x}", "v_mov_b32 v2, 0", | ||
| 116 | "buffer_load_format_x v4, v2, s[0:3], 0 offen", "s_waitcnt vmcnt(0)", | ||
| 117 | "v_mov_b32 v8, v4", "v_mov_b32 v9, v4", "v_mov_b32 v10, v4", "v_mov_b32 v11, v4"], | ||
| 118 | {0x7000: 3}) | ||
| 119 | unorm.norm_regs, unorm.export_sources = {4}, {0: 4, 1: 4, 2: 4, 3: 4} | ||
| 120 | self.assertEqual(md.run_one("ps_mem_unorm3", unorm)[0], "norm-ulp1") | ||
| 121 | |||
| 122 | |||
| 78 | class GlobalOffsetRegression(unittest.TestCase): | 123 | class GlobalOffsetRegression(unittest.TestCase): |
| 79 | """llvm-mc prints a gfx10 global_* immediate as signed decimal ('offset:-16'). The translation must add -16, not | 124 | """llvm-mc prints a gfx10 global_* immediate as signed decimal ('offset:-16'). The translation must add -16, not |
| 80 | sign-extend the printed value a second time (which reads 4 KiB lower).""" | 125 | sign-extend the printed value a second time (which reads 4 KiB lower).""" |