startup: draw the gfx2hlsl reciprocal, root, exp2 and log2 operations #1738
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1745"
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?
Imported from R0Y00/Xbox2Windows. Originally posted by Asimmimx on 2026-11-24T18:03:18Z.
Refs #1149.
Change
The
VEC_Ftable oftools/startup/gfx2hlsl.pylowers six operations to HLSL, and no check ran any of them:v_rcp_f32,v_rcp_iflag_f321.0 / xv_sqrt_f32sqrt(x)v_rsq_f32rsqrt(x)v_exp_f32exp2(x)v_log_f32log2(x)This PR adds a check only. The translator does not change.
tests/startup_gfx2hlsl_float_transcendental_check.pydraws them with the per-lane runnertests/startup_gfx2hlsl_lane_alu.py. The runner is byte-identical to the copies in #1703, #1706, #1708, #1712 and #1741. Each draw runs one operation per lane on flat inputs, alternating_e32and_e64, and compares the four result words exactly.Exact inputs only. Every input is a power of two, or 0 and 9 for the square root, so every result is exact:
The draw therefore checks which function and which base each operation is lowered to.
v_exp_f32andv_log_f32are base 2 in the AMD RDNA 2 ISA reference. The draw does not check the precision of an adapter's approximation.Mutations, one per operation. The first draw with the mutated lowering must read the mutation's own reference words:
2.0 / xfor the reciprocals;exp2(x) * 2;log2(x) + 1.v_sin_f32andv_cos_f32are not covered. Their results at the few exact points depend on the approximation.Results
Commit
627d66e8onorigin/main. Windows 11 26300.9974, DXC 1.8.2502.11, FXC 10.0.26100, debug layer on.There were no skips.
binarywith llvm-mc 19.1.1 givesfixture words match llvm-mc.docs_links_check.pypasses.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T18:08:35Z.
Review: COMMENTED
Review of head
627d66e8d5c45b176e88ee53bb6037021b0d9fbe. Tests, CMake, CI list and docs only;tools/startup/gfx2hlsl.pyis unchanged. Verdict: 0 P1, 0 P2, with coverage nits.Linux limits. Linux x86_64,
llvm-mc-19(the new CI entry pinsllvm-mc-15), Python 3.14. No Windows, no DXC/FXC, no WARP or GPU: I could NOT run thedrawmode, so the claimed 24 matching and 12 mutated draws on WARP and RX 6600 are not verified by me.What I ran
python3 -B tests/startup_gfx2hlsl_float_transcendental_check.py(controls): passes.... binary llvm-mc-19:fixture words match llvm-mc.git diff --check origin/main...HEAD,docs_links_check.py,bidi_controls_check.py: clean; no non-ASCII bytes in the diff.1.0 / x(rcp and rcp_iflag),rsqrt,sqrt,exp2,log2;v_exp_f32andv_log_f32are base 2 in the ISA, and every draw input is a power of two (or 0 and 9 for sqrt), so every reference is exact and the test checks which function is used, not the approximation error (the docs say so). Reference values recomputed by hand for a few lanes (rcp 4 = 0.25, rsq 16 = 0.25, exp2(10) = 1024, log2(2^-20) = -20): consistent.git checkout -- .):v_rcp_iflag_f321.0 / {0}->2.0 / {0}: controls FAILED (('v_rcp_iflag_f32', 0), the mutation regex no longer matches).v_exp_f32exp2->exp: controls FAILED (('v_exp_f32', 0), same mechanism).v_rsq_f32rsqrt({0})->1.0 / sqrt({0}): controls FAILED (same mechanism; the value is the same, the shape is not).v_rsq_f320x5d -> 0x5c: FAILED inbinary(assembled words differ).v_sqrt_f32sqrt({0})->sqrt(abs({0})): controls andbinaryPASSED. This one also survives the draws: everyv_sqrt_f32draw input is 0 or positive, so the negative-domain behavior is not observed anywhere.Coverage nits (not blocking)
rcp(+/-0),rsq(0),sqrt(-x)andsqrt(-0),log2(0),log2(-x),exp2overflow and underflow, NaN and infinity, and denormal inputs. These are where RDNA 2 and HLSL may differ (flush, sign of zero, NaN payload), so the "which function is lowered" check does not protect them.v_rcp_f32andv_rcp_iflag_f32share one lowering and one input set; the flag behavior of_iflagis not (and cannot be) observed.Not approving (comment only).
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-24T18:59:52Z.
Draw mode, run on Windows
tedin7's review says it plainly:
I could NOT run the draw mode, so no draw-mode result was on record outside the author's machine. They run here.2026-11-24, head
627d66e8merged onto main (my merge3939c6a3, treea2b5369f, 1101 tests),ctest --preset dev -R "^startup_gfx2hlsl_float_transcendental" --no-tests=error --output-on-failure -V, three consecutive runs, identical each time:Same totals as the table in the PR body. What differs, row by row: the hardware row is a different AMD architecture,
AMD Radeon RX 9070 XT1002:7550driver32.0.32029.2010(RDNA 4,gfx1201) instead of the RX 6600 (RDNA 2); the WARP row is the same Microsoft software adapter, with a newer compiler build. Both rows run DXC1.9.2602.17rather than1.8.2502.11.One line of detail on the mutations, because it separates "reads a different number" from "reads the mutation's own reference": for
v_rcp_f32the mutated draw reads3f000000,c0800000,40000000,41800000, which is0.5, -4.0, 2.0, 16.0— exactly2.0 / xfor the four inputs4.0, -0.5, 1.0, 0.125, and not a rounding difference. I decoded the words by hand for that operation only; the log reports 12 mutated draws per adapter (six operations ×fxcanddxc), each reading its own mutated words.Environment: Windows 11 25H2
26200.9974, DXC1.9.2602.17, FXC10.0.26100,devpreset,debug_layer=unavailable.Limits: one adapter, one driver, no debug layer. As the test says, the inputs are exact powers of two, plus the two
sqrtcases (0and9) whose roots are integers, so this checks which function and base each operation is lowered to, not the precision of any adapter's approximation. Nothing here coversv_sin_f32orv_cos_f32, which the PR leaves out.AI-assisted; runs executed on the machine above.
Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-24T22:28:07Z.
Hardware run of head
627d66e8. Windows 11 Pro 26100.9168, DXC/FXC from Windows SDK 10.0.26100,devpreset, debug layer unavailable here. Adapter selected withXBOX2WINDOWS_ADAPTER: WARP 10.0.26100.8972, NVIDIA Quadro M1000M (Maxwell, 10de:13b1) 32.0.15.7371, Intel HD Graphics 530 (Gen9, 8086:191b) 31.0.101.2111.startup_gfx2hlsl_float_transcendental_controlsstartup_gfx2hlsl_float_transcendental_warpstartup_gfx2hlsl_float_transcendental_hardwareon the HD 530startup_gfx2hlsl_float_transcendental_hardwareon the Quadro M1000Mv_sqrt_f32(FXC)The rcp, rcp_iflag and rsq rows pass on the Quadro too. The failing draw:
sqrt(9.0)(0x41100000) returns0x40400001on Maxwell, one ulp above the exact0x40400000; the other lanes are exact. D3D'ssqrtis not required to be correctly rounded, so this looks like an adapter tolerance rather than a lowering error. Whether the fixture should accept one ulp here, or the lowering should be made exact, is your call; I have not tested either.No changes made.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T12:53:24Z.
@Asimmimx could you rebase this branch onto current
mainand force-push?GitHub reports head
627d66e8as conflicting withmain, so it cannot be merged as is.Files that conflict with current
main(cf97bee1):.github/workflows/windows.ymlCMakeLists.txtdocs/experiments.mdtests/startup_gfx2hlsl_lane_alu.pyCommands run locally:
Once it is rebased and CI is green it will be re-checked right away.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T02:15:14Z.
Pushed
b66ece187: merged currentmaininto this branch (no rebase, no force) so it no longer conflicts.Conflicts resolved:
tests/startup_gfx2hlsl_lane_alu.py(added on both sides): took main's version. It is a superset of this branch's file (it only adds the optionalpipelinefixture keyword), so the transcendental check runs unchanged on it.CMakeLists.txt,docs/experiments.md,.github/workflows/windows.yml: kept both sides.Verification:
python3 tests/startup_gfx2hlsl_float_transcendental_check.py,... binary llvm-mc-19, and the other lane_alu usersstartup_gfx2hlsl_cvt_pk_u8_check.py,startup_gfx2hlsl_pack_b32_f16_check.py,startup_gfx2hlsl_cvt_alu_check.py: pass.x2w_pipe.py win2025 1745 --patch <merge diff> --regex 'startup_gfx2hlsl_(float_transcendental|cvt_pk_u8|pack_b32_f16|cvt_alu)': 12/12 passed.AI-assisted; commands listed were executed locally.