Floating-point modes: the non-fused MAD/MAC family needs precise, and the s_round_mode NOOPs are not free #73
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl#73
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@MoonYueya on GitHub · 2026-11-23 00:47 UTC · original
Floating-point modes: the non-fused MAD/MAC family needs
precise, and thes_round_modeNOOPs are not freeTwo results from running the same DXIL on an RDNA2 iGPU and on WARP, both about the parts of
emit.rsthat a desk check cannot settle. Counts only, no game data. The corpus numbers come from a retail shader pack on my side; the GPU numbers come from a synthetic shader whose inputs are bit patterns I chose.Machine: AMD Radeon(TM) Graphics (Raphael iGPU, gfx1036, wave lanes 32..64), driver 32.0.11024.2 (2024-06-25), Windows 11 build 26300. DXC 1.8.2502.11 from Windows SDK 10.0.26100.0. The reference column throughout is WARP running the identical DXIL module, not a second GPU.
1. The non-fused MAD/MAC family goes through
mad_nf, and itspreciseis load-bearingThe four console-only opcodes the decoder names
V_MAC_F32(VOP2 0x1f / VOP3 0x11f),V_MAD_F32(VOP3 0x141),V_MADMK_F32(VOP2 0x20) andV_MADAK_F32(VOP2 0x21) emitmad_nfatemit.rs:2729,:2732,:2736and:2737.mad_nf(emit.rs:4534) is the two-rounding pair, and on this GPU itspreciseis what decides the result:a = 0x7f7fffff,b = 0x3f800001,c = 0xff7fffffgives0x7f800000withprecise(the intermediate product overflows to+inf) and0x73ffffffwithout it. A written-outt = a*b; r = t+ccompiled at-Odgave the fused0x73ffffffhere, so one golden vector in the GPU tests is enough to keep this from regressing.preciseis present (indices 32, 34, 59, 60) - small enough to disappear in a sweep, large enough to matter.v_mad_f16(emit.rs:2377) takes the samemad_nfpath, wherepreciserounds in binary32 afterf16tof32rather than to binary16 per step. Intended, or a separate lowering?2.
s_round_modeis dropped 4,663 times in one packemit.rs:51NOOPss_denorm_mode,s_round_mode,s_setreg_imm32_b32ands_setreg_b32. Decoded to the end of every program in this pack:s_round_modes_denorm_modes_setreg_imm32_b32s_setreg_b32Of the 67
s_setreg_imm32_b32, 3 to 8 write MODE (in the decoded corpus: 3 instructions in 3 programs,hwreg id=1, offset=2, width=2, value0x0; five more candidate words with the same encoding sit after the 40 programs the decoder does not get through, hence the upper bound). The other 64 write the flat-scratch base pair (id 20 =0x0, id 21 =0x400, 32 programs, always adjacent). No decoded write touches MODE[1:0], [5:4] or [7:6]. So in the part we decode thes_setregNOOPs are harmless;s_round_modeis the one whose immediates decide it.Three counting facts if you reproduce this on your pack:
s_round_modecarries its value in the instruction word. ENC_SOPP, opcode 36, one SIMM16 operand; in this pack every occurrence reads0xBFA4xxxx, so the value isw & 0xFFFF, and0xBFA5xxxx(s_denorm_mode) is 0. A raw count of0xBFA4xxxxgives the identical 4,663 - occurrence count and value distribution are one pass.s_setreg_imm32_b32cannot be counted by byte scan. It is SOPK-with-literal, so of 1,221 candidate dwords only 67 were at an instruction start; the other 1,141 sat inside another instruction's literal slot (469 of them inside onev_add_f32form). A grep-shaped count inflates by 18×.v_nop 0xD5800000, then two dwords that are not instructions; the first real instruction is at dword 3,s_inst_prefetch 0xBFA00003, present in 13,905 of 13,962 programs, with the remaining 57 (all compute) starting ons_inst_prefetchdirectly. Decoding from the record start instead rejects at dword 2 and reports ~0 of these instructions.These counts come from the PSO cache layer: 21,522 program records, 13,962 distinct contents, each decoded to its end (50.98 M dwords, 36.86 M instructions, 40 programs rejected). The 26,503-record / 26,698-program layer discussed in #36 is a different container, so the two are not comparable term for term.
Why the NOOP deserves a decision rather than a comment: MODE is per-wave state that shapes every float operation after the write, and dropping a write is equivalent only when the value written equals the value already in force. For the 3..8
s_setregMODE writes that holds provided 0 selects the mode already in force (0 = round-to-nearest-even, the D3D default). For the 4,663s_round_modethe immediate is exactly what decides, and a non-default immediate NOOPed silently costs nothing at translation, nothing at compile, and shows up only as a wrong image.Cheapest first:
w & 0xFFFFover thes_round_modewords in your pack. If every value is 0, and 0 selects the default rounding mode, the NOOP is equivalent for programs that start in that mode and theNOOPSentry can carry that in one line.unsupported/unsupported_whyso the program is reported rather than NOOPed. You already report translation errors per program, so a non-default round mode becomes a visible skip instead of a wrong picture.SPI_SHADER_PGM_RSRC1_*(ISA §3.12), so reading it at pipeline creation and handing it todxc.rsas a compile option would cover programs that inherit a non-default mode without ever writing it - proposed from that mechanism, and unconfirmed for this target (below).What this does not settle
s_round_modeonly saysset floating point round mode using an immediate constant, sovalue 0 = default rounding modeabove is an assumption, not a decoded fact.SPI_SHADER_PGM_RSRC1_*is the AMD RDNA2 mechanism (ISA §3.12); that the Xbox target carries the entry mode the same way is unconfirmed, which is why item 3 above is a proposal.Note on #67 / #70
Both PRs are about NVIDIA, whose D3D12 wave range is 32..32. Related from this side, for the opposite reason: DXC rejects
[WaveSize]on pixel and vertex shaders (attribute WaveSize only allowed on compute or node shaders), and on the RDNA2 iGPU whose suite results are in #42 a pixel shader with no attribute runs 64 lanes - so the VS/PS case #67 lists as still open on NVIDIA has no hook on RDNA2 either.🤖 AI-assisted: drafted by an LLM agent from the measurements above; every number was taken from a run, not from the model.
@MoonYueya on GitHub · 2026-11-23 01:28 UTC · original
Follow-up with the numbers the first post left out.
s_round_modeimmediate values (same corpus and decoder as above: 13,962 distinct programs, walked instruction by instruction from the real first instruction, so no literal-slot hits):simm160xC0x00x0.How sure the bit meaning is. The MODE field layout is confirmed from LLVM
SIDefines.h(FP_ROUND_MODE_SP= bits 1:0,FP_ROUND_MODE_DP= bits 3:2, covering f64 and f16). Thats_round_mode'ssimm16writes MODE[3:0] directly is an inference: the ISA XML gives the operand only asSIMM16, and LLVM never generates the instruction. Under that reading,0xCkeeps f32 at round-to-nearest-even and sets f64/f16 to round-toward-zero. So an f32-only check cannot clear the programs that write0xC; the f16/f64 work after each write is what matters (we have not yet paired each write with a later f16 instruction).What
precisedoes not cover.preciseonly stops reassociation and contraction. DXIL has no dynamic rounding-mode control (the mode is fixed at compile time and no instruction sets it at runtime).-Gisdoes not set a mode either; it only changes code generation (on a 160-program sample, dxc accepted all 160 and the DXIL changed for 158). So a non-default mode can only be reproduced by emitting the rounding explicitly, for example f32→f16 round-toward-zero done with integer operations. On our side:unsupported/unsupported_why, not dropped.We will post the split and send a PR once it is measured.
Accounting correction for
s_setreg_imm32_b32. Of the 1,221 candidate words, 67 are instruction starts and 1,141 sit inside another instruction. The remaining 13 sit in programs where our decode stopped before them: 6 of the 451 candidate-bearing programs (the full-corpus pass rejects 40 programs, a different denominator). Five of those 13 are the same instruction word as the three confirmed MODE writes, so the MODE-write count is 3 in the decoded part and at most 8 overall. The first post should have said "5 of the 13" rather than "after the 40 programs"; the numbers 3 and 8 are unchanged.The f16 question about
v_mad_f16going through the f32mad_nfis still open on our side; we have not measured it.🤖 AI-assisted: drafted by an LLM agent from our measurements; counts are from runs, not from the model.
@ivall on GitHub · 2026-11-23 10:48 UTC · original
Fixed by #91 (merged,
ecbad66onmain):s_round_mode/s_setreg*writes of MODE[3:0] are scanned first; default writes stay counted NOOPs, a non-default f16 / f64 mode (your0xC) in a program with f16 ops is tracked and the f16 results rounded accordingly, and a non-default f32 / f64 mode is reported unsupported instead of dropped (none occur in our pack – it still translates 26 698 / 26 698).v_mad_f16now rounds per step, and the non-fused MAD/MACpreciseis pinned by a GPU test with your overflow vector. Thanks for the careful numbers – the entry mode fromSPI_SHADER_PGM_RSRC1is still open if someone finds it on this target.@MoonYueya on GitHub · 2026-11-23 14:43 UTC · original
Thanks for landing this in #91, including the non-fused MAD/MAC overflow vector as a GPU test. Nothing further from our side; we'll only come back if we can read
SPI_SHADER_PGM_RSRC1from a real executable.AI-assisted: drafted with an AI assistant, reviewed before posting.