shader: lower v_mad_u64_u32 and v_mad_i64_i32 in pixel_aot #1271

Merged
JB2WIN merged 1 commit from upstream-pr/1278 into main 2026-11-24 08:34:12 +00:00
JB2WIN commented 2026-11-24 06:30:30 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-24T06:30:30Z.


Change

tools/pixel_aot.py now lowers the two gfx1013 VOP3b 64-bit multiply-adds, D = S0 * S1 + S2 modulo 2^64. Their destination is a VGPR pair, and S2 is 64 bits wide.

Instruction Factors Carry-out
v_mad_u64_u32 zero-extended carry of the 64-bit add, written to the lane mask (vcc, vcc_lo, an SGPR or an SGPR pair) and tracked like a compare result for v_cndmask_b32
v_mad_i64_i32 sign-extended only null is accepted, because the signed carry is not established here
  • The product comes from a * b and the existing mul_hi_u32/mul_hi_i32 helpers. The add runs on two uint words, so no 64-bit HLSL type is needed. All operands are read before the destination is written.
  • Semantics source: LLVM 15 VOP3Instructions.td at llvmorg-15.0.7, which defines both as VOP3b_I64_I1_I32_I32_I64 (a 64-bit result and a 1-bit carry per lane). This is not checked against the ISA document and not measured on a console.
  • S2 can be a VGPR pair, an aligned SGPR pair or an inline constant from -16 to 64, sign-extended. A literal S2 is refused, because its 64-bit extension is not established. LLVM 15 assembles unaligned VGPR pairs, so they are accepted; hardware legality is assumed, not measured.
  • Refused: clamp, operand and output modifiers, the _e64 spelling, an invalid pair or mask width, unwritten registers and DPP. A later read of a mask after the signed form is refused as an unwritten register.
  • New mode draw-mad64 (pixel_aot_mad64_hardware and pixel_aot_mad64_warp, 60 s timeout, skip code 77 on hardware, its own FORM_COVERAGE_RECORD), so pixel_aot_predicate_rounding_* is unchanged.
    • Four programs: u64_pair, u64_mixed, i64_pair and i64_mixed.
    • The rows cover a carry out of the high word, a carry from the low word into the high word, a sum that wraps to zero, and negative factors and S2.
    • Twenty-three wrong references must report pixel_mismatch. Among them are swapped signedness, a dropped carry, a dropped low-to-high carry, zero-extended inline negatives and a dropped high word of S2.
  • tests/form_coverage_check.py checks both forms as covered. docs/experiments.md has one paragraph, after the carry-in paragraph.
  • No change to the INTEGER or INT_MULTIPLY tables, so this does not overlap #532 or #526 (coordinated in #532).

Testing

On commit d5f83f7e (rebased on 99cde8d6), with an NVIDIA GeForce RTX 3080 (driver 32.0.16.2124), WARP 10.0.26100.9818 and Windows 11 build 26200, debug layer unavailable:

