shader: keep D[31:16] in the direct path's binary16 add, sub, subrev and mul #3020

Merged
archielcqp-a11y merged 1 commit from upstream-pr/3020 into cpp-migration 2026-11-27 09:36:38 +00:00
archielcqp-a11y commented 2026-11-27 05:37:54 +00:00 (Migrated from github.com)

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


Fixes #3019 on cpp-migration (part of #2935). Refs #2964, #669.

Summary

In the direct compute path, the non-SDWA forms of v_add_f16, v_sub_f16, v_subrev_f16 and v_mul_f16 wrote the rounded binary16 result to D[15:0] and zeroed D[31:16]. They now keep D[31:16]. The change is one vector_write in src/gfx1013_direct_compute.inl.

Why:

  • LLVM: GCNSubtarget::zeroesHigh16BitsOfDest lists exactly these four ops, V_ADD/SUB/SUBREV/MUL_F16 in _e32 and _e64, under "On gfx10, all 16-bit instructions preserve the high bits", and returns false from GFX10 on.
  • The same path: its v_cvt_f16_f32 already keeps the high half.
  • #669: recorded the same rule for the non-packed 16-bit integer ops, from an inline-assembly measurement on RDNA 2 silicon.

No silicon measurement of these four f16 ops is known to me. #2964 states the zeroing "matches RDNA 2" without a source. I asked its author on #3019 and will adjust if a measurement says otherwise.

Unchanged: SDWA forms still place the result through dst_sel/dst_unused, and the refusals.

Test change

tests/native_f16_alu_check.py already put 0xabcd in the high half of every destination before the operation. Its comparator and model now require each stored word to be 0xabcd in the high half and the binary16 result in the low half.

The mutant it rejects changes from "a kept high half" to "a zeroed high half". The test isn't weaker: it pins the opposite contract with the same coverage (82 cases, 16 refusals), and the old lowering now fails it.

New page: docs/experiments/native-direct-f16-high-half.md.

Results

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

Check Result
native_f16_alu_check.py model pass: 82 results; a sub/subrev swap and a zeroed upper half are rejected
native_f16_alu_ir pass: 82 results match, 16 refusals carry their diagnostics
native_f16_alu_hardware (local Agility replay, see below) pass: 164 words, high half kept
Old zeroing restored: IR check fails at the first stored word
Old zeroing restored: readback fails at the first stored word (word 8)
docs_links_check, bidi_controls_check pass
ctest --preset dev --no-tests=error -R '^native_f16_alu_' -V

