Repository navigation
startup: translate the SDWA forms of the float-result conversions again - #1730
Conversation
Regression from R0Y00#1707, found in review by tedin7 after the merge (P1): moving the float-result conversions into VEC_U_TO_F left sdwa() looking only at VEC_U, so every v_cvt_f32_*_sdwa was refused with 'SDWA form of <name>'. sdwa() now accepts both tables and wraps a float result in U(...) before the destination selection writes its bit pattern; integer-result conversions keep the uint path unchanged. Test builds VOP1 SDWA encodings (SRC0=249 marks SDWA, control word in the next dword), decodes, then translates: u32/i32/f16 conversions, DWORD and BYTE selections, dst_sel masking and UNUSED_PRESERVE, the unchanged uint path, and an omod still refused. Fail-first removing the new branch fails the test. Both presets pass, all 9 startup_gfx2hlsl tests pass.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour 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. |
tedin7
left a comment
There was a problem hiding this comment.
Review of head e6a0cd79c1cedc76482e9acf3b3c1f11342599c7 (1 commit; tools/startup/gfx2hlsl.py +10/-2, new tests/startup_gfx2hlsl_sdwa_cvt_check.py +128, CMakeLists.txt +3, docs/experiments.md +5).
Linux limits. Linux x86_64, llvm-mc-19, Python 3.14. No CMake configure and no ctest (the startup_gfx2hlsl_sdwa_cvt registration is unexercised), no Windows, no DXC, no WARP or GPU. The translated HLSL is compared as text and was never compiled or run, so the arithmetic is judged by reading the emitted expressions.
What I ran
python3 -B tests/startup_gfx2hlsl_sdwa_cvt_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.git diff --check origin/main...HEAD: clean (no non-ASCII added, no lines removed from existing tests).tests/docs_links_check.pyandtests/bidi_controls_check.py: pass.git merge-treeagainst current main: no conflicts.- Binary check: the test builds its bytes with
encode_vop1_sdwa(). I assembled the same six instructions withllvm-mc-19 -show-encodingfor bothgfx1030andgfx1013(v_cvt_f32_u32 WORD_0, v_cvt_f32_i32 BYTE_0, v_cvt_f32_f16 WORD_0, v_cvt_f32_u32 BYTE_1 into BYTE_1 with UNUSED_PRESERVE, v_cvt_f16_f32 WORD_0, v_cvt_f32_u32 withmul:2): all twelve encodings are byte-identical to the encoder. - Extra probes with the same encoder:
clamp(bit 13), source negate (bit 20) and abs (bit 21) are refused (SDWA modifier clamp,operand '-v1',operand '|v1|');sexton the u32 source lowers tofloat(asuint(asint(v1 << 16u) >> 16u)), i.e. sign-extend the field then convert as unsigned, as the ISA describes. - Four mutations of
sdwa(), each run against the new test and restored (git statusclean):- drop the
U(...)wrapper: FAIL (4 mismatches). - look only at the uint table again (the bug being fixed): FAIL (
SDWA form of v_cvt_f32_u32). - wrap the uint-result path as a float: FAIL (
uint-result conversion stays on the uint path). - ignore unknown SDWA modifiers: FAIL (
an omod on an SDWA conversion stays refused).
- drop the
Semantics (RDNA 2 SDWA)
- Source selection, the float conversion and the
dst_sel/dst_unusedwrite are in the right order: the float result is bit-cast withU()and only then masked and shifted into the destination field, which is what an SDWA destination selection does to a 32-bit result.UNUSED_PRESERVEkeeps the other bits;UNUSED_SEXTis still refused. - Output modifier and
clampinside an SDWA form are refused instead of being dropped, which is the safe boundary (dropping them would silently change the value).
Findings: 0 P1, 0 P2, 2 nits
- Nit. The comment above
sdwa()still says "float forms are not lowered yet"; it is now wrong for the float-result conversions. - Nit. The new test file has no newline at the end.
- Not verified: DXC or FXC compilation of the emitted expressions, and any draw.
AI-assisted; commands listed were executed locally.
Follow-up to the merged #1707, fixing the review's P1 (SDWA forms of the moved conversions stopped translating). Reported by tedin7 after the merge.
Cause
Moving the float-result conversions into
VEC_U_TO_Fleftsdwa()looking only atVEC_U:so
v_cvt_f32_u32_sdwa,v_cvt_f32_i32_sdwa,v_cvt_f32_f16_sdwa,v_cvt_f32_ubyte0..3_sdwawere all refused on the merged tree.Fix
sdwa()accepts both tables and wraps a float result inU(...)before the destination selection writes its bit pattern; integer-result conversions keep the uint path unchanged.Destination selection still writes the result:
dst_sel:BYTE_1masks to& 0xffu) << 8u,dst_unused:UNUSED_PRESERVEreadsasuint(v0). An output modifier inside an SDWA form stays refused rather than dropped.Test
startup_gfx2hlsl_sdwa_cvtbuilds VOP1 SDWA encodings from the checked-in decoder's layout (SRC0 = 249marks SDWA, control word in the next dword:src0_sel[18:16],dst_sel[10:8],dst_unused[12:11],omod[15:14]), decodes them, then translates — no game-derived bytes.Fail-first: removing the
VEC_U_TO_Fbranch fromsdwa()fails the test withUnsupported: SDWA form of v_cvt_f32_u32.Still open from that review
The P2 (claiming
op_selis refused whileset_vf()silently ignores it) is not in this PR — that guard changes every float path that goes throughset_vf, so it needs its own test sweep rather than riding along a regression fix. Tracked as the next slice.What this does not establish
AI-assisted (Claude Code).