shader: compute both words of 64-bit SALU logic on numeric pairs #3806

Manually merged
github merged 2 commits from github-bot/gh-3804 into main 2026-12-02 01:54:20 +00:00 AGit
Owner

@⁠Leyukaka on GitHub · 2026-12-02 00:51 UTC · original
Leyukaka:py-salu64 → main · +340 −8 · 4 files · 2 commits · merged 2026-12-02 01:51 UTC

Problem

Stage.scalar() in tools/startup/gfx2hlsl.py lowered every _b64 scalar logic op and move as a lane-mask op: the low word was cut to the lane bit, the high word of the destination was written as 0, and SCC was read from the cut low word only. That is correct for a real lane mask (vcc, exec, a compare result), but not for two SGPR pairs that hold plain 64-bit numbers.

A source-built witness shows the defect on main: with two numeric pairs set by s_mov_b32 (low word 0, high word 1), s_and_b64 gives 0x1_00000000 on the guest, so SCC = 1. The translation produced SCC = 0 from the low word and zeroed the high word, so the following s_cbranch_scc0 / s_cbranch_scc1 ran the wrong arm. The same happens when one pair is first copied with s_mov_b64. Nothing was refused: the output was silently wrong.

This is part of making the translator base more solid: a form is either translated exactly or refused.

Change

  • When no source of a 64-bit scalar op is a lane mask (not vcc/exec, and no register of the pair carries a mask tag for its low or high word), the pairs are treated as plain numbers. Each half of a bitwise op or a move depends only on the same half of its sources, so both words are computed, and SCC is (lo | hi) != 0.
  • Sources may be an even SGPR pair, null or an inline integer (sign-extended to 64 bits). A literal, a float constant, or an operand that is not an even pair is refused with a message that names it.
  • Lane-mask operands keep the existing lowering unchanged.
  • One expectation in tests/startup_gfx2hlsl_compute_check.py changes from refused to whole-word: a s_mov_b64 of plain data (root constants) now copies both words exactly, so the low word can be read as the number it holds, like the 32-bit copy of the same word.

Validation

Run on Windows (MSVC) with the dev preset:

ctest --preset dev --no-tests=error -R "startup_gfx2hlsl_(salu64_scc_witness|compute|scalar_arity|join_symbols|mask_overwrite|readfirstlane|load_desc|image_)"
  • startup_gfx2hlsl_salu64_scc_witness is new. Its three witnesses (s_and_b64 of two numeric pairs, the same with one pair copied by s_mov_b64, and a pair with inline -1) failed on main and pass with this change. Each program is translated and its emitted blocks are run by the integer evaluator of the bit ALU check; the test accepts either the arm that SCC selects on the guest or a refusal.
  • Its controls pass before and after: s_and_b32 on the high words and on the low words take the right arm (this checks the harness), and a real lane mask (v_cmp into vcc, then s_and_b64 s[10:11], vcc, exec) still lowers as a mask op.
  • The lane-mask controls of the compute check are unchanged, and the neighbouring gfx2hlsl tests pass: compute, scalar_arity, join_symbols, mask_overwrite, the readfirstlane checks, load_desc and the image checks.
  • On a frozen local corpus of 216 translation requests, the generated HLSL, the manifests, the refusals and the compiled outputs are byte-identical before and after (measured with this change and its companion image-descriptor/SALU change applied together). No existing output changes: the fix closes a silent mistranslation that this corpus does not reach.

The fixtures are synthetic instruction words built in the test from the field layouts that tools/disasm_rdna2.py decodes; the decoded text of every word is checked first.

**@⁠Leyukaka** on GitHub · 2026-12-02 00:51 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3804) `Leyukaka:py-salu64` → `main` · +340 −8 · 4 files · 2 commits · merged 2026-12-02 01:51 UTC ## Problem `Stage.scalar()` in `tools/startup/gfx2hlsl.py` lowered every `_b64` scalar logic op and move as a lane-mask op: the low word was cut to the lane bit, the high word of the destination was written as 0, and SCC was read from the cut low word only. That is correct for a real lane mask (vcc, exec, a compare result), but not for two SGPR pairs that hold plain 64-bit numbers. A source-built witness shows the defect on `main`: with two numeric pairs set by `s_mov_b32` (low word 0, high word 1), `s_and_b64` gives `0x1_00000000` on the guest, so SCC = 1. The translation produced SCC = 0 from the low word and zeroed the high word, so the following `s_cbranch_scc0` / `s_cbranch_scc1` ran the wrong arm. The same happens when one pair is first copied with `s_mov_b64`. Nothing was refused: the output was silently wrong. This is part of making the translator base more solid: a form is either translated exactly or refused. ## Change - When no source of a 64-bit scalar op is a lane mask (not vcc/exec, and no register of the pair carries a mask tag for its low or high word), the pairs are treated as plain numbers. Each half of a bitwise op or a move depends only on the same half of its sources, so both words are computed, and SCC is `(lo | hi) != 0`. - Sources may be an even SGPR pair, `null` or an inline integer (sign-extended to 64 bits). A literal, a float constant, or an operand that is not an even pair is refused with a message that names it. - Lane-mask operands keep the existing lowering unchanged. - One expectation in `tests/startup_gfx2hlsl_compute_check.py` changes from refused to whole-word: a `s_mov_b64` of plain data (root constants) now copies both words exactly, so the low word can be read as the number it holds, like the 32-bit copy of the same word. ## Validation Run on Windows (MSVC) with the dev preset: ```text ctest --preset dev --no-tests=error -R "startup_gfx2hlsl_(salu64_scc_witness|compute|scalar_arity|join_symbols|mask_overwrite|readfirstlane|load_desc|image_)" ``` - `startup_gfx2hlsl_salu64_scc_witness` is new. Its three witnesses (`s_and_b64` of two numeric pairs, the same with one pair copied by `s_mov_b64`, and a pair with inline `-1`) failed on `main` and pass with this change. Each program is translated and its emitted blocks are run by the integer evaluator of the bit ALU check; the test accepts either the arm that SCC selects on the guest or a refusal. - Its controls pass before and after: `s_and_b32` on the high words and on the low words take the right arm (this checks the harness), and a real lane mask (`v_cmp` into vcc, then `s_and_b64 s[10:11], vcc, exec`) still lowers as a mask op. - The lane-mask controls of the compute check are unchanged, and the neighbouring gfx2hlsl tests pass: compute, scalar_arity, join_symbols, mask_overwrite, the readfirstlane checks, load_desc and the image checks. - On a frozen local corpus of 216 translation requests, the generated HLSL, the manifests, the refusals and the compiled outputs are byte-identical before and after (measured with this change and its companion image-descriptor/SALU change applied together). No existing output changes: the fix closes a silent mistranslation that this corpus does not reach. The fixtures are synthetic instruction words built in the test from the field layouts that `tools/disasm_rdna2.py` decodes; the decoded text of every word is checked first.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 00:53:50 +00:00
github manually merged commit 0dcf93317a into main 2026-12-02 01:54:20 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.