Skip to content

tools/div_fixup_diff.py: generate the f16 and f64 output multipliers (#6314) - #6698

Open
TreXito wants to merge 4 commits into
ItsNotRexed:mainfrom
TreXito:fuzz/div-fixup-omod
Open

TreXito wants to merge 4 commits into
ItsNotRexed:mainfrom
TreXito:fuzz/div-fixup-omod

Conversation

@TreXito

@TreXito TreXito commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Depends on: #5086. This branch is #5086's head (4f5e641f) merged with main 4beffda8 plus one commit, so only the last commit is new. Claimed in #6414 (#6414 (comment)).

#6314 measured on gfx1036 that mul:2/mul:4/div:2 are dropped on the f16 and binary64 results of v_div_fixup_f16 and v_div_fixup_f64 under denorm_mode_16_64 = 3, the game's MODE, while an f16 clamp still saturates. main now translates them that way (has_clamp in the lowering). #5086's tools/div_fixup_diff.py leaves both out: f16 multipliers because SHADER-297 was open, and every f64 output modifier because the translation needed Float64. This PR generates them.

Changes (tools/div_fixup_diff.py)

  • Generated:
    • v_div_fixup_f16: mul:2, mul:4, div:2, with and without clamp, in either destination half.
    • v_div_fixup_f64: mul:2, mul:4, div:2.
    • clamp on f64 is still not generated: it needs Float64, which spirv_mini_interp does not run.
  • Reference:
  • Edge grid:
    • every rule's result under the f16 multipliers (both halves, with and without clamp): +294 cases;
    • the same under the f64 multipliers: +147 cases.
  • --self-test:
    • f16 clamp div:2 of 1.5 is 1.0, not 0.75;
    • f64 mul:4 of 1.5 stays 1.5.

Tested

Linux, CPU only: the translator plus tests/semantic/spirv_mini_interp.py. Rig: an i5-12400F with Python 3.13.5.

Run Judged programs Match Mismatch
rig, all three ops, --programs 3000 --seed 11 --max-ops 8 4,100 4,100 0
rig, all three ops, --programs 3000 --seed 12 --max-ops 8 4,116 4,116 0
rig, all three ops, --programs 3000 --seed 13 4,225 4,225 0
rig, --ops v_div_fixup_f16 --programs 3000 --seed 14 2,937 2,937 0
rig, --ops v_div_fixup_f64 --programs 3000 --seed 15 3,682 3,682 0
local, all three ops, seeds 1 to 3, --programs 400 6,278 6,278 0
rig, the pre-#6314 translator (LEONIDA_TOOLS_DIR), seed 11 as above 4,100 3,234 866

Judged programs are the sweep, the edge grid and the random programs together. The not-judged counts are the kinds #5086 already lists (clamp of an f16 NaN, f32 multipliers on -0 or denormals, and the like); this PR adds none.

The last row is the check that the new cases bite: with tools/rdna2spirv.py from before #6314, which scaled the f16/f64 result, 866 of the same 4,100 programs mismatch (59 sweep, 44 edge grid, 763 random). Locally, seeds 1 and 2 against that translator give 206 of 2,100 and 197 of 2,093 mismatching programs.

  • tests/test_div_fixup_diff.py: 25 passed (22 before).
    • New tests: the f16 and f64 results are not scaled (reference); a fixed program with f16 mul:2, f16 op_sel + clamp div:2 and f64 mul:4 matches through the translator.
    • The same test plants a translator that applies the f16 mul:2 or the f64 mul:4 and checks that both are caught.
    • Updated tests: grid counts, the multipliers in the encodability test, and the harness errors.
  • tests/test_docs_*.py, compileall, git diff --check: pass.
  • python -I tools/div_fixup_diff.py --self-test: ok.

Docs

docs/shader_validation.md: the div_fixup section now states the f16/f64 multiplier rule and lists them as generated.

No game data. AI-assisted (Claude Code).

🤖 Generated with Claude Code

TreXito and others added 4 commits November 23, 2026 08:10
No fuzzer generated the three div_fixup ops. tools/div_fixup_diff.py runs
seeded programs through rdna2spirv and spirv_mini_interp against a bitwise
model of the docs/design.md rows (gfx1036 measurements) and compares the
exported words bit for bit.

- Sources: VGPRs, SGPRs, a literal (not on f64), inline constants; f64
  VGPR pairs (odd ones too) and SGPR pairs; abs/neg, f16 op_sel, clamp,
  f32 mul:2/mul:4/div:2.
- Stages: every encodable source-kind combination, an edge grid (rule
  order, the -151/-1076 exponent cutoffs, NaN payloads under abs/neg,
  output modifiers on each rule's result), random chained programs.
- tests/test_div_fixup_diff.py pins the model to the 73 measured f32
  rows and the f16/f64 rows in tests/semantic.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…uilding the whole list

run_sweep, grid_items and run_suite built every (label, lines, ops) tuple before _run
checked the first, so peak memory grew with --programs. sweep_items, grid_items and
suite_items now yield one at a time. Same seeded programs (SHA-256 of every program
matches), same output for --programs 300 --seed 1. Generation-only peak at 5,000
programs: 7,715,187 -> 28,026 bytes. From shdann's review.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the f16/f64 div_fixup output multipliers
…xed#6314)

ItsNotRexed#6314 measured on gfx1036 that an f16 or binary64 result ignores mul:2, mul:4
and div:2 under denorm_mode_16_64 = 3 (the game's MODE) while an f16 clamp
still saturates, and main now translates them that way. The fuzzer left
them out (f16: SHADER-297 open; f64: the translation needed Float64).

- v_div_fixup_f16: mul:2/mul:4/div:2, with and without clamp, either half.
- v_div_fixup_f64: mul:2/mul:4/div:2 (clamp still needs Float64: not
  generated).
- The reference leaves the result unscaled; two multipliers on one line
  are a harness error.
- Edge grid: every rule's result under the f16 multipliers (both halves,
  with and without clamp) and the f64 multipliers.
- --self-test pins f16 "clamp div:2" of 1.5 = 1.0 and f64 "mul:4" of 1.5.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested d224f7b9 on Windows 11, CPython 3.14.7, CPU only: pass. AI-assisted.

  • py -3.14 -I tests/test_div_fixup_diff.py passed all 25 tests.
  • py -3.14 -I tools/div_fixup_diff.py --self-test passed.
  • py -3.14 -I tools/div_fixup_diff.py --no-sweep --programs 128 --seed 2026 --max-ops 5 matched all 112 judged programs across the three operations. The harness left 16 programs unjudged and reported zero translator skips.

For a negative control, I ran the new fixed-program test against the harness from the immediate parent, 67d09ced. It raised HarnessError: output multiplier on v_div_fixup_f16. The head accepted the same program and detected both deliberately incorrect outputs in the test. This run used the CPU interpreter and synthetic listings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants