xshader: RDNA2 VOPC i16/u16/i64/u64 + class_f16 (RDNA2 734/779) #22

Closed
github-bot wants to merge 2 commits from gh-pr/22/head into gh-pr/22/base
Owner

@⁠QuentinDanblon on GitHub · 2026-11-21 17:49 UTC · original
QuentinDanblon:feat/vopc-16-64 → main · +1388 −823 · 13 files · 2 commits · closed without merging

Library / area: tombox-xshader (RDNA2 VOPC decode + translation), progress map

Exports changed (exports.txt rows): none

Source of the behaviour: LLVM VOPCInstructions.td (GFX10 section) for the opcode map; LLVM AMDGPUOperandSyntax for literal/inline extension; RDNA2 ISA for semantics. Design ported/adapted from brcly/TomBox (crates declare MIT OR Apache-2.0): rdna2/mnem.rs, hlsl/compare.rs, be622e8.

Rebased on main after #15 landed as ad43ad2: one code commit and one progress commit.

What

The decoder had no entries for the RDNA2 VOPC i16/u16/i64/u64 compares or for v_cmp(x)_class_f16. A title shader using one of them could not be translated. This PR adds:

  • rdna2/mnem.rs: 58 opcodes (i16/u16 ×6 ×cmp/cmpx, i64/u64 ×8 ×cmp/cmpx, class_f16 0x8f/0x9f). Checked against LLVM GFX10 and brcly's table.
  • hlsl/icmp.rs (new): 64-bit sources from register pairs. Inline ints are sign-extended. A 32-bit literal is sign-extended for i64 and zero-extended for u64. Anything else is refused.
  • hlsl.rs: one vcmp_cond path for all VOPC/VOP3 compares. 16-bit compares read [15:0], sign-extended for i16; VOP3 OPSEL selects the high half. tb_cmp_class16. Class abs/neg apply to src0 only (VOPC_Class_Profile), now also for class_f32/f64.
  • Refused, not guessed: OPSEL on constants, inline float constants as 16/64-bit integer sources, abs/neg on integer 16/64-bit compares.
  • GFX10 v_cmpx still writes EXEC only. The tests check that VCC keeps a sentinel.

SDWA operand selection before compares and CMPK zero-extension (the other parts of be622e8) were already correct here, so they are unchanged.

Tests (WARP, DXC 1.9.2609)

  • --test exec vop::vopc: 10/10 (5 existing + new vopc_i16, vopc_u16, vopc_i64, vopc_u64, vopc_class_f16). Expected values come from an i128 / ISA class-bit model. Cases: e32 cmp/cmpx, e64 with SGPR/VCC/NULL destinations, masked lanes, inline/literal/SGPR-pair src0, OPSEL 1/2/3, class abs/neg.
  • --test opcodes: 22/22 (18 new decode rows plus HLSL checks). --lib: 8/8.
  • Full --test exec: 61 pass, 4 fail. The 4 failures are the vop::basic ones already present at 226938c, fixed separately.

Progress

mnem_groups.json is regenerated from mnem.rs with the same rule as sync.py (I checked that the rule reproduces the committed file at 226938c exactly). The 58 new mnemonics are added to rdna2_verified. RDNA2 instructions 676/721 → 734/779.

