startup: flip the sign bit for a negated source on the vector select #1703
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1710"
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-24T17:35:04Z.
Fixes #1709. Fourth group from the loading-screen refusal census (#870): 2 of 29 shaders.
Note on authorship: the branch now carries R0Y00's
dfc73a1b("Preserve unmodified negative select immediates"), which replaces my first attempt with a better design, plus his merge of main (ab586947). The description below reflects the final tree.Change
In an integer instruction the
-source modifier is that source's sign bit flipped — the bit pattern a float negation produces. The vector select passed the printed operand straight to the uint helper, sov_cndmask_b32_e64 v31, v30, -v30did not translate:The helper is used only where the modifier is modelled. Another integer instruction carrying the same
-operand still refuses rather than silently flipping a bit, so this does not quietly widen the accepted set.Immediate operands (R0Y00's refinement)
The printed
-1is ambiguous: it can be the plain inline constant-1(0xffffffff) or inline1with NEG set (0x80000001). Rather than guess from the text, the ambiguity is resolved in the decoder:decode()inspects the encoded source field and refuses NEG on immediate and literal data operands, while plain immediates keep translating:Test
startup_gfx2hlsl_cndmask_negbuilds VOP2-as-VOP3 encodings from the checked-in decoder's layout (0b110101prefix, opcode0x100 + n, neg bitsw1[31:29]), decodes them, then translates — no game-derived bytes. Eleven checks: negation on either source and on both, the unchanged no-negation form, another integer op still refusing, plain-1/-1.0immediates translating, and NEG on an inline integer, an inline float and a literal all refused.Verified at the merged head
ab586947.Census A/B (local, aggregates only)
With the change, refusals grouped as
operand '-v…'go 2 → 0, and those shaders progress to the next form (v_cvt_pknorm_u16_f32,v_cmp_class_f32).What this does not establish
|vN|(absolute) on an integer source and negations on other integer instructions stay refused.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:42:04Z.
Review: COMMENTED
Review of head
efd7a2f86f93af91c0a11f749aaf9dac39788fb7(Linux only; no Windows or RDNA2 hardware here).Verdict: 0 P1, 1 P2, 1 P3. The change itself is correct for register and SGPR sources; the P2 is a neighbouring gap the new helper makes visible.
Semantics
v_cndmask_b32(VOP3) accepts the NEG source modifier, and it flips bit 31 of that source.u_srcemits(x ^ 0x80000000u), which is that behaviour. The select order is unchanged (mask ? src1 : src0).v_and_b32_e64 ... -v30still raises Unsupported. The widening claim in the PR text holds.|v|and-|v|still reachu()and are refused.P2: negated integer inline constant is read as a negative constant
The VOP3 decoder prints NEG on an inline constant as a plain
-. llvm-mc printsneg(1)for that encoding and-1for the different encoding src 193.v_cndmask_b32_e64 v31, <src 129 (=1)>, v30, s0with neg0 decodes to-1.0xffffffffu. Hardware gives0x80000001.u('-1')), so it is not a regression. Butu_srcnow claims to model the modifier and itsre.match(r'-[\d.]', tok)guard cannot tell the two cases apart.neg(c)for a constant (as_format_sdwa_float_modifiersalready does), or refuse a negated integer constant, and add a control.P3: the numeric guard is untested
Dropping
not re.match(r'-[\d.]', tok)makesu_src('-1')return(0x00000001u ^ 0x80000000u), and the test still passes. A control with a plain-1or-4.0source would pin it.Commands executed locally
python3 -B tests/startup_gfx2hlsl_cndmask_neg_check.py: 6 ok, PASS.llvm-mc-19 -triple=amdgcn -mcpu=gfx1030 -show-encodingon the four select spellings (no neg, neg on src1, neg on src0, both). The bytes equal the ones the test builds (..., 0x00/0x40/0x20/0x60in the last byte).tools/startup/gfx2hlsl.py, each run against the test and then reverted:0x8000000u(one zero short): FAIL|instead of^: FAILLimits: CMake registration and the
ctestpresets were not run; the Windows build and the loading-screen census claim (2 to 0) were not reproduced.AI-assisted review.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:58:53Z.
Review: COMMENTED
Review of head
ab586947d920895a98d5b6601d11dd6daa9396a2(4 commits: the original select change,b019275danddfc73a1bwhich refuse NEG on an immediate and keep plain negative immediates, and a merge of main;tools/startup/gfx2hlsl.py+21/-1, newtests/startup_gfx2hlsl_cndmask_neg_check.py+126,CMakeLists.txt+3,docs/experiments.md+10). I reviewed the whole diff again; my earlier review was ofefd7a2f8.Linux limits. Linux x86_64,
llvm-mc-19, Python 3.14. No CMake configure and noctest(thestartup_gfx2hlsl_cndmask_negregistration is unexercised), no Windows, no DXC, no WARP or GPU. The emitted HLSL is compared as text and was never compiled or run.What I ran
python3 -B tests/startup_gfx2hlsl_cndmask_neg_check.py: PASS. Also exit 0:startup_gfx2hlsl_sdwa_check.py,startup_gfx2hlsl_vcvt_omod_check.py,startup_translator_check.py,startup_gfx2hlsl_bit_alu_check.py,startup_gfx2hlsl_smem_offset_check.py.git diff --check origin/main...HEAD: clean; no non-ASCII added; no existing test line removed.tests/docs_links_check.pyandtests/bidi_controls_check.py: pass.git merge-treeagainst current main: no conflicts.encode_vop2_e64()usingllvm-mc-19 -show-encodingforgfx1030andgfx1013:v30, -v30,-v30, v30,-v30, -v30, plain-1(src 193), plain-1.0(src 243) andneg(1)(src 129 with NEG) are byte-identical to the encoder on both. The NEG bits (29 for src0, 30 for src1) and the 9-bit source fields indecode()therefore match the assembler.|v30|,-|v30|and-s0on the mask are refused (operand '|v30|',operand '-s0'), so abs and a negated mask do not slip through.git statusclean):NEG on literal remains refused).plain inline -1.0 still translates).Semantics
v_cndmask_b32flips bit 31 exactly:(v ^ 0x80000000u)keeps NaN payloads and turns -0.0 into +0.0, which is what a sign-bit flip does, without any canonicalisation. It applies to the source it is printed on, and the select order is unchanged ((mask & 1) ? src1 : src0).-1(plain inline -1, or inline 1 with NEG) is resolved from the encoded fields: NEG on 128..208, 240..248 and 255 is refused, plain negative immediates keep their bit pattern. I found no case where NEG is silently dropped.Findings: 0 P1, 0 P2, 3 nits
op_v_cndmask_b32ignoresmods, soclampandmul:2onv_cndmask_b32_e64translate to the same text with the modifier dropped (I checked with the encoder). This is not introduced by the PR (the handler ignored them before), and I did not verify whether the hardware applies them to this instruction, so I only flag it.startup_gfx2hlsl_cndmask_neg_check.pyusesencode_vop2_e64(AND_B32, ... neg1=1)for "another integer op stays refused";llvm-mc-19rejectsv_and_b32_e64 ..., -v30, so that bytes pattern is not one an assembler produces. It still checks the intended property (the decoder's text is refused).AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T17:35:19Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
efd7a2fℹ️ 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.
Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T17:43:17Z.
Both addressed in
b019275d(rebased onto current main).P2 — the ambiguous spelling is now refused, not guessed. You are right that the printed operand does not identify the value:
src 193is the literal-1(0xffffffff) andsrc 129with NEG is inline1with its sign bit flipped (0x80000001), and both print as-1.u_srcnow raises for that exact spelling instead of picking one reading, so the select no longer translates to 0xffffffff for a case that may be 0x80000001:I did not change the decoder to print
neg(1): that is a disassembly-wide output change and belongs in its own slice, not inside a select fix. Refusing keeps this PR's claim honest — it models the modifier only where the printed operand identifies the source.P3 — the guard is pinned. Two controls, one per encoding, plus a check that both decode to the same text (which is why refusal is the right answer):
Your mutation now fails: dropping the guard gives
fail-first exit: 1 | a negative literal source is refused as ambiguous too.Verified after rebase on
107a0466: test passes in dev (0.16 s) and release (0.14 s). Re-running the CMake configure per preset first, since your review correctly noted the presets were not exercised.Thanks for probing the constant sources — that is precisely the class of thing a register-only fixture hides.
AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T17:51:27Z.
I pushed
dfc73a1bto fix the Linux regression. Plain negative inline constants keep their existing value in both encodings. Encoded NEG on an immediate is still refused, even when it disassembles with the same spelling as a plain constant. The new select fixture and both failing Linux cases (startup_flat_param_check.py and startup_gfx2hlsl_bit_alu_check.py) passed locally. Waiting on the checks for this new head.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T18:17:57Z.
Review: COMMENTED
Re-review of head
f9e815d5f6(comment only, not an approval). My earlier review was atab586947.Verdict: 0 P1 / 0 P2, three nits. Update: while I was reviewing, the head moved from
9bed7ffctof9e815d5, which is a merge of main. The PR's own changes are identical (the added and removed lines of gfx2hlsl.py, the test, docs/experiments.md and CMakeLists.txt compare equal to the9bed7ffcdiff against main). At the new head the cndmask test (PASS), the sdwa and vcvt_omod checks, docs_links_check (17 files, 366 links), bidi_controls_check (1303 files) andgit diff --check origin/main...HEADpass again. The mutation results below were run at9bed7ffcand not repeated.Earlier points, all fixed: the NEG range edges are now tried on 128, 208, 240 and 248 plus a plain 0.5 (240 -> 241 and 208 -> 207 both fail);
clampandmul:2are no longer dropped silently (op_v_cndmask_b32raises on anymods, two tests pin it); thev_and_b32_e64fixture is kept with a comment. The only commit since is9bed7ffc(+3 lines in gfx2hlsl.py and the test).Semantics
(x ^ 0x80000000u)is an exact sign-bit flip: NaN payloads are kept and -0.0 becomes +0.0, with no canonicalisation. It applies to the source it is printed on and the select order is unchanged.v_cndmask_b32_e64 ..., -s0does not assemble in llvm-mc.|v30|and-|v30|(assembled for gfx1030) are refused withoperand '|v30|'. The e32 form has no modifiers; the SDWA form with-v30is refused as a whole.-0x3f800000assembles to inline -4.0 and translates to0xc0800000u; NEG on a constant source is refused by encoded field indecode()(128..208, 240..248, 255).Run
python3 -B tests/startup_gfx2hlsl_cndmask_neg_check.py: PASS. sdwa, vcvt_omod, translator, bit_alu, smem_offset and flat_param checks: pass. docs_links_check (17 files, 365 links), bidi_controls_check (1296 files),git diff --check origin/main...HEAD: clean. llvm-mc-19-mcpu=gfx1030was used on the probe forms and its bytes fed throughG.decodeandStage.one.git checkout --). Caught: bit 30 instead of 31; swapped sources; droppedmodsrefusal; neg check only on src0; literal 255 no longer refused; NEG bit read from position 28+i; range 208 -> 207; range 240 -> 241.u_src(no test pins "a negated mask is refused"; no assembler can emit it); stripping|inu_src(self.u(tok[1:].strip('|'))), which would turn-|v30|into a plain negation, although production refuses both today; and 248 -> 247, which is equivalent because source 248 is not a decodable inline constant.Nits
-s0mask control, or document why it cannot be encoded.|v30|and-|v30|refusal controls; the PR text says abs stays refused but nothing pins it.v_cndmask_b32_e64 ... vcc_loemits(vcc & 1); pre-existing and out of scope.Overlap: no
cndmaskoru_srchits in #1755, #1747, #1703, #1706, #1712, #1708, #1745 and #1741 (only those eight were grepped). Main has moved; I did not check whether a rebase conflicts.Not run: CMake/ctest (so the
startup_gfx2hlsl_cndmask_negadd_test is unexercised), DXC or WARP (the emitted HLSL is compared as text, never compiled), the census claim (2 of 29 shaders, 2 -> 0), mingw (no C++ in the diff).Linux limits: no Windows, WARP, DXC or GPU here; LLVM 19 only (CI pins LLVM 15). Anything that needs them was not run.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T18:05:24Z.
All three nits addressed in
9bed7ffc(on top of yourab586947).1 — range edges. The test now tries NEG on each boundary the decoder refuses (128, 208, 240, 248) and a plain
0.5that must keep translating, so your surviving mutation no longer passes:2 — modifiers silently dropped. You are right that this predates the PR, and the same reasoning as the PR itself applies: a modifier the text drops changes the value.
op_v_cndmask_b32now refuses any modifier instead of ignoring it, and both cases are pinned:I did not try to establish what the hardware does with those bits on this instruction — same limit you noted, so refusal is the safe side.
3 — non-assembler encoding. Kept, with a comment stating that
llvm-mcrejects-v30onv_and_b32_e64and that the property under test is only that a handler which does not model the modifier refuses the decoder's text.Verification: the Python-level tests that reach
gfx2hlslpass in dev (startup_image_sample_l,startup_image_sample_c, the image control tests,startup_translator) andstartup_gfx2hlsl_cndmask_negpasses in release. The dev tree here has no built executables (5 files inout/build/dev), so the wholestartup_*family returned 142 failures for missing binaries — not a signal about this change. Flagging that plainly rather than quoting a green family I did not get.Thanks for the byte-level assembler cross-check against both
gfx1030andgfx1013; that is the part of the encoder I could not verify locally.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T18:23:47Z.
Both coverage nits are closed in #
+ (($pr -split '/')[-1].Trim()) +.w1[31]makes the decoder print-s0(LLVM just refuses to assemble it, which is why no fixture existed). The test now assertsREFUSED: operand '-s0'with a comment saying the word is decoder-produced only. So the answer to your nit 1 is "encodable from the word, only refused before by accident" rather than "cannot be encoded".|v30|on the first source, the second source and both are pinned as refused (operand '|v30|').Fail-first: routing the mask through
u_srcfails a negated mask is refused; stripping the abs bars inu_srcfails absolute values on both sources are refused. 22 checks; devstartup_gfx2hlsl*10/10 and the release test pass; docs/bidi checks pass.Your nit 3 (
vcc_loemitting(vcc & 1)) stays out of scope, as you flagged.AI-assisted (Claude Code).