Repository navigation
Conversation
After s_setreg_imm32_b32 hwreg(HW_REG_MODE, 2, 2), 3 every VALU f16 result except the transcendentals rounds toward zero (docs/design.md), but the v_ldexp_f16 branch never read %mode_r16: an overflow still gave +-inf (0x7c00 for 0x7bff * 2, want 0x7bff) and a denormal result still rounded to nearest even (0x3c03 * 2^-15 gave 0x0202, want 0x0201). When the program writes the field, overflow now gives +-65504 and the denormal rounding increment is dropped while the mode is 3. Programs that never write MODE emit the same code as before. tests/semantic/test_ldexp_f16_mode_round.py: edge cases, a seeded sweep against an exact rational reference in both modes, and a check that every f16 case of tools/mode_round_probe.py is the translator's word. The probe gets two ldexp cases so an RDNA2 GPU can confirm the toward-zero words, which are not measured on hardware. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested I tested the translated
The last pair crosses from the largest subnormal to the smallest normal when nearest-even is restored. This covers the Vulkan translation on NVIDIA. Native GFX10 behavior remains a separate measurement. AI-assisted verification. |
kacper-serewis
left a comment
There was a problem hiding this comment.
AI-assisted independent review at 64ed15f. On an RTX 5070 (Windows driver 616.56), all 36 synthetic readback words matched an independent integer reference while switching rounding modes in one dispatch. The parent matched 28. Its eight toward-zero failures covered both signs at overflow, a subnormal tie, the smallest-normal boundary and underflow to zero. Both modules passed spirv-val.
|
Tested
Counts only, no game files. AI-assisted. |
Kam471
left a comment
There was a problem hiding this comment.
Head 64ed15f25. git diff --check clean.
python tests/semantic/test_ldexp_f16_mode_round.py-> 5 tests OK (17 edge cases, Fraction sweep, VOP3/RTZ-then-RNE, probe cases).- Same file against
origin/main's translator (probe file copied too) ->Ran 5 tests ... FAILED (failures=18), matching the PR: 4 of 5 fail. python -I tools/mode_round_probe.py --self-test->self-test OK;--oracle rulelists the two new ldexp cases.tests/semantic/test_alu_frexp_ldexp_f16.py25 OK,test_valu_f16_round.py35 OK,test_f16_fma_rounding.py5 OK.python -I -m pytest tests/test_mode_round.py tests/test_mode_round_probe.py tests/test_shader_checks.py -q-> 164 passed, 278 subtests.
Verdict: approve. The new branches only run after a MODE write (Gen.round_mode) and leave exact/zero/inf/NaN results alone; RTZ overflow -> 65504 and truncating denormals for v_ldexp_f16 are still unmeasured on hardware, and docs/design.md says so.
FP_ROUND[3:2] is the round mode of the double- and half-precision results (RDNA2 ISA, MODE register), and the translator tracks it in %mode_r16 for the f16 results and v_add_f64. The v_ldexp_f64 branch never read it, so after s_setreg_imm32_b32 hwreg(HW_REG_MODE, 2, 2), 3 an overflow still gave +-inf and a subnormal result still rounded to nearest even. While the mode is toward zero an overflow now gives +-DBL_MAX and a subnormal result is truncated. Programs that never write the field emit the same code as before. The f64 sibling of ItsNotRexed#5310 (v_ldexp_f16). Tests: tests/semantic/test_ldexp_f64_mode_round.py (cases, exact rational reference sweep, mode switch back, clamp, the probe's words); tools/mode_round_probe.py gets two v_ldexp_f64 cases for an RDNA2 owner to run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Corpus check on a second copy of the same package (26,503 disasm listings, counts only): v_ldexp_f16 and the v_frexp_*_f16 forms have 0 occurrences in the whole corpus (in fact no ldexp/frexp mnemonic of any width appears). The MODE.FP_ROUND path is latent on game shaders, consistent with fixture-level coverage. Counted with grep -o on Windows, AI-assisted. |
Conflict in docs/design.md: kept main's wording for the three rows and re-added the v_ldexp_f16 sentence to the MODE.FP_ROUND row. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested
AI-assisted (Claude Code). |
|
Tested 4a92a11 (merged onto main 86a7807) on NVIDIA GeForce RTX 2060 (Turing), NVIDIA 621.24, Vulkan 1.4.357, Windows 11 (10.0.26300), subgroup size 32: pass (no regression) What I ran:
No GPU test changed status against main. This PR adds no GPU fixture of its own, so the run checks that the translator change breaks none of the existing GPU tests; it does not exercise the new rule directly. Unit tests changed by the PR: The one failure on both sides is AI-assisted run (Claude Code); the numbers are from my machine. |
Coordination: finding and claim.
What was wrong
docs/design.md(Known approximations, MODE) says that afters_setreg_imm32_b32 hwreg(HW_REG_MODE, 2, 2), 3, every VALU f16 result except the transcendentals rounds toward zero. Thev_ldexp_f16branch never read%mode_r16, so it emitted the same code in both modes.v_ldexp_f16only rounds when the result leaves the normal range, and both of those cases came out wrong:v_ldexp_f16_e32 v8, v1, v23faac5570x7bff, n = 10x7c000x7c000x7bff0xfbff, n = 10xfc000xfc000xfbff0x3c03, n = -150x02020x02020x02010x3bff, n = -140x04000x04000x03ffIt was found by a sweep of 15 MODE-aware f16 forms against an exact rational reference. Every other form matched in both modes.
Fix (
tools/rdna2spirv.py, thev_ldexp_f16branch only)The fix only applies when the program writes the field (
Gen.round_mode). While%mode_r16is 3:sign | 0x7BFFinstead ofsign | 0x7C00;Exact results, zeros, infinities and NaNs are unchanged. Programs that never write MODE emit the same code as before.
v_frexp_*_f16are exact and untouched. This does not overlap #4311's hunk in this branch: that PR changes the output-modifier check, and this one changes the ldexp rounding.Tests
New file
tests/semantic/test_ldexp_f16_mode_round.py(spirv_mini_interp).tests/spirv_interp.pyhas noFindUMsb, so these could not go intotests/test_mode_round.py. It contains:test_cases: 17 edge cases (overflow, n clamped to 64, a tie in the denormal range, a carry into the smallest normal, below the smallest denormal, exact results, inf, -0, switching back to nearest even);test_seeded_sweep_against_exact_reference: 40 results per mode against aFractionreference that shares no code with the translator;test_mode_switches_back_and_vop3: VOP3 with-v1, RTZ then RNE in one program;test_probe_cases_match_the_translator: every f16 case intools/mode_round_probe.pygives the translator's word in both modes, so a GPU run of the probe checks the translation directly.On main (with this PR's probe file): 4 of the 5 fail, with 18 failures: 7 edge cases, 8 of the 40 RTZ sweep results, the VOP3 test, and both new probe cases. Only the reference self-check passes.
With the change: all 5 pass.
tools/mode_round_probe.pygetsldexp_f16_ovfandldexp_f16_sub(RNE vs RTZ words), and--self-testpasses.Verification
v_ldexp_f16programs (n in [-30, 30], both modes) vs the exact reference--opt)tests/test_mode_round.py,tests/test_mode_round_probe.py,test_alu_frexp_ldexp_f16,test_valu_f16_round,test_f16_fma_rounding,tests/test_shader_checks.py,tests/test_docs_*.pydocs/design.md: one sentence in the MODE paragraph (not the frexp/ldexp row that #4311 edits). It says the toward-zero behaviour applies the documented rule and is not measured on hardware.Not done: no GPU run. I have no RDNA2 card.
python -I tools/mode_round_probe.pyon a GFX10 GPU would confirm the two new cases.Environment
AI-assisted (Claude Code).
🤖 Generated with Claude Code