shader: lower the non-packed 16-bit integer VOP3 ops in the direct C++ compute path #3018

Merged
archielcqp-a11y merged 1 commit from upstream-pr/3018 into main 2026-11-27 11:55:09 +00:00
archielcqp-a11y commented 2026-11-27 05:29:24 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by archielcqp-a11y on 2026-11-27T05:29:24Z.


Fixes #3017 on main (part of #2935, instruction coverage: integer ALU). Refs #669.

Summary

The direct compute frontend refused twelve VOP3-only 16-bit integer operations with direct DXIL lowering for <name>:

  • v_add_nc_u16, v_sub_nc_u16, v_add_nc_i16 and v_sub_nc_i16;
  • v_mul_lo_u16;
  • v_lshlrev_b16, v_lshrrev_b16 and v_ashrrev_i16;
  • v_min_u16, v_max_u16, v_min_i16 and v_max_i16.

Semantics: each writes D[15:0] from S0[15:0] and S1[15:0], and D[31:16] keeps its value. #669 records two sources for that:

  • an inline-assembly measurement on RDNA 2 silicon;
  • LLVM's GCNSubtarget::zeroesHigh16BitsOfDest, which says "On gfx10, all 16-bit instructions preserve the high bits".

The shifts take S1 shifted by S0[3:0]. Additions, subtractions and the multiply wrap modulo 2^16. The _i16 minimum and maximum compare signed halves, and v_ashrrev_i16 sign-extends.

Refused: op_sel selects other halves, so it stays refused (unsupported <name> op_sel). Source modifiers and clamp stay refused by the path's existing rule.

Not covered: the three-source 16-bit forms (v_mad_u16, v_mad_i16, min3, max3 and med3).

Separate observation, not changed: the direct path's binary16 v_add_f16, v_sub_f16, v_subrev_f16 and v_mul_f16 (#2964) zero D[31:16] in their non-SDWA form (and rounded, 65535). By the same gfx10 rule they should keep it. That belongs in a separate fix with its own readback.

Fixture

tests/native_int16_check.py controls|hardware (tests/cmake/native_int16.cmake). The words were assembled with LLVM 15 (llvm-mc -mcpu=gfx1013).

  • Dispatch: two groups of 32 lanes. G = L + 32g is the lane's global index.
  • Sources: S0 = G * 0x9e3779b9 and S1 = (G * 0x7f4a7c15) ^ 0x5bd1e995. Both high halves are nonzero, the shift counts cover 0..15, and bit 4 of S0 varies.
  • Destinations: each is set to 0xcafebabe before its operation, then the twelve results are stored per lane.
  • Readback: the 768 results and the guard words are compared with a CPU reference.
  • Controls:
    • spot values of each definition;
    • op_sel on v_add_nc_u16 is refused;
    • these references must each differ from the expected words: a zeroed high half, a five-bit shift count, signed and unsigned order exchanged, and a logical v_ashrrev_i16.

Results

cpp-migration 999e17cd plus this change, Windows 10 build 19045, NVIDIA GeForce RTX 3080, driver 32.0.15.9174.

Check Result
native_int16_controls pass
native_int16_hardware (local Agility replay, see below) pass: 768 words and the guards matched, high halves kept
Lowering mutated: high half zeroed readback fails (word 8: 0x0000e995 against 0xcafee995)
Lowering mutated: five-bit shift count readback fails (word 30 first)
Lowering mutated: signed min/max compared unsigned readback fails (word 18 first)
native_align_bfm_hardware (neighbour, same local replay) pass
docs_links_check, bidi_controls_check pass
ctest --preset dev --no-tests=error -R '^native_int16_' -V

Capability skip. The registered native_store_replay uses the inbox D3D12 runtime. On Windows 10 that runtime doesn't report shader model 6.6, so native_int16_hardware reports a skip (77) here. The readback rows above used a local copy of the replay linked with the app-local Agility SDK exports (D3D12SDKVersion 620, as in offscreen_check). That copy isn't part of this change. A run on Windows 11 or with Agility would confirm the registered test.

