Skip to content

startup: lower s_cselect_b32 into vcc_lo and exec_lo in gfx2hlsl - #2121

Merged
R0Y00 merged 2 commits into
R0Y00:mainfrom
denn0x:startup/gfx2hlsl-cselect-lane-mask
Nov 25, 2026
Merged

R0Y00 merged 2 commits into
R0Y00:mainfrom
denn0x:startup/gfx2hlsl-cselect-lane-mask

Conversation

@denn0x

@denn0x denn0x commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Part of #1723

In wave32, vcc_lo and exec_lo hold the whole lane mask, and the generic scalar path in tools/startup/gfx2hlsl.py already writes them as vcc and exec. s_cselect_b32 goes through a separate select path that assumed an SGPR destination, so s_cselect_b32 vcc_lo, -1, 0 stopped the translation with a TypeError instead of a lowering or an Unsupported refusal.

Now:

  • vcc_lo and exec_lo get the lane's bit of the selected word; an exec_lo write clears exec_known.
  • SGPR and m0 destinations are lowered as before.
  • Any other destination, such as the null SGPR, is refused with an Unsupported message.

New test tests/startup_gfx2hlsl_cselect_mask_check.py, registered as startup_gfx2hlsl_cselect_mask_controls in CMakeLists.txt, AGENTS.md and the Python job, and described in docs/experiments.md. It decodes synthetic SOP2 words and evaluates the emitted select for both SCC values with the restricted evaluator of startup_gfx2hlsl_bit_alu_check.py. Negative control: the select with its & 1 removed gives a different vcc.

Verification (branch head 3dc861e2 on main 246a875d, Windows 11 Pro 10.0.26300, Python 3.13):

  • python -B tests/startup_gfx2hlsl_cselect_mask_check.py -> exit 0 (cselect mask: vcc_lo and exec_lo are the lane mask; SGPR and m0 unchanged; null refused). On main the same test fails with TypeError: 'NoneType' object is not subscriptable.
  • every tests/startup_gfx2hlsl_*_check.py, tests/startup_translator_check.py, tests/docs_links_check.py and tests/startup_tools_lint_check.py tools/startup -> 33 scripts, all exit 0.
  • git diff --check main..HEAD -> clean.
  • Not run: a DXC compile or a draw with this select; the check evaluates the emitted HLSL text only.

AI-assisted.

denn0x and others added 2 commits November 25, 2026 00:42
In wave32, vcc_lo and exec_lo hold the whole lane mask, and the generic
scalar path already writes them as vcc and exec. The select path assumed
an SGPR destination, so s_cselect_b32 vcc_lo, -1, 0 stopped the
translation with a TypeError. It now writes the lane's bit of the selected
word to vcc or exec (an exec_lo write clears exec_known), keeps the SGPR
and m0 destinations as before, and refuses any other destination with an
Unsupported message.

tests/startup_gfx2hlsl_cselect_mask_check.py decodes synthetic SOP2 words
and evaluates the emitted select for both SCC values, with an unreduced
select as the negative control. On the translator before this change it
fails with the TypeError.

Test: ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_cselect_mask_controls$' -V
@R0Y00

R0Y00 commented Nov 25, 2026

Copy link
Copy Markdown
Owner

I merged main after #2116 and kept both this scalar select fixture and #2122's mask-overwrite fixture in Linux and CTest. The select, mask-overwrite, scalar arity and SOPK checks and docs links all pass together on Windows. The fixture evaluates emitted HLSL; this update does not add a GPU draw.

@R0Y00
R0Y00 merged commit 38fa531 into R0Y00:main Nov 25, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants