startup: sign-extend the SOPK i32 immediates in gfx2hlsl #2116
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!2116
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2116/head"
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?
@JB2WIN on GitHub · 2026-11-25 00:47 UTC · original
JB2WIN:startup/gfx2hlsl-sopk-signext→main· +151 −1 · 6 files · 3 commits · merged 2026-11-25 01:19 UTCProblem
tools/startup/gfx2hlsl.pydoes not sign-extend the 16-bit SOPK immediates of the i32 forms, so it computes wrong values without any refusal:mains_movk_i32 s0, 0x8000(constant path)0x000080000xffff8000s_movk_i32 m0, 0x8000(run-time path)0x000080000xffff8000s_cmpk_lt_i32 s5, 0xffffwiths5 = 0The cause is how the immediates are read:
tools/disasm_rdna2.pyprints SOPK immediates as unsigned hex, as LLVM 15 does.s_movk_i32throughint(srcs[0], 0)and the{0}scalar-table entry.s_cmpk_*handlers came from the same factory ass_cmp_*.So none of them applied the sign extension the i32 forms define.
Semantics
S_MOVK_I32isD.i32 = signext(SIMM16[15:0]). TheS_CMPK_*_I32forms compare againstsignext(SIMM16[15:0]), and theS_CMPK_*_U32forms againstSIMM16[15:0]without extension.SOPInstructions.td:s_movk_i32ands_cmovk_i32takes16imm. Everys_cmpk_*_i32isSOPK_SCC <…, 1>(isSignExt,s16imm), and everys_cmpk_*_u32isSOPK_SCC <…, 0>(u16imm).tools/pixel_aot.py(sopk_imm16) already applies the same rule.Change
sopk_imm(token, signed), accepts a 16-bit immediate and sign- or zero-extends it. It refuses values outside 16 bits and register operands; the translator accepted both before.s_movk_i32: it uses the helper throughscalar(), which covers both the constant and the run-time path.s_cmpk_*: these get their own handler factory:_i32is signed,_u32unsigned.s_cmovk_i32: not lowered, and it stays refused; the check asserts this.Test
New device-free check
tests/startup_gfx2hlsl_sopk_signext_check.py, registered asstartup_gfx2hlsl_sopk_signextand listed in the pure-Python job andAGENTS.md.s_movk_i32in both paths with0x0,0x7fff,0x8000and0xffff, and everys_cmpk_*_i32and_u32form with boundary and negative immediates. There are also 10 refusals.main: the check fails with 130 mismatches and also reports the accepted out-of-range and register operands._u32, it fails with 117.Results:
c75f6659, alltests/startup_gfx2hlsl_*_check.py,tests/startup_translator_check.pyandtests/docs_links_check.pypass.ctest --preset dev --no-tests=error -R '^startup_'was run on an un-rebuilt tree before the rebase. The new test passed, and the remaining failures were draw tests whose binaries were not rebuilt. They fail the same way withmain'sgfx2hlsl.py.Related: #2102 (
s_addk_i32/s_mulk_i32, from me) already sign-extends its immediate and is checked for it. Once both have landed, it could switch to this helper.AI-assisted (Claude Code).
🤖 Generated with Claude Code
b6b4dbc274' into HEAD ecb08c40e0@R0Y00 on GitHub · 2026-11-25 01:16 UTC · original
I combined this with current main and retained the scalar arity diagnostics. Empty s_movk now refuses before reading its destination. The AMD RDNA 2 SOPK table specifies signed extension for I32 and zero extension for U32. Retested 1,152 comparisons, both movk paths, 11 refusals, and the existing arity, mask-overwrite and startup translator checks.