startup: lower v_add_co_u32, v_sub_co_u32 and v_subrev_co_u32 in gfx2hlsl #2115

Merged
denn0x merged 1 commit from upstream-pr/2123 into main 2026-11-25 06:33:48 +00:00
denn0x commented 2026-11-25 00:53:56 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-25T00:53:56Z.


Part of #1723

The VOP3b add and subtract forms with a carry out and no carry-in were refused by tools/startup/gfx2hlsl.py as unknown instructions. They are now lowered from the AMD RDNA 2 ISA description:

Form Result Carry or borrow out
v_add_co_u32 D = S0 + S1 carry out of bit 31
v_sub_co_u32 D = S0 - S1 borrow when S1 > S0
v_subrev_co_u32 D = S1 - S0 borrow when S0 > S1
  • The carry goes to the lane's bit of vcc or of the SGPR destination. The SGPR becomes a lane mask and is recorded as varying (#1931), so a v_readfirstlane_b32 of a copy of it is refused; D is not proven uniform either.
  • The result and the carry are computed into the scratch registers a and w before either destination is written, so a destination may overlap a source.
  • When exec is not known, an inactive lane keeps D and writes a 0 carry, as the compare lowering does.
  • clamp, other modifiers, an exec carry-out and a wrong operand count are refused.

The carry-in forms are not part of this change: v_add_co_ci_u32 is in #2033 and v_sub_co_ci_u32 / v_subrev_co_ci_u32 are in #2041. The two changes touch different handlers and do not depend on each other.

