feat: 16-bit integer compares, s_pack_*_b32_b16 and global addtid in the RDNA 2 interpreter and HLSL — 1,113/1,490 #221

Closed
github-bot wants to merge 1 commit from gh-pr/221/head into gh-pr/221/base
Owner

@⁠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 merging

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:

  1. 16-bit integer compares v_cmp[x]_{lt,eq,le,gt,ne,ge}_{i16,u16} (there are no f/t forms for these types on RDNA 2), in VOPC, VOP3 and SDWA encodings: S0[15:0] against S1[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_cmp writes VCC (VOPC) or the SGPR (VOP3), v_cmpx writes EXEC only.
    • Inline float constants (codes 240-248) read their half-precision value on these 16-bit sources (0.5 = 0x3800, 1/(2π) = 0x3118), not the f32 bits.
    • Refused by name instead of guessed (rule 3): VOP3 with op_sel set (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.
    • DPP forms of VOPC stay refused, as for every VOPC on main.
  2. 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 of ll, S0 of lh) 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 of lh) read the f32 constant.
  3. global_load_dword_addtid / global_store_dword_addtid: no VGPR address, SADDR(64) + inst_offset + lane × 4. SADDR = off is refused by name (the ISA gives no address for it). In HLSL the address uses lane; wave64 programs accept it (lane = SV_GroupIndex 0-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.svg and traduction.svg are 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 by anyxboxx_gpu_run.exe --adaptateur:

default (NVIDIA GeForce RTX 4060 Laptop GPU, driver 32.0.16.1047): 1236 passed, 17 skipped (new files: 61 passed)
ANYXBOXX_GPU=warp (Microsoft Basic Render Driver 10.0.26100.9818): 1236 passed, 17 skipped (new files: 61 passed)
ANYXBOXX_GPU=Intel (Intel UHD Graphics 8086:a78b, driver 31.0.101.5445): 1234 passed, 19 skipped (new files: 61 passed)
python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools → All checks passed!

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

  • HLSL checked against the reference interpreter, byte for byte, on RTX, WARP and Intel UHD:
    • 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_0 selects, byte selects with sext, an SGPR destination), on low halves at the boundaries 0x0000/0x0001/0x7FFE/0x7FFF/0x8000/0x8001/0xFFFE/0xFFFF under junk high halves; the 51 masks are stored and compared.
    • inline half constants 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.
  • Interpreter expectations are written by hand: the signed and unsigned relation of each (S0, S1) pair (RELATIONS in tests/test_rdna2_exec_cmp16.py), the packed words of 0x12345678/0x9ABCDEF0, and the addtid addresses.
  • All test data is built in the tests; no external data.
  • Failure case: the 61 new tests in tests/test_rdna2_exec_cmp16.py and tests/test_rdna2_exec_pack_addtid.py all fail on main (checked by reverting PrototypeScarlett/ only: 61 failed).

Sources (labelled per docs/research/rdna2-sources.md; printed page numbers of the archived PDF, SHA-256 22aec03f…4795):

  • AMD, "RDNA 2" ISA, November 2020: table 61 "VOPC Compare Opcodes" (p. 156-159, 137 V_CMP_LT_I16 … 190 V_CMPX_GE_U16, "D[threadId] = (S0 < S1)"; table 60's hex ranges 0xA0-0xBF disagree with table 61 and LLVM, the opcodes here are LLVM's 0x89-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", half 1/(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").
  • AMD machine-readable ISA, amdgpu_isa_rdna2.xml (GPUOpen): V_CMP_*_I16/U16 sources have OperandSize 16; S_PACK_LL SSRC0/SSRC1 16, S_PACK_LH SSRC0 16 / SSRC1 32, S_PACK_HH 32/32; GLOBAL_LOAD_DWORD_ADDTID: "The memory base address is provided in a scalar register and the lane ID is used as an offset".
  • LLVM 20.1.8 (cross-check): SIRegisterInfo.td gives VSrc_b16/SSrc_b16 an immediate width of 16 and AMDGPUDisassembler::decodeFPImmed maps width 16 to getInlineImmValF16 (240 → 0x3800 … 248 → 0x3118); SOPInstructions.td declares the packs SOP2_32; llvm/test/MC/AMDGPU/gfx10_asm_vopc*.s has no op_sel on VOPC in VOP3 for GFX10, and encodes v_cmpx_*_e64 with vdst = 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, v1 and of s_pack_ll_b32_b16 s0, 0.5, s1 would settle the two refused/assumed constant cases.