This PR is independent of #3016. Both add branches to the same function in src/gfx1013_direct_compute.inl, at different places.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5521721151 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3018). Originally posted by [archielcqp-a11y](https://github.com/archielcqp-a11y) on 2026-11-27T05:29:24Z. --- Fixes #3017 on `main` (part of #2935, instruction coverage: integer ALU). Refs #669. ## Summary The direct compute frontend refused twelve VOP3-only 16-bit integer operations with `direct DXIL lowering for <name>`: - `v_add_nc_u16`, `v_sub_nc_u16`, `v_add_nc_i16` and `v_sub_nc_i16`; - `v_mul_lo_u16`; - `v_lshlrev_b16`, `v_lshrrev_b16` and `v_ashrrev_i16`; - `v_min_u16`, `v_max_u16`, `v_min_i16` and `v_max_i16`. **Semantics:** each writes D[15:0] from S0[15:0] and S1[15:0], and **D[31:16] keeps its value**. #669 records two sources for that: - an inline-assembly measurement on RDNA 2 silicon; - LLVM's `GCNSubtarget::zeroesHigh16BitsOfDest`, which says "On gfx10, all 16-bit instructions preserve the high bits". The shifts take S1 shifted by S0[3:0]. Additions, subtractions and the multiply wrap modulo 2^16. The `_i16` minimum and maximum compare signed halves, and `v_ashrrev_i16` sign-extends. **Refused:** `op_sel` selects other halves, so it stays refused (`unsupported <name> op_sel`). Source modifiers and `clamp` stay refused by the path's existing rule. **Not covered:** the three-source 16-bit forms (`v_mad_u16`, `v_mad_i16`, `min3`, `max3` and `med3`). **Separate observation, not changed:** the direct path's binary16 `v_add_f16`, `v_sub_f16`, `v_subrev_f16` and `v_mul_f16` (#2964) zero D[31:16] in their non-SDWA form (`and rounded, 65535`). By the same gfx10 rule they should keep it. That belongs in a separate fix with its own readback. ## Fixture `tests/native_int16_check.py controls|hardware` (`tests/cmake/native_int16.cmake`). The words were assembled with LLVM 15 (`llvm-mc -mcpu=gfx1013`). - **Dispatch:** two groups of 32 lanes. G = L + 32g is the lane's global index. - **Sources:** S0 = G * 0x9e3779b9 and S1 = (G * 0x7f4a7c15) ^ 0x5bd1e995. Both high halves are nonzero, the shift counts cover 0..15, and bit 4 of S0 varies. - **Destinations:** each is set to 0xcafebabe before its operation, then the twelve results are stored per lane. - **Readback:** the 768 results and the guard words are compared with a CPU reference. - **Controls:** - spot values of each definition; - `op_sel` on `v_add_nc_u16` is refused; - these references must each differ from the expected words: a zeroed high half, a five-bit shift count, signed and unsigned order exchanged, and a logical `v_ashrrev_i16`. ## Results `cpp-migration` `999e17cd` plus this change, Windows 10 build 19045, NVIDIA GeForce RTX 3080, driver 32.0.15.9174. | Check | Result | |---|---| | `native_int16_controls` | pass | | `native_int16_hardware` (local Agility replay, see below) | pass: 768 words and the guards matched, high halves kept | | Lowering mutated: high half zeroed | readback fails (word 8: `0x0000e995` against `0xcafee995`) | | Lowering mutated: five-bit shift count | readback fails (word 30 first) | | Lowering mutated: signed min/max compared unsigned | readback fails (word 18 first) | | `native_align_bfm_hardware` (neighbour, same local replay) | pass | | `docs_links_check`, `bidi_controls_check` | pass | ```powershell ctest --preset dev --no-tests=error -R '^native_int16_' -V ``` **Capability skip.** The registered `native_store_replay` uses the inbox D3D12 runtime. On Windows 10 that runtime doesn't report shader model 6.6, so `native_int16_hardware` reports a skip (77) here. The readback rows above used a local copy of the replay linked with the app-local Agility SDK exports (`D3D12SDKVersion` 620, as in `offscreen_check`). That copy isn't part of this change. A run on Windows 11 or with Agility would confirm the registered test. This PR is independent of #3016. Both add branches to the same function in `src/gfx1013_direct_compute.inl`, at different places. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
KelboLive commented 2026-11-27 05:37:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-27T05:37:19Z.

Review: COMMENTED


What works

  1. Comprehensive lowering of twelve 16-bit integer VOP3 ops that the
    direct compute frontend previously refused. Each correctly preserves
    D[31:16] while writing D[15:0] from S0[15:0]+S1[15:0], matching RDNA
    2 silicon measurements and LLVM's zeroesHigh... behavior.
  2. Clean IR construction: the low() mask helper (and x, 65535 ~16 bits), the sext() for signed operations, and the shift/compare
    logic all follow the existing patterns in the direct compute lowering.
  3. Good test coverage: controls check op_sel refusal and mutant
    references; hardware mode validates all 384 words across 32 lanes.
  4. Clear experiment doc tracing both silicon and LLVM sources.

