tombox-xshader: VOP3 op_sel, v_cube* denormals and v_sat_pk_u8_i16 as measured on RDNA2 silicon #385

Open
github-bot wants to merge 1 commit from github-bot/gh-385 into main AGit
Owner

@⁠SchmashinPrunes on GitHub · 2026-11-25 17:33 UTC · original
SchmashinPrunes:rdna2-silicon-model-fixes → main · +41 −29 · 5 files · 1 commits · open

@⁠omonkeyz, I ran the ISA sweep's own test cases on RDNA2 silicon. Each case went in as raw machine code on a gfx1036 iGPU (Ryzen 5 9600X, ROCm/HIP), with no translator involved, and the outputs were checked with the sweep's reference models and tolerance rules.

That covers 2,196 cases over 550 mnemonics, and 530 matched bit for bit. This PR fixes three rules that the translator and the sweep models both had wrong. With it, 542 of 550 match. The other 8 are listed under "Not in this PR".

gfx1036 is RDNA2 but not the console's gfx1013, so wherever the two could differ I checked LLVM's gfx1013 tables too.

1. op_sel only exists on VOP3-native opcodes

The translator honoured VOP3 op_sel on any f16/16-bit op. On silicon, VOPC, VOP2 and VOP1 ops in the VOP3 encoding ignore the op_sel bits. They read the low source halves and write the low half of the destination, keeping the high half.

  • Measured: v_add/sub/subrev/mul/min/max_f16 with op_sel src0hi/src1hi/dsthi, v_cvt_f16_f32 with op_sel dst hi, and v_cmp_eq_f16 / v_cmp_class_f16 with op_sel src0hi. For the compares I added a positive control (v2 == v2 gives ffffffff).
  • LLVM rejects op_sel on these encodings for gfx1013 as well, so real console code shouldn't contain them.
  • The VOP3-native 16-bit ops do honour op_sel on silicon, and all their sweep op_sel variants pass. That's v_add_nc_*16, v_max/min_[iu]16, v_lshlrev/lshrrev/ashrrev_*16, v_mul_lo_u16, v_mad_[iu]16, the *3_*16 forms, v_fma_f16, v_pack_b32_f16 and v_cvt_pknorm_*.
  • So the rule is the opcode range. vop3_opsel_ok() is true for VOP3 opcodes 0x140–0x17f and 0x300–0x3ff, and every op_sel read outside VOP3P and interp now goes through it: h16, the dst-hi merge, the f16 transcendental path, f16 compares, is16 and mode::hsel.

2. v_cube* treat denormal inputs as zero when picking the face

  • The major axis is chosen on magnitudes with denormals as zero. The returned sc/tc/ma values use the raw inputs.
  • v_cubema of a zero axis is +0. For example, (-0, -denorm, -0) gives 0x00000000, not 0x80000000.
  • The result is the same under all four f32 denormal modes.
  • This model matches all 588 recorded non-NaN cases of each of the four ops. The previous model matched 586–587.
  • One case isn't pinned by the record: a negative denormal as the chosen axis (its sign test). It keeps today's behaviour.

3. v_sat_pk_u8_i16 writes the whole dword

D[31:16] becomes 0. The translator merged it as a 16-bit result and kept the old high half.

Tests

  • The sweep models (ops_v.rs) follow the three rules.
  • Three exec expectations change:
    • vector_vop1 v_sat_pk_u8_i16 now checks the full dword;
    • vector_f16_preserves_high_half case 3 (v_add_f16 VOP3 with op_sel 0b1001) now expects the low half;
    • exec_vop/vopc.rs add_opsel and the v_cmp_class_f16 op_sel cases now compare the low halves.
run result
WARP, full tombox-xshader suite every target ok; tests/exec.rs 189/189
Radeon RX 9060 XT, tests/exec.rs 189/189
Radeon RX 9060 XT, isa_sweep 553/556. The 3 are the known AMD-host SDWA byte-select + abs f16 case from #375, unrelated
gfx1036 silicon vs sweep models 542/550 (was 530)

The PR gate is clean.

Not in this PR

  • f32 omod, 7 mnemonics. On silicon it is applied only when IEEE = 0 and f32 output denormals are flushed. That's the f16 rule from #363, and LLVM's condition for folding omod. The translator applies it unconditionally, and with MODE_DEFAULT = 0xf0 the right fix is your call, so I wrote it up separately as #386.
  • v_mul_lo_i32. gfx10.3 doesn't have it, so it can't be measured here. Its low 32 bits are identical to v_mul_lo_u32's, which matches silicon.
  • v_mac/mad/madak/madmk(_legacy)_f32. gfx10.3 removed these (and reuses two of the opcodes for fma_legacy), so they can't be checked on this iGPU.

The silicon harness (exporter, runner and checker) is a separate PR. I'm still working out a record format that fits the repo.

🤖 Generated with Claude Code