Checklist

  • The PR covers a single reviewable behaviour. (Three small groups of 16-bit / lane-id data instructions in one PR, as one coverage step; I can split it if you prefer.)
  • A test fails without this change and passes with it.
  • The commands and results of each check are given above.
  • An unimplemented function returns an error (E_NOTIMPL), never a fake success. (Unsettled forms raise Untranslated / Untranslatable naming the instruction.)
  • README: the same change in all 9 languages (test_readme_sync.py checks it).
  • No game, console or SDK file, no key, no dump, no download link.
  • Findings drawn from a title: none.
  • Code taken from another project: none.

Made with AI assistance: Claude Code with Claude Opus 5.5, for KainanP.

🤖 Generated with Claude Code

**@⁠KainanP** on GitHub · 2026-11-25 16:48 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/221) `KainanP:feat/i16-compares-s-pack` → `main` · +610 −39 · 24 files · 1 commits · closed without merging ## 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: 1. **16-bit integer compares** `v_cmp[x]_{lt,eq,le,gt,ne,ge}_{i16,u16}` (there are no `f`/`t` forms for these types on RDNA 2), in VOPC, VOP3 and SDWA encodings: `S0[15:0]` against `S1[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_cmp` writes VCC (VOPC) or the SGPR (VOP3), `v_cmpx` writes EXEC only. - Inline float constants (codes 240-248) read their **half-precision** value on these 16-bit sources (`0.5` = `0x3800`, `1/(2π)` = `0x3118`), not the f32 bits. - Refused by name instead of guessed (rule 3): VOP3 with `op_sel` set (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. - DPP forms of VOPC stay refused, as for every VOPC on main. 2. **`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 of `ll`, S0 of `lh`) 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 of `lh`) read the f32 constant. 3. **`global_load_dword_addtid` / `global_store_dword_addtid`**: no VGPR address, `SADDR(64) + inst_offset + lane × 4`. `SADDR = off` is refused by name (the ISA gives no address for it). In HLSL the address uses `lane`; wave64 programs accept it (`lane` = `SV_GroupIndex` 0-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.svg` and `traduction.svg` are 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 by `anyxboxx_gpu_run.exe --adaptateur`: ``` default (NVIDIA GeForce RTX 4060 Laptop GPU, driver 32.0.16.1047): 1236 passed, 17 skipped (new files: 61 passed) ANYXBOXX_GPU=warp (Microsoft Basic Render Driver 10.0.26100.9818): 1236 passed, 17 skipped (new files: 61 passed) ANYXBOXX_GPU=Intel (Intel UHD Graphics 8086:a78b, driver 31.0.101.5445): 1234 passed, 19 skipped (new files: 61 passed) python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools → All checks passed! ``` 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 - HLSL checked against the reference interpreter, byte for byte, on RTX, WARP and Intel UHD: - `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_0` selects, byte selects with `sext`, an SGPR destination), on low halves at the boundaries `0x0000/0x0001/0x7FFE/0x7FFF/0x8000/0x8001/0xFFFE/0xFFFF` under junk high halves; the 51 masks are stored and compared. - inline half constants 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. - Interpreter expectations are written by hand: the signed and unsigned relation of each (S0, S1) pair (`RELATIONS` in `tests/test_rdna2_exec_cmp16.py`), the packed words of `0x12345678`/`0x9ABCDEF0`, and the addtid addresses. - All test data is built in the tests; no external data. - Failure case: the 61 new tests in `tests/test_rdna2_exec_cmp16.py` and `tests/test_rdna2_exec_pack_addtid.py` all fail on main (checked by reverting `PrototypeScarlett/` only: 61 failed). Sources (labelled per `docs/research/rdna2-sources.md`; printed page numbers of the archived PDF, SHA-256 `22aec03f…4795`): - AMD, "RDNA 2" ISA, November 2020: table 61 "VOPC Compare Opcodes" (p. 156-159, `137 V_CMP_LT_I16` … `190 V_CMPX_GE_U16`, "D[threadId] = (S0 < S1)"; table 60's hex ranges `0xA0-0xBF` disagree with table 61 and LLVM, the opcodes here are LLVM's `0x89-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", half `1/(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"). - AMD machine-readable ISA, `amdgpu_isa_rdna2.xml` (GPUOpen): `V_CMP_*_I16/U16` sources have `OperandSize` 16; `S_PACK_LL` SSRC0/SSRC1 16, `S_PACK_LH` SSRC0 16 / SSRC1 32, `S_PACK_HH` 32/32; `GLOBAL_LOAD_DWORD_ADDTID`: "The memory base address is provided in a scalar register and the lane ID is used as an offset". - LLVM 20.1.8 (cross-check): `SIRegisterInfo.td` gives `VSrc_b16`/`SSrc_b16` an immediate width of 16 and `AMDGPUDisassembler::decodeFPImmed` maps width 16 to `getInlineImmValF16` (240 → `0x3800` … 248 → `0x3118`); `SOPInstructions.td` declares the packs `SOP2_32`; `llvm/test/MC/AMDGPU/gfx10_asm_vopc*.s` has no `op_sel` on VOPC in VOP3 for GFX10, and encodes `v_cmpx_*_e64` with `vdst = 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, v1` and of `s_pack_ll_b32_b16 s0, 0.5, s1` would settle the two refused/assumed constant cases. ## Checklist - [x] The PR covers a single reviewable behaviour. (Three small groups of 16-bit / lane-id data instructions in one PR, as one coverage step; I can split it if you prefer.) - [x] A test fails without this change and passes with it. - [x] The commands and results of each check are given above. - [x] An unimplemented function returns an error (`E_NOTIMPL`), never a fake success. (Unsettled forms raise `Untranslated` / `Untranslatable` naming the instruction.) - [x] README: the same change in all 9 languages (`test_readme_sync.py` checks it). - [x] No game, console or SDK file, no key, no dump, no download link. - [x] Findings drawn from a title: none. - [x] Code taken from another project: none. Made with AI assistance: Claude Code with Claude Opus 5.5, for KainanP. 🤖 Generated with [Claude Code](https://claude.com/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]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:38:16 +00:00
github-bot closed this pull request 2026-11-26 05:38:16 +00:00
Author
Owner

@⁠KainanP on GitHub · 2026-11-25 18:19 UTC · original

Rebased onto main 6eeda6c after #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).

**@⁠KainanP** on GitHub · 2026-11-25 18:19 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/221#issuecomment-7170759327) Rebased onto main 6eeda6c after #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)._
Author
Owner

@⁠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!

**@⁠LooperSalty** on GitHub · 2026-11-25 18:38 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/221#issuecomment-7171198922) This PR now conflicts with main after the other merges (RDNA 2 interpreter/HLSL files). Please rebase on main and reopen. Thanks!
Author
Owner

@⁠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 18:59 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/221#issuecomment-7171676582) Hardware measurement requested: https://github.com/akimfomin/PortBridge/issues/83 _AI use: Claude Code (Claude Opus 5.5)._
Author
Owner

@⁠KainanP on GitHub · 2026-11-25 19:15 UTC · original

Superseded by #226: rebased onto main cf84f8d as 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).

**@⁠KainanP** on GitHub · 2026-11-25 19:15 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/221#issuecomment-7172044432) Superseded by #226: rebased onto main cf84f8d as 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

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