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

Merged
jarvixaiassistant-glitch merged 1 commit from upstream-pr/1525 into main 2026-11-28 19:39:52 +00:00
jarvixaiassistant-glitch commented 2026-11-25 03:26:16 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by jarvixaiassistant-glitch on 2026-11-25T03:26:16Z.


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.)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5484576460 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1525). Originally posted by [jarvixaiassistant-glitch](https://github.com/jarvixaiassistant-glitch) on 2026-11-25T03:26:16Z. --- 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.)*
ytsodacan commented 2026-11-25 03:34:17 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ytsodacan on 2026-11-25T03:34:17Z.


[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.
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7152037944 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1525#issuecomment-7152037944). Originally posted by [ytsodacan](https://github.com/ytsodacan) on 2026-11-25T03:34:17Z. --- **[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.
tiguan26 commented 2026-11-25 03:54:08 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-25T03:54:08Z.

Review: APPROVED


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).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6051626351 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1525#pullrequestreview-6051626351). Originally posted by [tiguan26](https://github.com/tiguan26) on 2026-11-25T03:54:08Z. **Review:** APPROVED --- 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).
MoonEyes commented 2026-11-28 02:52:22 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T02:52:22Z.


Hi @jarvixaiassistant-glitch, thanks for this pull request. It currently conflicts with main (conflicting file(s): tests/test_rdna2_decode.py), so it carries the needs rebase label. CONTRIBUTING.md asks authors to rebase their branch on main; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7232647824 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1525#issuecomment-7232647824). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T02:52:22Z. --- Hi @jarvixaiassistant-glitch, thanks for this pull request. It currently conflicts with `main` (conflicting file(s): `tests/test_rdna2_decode.py`), so it carries the `needs rebase` label. CONTRIBUTING.md asks authors to rebase their branch on `main`; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here. AI-assisted (Claude Code, Claude Opus 5.5).
jarvixaiassistant-glitch commented 2026-11-28 09:18:52 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by jarvixaiassistant-glitch on 2026-11-28T09:18:52Z.


Hi @MoonEyes — rebased cleanly onto latest main (493867366) and resolved the test-append conflict in tests/test_rdna2_decode.py (preserving both #633's MIMG test and this PR's VOP16 inline-constant test).

Verified locally after rebase:

  • python -I tests/test_rdna2_decode.py: 23/23 passed (including LLVM-MC cross-check)
  • python -I tests/test_runner_calls_all_tests.py: 3/3 passed
  • python scripts/check_no_game_data.py & scripts/check_bidi_controls.py: clean

Ready for fresh CI and review!

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7237158277 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1525#issuecomment-7237158277). Originally posted by [jarvixaiassistant-glitch](https://github.com/jarvixaiassistant-glitch) on 2026-11-28T09:18:52Z. --- Hi @MoonEyes — rebased cleanly onto latest `main` (`493867366`) and resolved the test-append conflict in `tests/test_rdna2_decode.py` (preserving both `#633`'s MIMG test and this PR's VOP16 inline-constant test). Verified locally after rebase: - `python -I tests/test_rdna2_decode.py`: **23/23 passed** (including LLVM-MC cross-check) - `python -I tests/test_runner_calls_all_tests.py`: **3/3 passed** - `python scripts/check_no_game_data.py` & `scripts/check_bidi_controls.py`: **clean** Ready for fresh CI and review!
MoonEyes commented 2026-11-28 19:39:49 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T19:39:49Z.


Red/green: tests/test_rdna2_decode.py fails 42 assertions on main (16-bit integer inline constants 240..248 decoded as floats) and passes with the PR (cloud run on main 7daa4a4; on Windows 43 to 1 failure, the remaining llvm-mc parity failure already fails on main).
Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main 7daa4a4a5 in GitHub Actions: no new failure.
AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7244712728 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1525#issuecomment-7244712728). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T19:39:49Z. --- Red/green: tests/test_rdna2_decode.py fails 42 assertions on main (16-bit integer inline constants 240..248 decoded as floats) and passes with the PR (cloud run on main 7daa4a4; on Windows 43 to 1 failure, the remaining llvm-mc parity failure already fails on main). Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main 7daa4a4a5 in GitHub Actions: no new failure. AI-assisted (Claude Code, Claude Opus 5.5)
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!1525
No description provided.