feat: 16-bit integer compares, s_pack_*_b32_b16 and global addtid in the RDNA 2 interpreter and HLSL — 1,138/1,490 #226
No reviewers
Labels
No labels
accessibility
bloqué : binaire console
bug
chargeur
console-dll
cpu
documentation
duplicate
enhancement
good first issue
gpu
help wanted
invalid
performance
question
runtime-gdk
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/LooperSalty--AnyXboxX!226
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/226/head"
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?
@KainanP on GitHub · 2026-11-25 19:15 UTC · original
KainanP:feat/i16-compares-s-pack→main· +582 −39 · 21 files · 1 commits · merged 2026-11-25 19:38 UTCSupersedes #221 (closed by the maintainer for conflicts; rebased onto main
cf84f8das asked)The import lines of
rdna2_exec.py,rdna2_exec_vop3.pyandrdna2_hlsl.pynow carry both the f16 modules (#218, #219) and the 16-bit compare module; README numbers recomputed.Change
Three groups of RDNA 2 instructions that the reference interpreter and the HLSL recompiler refused until now, all small 16-bit or lane-id data operations:
v_cmp[x]_{lt,eq,le,gt,ne,ge}_{i16,u16}(there are nof/tforms for these types on RDNA 2), in VOPC, VOP3 and SDWA encodings:S0[15:0]againstS1[15:0], signed or unsigned; the high halves are ignored. The mask is written whole like the 32-bit compares (inactive lanes cleared, ISA §3.9);v_cmpwrites VCC (VOPC) or the SGPR (VOP3),v_cmpxwrites EXEC only.0.5=0x3F000000compares as0x0000,1/(2π)=0x3E22F983as0xF983), not the f16 value. In SDWA the pattern goes throughsrc_sellike a register. See "Inline floats on 16-bit integer sources" below; the first version of this PR used the f16 value and is changed by hardware data.op_selset (ISA §6.2.5 says OPSEL is not usable for VOPC in VOP3 encoding, so which half the hardware reads is not documented).s_pack_ll_b32_b16/s_pack_lh_b32_b16/s_pack_hh_b32_b16(SOP2 50-52):{S1[15:0], S0[15:0]},{S1[31:16], S0[15:0]},{S1[31:16], S0[31:16]}, SCC unchanged. An inline float is its f32 pattern on every source, including those AMD's RDNA 2 XML sizes at 16 bits (both sources ofll, S0 oflh): LLVM declares the packsSOP2_32, and the 16-bit integer VALU sources measured on gfx1036 read the f32 bits. This is assumed fors_pack(not measured directly; the earlier version refused it). An inline float on a sourceglobal_load_dword_addtid/global_store_dword_addtid: no VGPR address,SADDR(64) + inst_offset + lane × 4.SADDR = offis refused by name (the ISA gives no address for it). In HLSL the address useslane; wave64 programs accept it (lane=SV_GroupIndex0-63, the TID in the 64-lane wave), and graphics shaders using it take the multi-lane path (it is listed with the other lane-dependent operations).Coverage of the reference interpreter (
rdna2_exec.coverage()): 1,085 → 1,138 of 1,490 encodings (+48 compares, +3 packs, +2 addtid); all 9 READMEs go from 73% to 76%. The suite collects 1,329 tests, so the 9 READMEs say1300+.docs/images/carte-avancee.svgandtraduction.svgare not regenerated: they need a test package and still show 521/1487 from long before this PR (none of the recent RDNA 2 PRs regenerated them either).Linked issue: none (follows the RDNA 2 interpreter work of #133-#151).
Verification
Full suite on this branch rebased onto
d3344ed(cf84f8donly adds #225, Rust files underthird_party/victory; after the final rebasetest_readme_sync.pyand ruff pass again and the suite still collects 1,329 tests). Runtime built from this branch (cmake -S runtime -B runtime/build -A x64,--config Release),ANYXBOXX_RUNTIME=<worktree>/runtime/build/bin. Adapters as reported byanyxboxx_gpu_run.exe --adaptateur:The skips are the usual ones on this machine (Rust crates and TomBox DLLs not built, no Vulkan SDK for
spirv-as; Intel also skips the FP64 tests).Oracle and test data
test_16_bit_compares_match_interpreter_on_gpu: all 48 compare encodings (12 ×v_cmp/v_cmpx× VOPC/VOP3) under a partial EXEC (0x0F0FF0F3), plus three SDWA compares (WORD_1/WORD_0selects, byte selects withsext, an SGPR destination), on low halves at the boundaries0x0000/0x0001/0x7FFE/0x7FFF/0x8000/0x8001/0xFFFE/0xFFFFunder junk high halves; the 51 masks are stored and compared.v_cmpx, and SDWA withsrc0_sel) and literals, a wave64 program (VOPC/VOP3/cmpx with a partial 64-bit EXEC), the packs (with SCC kept), and addtid loads and stores in wave32 and wave64 under partial EXEC.RELATIONSintests/test_rdna2_exec_cmp16.py), the packed words of0x12345678/0x9ABCDEF0, and the addtid addresses.tests/test_rdna2_exec_cmp16.pyandtests/test_rdna2_exec_pack_addtid.pyall fail on main (checked with main'sPrototypeScarlett/: the compare file does not import, the pack/addtid file has 11 of 11 CPU tests failing).Sources (labelled per
docs/research/rdna2-sources.md; printed page numbers of the archived PDF, SHA-25622aec03f…4795):137 V_CMP_LT_I16…190 V_CMPX_GE_U16, "D[threadId] = (S0 < S1)"; table 60's hex ranges0xA0-0xBFdisagree with table 61 and LLVM, the opcodes here are LLVM's0x89-0xBE); §3.9 (p. 19-20, "VCC is fully written"); §6.2.5 "OPSEL Field Restrictions" (p. 44); §12.1 SOP2 opcodes 50-52 (p. 106); §12.18.3 GLOBAL opcodes 22-23 (p. 230, "memory_Addr = sgpr_addr(64) + inst_offset(12) + tid*4").amdgpu_isa_rdna2.xml(GPUOpen):V_CMP_*_I16/U16sources haveOperandSize16;S_PACK_LLSSRC0/SSRC1 16,S_PACK_LHSSRC0 16 / SSRC1 32,S_PACK_HH32/32;GLOBAL_LOAD_DWORD_ADDTID: "The memory base address is provided in a scalar register and the lane ID is used as an offset".SOPInstructions.tddeclares the packsSOP2_32;llvm/test/MC/AMDGPU/gfx10_asm_vopc*.shas noop_selon VOPC in VOP3 for GFX10, and encodesv_cmpx_*_e64withvdst = exec_lo(used in the tests).Inline floats on 16-bit integer sources
SIInstrInfo::isInlineConstant, caseOPERAND_REG_*_INT16: "in the case of 16-bit integer operations, the "floating point" values appear to not work. It seems read the low 16-bits of 32-bit immediates" (bugzilla 46302). Its disassembler still prints the f16 value (decodeFPImmedwidth 16), which is what the first version of this PR followed.v_cvt_f16_u16_sdwa d, 1.0 src0_sel:WORD_1converts0x3F80(the f32 pattern, then the select), and an inline float in S2 ofv_mad_i32_i16adds its f32 pattern (1.0adds0x3F80): design.md L331, design.md L359.s_packthemselves are not measured. The direct case is requested as PortBridge #83 (VOPC/VOP3v_cmp_eq_u16with 0.5, -4.0 and 1/(2π), and fives_packforms); its expected outputs under the f32-bits rule are what this PR now gives.Checklist
E_NOTIMPL), never a fake success. (Unsettled forms raiseUntranslated/Untranslatablenaming the instruction.)test_readme_sync.pychecks it).Made with AI assistance: Claude Code with Claude Opus 5.5, for KainanP.
🤖 Generated with Claude Code
- v_cmp[x]_{lt,eq,le,gt,ne,ge}_{i16,u16} in VOPC, VOP3 and SDWA: S0[15:0] against S1[15:0], signed or unsigned, mask fully written (inactive lanes cleared). An inline float constant is its float32 pattern, of which the compare reads bits 15:0 (0.5 compares as 0x0000): LLVM's SIInstrInfo notes that 16-bit integer operations read the low 16 bits of the 32-bit immediate, and on gfx1036 v_cvt_f16_u16_sdwa and S2 of v_mad_i32_i16 read the float32 bits (ubiquitarianism/leonida docs/design.md at 9f9a7c5, lines 331 and 359); the compares themselves are requested as PortBridge #83. In SDWA the pattern goes through src_sel like a register. VOP3 op_sel is refused by name (ISA section 6.2.5: OPSEL not usable on VOPC in VOP3). The SDWA forms take their operand types from the shared operand_float_flags (#215): 16-bit integer sources, so sext applies and neg/abs do not. - s_pack_ll/lh/hh_b32_b16 (SOP2 50-52): D = {S1 half, S0 half}, SCC kept. An inline float is its float32 pattern on every source, also those AMD's RDNA 2 XML sizes at 16 bits: LLVM declares the packs SOP2_32, and the 16-bit integer VALU sources measured on gfx1036 read the float32 bits (assumed for s_pack, PortBridge #83). - global_load/store_dword_addtid: address = SADDR(64) + offset + lane x 4 (ISA section 12.18.3); SADDR off refused by name. Marked lane-dependent for graphics shaders; allowed in wave64 HLSL (lane = SV_GroupIndex). Interpreter coverage 1,085 -> 1,138 of 1,490 encodings (README 73% -> 76%); test count 1300+. New tests in tests/test_rdna2_exec_cmp16.py and tests/test_rdna2_exec_pack_addtid.py (62 tests, all failing without this change), with byte-for-byte GPU parity in wave32 and wave64. Co-Authored-By: Claude Opus 5.5 <[email protected]>github-bot referenced this pull request2026-11-26 05:40:36 +00:00