Skip to content

Translator: s_cmov_b32 and s_cmovk_i32 - #613

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
LouisRiverstone:salu-cmov
Nov 22, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
LouisRiverstone:salu-cmov

Conversation

@LouisRiverstone

Copy link
Copy Markdown
Contributor

tools/rdna2spirv.py raises Unsupported on the scalar conditional moves s_cmov_b32 and s_cmovk_i32. (tools/shader_meta.py already lists s_cmovk_i32 as an SGPR read-modify-write op.) They aren't in the translated corpus, so this is future-proofing. Claimed in #374.

Change

  • tools/rdna2spirv.py: D = SCC ? S0 : D.
  • tests/semantic/test_salu_cmov.py (new, stdlib unittest) checks against a plain-Python reference:
    • both ops with SCC 0 and 1, with edge sources and immediates such as 0x8000 and 0xFFFF
    • an inline and a literal source
    • SCC coming from an s_cmp_gt_u32
    • SCC unchanged afterwards
    • D leaves exp as 16-bit halves ORed into 0x40000000, so no export channel can be a NaN pattern

Tested

  • python -I -m unittest discover -s tests/semantic: all pass. Without the translator change, the new file has 31 errors (Unsupported).
  • python -m compileall -q tools tests passes. Not run on a GPU, and no game files used.

AI-assisted (Claude Code): it wrote the change and the tests, and ran the checks listed above.

@tylerstraub

Copy link
Copy Markdown
Contributor

Tested f2f248ab61db41b16f7eff96487b96aa689a5287 on NVIDIA GeForce RTX 5090, 595.99.02 (Linux).

I tested both scalar conditional moves in eight synthetic fragment shaders, drawing each with SCC clear and set. All 16 draws matched the expected destination and post-move SCC in all 4,096 pixels per draw. All nine modules, including the shared vertex shader, passed Vulkan 1.2 SPIR-V validation.

With SCC clear the destination retained its initial 0x89abcdef in every case. With SCC set, s_cmov_b32 copied its register, inline or literal source, and s_cmovk_i32 sign-extended the five immediates (0, 1, 0x7fff, 0x8000, 0xffff). The last two produced 0xffff8000 and 0xffffffff. A scalar select immediately following each move confirmed that SCC was preserved.

Coverage is translated Vulkan execution with ordinary scalar-register destinations on this GPU.

AI-assisted verification.

@esteban-dcp

Copy link
Copy Markdown

Tested f2f248a on two GPUs, Linux 7.3.5 (CachyOS): pass.

  • NVIDIA RTX 4050 Laptop (Ada), driver 620.73.04, subgroup 32: 86 shaders: 86 translated, 86 pass spirv-val; 57/83 passed, 26 wave64 skipped; with LEONIDA_W64_EMULATE=1: 83/83 passed
  • AMD Radeon 740M (RDNA3, RADV, Mesa 26.3.1), subgroup 32..64: 83/83 passed
  • This PR adds no GPU test of its own, so this checks that it breaks nothing in the existing suite on either vendor.
  • CPU: unittest discover -s tests/semantic 788 OK; tests/test_run_gpu_tests.py and tests/test_shader_checks.py OK

python -I scripts/run_gpu_tests.py --build runtime/build/linux on the PR head as-is (test programs built from this branch), VK_LOADER_DRIVERS_SELECT pinning each GPU (device line checked), VK_LOADER_LAYERS_DISABLE=~implicit~. 0 failures.

@IAmNotSiob IAmNotSiob left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, SCC read not written, cmovk sign-extends the 16-bit imm. tests pass with main (810). AI-assisted review (Claude Code).

@matheuskshn

Copy link
Copy Markdown
Contributor

Tested f2f248a on Windows 11 / Python 3.12.14. All five tests in test_salu_cmov.py passed. The suite covers conditional writes for both SCC states, immediate and register sources, and a predicate produced by a scalar compare. The conditional-move subset errored with the c432cdc translator. AI-assisted CPU validation.

Both raised Unsupported. D = SCC ? S0 : D; s_cmovk_i32's S0 is the 16-bit
immediate, sign-extended. SCC is read and left unchanged.

tests/semantic/test_salu_cmov.py checks both against a plain-Python
reference, with SCC 0 and 1, constant sources, and SCC set by a compare.
main pins 48557ea again since the ItsNotRexed#666-ItsNotRexed#698 merge round, while
tools/rpf9dump/Program.cs (3816356) already uses ArchiveEntry.ResourceDrawableOffset
from 917e9b9, so the Windows 'check' job fails to compile rpf9dump on every
PR. Same one-line change as ItsNotRexed#713 / ItsNotRexed#732; whichever lands first, this merges
cleanly.
@LouisRiverstone

Copy link
Copy Markdown
Contributor Author

CI note: the Windows check job failed here because main pins third_party/rpf9-explorer at 48557ea again since the #666–#698 merge round, while tools/rpf9dump/Program.cs (3816356) already uses ArchiveEntry.ResourceDrawableOffset from 917e9b9, so rpf9dump does not compile on any PR. I added the same one-line re-pin to 917e9b9 that #713 / #732 make (a separate commit, nothing else in it), so this PR gets a clean run; whichever lands first, the other merges cleanly.

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.

6 participants