diff options
| author | dwwite <bigjbrown2109@gmail.com> | 2026-11-22 02:06:42 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-11-22 02:06:42 +0000 |
| commit | b228b56c2e3068fe5dbeb59c0d22b233e651548e (patch) | |
| tree | 94084834c6adb6980d606e2efb5d7b147fff68e9 /tools/shader_diff.py | |
| parent | 33070ca9b05d966f808bfd859322f25a6cac9737 (diff) | |
Add files via upload
Diffstat (limited to 'tools/shader_diff.py')
| -rw-r--r-- | tools/shader_diff.py | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/tools/shader_diff.py b/tools/shader_diff.py index 6b323da8e..de397cd09 100644 --- a/tools/shader_diff.py +++ b/tools/shader_diff.py | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | r"""Differential oracle for the RDNA2 translator (standard library only). | 1 | r"""Differential oracle for the RDNA2 translator (standard library only). |
| 2 | 2 | ||
| 3 | Runs seeded straight-line ALU programs through two independent oracles and | 3 | Runs seeded straight-line ALU programs through two independent oracles and |
| 4 | compares them bit-exact: | 4 | compares their output words: |
| 5 | * tools/cpu_ref.py - the ISA model, executed per lane (lanes=1, lane=0) | 5 | * tools/cpu_ref.py - the ISA model, executed per lane (lanes=1, lane=0) |
| 6 | * rdna2spirv + tests/semantic/spirv_mini_interp.py - the translated SPIR-V | 6 | * rdna2spirv + tests/semantic/spirv_mini_interp.py - the translated SPIR-V |
| 7 | 7 | ||
| @@ -186,27 +186,31 @@ def _write_listing(path, lines, with_export): | |||
| 186 | f.write("\ts_endpgm\n") | 186 | f.write("\ts_endpgm\n") |
| 187 | 187 | ||
| 188 | 188 | ||
| 189 | def compare_pair(cpu_words, spv_words): | 189 | def compare_pair(cpu_words, spv_words, *, writers=None): |
| 190 | """Bit-exact compare of two 4-word exports. Returns a mismatch string or None. | 190 | """Compare two 4-word exports and return the first mismatch or None. |
| 191 | 191 | ||
| 192 | NaN words match only if both sides are NaN (payloads recorded); finite | 192 | Results of floating-point instructions can have different NaN payloads. |
| 193 | words must be exactly equal. | 193 | All other words must match bit for bit. |
| 194 | """ | 194 | """ |
| 195 | if len(cpu_words) != 4 or len(spv_words) != 4: | 195 | if len(cpu_words) != 4 or len(spv_words) != 4: |
| 196 | return f"shape mismatch: cpu has {len(cpu_words)} words, spv has {len(spv_words)}" | 196 | return f"shape mismatch: cpu has {len(cpu_words)} words, spv has {len(spv_words)}" |
| 197 | writers = writers or {} | ||
| 197 | for i in range(4): | 198 | for i in range(4): |
| 198 | c = cpu_words[i] & 0xFFFFFFFF | 199 | c = cpu_words[i] & 0xFFFFFFFF |
| 199 | s = spv_words[i] & 0xFFFFFFFF | 200 | s = spv_words[i] & 0xFFFFFFFF |
| 200 | if c == s: | 201 | if c == s: |
| 201 | continue | 202 | continue |
| 202 | c_nan, s_nan = _is_nan_bits(c), _is_nan_bits(s) | 203 | writer = writers.get(EXPORT_REGS[i]) |
| 203 | if c_nan and s_nan: | 204 | mismatch = f"lane word {i}: expected 0x{c:08x} ({c}), actual 0x{s:08x} ({s})" |
| 204 | continue # both NaN: payloads legitimately differ, not a mismatch | 205 | if writer and writer[0] in _FLOAT_OPS: |
| 205 | if c_nan or s_nan: | 206 | c_nan, s_nan = _is_nan_bits(c), _is_nan_bits(s) |
| 206 | return (f"lane word {i}: only one side is NaN " | 207 | if c_nan and s_nan: |
| 207 | f"(cpu=0x{c:08x} spv=0x{s:08x})") | 208 | continue |
| 208 | return (f"lane word {i}: expected 0x{c:08x} ({c}), " | 209 | if c_nan or s_nan: |
| 209 | f"actual 0x{s:08x} ({s})") | 210 | mismatch = f"lane word {i}: only one side is NaN (cpu=0x{c:08x} spv=0x{s:08x})" |
| 211 | if writer: | ||
| 212 | mismatch += f" (last writer {writer[0]} at body line {writer[1]})" | ||
| 213 | return mismatch | ||
| 210 | return None | 214 | return None |
| 211 | 215 | ||
| 212 | 216 | ||
| @@ -246,16 +250,10 @@ def run_one(name, lines, writers): | |||
| 246 | regs = cpu_res["registers"]["vgpr"] | 250 | regs = cpu_res["registers"]["vgpr"] |
| 247 | cpu_words = [regs.get(r, [0])[0] if isinstance(regs.get(r), list) else regs.get(r, 0) | 251 | cpu_words = [regs.get(r, [0])[0] if isinstance(regs.get(r), list) else regs.get(r, 0) |
| 248 | for r in EXPORT_REGS] | 252 | for r in EXPORT_REGS] |
| 249 | mismatch = compare_pair(cpu_words, list(out["%out_mrt0"])) | 253 | mismatch = compare_pair(cpu_words, list(out["%out_mrt0"]), writers=writers) |
| 250 | if mismatch is None: | 254 | if mismatch is None: |
| 251 | return ("match", "") | 255 | return ("match", "") |
| 252 | first_bad = next(i for i in range(4) | 256 | return ("mismatch", mismatch) |
| 253 | if (cpu_words[i] & 0xFFFFFFFF) != (list(out["%out_mrt0"])[i] & 0xFFFFFFFF) | ||
| 254 | or (_is_nan_bits(cpu_words[i] & 0xFFFFFFFF) != | ||
| 255 | _is_nan_bits(list(out["%out_mrt0"])[i] & 0xFFFFFFFF))) | ||
| 256 | writer = writers.get(EXPORT_REGS[first_bad], ("?", 0)) | ||
| 257 | return ("mismatch", | ||
| 258 | f"{mismatch} (last writer {writer[0]} at body line {writer[1]})") | ||
| 259 | 257 | ||
| 260 | 258 | ||
| 261 | def run_suite(programs, seed, max_ops, limit=None): | 259 | def run_suite(programs, seed, max_ops, limit=None): |