Not verified on hardware: OPSEL on VOPC-in-VOP3 (LLVM does not encode op_sel for GFX10 VOPC, so compilers shouldn't emit it) and the 64-bit literal extension rule. brcly's tools/progress/native-vopc.tsv reports all of these mnemonics as matching on gfx1036, but it doesn't include the test vectors.

  • cargo test -p tombox-xshader passes (except the pre-existing vop::basic failures)
  • No game or console files and no binaries included
  • No fake success; anything not possible is left missing with a note
**@⁠QuentinDanblon** on GitHub · 2026-11-21 17:49 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/22) `QuentinDanblon:feat/vopc-16-64` → `main` · +1388 −823 · 13 files · 2 commits · closed without merging **Library / area:** tombox-xshader (RDNA2 VOPC decode + translation), progress map **Exports changed (exports.txt rows):** none **Source of the behaviour:** LLVM `VOPCInstructions.td` (GFX10 section) for the opcode map; LLVM AMDGPUOperandSyntax for literal/inline extension; RDNA2 ISA for semantics. Design ported/adapted from brcly/TomBox (crates declare MIT OR Apache-2.0): [`rdna2/mnem.rs`](https://github.com/brcly/TomBox/blob/master/crates/tuxbox-xshader/src/rdna2/mnem.rs), [`hlsl/compare.rs`](https://github.com/brcly/TomBox/blob/master/crates/tuxbox-xshader/src/hlsl/compare.rs), be622e8. Rebased on main after #15 landed as ad43ad2: one code commit and one progress commit. ### What The decoder had no entries for the RDNA2 VOPC i16/u16/i64/u64 compares or for `v_cmp(x)_class_f16`. A title shader using one of them could not be translated. This PR adds: - `rdna2/mnem.rs`: 58 opcodes (i16/u16 ×6 ×cmp/cmpx, i64/u64 ×8 ×cmp/cmpx, class_f16 0x8f/0x9f). Checked against LLVM GFX10 and brcly's table. - `hlsl/icmp.rs` (new): 64-bit sources from register pairs. Inline ints are sign-extended. A 32-bit literal is sign-extended for i64 and zero-extended for u64. Anything else is refused. - `hlsl.rs`: one `vcmp_cond` path for all VOPC/VOP3 compares. 16-bit compares read [15:0], sign-extended for i16; VOP3 OPSEL selects the high half. `tb_cmp_class16`. Class abs/neg apply to src0 only (VOPC_Class_Profile), now also for class_f32/f64. - Refused, not guessed: OPSEL on constants, inline float constants as 16/64-bit integer sources, abs/neg on integer 16/64-bit compares. - GFX10 `v_cmpx` still writes EXEC only. The tests check that VCC keeps a sentinel. SDWA operand selection before compares and CMPK zero-extension (the other parts of be622e8) were already correct here, so they are unchanged. ### Tests (WARP, DXC 1.9.2609) - `--test exec vop::vopc`: 10/10 (5 existing + new `vopc_i16`, `vopc_u16`, `vopc_i64`, `vopc_u64`, `vopc_class_f16`). Expected values come from an i128 / ISA class-bit model. Cases: e32 cmp/cmpx, e64 with SGPR/VCC/NULL destinations, masked lanes, inline/literal/SGPR-pair src0, OPSEL 1/2/3, class abs/neg. - `--test opcodes`: 22/22 (18 new decode rows plus HLSL checks). `--lib`: 8/8. - Full `--test exec`: 61 pass, 4 fail. The 4 failures are the `vop::basic` ones already present at 226938c, fixed separately. ### Progress `mnem_groups.json` is regenerated from `mnem.rs` with the same rule as `sync.py` (I checked that the rule reproduces the committed file at 226938c exactly). The 58 new mnemonics are added to `rdna2_verified`. **RDNA2 instructions 676/721 → 734/779.** Not verified on hardware: OPSEL on VOPC-in-VOP3 (LLVM does not encode op_sel for GFX10 VOPC, so compilers shouldn't emit it) and the 64-bit literal extension rule. brcly's `tools/progress/native-vopc.tsv` reports all of these mnemonics as matching on gfx1036, but it doesn't include the test vectors. - [x] `cargo test -p tombox-xshader` passes (except the pre-existing `vop::basic` failures) - [x] No game or console files and no binaries included - [x] No fake success; anything not possible is left `missing` with a note
Decode the GFX10 VOPC opcodes 0x89-0x8f, 0x99-0x9f, 0xa0-0xa7, 0xa9-0xae,
0xb0-0xb7, 0xb9-0xbe, 0xe0-0xe7 and 0xf0-0xf7 (v_cmp/v_cmpx lt..ge i16/u16,
f..t i64/u64, class_f16), mapping verified against LLVM
llvm/lib/Target/AMDGPU/VOPCInstructions.td (GFX10 section).

Translation (all VOPC/VOP3 compares now go through one vcmp_cond):
- 16-bit integer compares read the low half (sign-extended for i16); VOP3
  OPSEL[12:11] selects the high half of a register source, as already done
  for f16 arithmetic; f16 compares now honour OPSEL too (incl. NaN test).
  OPSEL on a constant, inline float constants and abs/neg on integer
  compares are refused.
- 64-bit integer compares on register pairs (high dword decides, low dword
  unsigned); inline integers sign-extend, a 32-bit literal sign-extends for
  i64 and zero-extends for u64 (LLVM AMDGPUOperandSyntax, "Conversion of
  Integer Values").
- v_cmp_class_f16 via tb_cmp_class16; VOP3 abs/neg apply to src0 of every
  class compare (LLVM VOPC_Class_Profile: Src0Mod, no src1 modifiers).
- GFX10 v_cmpx writes EXEC only (unchanged).

SDWA operand selection already happens before the compare lowering and
s_cmpk_*_u32 already zero-extends SIMM16, so those parts need no change.

Ported/adapted from brcly/TomBox (MIT OR Apache-2.0):
- be622e8 (be622e8): 16-bit integer
  compare opcodes and operand extension.
- master crates/tuxbox-xshader/src/rdna2/mnem.rs (VOPC table) and
  src/hlsl/compare.rs (64-bit integer compares on register pairs, literal
  extension, class_f16 parameters):
  https://github.com/brcly/TomBox/blob/master/crates/tuxbox-xshader/src/hlsl/compare.rs

Tests: exec vop::vopc gains i16, u16, i64, u64 and class_f16 groups (e32,
e64, cmpx, SDST, masked lanes, inline/literal/SGPR-pair sources, OPSEL,
class abs/neg); opcodes.rs covers the new decode and HLSL forms.
mnem_groups.json regenerated from rdna2/mnem.rs (same rule as sync.py):
58 new VOPC mnemonics, all verified by the new vopc_{i16,u16,i64,u64,
class_f16} exec groups on WARP.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:07:30 +00:00
github-bot closed this pull request 2026-11-26 06:07:30 +00:00
Author
Owner

@⁠QuentinDanblon on GitHub · 2026-11-21 21:03 UTC · original

Merged in the source sync 1159c96 (adapted). Thanks! Closing.

**@⁠QuentinDanblon** on GitHub · 2026-11-21 21:03 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/22#issuecomment-7069202192) Merged in the source sync 1159c96 (adapted). Thanks! Closing.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.