Capability skip. The registered native_store_replay uses the inbox D3D12 runtime, which doesn't report shader model 6.6 on Windows 10, so native_f16_alu_hardware reports a skip (77) here. The readback rows used a local copy of the replay linked with the app-local Agility SDK exports (D3D12SDKVersion 620). That copy isn't part of this change.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5521794753 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3020). Originally posted by [archielcqp-a11y](https://github.com/archielcqp-a11y) on 2026-11-27T05:37:54Z. --- Fixes #3019 on `cpp-migration` (part of #2935). Refs #2964, #669. ## Summary In the direct compute path, the non-SDWA forms of `v_add_f16`, `v_sub_f16`, `v_subrev_f16` and `v_mul_f16` wrote the rounded binary16 result to D[15:0] and zeroed D[31:16]. They now keep D[31:16]. The change is one `vector_write` in `src/gfx1013_direct_compute.inl`. **Why:** - **LLVM:** `GCNSubtarget::zeroesHigh16BitsOfDest` lists exactly these four ops, `V_ADD/SUB/SUBREV/MUL_F16` in `_e32` and `_e64`, under "On gfx10, all 16-bit instructions preserve the high bits", and returns false from GFX10 on. - **The same path:** its `v_cvt_f16_f32` already keeps the high half. - **#669:** recorded the same rule for the non-packed 16-bit integer ops, from an inline-assembly measurement on RDNA 2 silicon. No silicon measurement of these four f16 ops is known to me. #2964 states the zeroing "matches RDNA 2" without a source. I asked its author on #3019 and will adjust if a measurement says otherwise. **Unchanged:** SDWA forms still place the result through `dst_sel`/`dst_unused`, and the refusals. ## Test change `tests/native_f16_alu_check.py` already put `0xabcd` in the high half of every destination before the operation. Its comparator and model now require each stored word to be `0xabcd` in the high half and the binary16 result in the low half. The mutant it rejects changes from "a kept high half" to "a zeroed high half". The test isn't weaker: it pins the opposite contract with the same coverage (82 cases, 16 refusals), and the old lowering now fails it. New page: `docs/experiments/native-direct-f16-high-half.md`. ## Results `cpp-migration` `999e17cd` plus this change, Windows 10 build 19045, NVIDIA GeForce RTX 3080, driver 32.0.15.9174. | Check | Result | |---|---| | `native_f16_alu_check.py model` | pass: 82 results; a sub/subrev swap and a zeroed upper half are rejected | | `native_f16_alu_ir` | pass: 82 results match, 16 refusals carry their diagnostics | | `native_f16_alu_hardware` (local Agility replay, see below) | pass: 164 words, high half kept | | Old zeroing restored: IR check | fails at the first stored word | | Old zeroing restored: readback | fails at the first stored word (word 8) | | `docs_links_check`, `bidi_controls_check` | pass | ```powershell ctest --preset dev --no-tests=error -R '^native_f16_alu_' -V ``` **Capability skip.** The registered `native_store_replay` uses the inbox D3D12 runtime, which doesn't report shader model 6.6 on Windows 10, so `native_f16_alu_hardware` reports a skip (77) here. The readback rows used a local copy of the replay linked with the app-local Agility SDK exports (`D3D12SDKVersion` 620). That copy isn't part of this change. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
KelboLive commented 2026-11-27 05:42:34 +00:00 (Migrated from github.com)

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

Review: COMMENTED


What works

  1. Minimal, surgical change: one vector_write in
    gfx1013_direct_compute.inl switches and rounded, 65535 to
    or and(old_dst, 0xFFFF0000), and(rounded, 65535). This keeps
    D[31:16] exactly matching the LLVM zeroesHigh16BitsOfDest behavior
    for these four f16 VOP3 ops.
  2. Consistent with the existing path: v_cvt_f16_f32 above this
    block already keeps the high half, and #669 established the same
    rule for non-packed 16-bit integer ops from silicon measurements.
  3. Test changes are clean: native_f16_alu_check.py swaps the
    mutant from reject_zeroed_high to reject_zeroed_lo (now that the
    high half is kept instead of zeroed). The HI_A reference value
    must be present in every stored destination.

Issues

  1. SDWA forms are unchanged: they place the result through
    dst_sel/dst_unused which already handle the layout. The comment
    acknowledges this -- good.
  2. The packed_half_rne(bits) path is only taken when
    !i.subword. For the subword variant, place_subword handles the
    layout and the diff doesn't change it. Verify this is consistent with
    RDNA 2 where subword forms also keep D[31:16].

Recommendations

  • Consider whether the subword path should also preserve the high half.
  • The magic literals 4294901760 (0xFFFF0000) and 65535 could
    be commented as hex for readability.

Overall

Tiny, correct change matching LLVM and existing code in the
same function. The model/IR/gpu readback tests confirm the fix.
Approvable.
function. The model/IR/gpu readback tests confirm the fix.
Approvable.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6083959980 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3020#pullrequestreview-6083959980). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-27T05:42:34Z. **Review:** COMMENTED --- ## What works 1. Minimal, surgical change: one vector_write in gfx1013_direct_compute.inl switches `and rounded, 65535` to `or and(old_dst, 0xFFFF0000), and(rounded, 65535)`. This keeps D[31:16] exactly matching the LLVM zeroesHigh16BitsOfDest behavior for these four f16 VOP3 ops. 2. Consistent with the existing path: `v_cvt_f16_f32` above this block already keeps the high half, and #669 established the same rule for non-packed 16-bit integer ops from silicon measurements. 3. Test changes are clean: `native_f16_alu_check.py` swaps the mutant from reject_zeroed_high to reject_zeroed_lo (now that the high half is kept instead of zeroed). The `HI_A` reference value must be present in every stored destination. ## Issues 1. SDWA forms are unchanged: they place the result through `dst_sel`/`dst_unused` which already handle the layout. The comment acknowledges this -- good. 2. The `packed_half_rne(bits)` path is only taken when `!i.subword`. For the subword variant, `place_subword` handles the layout and the diff doesn't change it. Verify this is consistent with RDNA 2 where subword forms also keep D[31:16]. ## Recommendations - Consider whether the subword path should also preserve the high half. - The magic literals `4294901760` (0xFFFF0000) and `65535` could be commented as hex for readability. ## Overall Tiny, correct change matching LLVM and existing code in the same function. The model/IR/gpu readback tests confirm the fix. Approvable. function. The model/IR/gpu readback tests confirm the fix. Approvable.
R0Y00 commented 2026-11-27 06:04:24 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Independent Release /O2 retest at b4128920163840ef75d7b903049a1b8c9c2a2833. I rebuilt native_compute_ir_dump, native_store_replay, and compile_dxil, then ran ctest --preset release --no-tests=error -V -R '^native_f16_alu_(ir|hardware)$' as separate per-test invocations. The IR check matched 82 results and all 16 rejection diagnostics. The registered inbox D3D12 hardware check matched all 164 words, including the high-half sentinels, on Windows 11 build 26200.9974 with RTX 4060 Laptop and driver 32.0.16.1656. The replay does not enable the D3D12 debug layer. Neither test skipped.

LLVM 20.1.8 lists all four e32/e64 opcode pairs and returns false from GFX10 onward. The desktop readback verifies the lowering. Direct RDNA 2 measurement for these four floating-point opcodes is still open.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6084172898 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3020#pullrequestreview-6084172898). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-27T06:04:24Z. **Review:** COMMENTED --- Independent Release `/O2` retest at `b4128920163840ef75d7b903049a1b8c9c2a2833`. I rebuilt `native_compute_ir_dump`, `native_store_replay`, and `compile_dxil`, then ran `ctest --preset release --no-tests=error -V -R '^native_f16_alu_(ir|hardware)$'` as separate per-test invocations. The IR check matched 82 results and all 16 rejection diagnostics. The registered inbox D3D12 hardware check matched all 164 words, including the high-half sentinels, on Windows 11 build 26200.9974 with RTX 4060 Laptop and driver 32.0.16.1656. The replay does not enable the D3D12 debug layer. Neither test skipped. [LLVM 20.1.8 lists all four e32/e64 opcode pairs and returns false from GFX10 onward](https://github.com/llvm/llvm-project/blob/llvmorg-20.1.8/llvm/lib/Target/AMDGPU/GCNSubtarget.cpp#L280-L306). The desktop readback verifies the lowering. Direct RDNA 2 measurement for these four floating-point opcodes is still open.
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!3020
No description provided.