shader: lower s_pack_*_b32_b16, s_bfm_b64, s_bitreplicate_b64_b32 and v_mad_u32_u16 #84

Merged
Olima34 merged 2 commits from upstream-pr/84 into main 2026-11-26 15:08:56 +00:00
Olima34 commented 2026-11-26 13:52:07 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-26T13:52:07Z.


What this changes

In the tester logs of #66 and #68, 10 title shaders are first refused on s_pack_ll_b32_b16 (3), s_pack_hh_b32_b16 (1), s_bitreplicate_b64_b32 (4), s_bfm_b64 (1) or v_mad_u32_u16 (1). They were decoded but had no lowering. This lowers them, with s_pack_lh_b32_b16 for the family, from the RDNA2 ISA reference (cross-checked with LLVM's SOPInstructions.td and VOP3Instructions.td):

Opcode Result SCC
s_pack_ll_b32_b16 S1[15:0] << 16 | S0[15:0] no
s_pack_lh_b32_b16 S1[31:16] << 16 | S0[15:0] no
s_pack_hh_b32_b16 S1[31:16] << 16 | S0[31:16] no
s_bfm_b64 ((1 << S0[5:0]) - 1) << S1[5:0] in 64 bits no
s_bitreplicate_b64_b32 bit i of S0 to bits 2i and 2i+1 no
v_mad_u32_u16 S0.u16 * S1.u16 + S2.u32, wrapping; op_sel bits 0 and 1 pick the high halves n/a

ir::writes_scc already agrees that the scalar ones write no SCC. v_mad_u32_u16's op_sel bits 2 and 3 (the 32-bit S2 and D) are undefined in the manual, so they are refused rather than guessed, as are integer source modifiers. The manual's summary table gives s_bfm_b64 5-bit fields, its opcode entry 6-bit ones; the entry is followed.

Tests: a hand-assembled translation test (llvm-mc -mcpu=gfx1030) in gfx_refusal_tests.rs covering all six, with op_sel combinations and wave32 on and off (fails on main with "s_pack_ll_b32_b16 is not supported"), and value probes in semantics_tests.rs for the Windows CI (edge values, s_bfm_b64 widths and offsets 0 to 65, the four op_sel combinations, a wrapping sum). Whether these 10 shaders now translate end to end still needs a live run: they may meet another refusal next.

How it was tested

  • cargo test -p victory-shader (the value probes run only in the Windows CI)
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings, also with --all-features
  • arm64 cargo test --workspace and cargo xtask policy
  • Ran the game: not done, no copy of it here

Checklist

  • No game files, game code, disassembly listings or SDK files are included
  • Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md
  • New diagnostics are behind a VICTORY_* variable and documented (none added)
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:6628113045 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/84). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-26T13:52:07Z. --- ## What this changes In the tester logs of #66 and #68, 10 title shaders are first refused on `s_pack_ll_b32_b16` (3), `s_pack_hh_b32_b16` (1), `s_bitreplicate_b64_b32` (4), `s_bfm_b64` (1) or `v_mad_u32_u16` (1). They were decoded but had no lowering. This lowers them, with `s_pack_lh_b32_b16` for the family, from the RDNA2 ISA reference (cross-checked with LLVM's `SOPInstructions.td` and `VOP3Instructions.td`): | Opcode | Result | SCC | |---|---|---| | `s_pack_ll_b32_b16` | `S1[15:0] << 16 \| S0[15:0]` | no | | `s_pack_lh_b32_b16` | `S1[31:16] << 16 \| S0[15:0]` | no | | `s_pack_hh_b32_b16` | `S1[31:16] << 16 \| S0[31:16]` | no | | `s_bfm_b64` | `((1 << S0[5:0]) - 1) << S1[5:0]` in 64 bits | no | | `s_bitreplicate_b64_b32` | bit i of S0 to bits 2i and 2i+1 | no | | `v_mad_u32_u16` | `S0.u16 * S1.u16 + S2.u32`, wrapping; op_sel bits 0 and 1 pick the high halves | n/a | `ir::writes_scc` already agrees that the scalar ones write no SCC. `v_mad_u32_u16`'s op_sel bits 2 and 3 (the 32-bit S2 and D) are undefined in the manual, so they are refused rather than guessed, as are integer source modifiers. The manual's summary table gives `s_bfm_b64` 5-bit fields, its opcode entry 6-bit ones; the entry is followed. Tests: a hand-assembled translation test (`llvm-mc -mcpu=gfx1030`) in `gfx_refusal_tests.rs` covering all six, with op_sel combinations and wave32 on and off (fails on `main` with "s_pack_ll_b32_b16 is not supported"), and value probes in `semantics_tests.rs` for the Windows CI (edge values, `s_bfm_b64` widths and offsets 0 to 65, the four op_sel combinations, a wrapping sum). Whether these 10 shaders now translate end to end still needs a live run: they may meet another refusal next. ## How it was tested - [x] `cargo test -p victory-shader` (the value probes run only in the Windows CI) - [x] `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings`, also with `--all-features` - [x] arm64 `cargo test --workspace` and `cargo xtask policy` - [ ] Ran the game: not done, no copy of it here ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included - [x] Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md - [x] New diagnostics are behind a `VICTORY_*` variable and documented (none added)
LakshanSivakumar commented 2026-11-26 14:54:45 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T14:54:45Z.

Review: APPROVED


Thanks, the opcode numbers and semantics check out, and refusing op_sel bits 2-3 is the right call.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6076249342 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/84#pullrequestreview-6076249342). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T14:54:45Z. **Review:** APPROVED --- Thanks, the opcode numbers and semantics check out, and refusing op_sel bits 2-3 is the right call.
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
LakshanSivakumar/Native-Victory-macOS!84
No description provided.