rdna2_decode: decode 16-bit integer inline constants 240..248 as binary16 hex (DECODE-VOP16-INT-INLINE) #1525

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

@⁠jarvixaiassistant-glitch on GitHub · 2026-11-25 03:26 UTC · original
jarvixaiassistant-glitch:fix/decode-vop16-int-inline → main · +172 −7 · 2 files · 1 commits · open

Claimed in the coordination issue as: DECODE-VOP16-INT-INLINE

What and why

On RDNA2, inline constant codes 240..248 (0.5, -0.5, 1.0, -1.0, 2.0, -2.0, 4.0, -4.0, 1/(2*pi)) on scalar 16-bit integer operands (LLVM OPERAND_REG_IMM_INT16 / OPERAND_REG_INLINE_C_INT16) deliver the 16-bit binary16 bit patterns (0x3800, 0xB800, 0x3C00, 0xBC00, 0x4000, 0xC000, 0x4400, 0xC400, 0x3118), which LLVM prints as hex integer immediates rather than float literals.

Previously tools/rdna2_decode.py:_src() unconditionally emitted {k: fimm, ...} for codes 240..248 even on 16-bit integer VOP1/VOPC/VOP3 instructions, causing 126 mismatches against LLVM 21.1.8's GFX10 disassembler test vectors and producing wrong 32-bit float bit patterns if translated through --backend python.

This PR:

  1. Adds _INLINE_INT16, _INT16_ALL_SRCS, _INT16_SRC01_ONLY, and _src_is_int16(name, src_idx) in tools/rdna2_decode.py, emitting {k: imm, v: _INLINE_INT16[code]} on 16-bit integer VOP1/VOPC/VOP3 sources while carefully preserving:
    • Mixed-width v_mad_i32_i16 / v_mad_u32_u16 SRC2 (32-bit, stays fimm).
    • v_sat_pk_u8_i16 and VOP3P V2INT16 operands.
    • Hardware-verified SDWA 16-bit ops (ps_sdwa_f16_const.asm), which take 32-bit float bits on RDNA2 and remain fimm.
  2. Adds targeted unit tests + an end-to-end rdna2_decode -> rdna2spirv -> spirv_mini_interp test in tests/test_rdna2_decode.py.

Tested

All synthetic CPU/stdlib/docs/CI checks on Windows 11 x64, Python 3.12.14, Khronos SPIRV-Tools (LEONIDA_REQUIRE_SPIRV_TOOLS=1), no game data, no llvm-mc installed locally:

  • python -I tests/test_rdna2_decode.py -v — 21/21 passed (1 skipped: llvm-mc not installed)
  • python -I tests/test_shader_disasm.py — 31/31 passed
  • python -I tests/test_ci_registration.py — 16/16 passed
  • python -I scripts/check_no_game_data.py — passed
  • python -m compileall -q tools/rdna2_decode.py tests/test_rdna2_decode.py — passed
  • Cross-check against LLVM 21.1.8 GFX10 disassembler vectors: 126 mismatches -> 0 (including gfx10_vopc.txt 1,438/1,438 exact)

GPUs tested: n/a (pure-Python ISA binary decoder + CPU SPIR-V interpreter round-trip only)

AI-assisted: yes (JARVIX multi-model team: Antigravity + DeepSeek V4 Flash)

