feat: 16-bit integer compares, s_pack_*_b32_b16 and global addtid in the RDNA 2 interpreter and HLSL — 1,113/1,490 #221
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!221
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/221/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 16:48 UTC · original
KainanP:feat/i16-compares-s-pack→main· +610 −39 · 24 files · 1 commits · closed without mergingChange
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=0x3800,1/(2π)=0x3118), not the f32 bits.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), and an SDWA scalar source that is an inline float.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 on a source that AMD's RDNA 2 XML sizes at 16 bits (both sources ofll, S0 oflh) is refused by name: the XML says 16 bits (so the half constant), LLVM declares the operands 32-bit (SOP2_32), so the value is not settled. The 32-bit sources (hh, S1 oflh) read the f32 constant.global_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,060 → 1,113 of 1,490 encodings (+48 compares, +3 packs, +2 addtid). The README still said 1,046 (70%); all 9 READMEs now say 1,113 (75%). Test count crosses 1,200 →1200+in the 9 languages.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
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.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 by revertingPrototypeScarlett/only: 61 failed).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 (p. 41-42, codes 240-248 are "Single, double, or half-precision inline floats", half1/(2π)=0x3118); §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".SIRegisterInfo.tdgivesVSrc_b16/SSrc_b16an immediate width of 16 andAMDGPUDisassembler::decodeFPImmedmaps width 16 togetInlineImmValF16(240 →0x3800… 248 →0x3118);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).Not measured on RDNA 2 hardware: the half-precision inline constants and the refused forms are taken from the documents above. A hardware measurement (for example through PortBridge) of
v_cmp_eq_u16 vcc, 0.5, v1and ofs_pack_ll_b32_b16 s0, 0.5, s1would settle the two refused/assumed constant cases.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). Inline float constants read their half-precision value for 16-bit operands (ISA section 6.2; LLVM decodeFPImmed width 16). VOP3 op_sel is refused by name (ISA section 6.2.5: OPSEL not usable on VOPC in VOP3), as is an SDWA scalar inline float source. 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 on a source AMD's RDNA 2 XML sizes at 16 bits is refused by name (LLVM declares it 32-bit: the constant's value is not settled). - 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,060 -> 1,113 of 1,490 encodings (README 70% -> 75%, it still showed 1,046); test count 1200+. 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]>@KainanP on GitHub · 2026-11-25 18:19 UTC · original
Rebased onto main
6eeda6cafter #215; operand types now come from the shared operand_float_flags; full suite 1260 passed / 17 skipped on RTX and WARP, 1258 passed / 19 skipped on Intel.AI use: Claude Code (Claude Opus 5.5).
@LooperSalty on GitHub · 2026-11-25 18:38 UTC · original
This PR now conflicts with main after the other merges (RDNA 2 interpreter/HLSL files). Please rebase on main and reopen. Thanks!
@KainanP on GitHub · 2026-11-25 18:59 UTC · original
Hardware measurement requested: https://github.com/akimfomin/PortBridge/issues/83
AI use: Claude Code (Claude Opus 5.5).
@KainanP on GitHub · 2026-11-25 19:15 UTC · original
Superseded by #226: rebased onto main
cf84f8das asked, with the inline-float handling corrected from hardware data (f32 pattern on 16-bit integer sources); full suite 1312/1312/1310 passed on RTX/WARP/Intel.AI use: Claude Code (Claude Opus 5.5).
Pull request closed