Repository navigation
Conversation
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>
This was referenced Nov 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Coordination: finding and claim. The f64 sibling of #5310 (which fixes
v_ldexp_f16only); no overlap with its hunks.What was wrong
FP_ROUND[3:2] is the round mode of the double- and half-precision results (RDNA2 ISA, MODE register). The translator tracks it per invocation in
%mode_r16(docs/design.md, Known approximations: afters_setreg_imm32_b32 hwreg(HW_REG_MODE, 2, 2), 3the f16 results andv_add_f64round toward zero, a finite overflow gives the largest finite value;v_add_f64was measured that way on an RX 6800). Thev_ldexp_f64branch (tools/rdna2spirv.py:10602on561b65a8) never read%mode_r16, so it emitted the same code in both modes.v_ldexp_f64(D = S0 * 2^S1) only rounds when the result leaves the normal range, and both of those cases came out wrong toward zero:v_ldexp_f64 v[0:1], v[2:3], v4after the toward-zero writemain0x7fefffff_ffffffff(DBL_MAX)0x7fefffff_ffffffff0x7ff00000_00000000(inf)0x7fefffff_ffffffff0xffefffff_ffffffff0xffefffff_ffffffff0xfff00000_000000000xffefffff_ffffffff0x3ff00000_000000030x00080000_000000010x00080000_000000020x00080000_000000010x3fefffff_ffffffff0x000fffff_ffffffff0x00100000_000000000x000fffff_ffffffff0x3ff80000_000000000x00000000_000000000x00000000_000000010x00000000_00000000Without a MODE write (or after writing 0 back) nothing changes: overflow is ±inf and a subnormal result rounds to nearest even, as measured on gfx1036 (the existing row).
Fix (
tools/rdna2spirv.py, thev_ldexp_f64branch only)Only when the program writes the field (
Gen.round_mode), as #5310 does for f16. While%mode_r16is 3:sign | 0x7FEFFFFF_FFFFFFFFinstead ofsign | 0x7FF00000_00000000;clampstill applies after the rounding (+DBL_MAX clamps to 1.0, as +inf did). NaN, inf and zero inputs pass unchanged. A program without a MODE write gets the same SPIR-V as before.Reference and confirmation
V_LDEXP_F64is a double result (IEEE 754 scaleB rounds by the rounding-direction attribute). The same field already drivesv_add_f64in the translator, measured on an RX 6800.tools/mode_round_probe.pygets two cases (ldexp_f64_ovf,ldexp_f64_sub) an RDNA2 owner can run withpython -I tools/mode_round_probe.py; the new test checks that the probe's words are the translator's.v_ldexp_f64contract row says this (I left the Known approximations row alone, since rdna2spirv: v_ldexp_f16 follows a MODE.FP_ROUND toward-zero write #5310 edits it).Tests
tests/semantic/test_ldexp_f64_mode_round.py, hand-written programs: 18 cases (overflow both signs, S1 clamped to 4096, inf/NaN/-0, the subnormal round-up, tie, carry-into-min-normal and below-min-subnormal cases in both modes, exact results), an exactfractions.Fractionreference checked against the cases and a seeded sweep (overflow edge, subnormal range, subnormal operands) in both modes, switching back to nearest even with a sourceneg,clampafter the toward-zero overflow, and the probe words. 13 of its checks fail onmain, all pass here.vk_compute_test: every word equals the CPU result (toward-zero words wrong onmain, right here).spirv-val --target-env vulkan1.2clean.python -m unittest discover -s tests/semantic: 6156 tests OK (1 skipped, 1 expected failure, as onmain). Alsotests/test_mode_round.py(pytest, 74 passed),tests/test_mode_round_probe.py,tools/mode_round_probe.py --self-test,test_design_contract_rows,test_docs_design_rows,test_docs_table_rows,test_docs_repeated_lines,test_semantic_translator_use,test_text_write_line_endings,compileall.No game data used. AI-assisted (Claude Code).
🤖 Generated with Claude Code