Repository navigation
Conversation
Source code 253 reads the SCC bit as the integer 0 or 1, so s_mul_i32 s28, 1.0, src_scc multiplies the raw bits of the inline float by it. The translator refused the operand as unknown; the generated scalar code keeps SCC in scc, so lower it to (scc ? 1u : 0u). Refs R0Y00#1820.
tedin7
left a comment
There was a problem hiding this comment.
Review of exact head 6eb338bf770cebe3cdd765c3609ccbffd94eed5a (verified equal to gh pr view 1896 --json headRefOid at review time). Diff: tools/startup/gfx2hlsl.py (+4), tests/startup_gfx2hlsl_src_scc_check.py (+84, new), CMakeLists.txt (+4). No Windows code is touched, so no Windows run was needed.
Verdict: no P1, no P2. Approach is correct; one P3 nit. (Comment only, not an approval.)
Clean-room and title
- Title is neutral and describes the change. Commit message cites
#1820, matching the PR body. - The only facts used are the public source-code table in
tools/disasm_rdna2.py(253 =src_scc) and the generated code's existingsccvariable. No third-party code or text was found. - Author/committer is the contributor's own noreply identity.
Semantics
Stage.u()now returns(scc ? 1u : 0u)forsrc_scc(tools/startup/gfx2hlsl.py:214-217).sccis declared asbool scc = falsein the prologue (gfx2hlsl.py:1168), so the expression is well-typed and the initial value is defined.- The ternary gives a 32-bit 0/1 integer with no sign or overflow issue, and the raw bits of the inline float are kept (
0x3f800000u). - The SCC definition order is preserved because every SCC writer already emits
scc = ...;inline in program order. - The branch is checked before
reg_range(tok), so it cannot shadow a real register name, and it only matches the exact token.
I also probed neighbouring scalar forms that now reach the new branch, using the PR's own stage() helper (output of the probe):
s_mov_b32 s4, src_scc -> s4 = (scc ? 1u : 0u);
s_mov_b64 s[4:5], src_scc -> s4 = ((scc ? 1u : 0u)) & 1; s5 = 0u;
s_and_b64 s[4:5], src_scc, s[6:7] -> s4 = ((scc ? 1u : 0u) & s6) & 1; scc = s4 != 0; s5 = 0u;
s_cselect_b32 s4, src_scc, s5 -> s4 = scc ? (scc ? 1u : 0u) : s5;
All are consistent with the existing handling of 32-bit scalar operands and the 64-bit mask path (a 64-bit read of SCC is zero-extended, high word 0). No crash and no wrong-width result.
Commands run locally (venv python, in the clean worktree at the SHA above)
git diff --check origin/main...HEAD exit 0
python -B tests/startup_gfx2hlsl_src_scc_check.py "src_scc operand: 5 cases passed" rc=0
python -B tests/startup_gfx2hlsl_operand_count_check.py "operand count checks: 0 failed" rc=0
python -B tests/startup_gfx2hlsl_mad_check.py passed rc=0
python -B tests/startup_gfx2hlsl_op_refusals_check.py "3 cases passed" rc=0
python -B tests/startup_gfx2hlsl_bit_alu_check.py passed rc=0
python -B tests/startup_translator_check.py "startup translator checks: 0 failed"
python -B tests/docs_links_check.py "Self-test passed. Checked 18 Markdown files and 376 links." rc=0
python -B tests/bidi_controls_check.py "no bidirectional controls" (1331 files) rc=0
Mutations (each applied to gfx2hlsl.py, test run, then git checkout -- .)
M1 return -> raise Unsupported('operand src_scc') FAIL rc=1 (Unsupported: operand src_scc)
M2 return '1u' FAIL rc=1 (['s28 = 0x3f800000u * 1u;'])
M3 inverted (scc ? 0u : 1u) FAIL rc=1
M4 bare '(scc)' FAIL rc=1
M5 widen branch to also accept 'ttmp0' FAIL rc=1 (ttmp0 was accepted by u())
The test fails for every mutation, including the "silently widened operand set" case. The worktree was clean afterwards.
Findings
- P1: none.
- P2: none.
- P3 (nit),
CMakeLists.txtnear line 1872: the newstartup_gfx2hlsl_src_sccblock was inserted between the comment "Two integer operations whose refusal was never reached: v_cvt_i32_f32 ... v_readfirstlane_b32 ..." and thestartup_gfx2hlsl_op_refusalstest it describes. That comment is now separated from its test. Moving the new block above the comment would fix it. - P3 (observation, not blocking): the test checks exact emitted strings, so a harmless rewrite such as
bool(scc) ? 1u : 0uwould need the test updated. That is acceptable for a translator whose output is the contract.
AI-assisted; commands listed were executed locally.
R0Y00
left a comment
There was a problem hiding this comment.
This overlaps #1821 and has the same stale SCC blocker. For example, a compare first sets SCC to 0, s_add_u32 then adds 0xffffffff and 1, and the next src_scc read must return the carry (1). Stage.scalar currently emits the sum without updating SCC, so this change reads the old 0. The existing checks exercise only modeled writers and the default HLSL bool.
Please coordinate with #1821 and keep one implementation. Accept a src_scc read only when the reaching SCC value is modeled, including across branches, or explicitly refuse it. Retain the raw-bit operand case and add the distinguishing carry or stale-writer refusal control, together with a valid defined comparison.
|
Adding the scope to the blocker above, because it changes the size of the fix: it is not only Eight
So a guard scoped to Control: substituting Code reading and translation output only — no hardware run is claimed here. AI-assisted. |
|
Closing this as a duplicate: #1821 by @triggered02 landed the same change first. For the record, so nothing of the verification is lost — Two things from my run that are worth keeping if you want them in #1821 (I am not pushing them):
Both branches use the same test filename, so whichever merges will decide the other's history; #1821 is first and has the doc
|
Implements #1820.
Change
Stage.u()learns the scalar source code 253:The generated scalar code already carries SCC in
scc(initialised and updated by the instructions that set it), sonothing else moves.
Tested
The new
tests/startup_gfx2hlsl_src_scc_check.pybuilds SOP2 words from the layouttools/disasm_rdna2.pydecodes(
[31:30] == 0b10, opcodew0[29:23],sdstw0[22:16],src1w0[15:8],src0w0[7:0]; inline1.0is source code242,
src_sccis 253), decodes them, and translates:s_mul_i32 s28, 1.0, src_scc(the census form)s28 = 0x3f800000u * (scc ? 1u : 0u);s_mul_i32 s29, src_scc, 1.0s29 = (scc ? 1u : 0u) * 0x3f800000u;s_and_b32 s28, src_scc, s5s28 = (scc ? 1u : 0u) & s5;thenscc = s28 != 0;The census form keeps the raw bits of the inline float (
0x3f800000u), which is what a scalar integer multiply does —an implementation that emitted
1uwould produce a different instruction.Fail-first
Both controls, each reverted:
The second one is the reason the first case exists: it catches an implementation that accepts the operand but drops the
multiply's operand bits.
Neighbours
startup_gfx2hlsl_operand_count,startup_gfx2hlsl_madandstartup_translatorall pass unchanged. The last case in the newcheck also asserts that
ttmp0,vcc_hiandexec_hiare still refused byu(), so this branch did not widen the scalaroperand set.
Scope
One production branch, one new device-free check, one
CMakeLists.txtregistration withTIMEOUT 60. No draw mode, nohardware dependency.
Notes