New test tests/startup_gfx2hlsl_add_sub_co_check.py, registered as startup_gfx2hlsl_add_sub_co_controls in CMakeLists.txt, AGENTS.md and the Python job, and described in docs/experiments.md. It decodes synthetic VOP3b words for the three forms with an SGPR and a vcc_lo carry-out and evaluates the emitted lines with the restricted evaluator of startup_gfx2hlsl_bit_alu_check.py on 384 edge-value inputs against Python references written from the ISA description. It also checks the exec-masked form, an overlapping destination, the readfirstlane refusals for D and the carry-out copy, and the refusals above. Negative control: a borrow with the comparison reversed disagrees with the reference.

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

  • python -B tests/startup_gfx2hlsl_add_sub_co_check.py -> exit 0 (add/sub co forms: 6 forms match the ISA references on 384 inputs; exec, overlap and refusals checked). On main the same test fails with Unsupported: v_add_co_u32.
  • 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. The carry value of an inactive lane is written as 0 following the compare lowering, not checked against hardware.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6594599708 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2123). Originally posted by [denn0x](https://github.com/denn0x) on 2026-11-25T00:53:56Z. --- Part of #1723 The VOP3b add and subtract forms with a carry out and no carry-in were refused by `tools/startup/gfx2hlsl.py` as unknown instructions. They are now lowered from the AMD RDNA 2 ISA description: | Form | Result | Carry or borrow out | |---|---|---| | `v_add_co_u32` | `D = S0 + S1` | carry out of bit 31 | | `v_sub_co_u32` | `D = S0 - S1` | borrow when `S1 > S0` | | `v_subrev_co_u32` | `D = S1 - S0` | borrow when `S0 > S1` | - The carry goes to the lane's bit of `vcc` or of the SGPR destination. The SGPR becomes a lane mask and is recorded as varying (#1931), so a `v_readfirstlane_b32` of a copy of it is refused; D is not proven uniform either. - The result and the carry are computed into the scratch registers `a` and `w` before either destination is written, so a destination may overlap a source. - When `exec` is not known, an inactive lane keeps D and writes a 0 carry, as the compare lowering does. - `clamp`, other modifiers, an `exec` carry-out and a wrong operand count are refused. The carry-in forms are not part of this change: `v_add_co_ci_u32` is in #2033 and `v_sub_co_ci_u32` / `v_subrev_co_ci_u32` are in #2041. The two changes touch different handlers and do not depend on each other. New test `tests/startup_gfx2hlsl_add_sub_co_check.py`, registered as `startup_gfx2hlsl_add_sub_co_controls` in `CMakeLists.txt`, `AGENTS.md` and the Python job, and described in `docs/experiments.md`. It decodes synthetic VOP3b words for the three forms with an SGPR and a `vcc_lo` carry-out and evaluates the emitted lines with the restricted evaluator of `startup_gfx2hlsl_bit_alu_check.py` on 384 edge-value inputs against Python references written from the ISA description. It also checks the exec-masked form, an overlapping destination, the readfirstlane refusals for D and the carry-out copy, and the refusals above. Negative control: a borrow with the comparison reversed disagrees with the reference. Verification (branch head `c31d1ef2` on `main` `246a875d`, Windows 11 Pro 10.0.26300, Python 3.13): - `python -B tests/startup_gfx2hlsl_add_sub_co_check.py` -> exit 0 (`add/sub co forms: 6 forms match the ISA references on 384 inputs; exec, overlap and refusals checked`). On `main` the same test fails with `Unsupported: v_add_co_u32`. - 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. The carry value of an inactive lane is written as 0 following the compare lowering, not checked against hardware. AI-assisted.
tedin7 commented 2026-11-25 02:01:49 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:51:17Z.

Review: COMMENTED


Review of head c31d1ef26dffa1b9fe5de1c7401a7ff78ec266ba.

Summary: The lowering of v_add_co_u32, v_sub_co_u32 and v_subrev_co_u32 matches the ISA semantics. I found no correctness bugs. There is one blocker for merge (conflicts) and one coverage note.

Commands executed locally (Linux):

  • python3 tests/startup_gfx2hlsl_add_sub_co_check.py -> pass ("6 forms match the ISA references on 384 inputs; exec, overlap and refusals checked")
  • python3 tests/docs_links_check.py -> pass (18 files, 395 links)
  • python3 tests/bidi_controls_check.py -> pass (1424 files)
  • git diff --check origin/main...HEAD -> clean
  • gh pr checks 2123: Linux Python checks, gfx1013 fixtures and Windows build/test all pass.
  • Mutation 1: w = b > a changed to b >= a in the sub/subrev borrow -> test fails (4 checks). Killed.
  • Mutation 2: add carry (a+b) < a changed to <= a -> test fails (4 checks). Killed.
  • Both mutations reverted with git checkout -- ..

Findings

P1

  • Merge conflicts: the PR is CONFLICTING. git merge-tree origin/main HEAD reports conflicts in AGENTS.md, CMakeLists.txt, docs/experiments.md and .github/workflows/windows.yml. These are registry lines (the new test entry) that collided with other merged changes. tools/startup/gfx2hlsl.py merges cleanly. A rebase is needed before this can land.

P2

  • None.

Nits / notes

  • tools/startup/gfx2hlsl.py carry_out_op: the carry-out destination check accepts only vcc, vcc_lo and a single SGPR up to s105. This is correct and refuses the exec carry-out as described. Pairs of SGPRs (wave64 masks) are not special-cased. This is fine as the code already treats the destination as a lane mask.
  • Both a and w are computed before set_v/set_s, so overlap of D or SDST with a source is safe. The overlap test covers it.
  • The test compares the lowering against a Python reference model only. It does not run the HLSL on D3D12 WARP. I did not run a Windows 2025 WARP job for this review. The Windows CI job passed, but a GPU-readback comparison for these three opcodes would add confidence. This is a suggestion, not a blocker for a Python-level lowering.
  • Title and body are neutral and the change references #1723, #2033 and #2041 consistently.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6050405886 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2123#pullrequestreview-6050405886). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:51:17Z. **Review:** COMMENTED --- Review of head `c31d1ef26dffa1b9fe5de1c7401a7ff78ec266ba`. **Summary:** The lowering of `v_add_co_u32`, `v_sub_co_u32` and `v_subrev_co_u32` matches the ISA semantics. I found no correctness bugs. There is one blocker for merge (conflicts) and one coverage note. **Commands executed locally (Linux):** - `python3 tests/startup_gfx2hlsl_add_sub_co_check.py` -> pass ("6 forms match the ISA references on 384 inputs; exec, overlap and refusals checked") - `python3 tests/docs_links_check.py` -> pass (18 files, 395 links) - `python3 tests/bidi_controls_check.py` -> pass (1424 files) - `git diff --check origin/main...HEAD` -> clean - `gh pr checks 2123`: Linux Python checks, gfx1013 fixtures and Windows build/test all pass. - Mutation 1: `w = b > a` changed to `b >= a` in the sub/subrev borrow -> test fails (4 checks). Killed. - Mutation 2: add carry `(a+b) < a` changed to `<= a` -> test fails (4 checks). Killed. - Both mutations reverted with `git checkout -- .`. **Findings** P1 - Merge conflicts: the PR is `CONFLICTING`. `git merge-tree origin/main HEAD` reports conflicts in `AGENTS.md`, `CMakeLists.txt`, `docs/experiments.md` and `.github/workflows/windows.yml`. These are registry lines (the new test entry) that collided with other merged changes. `tools/startup/gfx2hlsl.py` merges cleanly. A rebase is needed before this can land. P2 - None. Nits / notes - `tools/startup/gfx2hlsl.py` `carry_out_op`: the carry-out destination check accepts only `vcc`, `vcc_lo` and a single SGPR up to s105. This is correct and refuses the `exec` carry-out as described. Pairs of SGPRs (wave64 masks) are not special-cased. This is fine as the code already treats the destination as a lane mask. - Both `a` and `w` are computed before `set_v`/`set_s`, so overlap of D or SDST with a source is safe. The overlap test covers it. - The test compares the lowering against a Python reference model only. It does not run the HLSL on D3D12 WARP. I did not run a Windows 2025 WARP job for this review. The Windows CI job passed, but a GPU-readback comparison for these three opcodes would add confidence. This is a suggestion, not a blocker for a Python-level lowering. - Title and body are neutral and the change references #1723, #2033 and #2041 consistently. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 04:03:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T03:21:38Z.

Review: COMMENTED


Re-review of head 1527e76124f203c9673f855564d5b1e63b75c0e6 (previous review was on c31d1ef2).

Summary: The earlier P1 (merge conflicts) is resolved. The branch is now rebased on main and merges cleanly. The lowering still matches the ISA semantics for v_add_co_u32, v_sub_co_u32 and v_subrev_co_u32. No new findings.

Commands executed locally (Linux):

  • git merge-tree --write-tree origin/main HEAD -> clean, no conflicts. gh pr view reports MERGEABLE.
  • python3 tests/startup_gfx2hlsl_add_sub_co_check.py -> pass ("6 forms match the ISA references on 384 inputs; exec, overlap and refusals checked")
  • python3 tests/docs_links_check.py -> pass (18 files, 404 links)
  • python3 tests/bidi_controls_check.py -> pass (1466 files)
  • git diff --check origin/main...HEAD -> clean
  • gh pr checks 2123: Linux Python checks, gfx1013 fixtures and Windows build/test pass. The /O2 job and the chart publish job are skipped.
  • Mutation 1: borrow w = b > a changed to b >= a -> test fails (4 checks). Killed.
  • Mutation 2: add carry (a+b) < a changed to <= a -> test fails (4 checks). Killed.
  • Both mutations reverted with git checkout -- . (worktree clean).

Findings

P1

  • None. The previous conflict is fixed.

P2

  • None.

Nits / notes

  • The test compares the lowering to a Python reference model only. It does not run the HLSL on D3D12 WARP. I did not run a Windows 2025 WARP job for this review. The Windows CI job passed. A GPU-readback check for these three opcodes would add confidence, but it is a suggestion for a follow-up and not a blocker.
  • Title and body are neutral.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6051375584 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2123#pullrequestreview-6051375584). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T03:21:38Z. **Review:** COMMENTED --- Re-review of head `1527e76124f203c9673f855564d5b1e63b75c0e6` (previous review was on `c31d1ef2`). **Summary:** The earlier P1 (merge conflicts) is resolved. The branch is now rebased on main and merges cleanly. The lowering still matches the ISA semantics for `v_add_co_u32`, `v_sub_co_u32` and `v_subrev_co_u32`. No new findings. **Commands executed locally (Linux):** - `git merge-tree --write-tree origin/main HEAD` -> clean, no conflicts. `gh pr view` reports `MERGEABLE`. - `python3 tests/startup_gfx2hlsl_add_sub_co_check.py` -> pass ("6 forms match the ISA references on 384 inputs; exec, overlap and refusals checked") - `python3 tests/docs_links_check.py` -> pass (18 files, 404 links) - `python3 tests/bidi_controls_check.py` -> pass (1466 files) - `git diff --check origin/main...HEAD` -> clean - `gh pr checks 2123`: Linux Python checks, gfx1013 fixtures and Windows build/test pass. The /O2 job and the chart publish job are skipped. - Mutation 1: borrow `w = b > a` changed to `b >= a` -> test fails (4 checks). Killed. - Mutation 2: add carry `(a+b) < a` changed to `<= a` -> test fails (4 checks). Killed. - Both mutations reverted with `git checkout -- .` (worktree clean). **Findings** P1 - None. The previous conflict is fixed. P2 - None. Nits / notes - The test compares the lowering to a Python reference model only. It does not run the HLSL on D3D12 WARP. I did not run a Windows 2025 WARP job for this review. The Windows CI job passed. A GPU-readback check for these three opcodes would add confidence, but it is a suggestion for a follow-up and not a blocker. - Title and body are neutral. AI-assisted; commands listed were executed locally.
denn0x commented 2026-11-25 04:04:18 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-25T03:17:10Z.


Thanks for the review. I rebased the branch on current main (166d8666); the new head is 1527e761. The conflicts were only the registry lines for the new check in AGENTS.md, CMakeLists.txt, docs/experiments.md and windows.yml, and I kept both sides of each. After the rebase, tests/startup_gfx2hlsl_add_sub_co_check.py, every other tests/startup_gfx2hlsl_*_check.py, tests/startup_translator_check.py, tests/docs_links_check.py and the tools lint pass, and git diff --check is clean.

On the WARP readback: I agree it would add confidence. I would keep this PR to the Python-level lowering and its reference model, which compares all six forms on 384 inputs. A draw check could follow in a separate PR that covers the other carry ops too.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7151770476 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2123#issuecomment-7151770476). Originally posted by [denn0x](https://github.com/denn0x) on 2026-11-25T03:17:10Z. --- Thanks for the review. I rebased the branch on current `main` (`166d8666`); the new head is `1527e761`. The conflicts were only the registry lines for the new check in `AGENTS.md`, `CMakeLists.txt`, `docs/experiments.md` and `windows.yml`, and I kept both sides of each. After the rebase, `tests/startup_gfx2hlsl_add_sub_co_check.py`, every other `tests/startup_gfx2hlsl_*_check.py`, `tests/startup_translator_check.py`, `tests/docs_links_check.py` and the tools lint pass, and `git diff --check` is clean. On the WARP readback: I agree it would add confidence. I would keep this PR to the Python-level lowering and its reference model, which compares all six forms on 384 inputs. A draw check could follow in a separate PR that covers the other carry ops too.
stan495 commented 2026-11-25 06:01:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by stan495 on 2026-11-25T05:42:09Z.

Review: APPROVED


Verified head 1527e761 on Windows x64 (Python 3.12).

  • python -B tests/startup_gfx2hlsl_add_sub_co_check.py -> passed (add/sub co forms: 6 forms match the ISA references on 384 inputs; exec, overlap and refusals checked)
  • python -B tests/docs_links_check.py -> passed (18 Markdown files, 404 links)

Verdict: Approved at 1527e761.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6052424990 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2123#pullrequestreview-6052424990). Originally posted by [stan495](https://github.com/stan495) on 2026-11-25T05:42:09Z. **Review:** APPROVED --- Verified head `1527e761` on Windows x64 (Python 3.12). - `python -B tests/startup_gfx2hlsl_add_sub_co_check.py` -> passed (`add/sub co forms: 6 forms match the ISA references on 384 inputs; exec, overlap and refusals checked`) - `python -B tests/docs_links_check.py` -> passed (18 Markdown files, 404 links) Verdict: Approved at `1527e761`.
upstream-sync closed this pull request 2026-11-25 07:00:53 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
R0Y00/Xbox2Windows!2115
No description provided.