Repository navigation
startup: lower s_bfm_b64 in gfx2hlsl - #2007
Conversation
Ran it, broke it five ways — all caught — and checked the emitted formula against the ISA expressionWindows 11 build 26300.9974, device-free: out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_bfm_b64_check.py
mutation "offset masked to five bits" changes the text and reads a wrong word [(1, 32)]: ok
mutation "width 0 reads all ones" changes the text and reads a wrong word [(0, 0)]: ok
PASS exit 0
Your two controls and the first two of my mutations fail in the same place — the width boundary at 32 and the six-bit masking — which is a good sign that the check knows what can go wrong rather than merely comparing text. The arithmetic, checked exhaustivelyI reimplemented the emitted expression (mask split into two words, and that a width outside the six-bit field behaves exactly like its masked value, as the ISA says it must: So the two-word split at Two details worth keeping in the description
What I could not checkSCC being unchanged is argued from the ISA PDF entry, the neighbouring ScopeText and arithmetic; no shader was compiled or run. Constant folding is covered by your fixture, not by my probes. VerdictReviewed. Five independent breakages, five failures, and the formula agrees with the ISA expression on all 4,096 inputs. Notes
|
Two open PRs lower
|
| #2003 | #2007 | |
|---|---|---|
| modifiers and operand count | one combined message | two messages |
| destination alignment | dst[2] != dst[1] + 1 and dst[2] > 105 |
adds dst[1] % 2 |
| source register form | accepts anything reg_range maps to s |
refuses exec/vcc and any range r[1] != r[2] |
Two of those matter:
dst[1] % 2— a 64-bit scalar destination must be even-aligned in the register file. startup: lower s_bfm_b64 in gfx2hlsl #2007 enforces it; shader: lower s_bfm_b64 in gfx2hlsl (Part of #1723) #2003 does not, sos_bfm_b64 s[3:4], …would be accepted. That is the one substantive difference I would not want to lose.exec/vccas sources — startup: lower s_bfm_b64 in gfx2hlsl #2007 refuses them by name, shader: lower s_bfm_b64 in gfx2hlsl (Part of #1723) #2003 accepts them through the genericspath. Whether that is right depends on whether the ISA allows a 64-bit pair spelling here; worth agreeing on rather than leaving to merge order.
What I would suggest
Keep #2007's dst[1] % 2 and its explicit source refusal, and take #2003's split modifier/operand messages if you prefer them — then close the other, since neither check can be reused as is.
I have already reviewed #2007 at the behaviour level (five mutations, all caught, plus an exhaustive check of the emitted expression against the ISA formula over all 4,096 (width, offset) pairs). I have not reviewed #2003.
The same duplication exists for v_swap_b32 (#1995 and #2012), so this looks like a pattern worth a one-line note in CONTRIBUTING.md — "check open PRs for the mnemonic before starting" — rather than something either author did wrong.
Notes
- AI-assisted coordination note.
|
Please prefer this single implementation and coordinate the overlap with #2003. Before overwriting either destination word, reject a source SGPR tracked in Stage.masks. The current code drops the destination’s mask flag before reading its numeric sources, so aliases can bypass even a later check. Add a compare-derived scalar mask, with and without destination aliasing, as a refusal control. After rebasing on #1931, also prove or invalidate the uniformity of both written words and check that readfirstlane cannot consume a stale proof. |
00c2a6f to
9d0eb2c
Compare
|
Rebased on
The overlap with #2003 is in the thread there. AI-assisted (Claude Code). |
tedin7
left a comment
There was a problem hiding this comment.
Review of head 9d0eb2c41bafb99201e0a7bc9d824126b7fea5f3 (comment only, no approval).
Verdict: no blockers found. One P2 and one nit.
Checked
- Semantics:
D.u64 = ((1<<S0[5:0]) - 1) << S1[5:0], no SCC write. This matches thes_bfm_b32handler next to it. Width >= 32 gives low word0xffffffffand high word(1u << (w & 31)) - 1. No emitted shift count is 32 or more. Width 63 gives0x7fffffffin the high word, which is correct. Width 64 masks to 0, which gives 0. - Refusals are all taken before any state is written: modifiers, operand count, odd or non-SGPR destination, exec/vcc sources, and lane-mask sources. A source that aliases the destination is handled, because uniformity is judged first and the result comes from locals.
- Constant fold in in
op_s_bfm_b64matches the run-time path. - Wiring: the test is added to CMake (
startup_gfx2hlsl_bfm_b64),windows.ymlandAGENTS.md. Title is neutral and the diff is clean-room. - CI: Linux Python, gfx1013 fixtures and Windows build/test all pass. The Windows /O2 job is skipped.
Commands run locally on the PR head
python3 tests/startup_gfx2hlsl_bfm_b64_check.py: PASSpython3 tests/docs_links_check.py: 18 files, 393 links OKpython3 tests/bidi_controls_check.py: OKgit diff --check origin/main...HEAD: clean
Mutations of the new logic (each reverted with git checkout -- .)
- High-word mask
0xffffffffuchanged to0xfffffffeu: the test fails (killed). bw = width & 63uchanged to& 31u: the test fails (killed).- Removing
self.masks.discard(d + 1): the test still passes (survived).
Findings
- P2: The new check runs the emitted HLSL through a Python evaluator. It has no D3D12 WARP GPU readback against a CPU reference. For a gfx2hlsl math lowering, the HLSL compiler's own treatment of
shl64,bw >= 32u ? ... : ...anduint2is only covered indirectly. Please add a WARP readback on a Win2025 host (for example widths 0, 1, 31, 32, 33, 63 and offsets 0, 1, 31, 32, 63) and put the result in the PR body. I did not run Windows here. The Windows CI job only builds and runs the existing tests. - Nit: the survived mutation shows no test depends on
self.masks.discard(d + 1). Add a case wheres[d+1]was a lane mask before the write and is read as a number after it.
AI-assisted; commands listed were executed locally.
One of the refusals in the R0Y00#1723 census (1 pair). RDNA 2 SOP2 opcode 37 gives D.u64 = ((1ULL << S0[5:0]) - 1) << S1[5:0] with SCC unchanged, the 64-bit counterpart of the existing s_bfm_b32 entry. The handler writes both words of the destination pair through the shl64 helper, masks width and offset to six bits, gives 0 for width 0 and folds constant sources. New device-free check startup_gfx2hlsl_bfm_b64, covering all 64x64 width/offset pairs against a bit-loop reference. AI-assisted (Claude Code). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…niformity Read and check both sources (refuse a source SGPR in Stage.masks) before the destination mask flags or words change, so an aliased destination cannot hide a mask source. After R0Y00#1931, prove both written words uniform only when both sources are, and drop any older proof for s[d], s[d+1]. Checks: compare-derived mask refusals with and without aliasing, and stale-proof tests through v_readfirstlane_b32. AI-assisted (Claude Code). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…high-word case Review of R0Y00#2007: the CPU evaluator does not exercise the HLSL compiler's own treatment of shl64, the bw >= 32u selects and uint2. - startup_gfx2hlsl_bfm_b64_check.py draw: a translated pixel stage computes s_bfm_b64 s[20:21], s8, s9 and the swapped pair from root constants (the compiler cannot fold them) and exports the four words. Widths 0/1/31/32/33/63 against offsets 0/1/31/32/63 plus sources with bits above [5:0], compared with the bit-loop reference, FXC ps_5_1 and DXC ps_6_0. Negative controls shown in the draw: a reference without the cap at bit 63, and a mutated lowering (width 0 reads all ones). - startup_gfx2hlsl_bfm_b64_warp and _hardware (skip 77) registered. - --startup-flat-param takes optional entry constants (default all 0, so the existing callers are unchanged). - A lane mask in s[d+1] before the write is a number afterwards: accepted, and a mutation that drops self.masks.discard(d + 1) turns the check red. AI-assisted (Claude Code). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9d0eb2c to
283f03e
Compare
|
@tedin7, both points are addressed in WARP and hardware readback. New
Windows 11 build 26200, Windows SDK 10.0.26100.0 compilers.
Nit. New case:
AI-assisted (Claude Code). |
tedin7
left a comment
There was a problem hiding this comment.
Review of head 283f03ead8d7862aaaa76980ef14f082b2f8166d (s_bfm_b64 lowering in gfx2hlsl).
Summary: No P1 or P2 findings. The lowering matches the ISA definition D.u64 = ((1ULL << S0.u[5:0]) - 1) << S1.u[5:0], SCC unchanged.
Checked
- Semantics: width is masked to 6 bits. Width >= 32 gives low word 0xffffffff and high word
(1<<(w&31))-1. Width 32 gives high 0 and width 0 gives 0, so both edges are right. The offset goes throughshl64, which drops bits past bit 63. Every HLSL shift count stays below 32. - Both destination words are written from locals before either is stored, so a source aliasing the destination is safe. Uniformity is judged before the destination changes. Lane-mask, exec/vcc and register-pair sources, odd or unaligned destinations, extra modifiers and wrong operand counts are all refused.
- The constant-folding path agrees with the run-time path (control grid in the test).
- CI on this head: Linux checks pass, Windows build and test pass, gfx1013 fixtures pass. The Windows /O2 job was skipped.
- Wiring: CMake CPU and WARP/hardware entries,
windows.ymlandAGENTS.mdare all updated. The optional--startup-flat-paramconstants argument is bounds-checked (6..7 args, 4 hex words).
Commands run locally on the worktree
python3 -B tests/startup_gfx2hlsl_bfm_b64_check.py-> PASS (all controls and 3 built-in mutations caught)python3 -B tests/startup_gfx2hlsl_sopk_accum_check.py(sibling) -> PASSpython3 tests/docs_links_check.py-> OK (18 files, 401 links)python3 tests/bidi_controls_check.py-> OKgit diff --check origin/main...HEAD-> clean- Own mutation 1:
bw >= 32uchanged tobw > 32uin the emitted HLSL -> the test fails (rc=1, mismatch at width 32). Killed. - Own mutation 2:
& 63uchanged to& 31uon the width -> caught ("width masked with 31"). - Worktree restored with
git checkout -- ..
Nits (non-blocking)
- The CMake comment in the new
foreachblock says "review of #2007", which refers to the PR itself. Prefer describing the behaviour. - The new Python check is 628 lines. Consider moving the shared mutation grid into a helper if more
s_bf*ops follow.
Windows proof: I did not run a separate Win2025 job. The PR's own Windows CI is green and the draw test runs on WARP and hardware adapters. A fresh Win2025 WARP readback is still advisable before merge, if not already done for this exact head.
AI-assisted; commands listed were executed locally.
|
@JB2WIN could you rebase this branch onto current GitHub reports head Files that conflict with current
Commands run locally: Once it is rebased and CI is green it will be re-checked right away. AI-assisted; commands listed were executed locally. |
|
Independent verification requested after the rebase. In the saved-profile comparison at The author's next step is the rebase already requested above. An independent reviewer can claim the WARP/hardware rerun here now. Once the new head is posted, record its commit and run |
|
I’ll take the independent Release rerun requested above once the rebased head is up. I’ll use Windows 11 x64 build 26300.10075 with WARP and an RTX 4070 and report both destination words, the readback controls, and any skips. Pre-rebase baseline at cmake --build --preset release --target offscreen_check --parallel 4
ctest --preset release --no-tests=error -j 1 -R '^startup_gfx2hlsl_bfm_b64($|_(warp|hardware)$)' -VI’ll repeat this on the new head. |
|
The branch now includes the mainline conflict repair at |
tedin7
left a comment
There was a problem hiding this comment.
Review of head db5f84fe (comment only, Linux checks; no Windows run by me).
Code (tools/startup/gfx2hlsl.py, op_s_bfm_b64): matches the ISA expression. Width masked to 6 bits, offset handled in shl64, no emitted shift count of 32 or more. Both sources are read and checked against Stage.masks before either destination word changes, which covers the earlier request. Modifiers, operand count, odd or out-of-range destination pair, exec/vcc and descriptor sources are refused. Uniformity is recorded for both words from the old source state.
Checked locally on the exact head:
python3 -B tests/startup_gfx2hlsl_bfm_b64_check.py: PASSpython3 tests/docs_links_check.py: passpython3 tests/bidi_controls_check.py: passgit diff --check origin/main...HEAD: clean- Mutation: dropped
& 63uon the width -> check exits 1 (caught) - Mutation:
bw >= 32uchanged tobw >= 33u-> check exits 1 (caught)
Care items: the .github/workflows/windows.yml change is one line and must be exercised by this PR's own CI run. The offscreen_check/startup_flat_param edits are small and sit next to the new WARP/hardware cases.
Not covered by me: WARP/hardware readback (an independent Release rerun is already claimed above by @RonLogic) and anything about the startup path under #870. Because the PR is tied to the #870 saved-profile follow-up, the merge stays with @R0Y00 / MasterDomino, who can verify on the real executable. I am not merging it.
AI-assisted; commands listed were executed locally.
|
Measurement, on a local capture (counts and instruction shape only), at main AI-assisted. |
|
@JB2WIN, @R0Y00: this conflicts with https://github.com/Ybucaille/Xbox2Windows/tree/startup/gfx2hlsl-bfm-b64-merge (
AI-assisted (Claude Code). |
…via Ybucaille) (PC-Joshua)
|
Thanks @Ybucaille. I checked Windows run at
This covers the compile of the merged C++ and the WARP and hardware draws that were not run before. Refs #2618. AI-assisted (Claude Code); the commands above were executed locally. |
R0Y00
left a comment
There was a problem hiding this comment.
I verified the contributor merge is a fast-forward from the previous PR head. On its combination with main, the Release offscreen suite passed 11/11 on WARP and RTX 4060 Laptop, including the all-width/all-offset static grid, both DWORD outputs in FXC and DXC, the width and offset mutations, and the adjacent integer/negative-zero/culling checks. The newer main diff is the independent gather diagnostic. This verifies the source-built instruction lowering; the local refusal census is separate.
…n via Ybucaille) (PC-Joshua)
Refs #1723
Change
tools/startup/gfx2hlsl.pynow lowerss_bfm_b64. It is one of the refusals in the #1723 census (1 pair).D.u64 = ((1ULL << S0.u[5:0]) - 1) << S1.u[5:0]. The entry lists no SCC write; the bit operations next to it do list one. The existings_bfm_b32entry and thepixel_aotreference also leave SCC unchanged, so the handler emits noscc.s_and_b64and the others) keep only a lane bit and a zero high word.s_bfm_b64produces a real 64-bit value, so the newStage.op_s_bfm_b64writes both wordss[d]ands[d+1]. It uses the preamble'sshl64helper, asv_lshlrev_b64does.shl64masks the offset and cuts at bit 63. A width of 32 or more gives the low word0xffffffffand the high word(1u << (w & 31u)) - 1u. A width of 0 gives 0. No emitted shift count is 32 or more.exec/vccor descriptor sources.Test
New device-free check
tests/startup_gfx2hlsl_bfm_b64_check.py, registered asstartup_gfx2hlsl_bfm_b64and listed in the pure-Python job andAGENTS.md.shl64from the preamble and compares the result with an independent bit-loop reference.[5:0]that must be ignored, inline and literal sources, constant folding and destination equal to source. The check also asserts that no shift count reaches 32.& 31instead of& 63, a 5-bit offset, and width 0 giving all ones.main: withmain'sgfx2hlsl.pythe check fails withUnsupported: s_bfm_b64.Results on
1ebfe511plus this commit:ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl'passed 41/41.tests/startup_translator_check.pyandtests/docs_links_check.pypass.The check evaluates the emitted HLSL in Python. It does not compile it or draw with it.
AI-assisted (Claude Code).
🤖 Generated with Claude Code