[PR #1116] [CLOSED] rdna2spirv: SDWA selects on the long-form carry ops land on their sources (SHADER-SDWA-CO-CI-SELECT) #1152

Closed
opened 2026-11-26 20:20:15 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1116
Author: @tiguan26
Created: 11/24/2026
Status: ❌ Closed

Base: main ← Head: fix/sdwa-co-ci-select


📝 Commits (1)

  • b4288ec rdna2spirv: SDWA selects on the long-form carry ops land on their sources (SHADER-SDWA-CO-CI-SELECT)

📊 Changes

3 files changed (+111 additions, -1 deletions)

View changed files

📝 docs/design.md (+1 -1)
➕ tests/semantic/test_sdwa_carry_select.py (+103 -0)
📝 tools/rdna2spirv.py (+7 -0)

📄 Description

Claimed in the coordination issue as: SHADER-SDWA-CO-CI-SELECT

What and why

Gen.insn() attaches the SDWA src0_sel/src1_sel from args[1] on (first = 1). In the long form of v_add_co_ci_u32, v_sub_co_ci_u32 and v_subrev_co_ci_u32 (vD, carry out, src0, src1, carry in) args[1] is the carry out, so src0_sel landed on it, src1_sel narrowed src0 and src1 was read whole: a silent wrong result, not a refusal.

With v1 = v4 = 0x00050003, src0_sel:WORD_1 src1_sel:WORD_0 and no carry in, main gives:

op main expected
v_sub_co_ci_u32_sdwa 0xfffb0000, borrow 1 2, borrow 0
v_add_co_ci_u32_sdwa 0x50006, carry 0 8, carry 0
v_subrev_co_ci_u32_sdwa 0x50000, borrow 0 0xfffffffe, borrow 1

The fix starts the selects at src0 for these three ops when the long form is printed (SDWA_CARRY_OPS). The short form vD, src0, src1 already gave the expected words and is unchanged; so is every other op.

Impact: the SDWA row's hardware measurement over the 172 SDWA forms in the corpus lists no mismatch for these ops, so the current corpus most likely has no long-form carry op with a narrowing select. This is a correctness fix for the rule, not a known game bug. Found while reviewing #1093.

Tested

Linux, Python 3.13.18, on main 6293c1c:

  • New tests/semantic/test_sdwa_carry_select.py (4 tests): the reported words, both forms of all three ops with carry in 0 and 1 over byte/word/dword selects, and 24 seeded cases, against a plain-Python reference of the ISA semantics. On main the three long-form tests fail and the short-form control passes; with the fix all four pass.
  • python -I scripts/run_semantic_tests.py tests/semantic: 471 files, 6172 tests, 0 files failed.
  • tests/test_docs_design_rows.py, test_docs_table_rows.py, test_docs_links.py, test_text_write_line_endings.py, python -m compileall -q tools tests, scripts/check_no_game_data.py on the three files, git diff --check: clean.
  • The SDWA row in docs/design.md gains one sentence on the long-form carry ops and how it was checked.

GPUs tested: n/a (CPU interpreter only; not GPU-checked)

AI-assisted: yes (Claude)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1116 **Author:** [@tiguan26](https://github.com/tiguan26) **Created:** 11/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/sdwa-co-ci-select` --- ### 📝 Commits (1) - [`b4288ec`](https://github.com/ubiquitarianism/leonida/commit/b4288ecad26c6b581ead179b181ab60c5f19ab69) rdna2spirv: SDWA selects on the long-form carry ops land on their sources (SHADER-SDWA-CO-CI-SELECT) ### 📊 Changes **3 files changed** (+111 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+1 -1) ➕ `tests/semantic/test_sdwa_carry_select.py` (+103 -0) 📝 `tools/rdna2spirv.py` (+7 -0) </details> ### 📄 Description Claimed in the coordination issue as: SHADER-SDWA-CO-CI-SELECT ### What and why `Gen.insn()` attaches the SDWA `src0_sel`/`src1_sel` from `args[1]` on (`first = 1`). In the long form of `v_add_co_ci_u32`, `v_sub_co_ci_u32` and `v_subrev_co_ci_u32` (`vD, carry out, src0, src1, carry in`) `args[1]` is the carry out, so `src0_sel` landed on it, `src1_sel` narrowed src0 and src1 was read whole: a silent wrong result, not a refusal. With v1 = v4 = `0x00050003`, `src0_sel:WORD_1 src1_sel:WORD_0` and no carry in, `main` gives: | op | main | expected | |---|---|---| | `v_sub_co_ci_u32_sdwa` | `0xfffb0000`, borrow 1 | `2`, borrow 0 | | `v_add_co_ci_u32_sdwa` | `0x50006`, carry 0 | `8`, carry 0 | | `v_subrev_co_ci_u32_sdwa` | `0x50000`, borrow 0 | `0xfffffffe`, borrow 1 | The fix starts the selects at src0 for these three ops when the long form is printed (`SDWA_CARRY_OPS`). The short form `vD, src0, src1` already gave the expected words and is unchanged; so is every other op. Impact: the SDWA row's hardware measurement over the 172 SDWA forms in the corpus lists no mismatch for these ops, so the current corpus most likely has no long-form carry op with a narrowing select. This is a correctness fix for the rule, not a known game bug. Found while reviewing #1093. ### Tested Linux, Python 3.13.18, on `main` 6293c1c: - New `tests/semantic/test_sdwa_carry_select.py` (4 tests): the reported words, both forms of all three ops with carry in 0 and 1 over byte/word/dword selects, and 24 seeded cases, against a plain-Python reference of the ISA semantics. On `main` the three long-form tests fail and the short-form control passes; with the fix all four pass. - `python -I scripts/run_semantic_tests.py tests/semantic`: 471 files, 6172 tests, 0 files failed. - `tests/test_docs_design_rows.py`, `test_docs_table_rows.py`, `test_docs_links.py`, `test_text_write_line_endings.py`, `python -m compileall -q tools tests`, `scripts/check_no_game_data.py` on the three files, `git diff --check`: clean. - The SDWA row in `docs/design.md` gains one sentence on the long-form carry ops and how it was checked. GPUs tested: n/a (CPU interpreter only; not GPU-checked) AI-assisted: yes (Claude) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:20:15 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1152
No description provided.