Checklist

  • Based on current main (1cfc29af7) and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md).
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (N/A — pure-Python ISA decoder inline-constant parity with LLVM; no translator rule changed.)
**@⁠jarvixaiassistant-glitch** on GitHub · 2026-11-25 03:26 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1525) `jarvixaiassistant-glitch:fix/decode-vop16-int-inline` → `main` · +172 −7 · 2 files · 1 commits · open Claimed in the coordination issue as: DECODE-VOP16-INT-INLINE ### What and why On RDNA2, inline constant codes `240..248` (`0.5`, `-0.5`, `1.0`, `-1.0`, `2.0`, `-2.0`, `4.0`, `-4.0`, `1/(2*pi)`) on scalar 16-bit integer operands (LLVM `OPERAND_REG_IMM_INT16` / `OPERAND_REG_INLINE_C_INT16`) deliver the 16-bit binary16 bit patterns (`0x3800`, `0xB800`, `0x3C00`, `0xBC00`, `0x4000`, `0xC000`, `0x4400`, `0xC400`, `0x3118`), which LLVM prints as hex integer immediates rather than float literals. Previously `tools/rdna2_decode.py:_src()` unconditionally emitted `{k: fimm, ...}` for codes `240..248` even on 16-bit integer VOP1/VOPC/VOP3 instructions, causing **126 mismatches** against LLVM 21.1.8's GFX10 disassembler test vectors and producing wrong 32-bit float bit patterns if translated through `--backend python`. This PR: 1. Adds `_INLINE_INT16`, `_INT16_ALL_SRCS`, `_INT16_SRC01_ONLY`, and `_src_is_int16(name, src_idx)` in `tools/rdna2_decode.py`, emitting `{k: imm, v: _INLINE_INT16[code]}` on 16-bit integer VOP1/VOPC/VOP3 sources while carefully preserving: - Mixed-width `v_mad_i32_i16` / `v_mad_u32_u16` `SRC2` (32-bit, stays `fimm`). - `v_sat_pk_u8_i16` and VOP3P `V2INT16` operands. - Hardware-verified `SDWA` 16-bit ops (`ps_sdwa_f16_const.asm`), which take 32-bit float bits on RDNA2 and remain `fimm`. 2. Adds targeted unit tests + an end-to-end `rdna2_decode -> rdna2spirv -> spirv_mini_interp` test in `tests/test_rdna2_decode.py`. ### Tested All synthetic CPU/stdlib/docs/CI checks on Windows 11 x64, Python 3.12.14, Khronos SPIRV-Tools (`LEONIDA_REQUIRE_SPIRV_TOOLS=1`), no game data, no `llvm-mc` installed locally: - `python -I tests/test_rdna2_decode.py -v` — 21/21 passed (1 skipped: `llvm-mc` not installed) - `python -I tests/test_shader_disasm.py` — 31/31 passed - `python -I tests/test_ci_registration.py` — 16/16 passed - `python -I scripts/check_no_game_data.py` — passed - `python -m compileall -q tools/rdna2_decode.py tests/test_rdna2_decode.py` — passed - Cross-check against LLVM 21.1.8 GFX10 disassembler vectors: **126 mismatches -> 0** (including `gfx10_vopc.txt` **1,438/1,438 exact**) GPUs tested: n/a (pure-Python ISA binary decoder + CPU SPIR-V interpreter round-trip only) AI-assisted: yes (JARVIX multi-model team: Antigravity + DeepSeek V4 Flash) ### Checklist - [x] Based on current `main` (`1cfc29af7`) and merges cleanly. - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md). - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. *(N/A — pure-Python ISA decoder inline-constant parity with LLVM; no translator rule changed.)*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:55:22 +00:00
Author
Owner

@⁠ytsodacan on GitHub · 2026-11-25 03:34 UTC · original · edited 2026-11-25 03:45 UTC

[KEEP]

  • The change in tools/rdna2_decode.py (_INLINE_INT16, _src_is_int16, applied to VOP1/VOPC/VOP3 sources, with v_mad_i32_i16/v_mad_u32_u16 SRC2 and SDWA kept as float) is well reasoned and has a thorough test in tests/test_rdna2_decode.py including an end-to-end decode -> spirv -> interpreter check.
  • CI is still pending (windows, macos, linux-gpu-tools, no-game-data, change-scope); the PR is mergeable. The LLVM cross-check (126 -> 0 mismatches) was not run in the author's environment for the llvm-mc test (skipped), so CI results matter here.
  • #1524 also edits tools/rdna2_decode.py and tests/test_rdna2_decode.py (different hunks); rebase and re-run after whichever lands first.
  • Likely a MERGE once CI is green.
**@⁠ytsodacan** on GitHub · 2026-11-25 03:34 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1525#issuecomment-7152037944) · edited 2026-11-25 03:45 UTC **[KEEP]** - The change in `tools/rdna2_decode.py` (`_INLINE_INT16`, `_src_is_int16`, applied to VOP1/VOPC/VOP3 sources, with `v_mad_i32_i16`/`v_mad_u32_u16` SRC2 and SDWA kept as float) is well reasoned and has a thorough test in `tests/test_rdna2_decode.py` including an end-to-end decode -> spirv -> interpreter check. - CI is still pending (`windows`, `macos`, `linux-gpu-tools`, `no-game-data`, `change-scope`); the PR is mergeable. The LLVM cross-check (126 -> 0 mismatches) was not run in the author's environment for the llvm-mc test (skipped), so CI results matter here. - #1524 also edits `tools/rdna2_decode.py` and `tests/test_rdna2_decode.py` (different hunks); rebase and re-run after whichever lands first. - Likely a MERGE once CI is green.
Author
Owner

@⁠tiguan26 on GitHub · 2026-11-25 03:54 UTC · original · approved these changes

Approving. Merged into current main with no conflicts; the PR's tests pass (Linux, Python 3.13). The binary16 patterns are right (0.5 = 0x3800, -0.5 = 0xB800, 1.0 = 0x3C00, 2.0 = 0x4000, 4.0 = 0x4400, 1/(2*pi) = 0x3118) and only apply to 16-bit integer operands, so f16 and 32-bit operands keep their float spelling.

AI-assisted (Claude).

**@⁠tiguan26** on GitHub · 2026-11-25 03:54 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1525#pullrequestreview-6051626351) · **approved these changes** Approving. Merged into current main with no conflicts; the PR's tests pass (Linux, Python 3.13). The binary16 patterns are right (0.5 = 0x3800, -0.5 = 0xB800, 1.0 = 0x3C00, 2.0 = 0x4000, 4.0 = 0x4400, 1/(2*pi) = 0x3118) and only apply to 16-bit integer operands, so f16 and 32-bit operands keep their float spelling. AI-assisted (Claude).
This pull request has changes conflicting with the target branch.
  • tests/test_rdna2_decode.py
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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