**@⁠SchmashinPrunes** on GitHub · 2026-11-25 17:33 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/385) `SchmashinPrunes:rdna2-silicon-model-fixes` → `main` · +41 −29 · 5 files · 1 commits · open @⁠omonkeyz, I ran the ISA sweep's own test cases on RDNA2 silicon. Each case went in as raw machine code on a gfx1036 iGPU (Ryzen 5 9600X, ROCm/HIP), with no translator involved, and the outputs were checked with the sweep's reference models and tolerance rules. That covers 2,196 cases over 550 mnemonics, and 530 matched bit for bit. This PR fixes three rules that the translator and the sweep models both had wrong. With it, 542 of 550 match. The other 8 are listed under "Not in this PR". gfx1036 is RDNA2 but not the console's gfx1013, so wherever the two could differ I checked LLVM's gfx1013 tables too. ### 1. op_sel only exists on VOP3-native opcodes The translator honoured VOP3 op_sel on any f16/16-bit op. On silicon, **VOPC, VOP2 and VOP1 ops in the VOP3 encoding ignore the op_sel bits**. They read the low source halves and write the low half of the destination, keeping the high half. - Measured: `v_add/sub/subrev/mul/min/max_f16` with op_sel src0hi/src1hi/dsthi, `v_cvt_f16_f32` with op_sel dst hi, and `v_cmp_eq_f16` / `v_cmp_class_f16` with op_sel src0hi. For the compares I added a positive control (`v2 == v2` gives `ffffffff`). - LLVM rejects op_sel on these encodings for gfx1013 as well, so real console code shouldn't contain them. - The VOP3-native 16-bit ops do honour op_sel on silicon, and all their sweep op_sel variants pass. That's `v_add_nc_*16`, `v_max/min_[iu]16`, `v_lshlrev/lshrrev/ashrrev_*16`, `v_mul_lo_u16`, `v_mad_[iu]16`, the `*3_*16` forms, `v_fma_f16`, `v_pack_b32_f16` and `v_cvt_pknorm_*`. - So the rule is the opcode range. `vop3_opsel_ok()` is true for VOP3 opcodes 0x140–0x17f and 0x300–0x3ff, and every op_sel read outside VOP3P and interp now goes through it: `h16`, the dst-hi merge, the f16 transcendental path, f16 compares, `is16` and `mode::hsel`. ### 2. `v_cube*` treat denormal inputs as zero when picking the face - The major axis is chosen on magnitudes with denormals as zero. The returned `sc`/`tc`/`ma` values use the raw inputs. - `v_cubema` of a zero axis is +0. For example, `(-0, -denorm, -0)` gives `0x00000000`, not `0x80000000`. - The result is the same under all four f32 denormal modes. - This model matches all 588 recorded non-NaN cases of each of the four ops. The previous model matched 586–587. - One case isn't pinned by the record: a negative denormal as the chosen axis (its sign test). It keeps today's behaviour. ### 3. `v_sat_pk_u8_i16` writes the whole dword D[31:16] becomes 0. The translator merged it as a 16-bit result and kept the old high half. ### Tests - The sweep models (`ops_v.rs`) follow the three rules. - Three exec expectations change: - `vector_vop1` `v_sat_pk_u8_i16` now checks the full dword; - `vector_f16_preserves_high_half` case 3 (`v_add_f16` VOP3 with op_sel 0b1001) now expects the low half; - `exec_vop/vopc.rs` `add_opsel` and the `v_cmp_class_f16` op_sel cases now compare the low halves. | run | result | |---|---| | WARP, full `tombox-xshader` suite | every target ok; `tests/exec.rs` 189/189 | | Radeon RX 9060 XT, `tests/exec.rs` | 189/189 | | Radeon RX 9060 XT, `isa_sweep` | 553/556. The 3 are the known AMD-host SDWA byte-select + abs f16 case from #375, unrelated | | gfx1036 silicon vs sweep models | 542/550 (was 530) | The PR gate is clean. ### Not in this PR - **f32 `omod`, 7 mnemonics.** On silicon it is applied only when IEEE = 0 and f32 output denormals are flushed. That's the f16 rule from #363, and LLVM's condition for folding omod. The translator applies it unconditionally, and with `MODE_DEFAULT = 0xf0` the right fix is your call, so I wrote it up separately as #386. - **`v_mul_lo_i32`.** gfx10.3 doesn't have it, so it can't be measured here. Its low 32 bits are identical to `v_mul_lo_u32`'s, which matches silicon. - **`v_mac/mad/madak/madmk(_legacy)_f32`.** gfx10.3 removed these (and reuses two of the opcodes for `fma_legacy`), so they can't be checked on this iGPU. The silicon harness (exporter, runner and checker) is a separate PR. I'm still working out a record format that fits the repo. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Three translator rules disagreed with gfx1036 silicon (the ISA sweep's
own cases run as raw kernels):

- op_sel is honoured only by VOP3-native opcodes (0x140-0x17f,
  0x300-0x3ff). VOPC, VOP2 and VOP1 ops in the VOP3 encoding ignore the
  bits: they read the low source halves and write the low half (keeping
  the high half). LLVM rejects op_sel on those encodings for gfx1013 as
  well. vop3_opsel_ok() gates every op_sel read outside VOP3P/interp.
- v_cube{id,sc,tc,ma}_f32 pick the major axis with denormal inputs
  treated as zero and return raw coordinates; v_cubema of a zero axis is
  +0. 588 of 588 recorded non-NaN cases per op match.
- v_sat_pk_u8_i16 writes the full dword (D[31:16] = 0), so it is no
  longer merged as a 16-bit result.

The sweep reference models and three exec expectations follow.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:21:05 +00:00
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/385/head:github-bot/gh-385'
git switch 'github-bot/gh-385'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-385'
git switch 'github-bot/gh-385'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-385'
git switch 'github-bot/gh-385'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-385'
git switch 'main'
git merge --squash 'github-bot/gh-385'
git switch 'main'
git merge --ff-only 'github-bot/gh-385'
git switch 'main'
git merge 'github-bot/gh-385'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.