Commit Graph

2 Commits

Author SHA1 Message Date
aea8ca5968 div_scale_probe: preset D with a sentinel, pin the divide sequence, isolate the denormal-S1 branch
Review follow-ups for SHADER-DIV-SCALE-PROBE.

- D is written with a sentinel (no operand of the matrix and no candidate
  prediction equals it) before every v_div_scale of the plain and modifier
  kernels, so a D that is not written is reported (d_unwritten: summary line,
  --json field, --table marker) instead of reading as the previous row's value.
  The docstring and docs say that D = S0 where no branch assigns it is an
  assumption applied in every candidate, and name the emulator that initialises
  D differently.
- The f32 divide sequence omits LLVM's s_denorm_mode switch: the summary labels
  the f32 tallies of the MODEs that flush f32 denormals as not comparable with
  LLVM's lowering (llvm_comparable in the JSON), with a note.
- New pair 2^-60 [2^-284] over the smallest denormal: a gap below 96 [768], so
  the denormal-denominator branch is reached and not the gap branch. 49 pairs,
  108 rows per width.
- A run without --json ends with a line saying the summary is not the
  measurement. --json has mask_lo/mask_hi instead of the bare list; --table
  starts with a legend.
- isa_recip_width is described as the same text with the reciprocal classified
  in the operand's width; docstring and test references to a docs/design.md row
  that does not exist point at the docs/shader_validation.md section.
- tests: the preset and sentinel before every v_div_scale, the sequence against
  a hand-written table of LowerFDIV32/LowerFDIV64 and as a division on exact
  arithmetic, an unwritten D, the labels, the legend, a cr_ftz verdict.

AI-assisted.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y7fbZYVY7EtLknWBZUfSLf
2026-11-25 00:29:45 +00:00
a2209ec35d tools: div_scale_probe measures v_div_scale on GFX10 hardware (SHADER-DIV-SCALE-PROBE)
The translator refuses v_div_scale_f32/f64: the ISA text, the D = S0
pass-through LLVM's divide lowering relies on and the rule tinygrad's
RDNA3 emulator runs disagree at the edges, so the rule has to come from
a measurement. tools/div_scale_probe.py makes that one command on a
GFX10 GPU, built like tools/f64_omod_probe.py on tools/hw_oracle: raw
one-lane kernels, the five MODEs of that probe (game MODE first), wave32
and wave64.

Per width it runs 48 numerator/denominator pairs (special, denormal,
exponent gap 95/96/97 [767/768/769], denominators around 2^126 [2^1022],
quotients around 2^-126 [2^-1022], numerator fields 22/23/24
[52/53/54], ordinary) as the denominator and the numerator call, plus
10 S0 = S1 = S2 cases, each with VCC and with an SGPR mask destination
preset to all ones; 30 modifier rows; and LLVM's whole divide sequence
on every pair. Each row prints next to it what three candidate readings
predict (the newer ISA wording, the text with an f32-width reciprocal
test, tinygrad's emulator rule), so a run shows which one the hardware
follows. Not run on hardware; no rule goes into the contract table.

tests/test_div_scale_probe.py checks the matrix and its boundaries, the
candidates' known disagreements (including the 1.0 / 2^127 -> +inf
divide through the translator's measured v_div_fmas/v_div_fixup),
assembly with llvm-mc, and parsing and the CLI with a fake oracle.
docs/shader_validation.md documents the tool.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y7fbZYVY7EtLknWBZUfSLf
2026-11-24 23:36:17 +00:00