Issues

  1. The high variable and its use in the preceding block (line
    'z = ir.binary("and", read(i.dst), "4294901760") | low(r)').
    The mask 4294901760 = 0xFFFF0000 = ~0xFFFF = the high half.)
    This is correct but the magic number could be a comment or a named
    const for readability.
  2. The three-source 16-bit forms (v_mad_u16, v_mad_i16, v_min3,
    v_max3, v_med3) are explicitly acknowledged as not covered here.
    Good forward reference.

Recommendations

  • Add a comment or const for the high-half mask 4294901760 (0xFFFF
  1. to aid future readers.
  • Consider whether the low() helper could be a class method to make
    the pattern reusable for future lowerings.

Overall

Solid instruction lowering with thorough testing and documentation.
The RDNA 2 ISA references are well-grounded. Approvable.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6083922858 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3018#pullrequestreview-6083922858). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-27T05:37:19Z. **Review:** COMMENTED --- ## What works 1. Comprehensive lowering of twelve 16-bit integer VOP3 ops that the direct compute frontend previously refused. Each correctly preserves D[31:16] while writing D[15:0] from S0[15:0]+S1[15:0], matching RDNA 2 silicon measurements and LLVM's zeroesHigh... behavior. 2. Clean IR construction: the `low()` mask helper (`and x, 65535 ~16 bits`), the `sext()` for signed operations, and the shift/compare logic all follow the existing patterns in the direct compute lowering. 3. Good test coverage: controls check op_sel refusal and mutant references; hardware mode validates all 384 words across 32 lanes. 4. Clear experiment doc tracing both silicon and LLVM sources. ## Issues 1. The `high` variable and its use in the preceding block (line 'z = ir.binary("and", read(i.dst), "4294901760") | low(r)'). The mask `4294901760` = `0xFFFF0000` = `~0xFFFF` = the high half.) This is correct but the magic number could be a comment or a named const for readability. 2. The three-source 16-bit forms (v_mad_u16, v_mad_i16, v_min3, v_max3, v_med3) are explicitly acknowledged as not covered here. Good forward reference. ## Recommendations - Add a comment or const for the high-half mask `4294901760` (0xFFFF 0000) to aid future readers. - Consider whether the `low()` helper could be a class method to make the pattern reusable for future lowerings. ## Overall Solid instruction lowering with thorough testing and documentation. The RDNA 2 ISA references are well-grounded. Approvable.
R0Y00 commented 2026-11-27 11:54:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T11:54:43Z.

Review: APPROVED


Reviewed fb760133 after retargeting to main, with #3051 and #3048 before it in the tested integration tree d1a0367c. I rebuilt compile_dxil and native_store_replay, then ran ctest --preset <dev|release> --no-tests=error -V -R '^(native_int16_(ternary_)?(controls|hardware)|native_bitscan_(controls|hardware))$'. Debug and Release /O2 each passed 6/6. The RTX readback matched 768 words and guards across the two groups, with destination high halves preserved. The compile fixture refused op_sel; the zeroed-high, shift-width, reversed-order and logical-shift controls differ as expected. The separate ternary and bit-scan fixtures still pass. Windows 11 26200.9974, SDK 10.0.26100, RTX 4060 Laptop driver 32.0.16.1656, native replay debug layer off. Hosted Windows, Linux Python and gfx1013 checks passed for this head.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6087737442 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3018#pullrequestreview-6087737442). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-27T11:54:43Z. **Review:** APPROVED --- Reviewed `fb760133` after retargeting to `main`, with #3051 and #3048 before it in the tested integration tree `d1a0367c`. I rebuilt `compile_dxil` and `native_store_replay`, then ran `ctest --preset <dev|release> --no-tests=error -V -R '^(native_int16_(ternary_)?(controls|hardware)|native_bitscan_(controls|hardware))$'`. Debug and Release /O2 each passed 6/6. The RTX readback matched 768 words and guards across the two groups, with destination high halves preserved. The compile fixture refused `op_sel`; the zeroed-high, shift-width, reversed-order and logical-shift controls differ as expected. The separate ternary and bit-scan fixtures still pass. Windows 11 26200.9974, SDK 10.0.26100, RTX 4060 Laptop driver 32.0.16.1656, native replay debug layer off. Hosted Windows, Linux Python and gfx1013 checks passed for this head.
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!3018
No description provided.