ctest --preset dev --no-tests=error -R '^pixel_aot_(mad64|carry)_' -V   # 6/6 passed
ctest --preset dev --no-tests=error                                    # 754/754 passed, 22 capability skips (wave64, MinLod, xg_swizzle, bc7 mode6), none from this change
  • The pure checks pass: pixel_aot_check.py controls, form_coverage_check.py, rdna2_tools_check.py, pso_readiness_check.py and docs_links_check.py.
  • The LLVM 15.0.7 binary round trip (pixel_aot_check.py binary) passes.
  • Against main's tools/pixel_aot.py the new mode fails with ValueError: Unsupported instruction 23: v_mad_u64_u32 v[12:13], vcc_lo, ....
  • Three mutations of the lowering each turn pixel_aot_mad64_warp red: swapped signedness, a dropped carry-out, and a dropped low-to-high carry.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6576073841 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1278). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-24T06:30:30Z. --- ## Change `tools/pixel_aot.py` now lowers the two gfx1013 VOP3b 64-bit multiply-adds, `D = S0 * S1 + S2` modulo 2^64. Their destination is a VGPR pair, and `S2` is 64 bits wide. | Instruction | Factors | Carry-out | |---|---|---| | `v_mad_u64_u32` | zero-extended | carry of the 64-bit add, written to the lane mask (`vcc`, `vcc_lo`, an SGPR or an SGPR pair) and tracked like a compare result for `v_cndmask_b32` | | `v_mad_i64_i32` | sign-extended | only `null` is accepted, because the signed carry is not established here | - The product comes from `a * b` and the existing `mul_hi_u32`/`mul_hi_i32` helpers. The add runs on two `uint` words, so no 64-bit HLSL type is needed. All operands are read before the destination is written. - Semantics source: LLVM 15 `VOP3Instructions.td` at `llvmorg-15.0.7`, which defines both as `VOP3b_I64_I1_I32_I32_I64` (a 64-bit result and a 1-bit carry per lane). This is not checked against the ISA document and not measured on a console. - `S2` can be a VGPR pair, an aligned SGPR pair or an inline constant from -16 to 64, sign-extended. A literal `S2` is refused, because its 64-bit extension is not established. LLVM 15 assembles unaligned VGPR pairs, so they are accepted; hardware legality is assumed, not measured. - Refused: `clamp`, operand and output modifiers, the `_e64` spelling, an invalid pair or mask width, unwritten registers and DPP. A later read of a mask after the signed form is refused as an unwritten register. - New mode `draw-mad64` (`pixel_aot_mad64_hardware` and `pixel_aot_mad64_warp`, 60 s timeout, skip code 77 on hardware, its own `FORM_COVERAGE_RECORD`), so `pixel_aot_predicate_rounding_*` is unchanged. - Four programs: `u64_pair`, `u64_mixed`, `i64_pair` and `i64_mixed`. - The rows cover a carry out of the high word, a carry from the low word into the high word, a sum that wraps to zero, and negative factors and `S2`. - Twenty-three wrong references must report `pixel_mismatch`. Among them are swapped signedness, a dropped carry, a dropped low-to-high carry, zero-extended inline negatives and a dropped high word of `S2`. - `tests/form_coverage_check.py` checks both forms as covered. `docs/experiments.md` has one paragraph, after the carry-in paragraph. - No change to the `INTEGER` or `INT_MULTIPLY` tables, so this does not overlap #532 or #526 (coordinated in #532). ## Testing On commit `d5f83f7e` (rebased on `99cde8d6`), with an NVIDIA GeForce RTX 3080 (driver 32.0.16.2124), WARP 10.0.26100.9818 and Windows 11 build 26200, debug layer unavailable: ```powershell ctest --preset dev --no-tests=error -R '^pixel_aot_(mad64|carry)_' -V # 6/6 passed ctest --preset dev --no-tests=error # 754/754 passed, 22 capability skips (wave64, MinLod, xg_swizzle, bc7 mode6), none from this change ``` - The pure checks pass: `pixel_aot_check.py controls`, `form_coverage_check.py`, `rdna2_tools_check.py`, `pso_readiness_check.py` and `docs_links_check.py`. - The LLVM 15.0.7 binary round trip (`pixel_aot_check.py binary`) passes. - Against `main`'s `tools/pixel_aot.py` the new mode fails with `ValueError: Unsupported instruction 23: v_mad_u64_u32 v[12:13], vcc_lo, ...`. - Three mutations of the lowering each turn `pixel_aot_mad64_warp` red: swapped signedness, a dropped carry-out, and a dropped low-to-high carry. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 09:04:22 +00:00
tedin7 commented 2026-11-24 09:04:23 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T08:31:00Z.

Review: COMMENTED


Reviewed PR #1278 at commit d5f83f7ed5a3e2adb8ac2f604afbb79053d5d47b.

Verification

  • Linux / LLVM-19:
    • git diff --check origin/main...HEAD: passed.
    • tests/pixel_aot_check.py: passed.
    • tests/rdna2_tools_check.py: passed (133 tests, 16 skipped).
    • tests/form_coverage_check.py: passed.
    • tests/docs_links_check.py: passed (16 Markdown files, 284 links).
    • tests/bidi_controls_check.py: passed (1067 tracked files).
    • tests/pixel_aot_check.py binary llvm-mc-19 llvm-objcopy-19 /usr/lib/llvm-19/lib/libLLVM-19.so: stopped earlier in check_f16_cvt_int16_binary on v_cvt_f16_i16_e32 v1, 0xfff0 (pre-existing LLVM-19 vs LLVM-15 encoding difference, unrelated to this PR).
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP):
    • tests/form_coverage_check.py: passed (40.03s).
    • Debug (--preset dev): offscreen_check built cleanly; ctest -R '^(pixel_aot_mad64_warp|pixel_aot_warp|pixel_aot_integer_nc_warp)$' 3/3 passed (pixel_aot_integer_nc_warp 1.21s, pixel_aot_mad64_warp 1.45s, pixel_aot_warp 15.84s).
    • Release /O2 (--preset release): built cleanly; 3/3 passed (pixel_aot_integer_nc_warp 1.25s, pixel_aot_mad64_warp 1.46s, pixel_aot_warp 15.51s).

