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

Merged
descent81 merged 2 commits from upstream-pr/629 into main 2026-11-22 17:25:34 +00:00
descent81 commented 2026-11-22 16:29:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by descent81 on 2026-11-22T16:29:47Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6544830586 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/629). Originally posted by [descent81](https://github.com/descent81) on 2026-11-22T16:29:47Z. --- ## 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.
upstream-sync closed this pull request 2026-11-24 06:44:03 +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!623
No description provided.