startup: lower the 64-bit vector shifts #1811
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1818"
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 triggered02 on 2026-11-24T19:10:07Z.
Fixes #1817. The next census group (#870), and the first one that needed a new translator capability rather than a port.
Change
v_lshlrev_b64,v_lshrrev_b64andv_ashrrev_i64had no lowering, so the census form was refused:Two things make this more than a single shift:
sh < 32andsh >= 32are separate cases (the>= 32case takes the words from the other half).uint2; the handler then writes both in one statement. Passing the words in also means no shared temporaries or name collisions between instructions.The three preamble helpers mask the count to six bits:
Sources may be a VGPR pair, an SGPR pair or an integer inline constant. The low word always shifts unsigned; only the arithmetic form signs the high word.
Test
startup_gfx2hlsl_b64_shiftbuilds VOP3A encodings from the checked-in decoder's layout (0b110101prefix, opcodes0x2ff/0x300/0x301, low destination inw0[7:0], count inw1[8:0], value inw1[17:9]), decodes them, then translates. Nine checks: all three shifts reach their own helper, both destination words are written, the census form lowers to a zero pair, an inline constant count stays a constant, and the helpers are in the preamble with the count masked.Fail-first, all caught:
Pre-existing failures, not from this PR
startup_gfx2hlsl_mad_preserve_{warp,hardware}fail in this dev tree withUnknown GPU operation or invalid arguments: --raw-uav-dump-sm62— the builtoffscreen_checkis stale. Confirmed identical onorigin/main(ecc6e6ce) with the same binary. A rebuild fixes it; this branch does not touch that tool.What this does not establish
AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T19:18:50Z.
Review: COMMENTED
Review of
d819085a(startup: lower the 64-bit vector shifts). Verdict: 0 P1, 1 P2, 1 P2 on the test, plus P3 notes.What I checked
shl64,shr64u,shr64i). I transliterated them one to one, with 32-bit shifts masked to 5 bits as HLSL/DXIL do, and compared them to a 64-bit reference (Python integers) for 410 values (edge values, sign bits, 300 random) times counts 0..129, 255, 256 and 2^32-1, for the three shifts: 122,892 cases, 0 mismatches. The count is masked to six bits like the hardware's 64-bit shift; counts 32 and 63 are right for the logical and the arithmetic form.uint2, so an in-place destination is safe. It refuses modifiers, a non-pair destination and sources that are not a VGPR/SGPR pair or an integer inline constant in -16..64 (zero- or sign-extended to 64 bits as the hardware does for an integer operand). Float inline constants and literals are refused, which is the safe choice.P2 (code):
shift64does not clear the uniform-register recordset_v()doesself.uniform_v.discard(n)before every VGPR write.shift64()(tools/startup/gfx2hlsl.py, the new handler) writesv%d/v%ditself and skips that, so a register proven uniform earlier stays "uniform" after a shift that overwrites it with a lane-varying value.op_v_readfirstlane_b32trustsuniform_v, so it then accepts the register. Reproduction against this SHA (a Stage withv10marked uniform, thenv_lshrrev_b64 v[10:11], v8, v[8:9], thenv_readfirstlane_b32 s5, v10):Fix:
self.uniform_v.discard(dst[1]); self.uniform_v.discard(dst[2])before the emit (or route the write through a shared helper), and add a check for it.P2 (test): the numeric behaviour is not tested
tests/startup_gfx2hlsl_b64_shift_check.pychecks that certain substrings appear ('shr64u(v8, v9, v8)','sh &= 63u;'three times, ...). It never evaluates a helper. I mutated the PR code and ran the PR test:shl64: drop the carry word `shr64i: high result for counts >= 32 changed from the sign fill to0ushr64u: drop the carry (cy = 0)sh &= 63utosh &= 31u(all three)v_ashrrev_i64routed toshr64uSo three real arithmetic bugs survive the test. The helpers are correct today (see above), but nothing keeps them so. Suggested: evaluate the helper text in the check (a small Python transliteration, or compile the helper HLSL and read back) against a 64-bit reference at counts 0, 1, 31, 32, 33, 63 and 64+, for the three shifts.
P3
def op_v_cvt_pkrtz_f16_f32after the new handlers.Commands run (Linux, on exactly
d819085a220f8a12cb7919484fef0c7f55c6f761)Mutations were applied to the working tree and restored.
Limits
The generated HLSL was not compiled (no shader compiler on this host). The PR changes no C++, so I did not run the Windows pipeline.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T19:10:20Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
d819085ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.