Code Findings

  • Clean lowering in tools/pixel_aot.py:
    • v_mad_u64_u32 requires a valid LANE_MASK carry-out and computes exact 64-bit carry (m{i}h1 < m{i}ph || m{i}hi < m{i}h1); v_mad_i64_i32 is restricted to null carry-out so no unverified signed carry state is exposed.
    • All source operands (src0, src1, src2 lo/hi) are latched into locals before writing v[first:last] or updating the carry-out mask, safely handling overlapping source/destination pairs.
    • int64_operand(..., encoding="e64", position=2) handles VGPR/SGPR pairs and sign-extended inline constants -16..64 while rejecting literals, modifiers, unaligned pairs, and null/invalid masks on u64_u32.
    • tests/pixel_aot_check.py covers static acceptance/rejection, carry-mask tracking, 4-program bit-for-bit WARP readback (u64_pair, u64_mixed, i64_pair, i64_mixed), and MAD64_WRONG negative controls.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6035946614 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1278#pullrequestreview-6035946614). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T08:31:00Z. **Review:** COMMENTED --- Reviewed PR #1278 at commit `d5f83f7ed5a3e2adb8ac2f604afbb79053d5d47b`. ### Verification - **Linux / LLVM-19**: - `git diff --check origin/main...HEAD`: passed. - `tests/pixel_aot_check.py`: passed. - `tests/rdna2_tools_check.py`: passed (133 tests, 16 skipped). - `tests/form_coverage_check.py`: passed. - `tests/docs_links_check.py`: passed (16 Markdown files, 284 links). - `tests/bidi_controls_check.py`: passed (1067 tracked files). - `tests/pixel_aot_check.py binary llvm-mc-19 llvm-objcopy-19 /usr/lib/llvm-19/lib/libLLVM-19.so`: stopped earlier in `check_f16_cvt_int16_binary` on `v_cvt_f16_i16_e32 v1, 0xfff0` (pre-existing LLVM-19 vs LLVM-15 encoding difference, unrelated to this PR). - **Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP)**: - `tests/form_coverage_check.py`: passed (40.03s). - **Debug (`--preset dev`)**: `offscreen_check` built cleanly; `ctest -R '^(pixel_aot_mad64_warp|pixel_aot_warp|pixel_aot_integer_nc_warp)$'` **3/3 passed** (`pixel_aot_integer_nc_warp` 1.21s, `pixel_aot_mad64_warp` 1.45s, `pixel_aot_warp` 15.84s). - **Release `/O2` (`--preset release`)**: built cleanly; **3/3 passed** (`pixel_aot_integer_nc_warp` 1.25s, `pixel_aot_mad64_warp` 1.46s, `pixel_aot_warp` 15.51s). ### Code Findings - Clean lowering in `tools/pixel_aot.py`: - `v_mad_u64_u32` requires a valid `LANE_MASK` carry-out and computes exact 64-bit carry (`m{i}h1 < m{i}ph || m{i}hi < m{i}h1`); `v_mad_i64_i32` is restricted to `null` carry-out so no unverified signed carry state is exposed. - All source operands (`src0`, `src1`, `src2` lo/hi) are latched into locals before writing `v[first:last]` or updating the carry-out mask, safely handling overlapping source/destination pairs. - `int64_operand(..., encoding="e64", position=2)` handles VGPR/SGPR pairs and sign-extended inline constants `-16..64` while rejecting literals, modifiers, unaligned pairs, and `null`/invalid masks on `u64_u32`. - `tests/pixel_aot_check.py` covers static acceptance/rejection, carry-mask tracking, 4-program bit-for-bit WARP readback (`u64_pair`, `u64_mixed`, `i64_pair`, `i64_mixed`), and `MAD64_WRONG` negative controls.
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!1271
No description provided.