shader: lower scalar add-with-carry and subtract-with-borrow in pixel_aot #629

Manually merged
github merged 2 commits from gh-pr/629/head into gh-pr/629/base 2026-11-26 22:07:09 +00:00
Owner

@⁠descent81 on GitHub · 2026-11-22 16:29 UTC · original
descent81:shader/scalar-carry-chain → main · +70 −2 · 2 files · 2 commits · merged 2026-11-22 17:25 UTC

Change

pixel_aot now lowers s_addc_u32 and s_subb_u32. Each instruction consumes the prior SCC, returns a wrapping 32-bit word, and writes the resulting carry or borrow back to SCC. The lowering evaluates the binary operation and incoming flag as two unsigned steps so that wrap in either step is detected. Translation refuses the instruction if SCC has no tracked producer. This fills the carry-in and borrow-in gap documented in #257. AMD RDNA 2 ISA reference

Verification

Tested 3020b5d on 2f1f832. The fixture runs a low-word s_add_u32 or s_sub_u32 followed by the corresponding carry/borrow instruction on the high word, using the first high source as its destination. The integer render target exposes both 32-bit result words and both SCC values. Python computes the expected values from the full-width operation and the separate low-word operation.

The inputs distinguish carry/borrow from the two operands alone and carry/borrow caused only by the incoming SCC. The subtraction cases also include a high subtrahend of 0xffffffff with borrow-in set, which catches an implementation that wraps the subtrahend before checking the borrow. Replacing either new instruction with its ordinary add/subtract counterpart must produce pixel_mismatch on the unchanged reference.

  • Windows D3D12: 10 positive draws per backend, 4,096 pixels per draw, passed on RTX 4060 (32.0.16.1088) and WARP (10.0.26100.9818). Both backends caught both negative controls. The complete predicate/rounding CTests passed in 33.76 s and 6.54 s, respectively.
  • LLVM 15: The complete pixel binary suite and controls passed on base and head. The local binary-fixture counts increased from 465 to 467 for gfx1013 and 461 to 463 for gfx1030. Exactly the two SOP2 forms were added.
python -B tests/pixel_aot_check.py binary llvm-mc-15 llvm-objcopy-15 libLLVM-15.so.1
ctest --preset dev --no-tests=error -R '^pixel_aot_predicate_rounding_(hardware|warp)$' --output-on-failure

Evidence and follow-up

The tests use source-written assembly and synthetic operand words under the repository's MIT license. The coverage counts above describe the binary fixture suite.

AI-assisted.

**@⁠descent81** on GitHub · 2026-11-22 16:29 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/629) `descent81:shader/scalar-carry-chain` → `main` · +70 −2 · 2 files · 2 commits · merged 2026-11-22 17:25 UTC ## Change `pixel_aot` now lowers `s_addc_u32` and `s_subb_u32`. Each instruction consumes the prior SCC, returns a wrapping 32-bit word, and writes the resulting carry or borrow back to SCC. The lowering evaluates the binary operation and incoming flag as two unsigned steps so that wrap in either step is detected. Translation refuses the instruction if SCC has no tracked producer. This fills the carry-in and borrow-in gap documented in #257. [AMD RDNA 2 ISA reference](https://docs.amd.com/v/u/en-US/rdna2-shader-instruction-set-architecture) ## Verification Tested `3020b5d` on `2f1f832`. The fixture runs a low-word `s_add_u32` or `s_sub_u32` followed by the corresponding carry/borrow instruction on the high word, using the first high source as its destination. The integer render target exposes both 32-bit result words and both SCC values. Python computes the expected values from the full-width operation and the separate low-word operation. The inputs distinguish carry/borrow from the two operands alone and carry/borrow caused only by the incoming SCC. The subtraction cases also include a high subtrahend of `0xffffffff` with borrow-in set, which catches an implementation that wraps the subtrahend before checking the borrow. Replacing either new instruction with its ordinary add/subtract counterpart must produce `pixel_mismatch` on the unchanged reference. - **Windows D3D12:** 10 positive draws per backend, 4,096 pixels per draw, passed on RTX 4060 (32.0.16.1088) and WARP (10.0.26100.9818). Both backends caught both negative controls. The complete predicate/rounding CTests passed in 33.76 s and 6.54 s, respectively. - **LLVM 15:** The complete pixel binary suite and controls passed on base and head. The local binary-fixture counts increased from **465 to 467** for gfx1013 and **461 to 463** for gfx1030. Exactly the two SOP2 forms were added. ```sh python -B tests/pixel_aot_check.py binary llvm-mc-15 llvm-objcopy-15 libLLVM-15.so.1 ``` ```powershell ctest --preset dev --no-tests=error -R '^pixel_aot_predicate_rounding_(hardware|warp)$' --output-on-failure ``` ## Evidence and follow-up The tests use source-written assembly and synthetic operand words under the repository's MIT license. The coverage counts above describe the binary fixture suite. AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:07:07 +00:00
github manually merged commit d5ca3a1979 into gh-pr/629/base 2026-11-26 22:07:09 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.