tombox-xshader: VOP3 op_sel, v_cube* denormals and v_sat_pk_u8_i16 as measured on RDNA2 silicon #385
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
library
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/omonkeyz--xbox-emulator!385
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-385"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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.
v_add/sub/subrev/mul/min/max_f16with op_sel src0hi/src1hi/dsthi,v_cvt_f16_f32with op_sel dst hi, andv_cmp_eq_f16/v_cmp_class_f16with op_sel src0hi. For the compares I added a positive control (v2 == v2givesffffffff).v_add_nc_*16,v_max/min_[iu]16,v_lshlrev/lshrrev/ashrrev_*16,v_mul_lo_u16,v_mad_[iu]16, the*3_*16forms,v_fma_f16,v_pack_b32_f16andv_cvt_pknorm_*.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,is16andmode::hsel.2.
v_cube*treat denormal inputs as zero when picking the facesc/tc/mavalues use the raw inputs.v_cubemaof a zero axis is +0. For example,(-0, -denorm, -0)gives0x00000000, not0x80000000.3.
v_sat_pk_u8_i16writes the whole dwordD[31:16] becomes 0. The translator merged it as a 16-bit result and kept the old high half.
Tests
ops_v.rs) follow the three rules.vector_vop1v_sat_pk_u8_i16now checks the full dword;vector_f16_preserves_high_halfcase 3 (v_add_f16VOP3 with op_sel 0b1001) now expects the low half;exec_vop/vopc.rsadd_opseland thev_cmp_class_f16op_sel cases now compare the low halves.tombox-xshadersuitetests/exec.rs189/189tests/exec.rsisa_sweepThe PR gate is clean.
Not in this PR
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 withMODE_DEFAULT = 0xf0the 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 tov_mul_lo_u32's, which matches silicon.v_mac/mad/madak/madmk(_legacy)_f32. gfx10.3 removed these (and reuses two of the opcodes forfma_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
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]>View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.