rdna2_decode: decode GFX10 special sources 235..239 and f64 32-bit literals (DECODE-F64-LIT-AND-SPECIAL-SRCS) #1959

Closed
ShotTechOp wants to merge 1 commit from upstream-pr/1959 into main
ShotTechOp commented 2026-11-25 16:46:56 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ShotTechOp on 2026-11-25T16:46:56Z.


Claimed in #1608 as DECODE-F64-LIT-AND-SPECIAL-SRCS.

What and why

Two bugs in the pure-Python RDNA2 binary decoder (tools/rdna2_decode.py) broke parity with shader_ir.parse_line() and miscompiled or rejected instructions fed into tools/rdna2spirv.py:

  1. GFX10 special source operands 235..239 decoded as raw (src_235..src_239):
    • AMD RDNA2 ISA Table 21 defines source codes 235..239 as src_shared_base, src_shared_limit, src_private_base, src_private_limit, and src_pops_exiting_wave_id (all already listed in shader_ir.SPECIAL).
    • _src() only handled 251..254, so POPS pixel shaders using src_pops_exiting_wave_id (239, handled in tools/rdna2spirv.py:531) decoded as {"k": "raw", "t": "src_239"} and failed translation with Unsupported: operand src_239.
  2. Binary64 (f64) 32-bit literal sources (code == 255) lost their f64_literal tag and hex formatting:
    • tools/rdna2_isa_tables.py already marks binary64 source operands with type 'f64' across VOP1, VOPC, and VOP3 (while keeping non-f64 operands such as v_ldexp_f64 SRC1, v_cmp_class_f64 SRC1, and v_cvt_f64_i32 SRC0 typed 'i').
    • Previously _src(255, ...) returned plain {"k": "imm", "v": lit} without f64_literal: True / literal_hex_digits, so direct decode_bytes() input into rdna2spirv.f64_source_words() placed a 32-bit literal such as 0x40180000 (6.0) in bits [31:0] instead of bits [63:32].
    • In _format_operand(), values < 100 (such as 0x0, 0x1, 0x40) formatted in decimal (1) instead of hex (0x1), erasing the distinction between a trailing 32-bit literal ((0, 1)) and an inline integer ((1, 0)) when disasm_bytes() output is parsed by shader_ir.parse_line().

Changes

  • tools/rdna2_decode.py:
    • Added _SPECIAL_SRCS mapping codes 235..239 and 251..254 to their shader_ir special operand names.
    • Threaded f64=(typ == "f64") from the VOP1, VOPC, and VOP3 decode paths into _src(), setting f64_literal: True and literal_hex_digits: len(f"{val:x}") on code == 255 literals for 'f64' sources.
    • Updated _format_operand() to format f64_literal immediates in hex (0x...) regardless of magnitude so disasm_bytes() -> shader_ir.parse_line() round-trips bit-identically with decode_bytes().
  • tests/test_rdna2_decode.py:
    • Added test_gfx10_special_source_operands_235_to_239 (SOP1/VOP1/VOP3 decode + disasm_bytes round-trip + end-to-end POPS pixel shader translation & spirv_asm.assemble check for both text and direct decode_bytes paths).
    • Added test_f64_literal_sources_decode_format_and_translate (VOP1/VOPC/VOP3 decode + small < 100 hex formatting + VOP3 neg/abs modifiers + negative controls for non-f64 operands + end-to-end rdna2spirv + spirv_mini_interp execution of v_frexp_exp_i32_f64_e32 and v_frexp_mant_f64_e32 via both disasm_bytes and direct decode_bytes).

Verification

  • AI-assisted: yes.
  • Environment: Windows 11 (Python 3.12.10, CPU-only / spirv_mini_interp; no GPU, LLVM, or SPIRV-Tools installed locally).
  • Tests run (all GREEN):
    • python -I tests/test_rdna2_decode.py -v (21 passed, 1 skipped llvm-mc not available)
    • python -I tests/test_shader_ir_parse.py
    • python -m unittest discover -s tests/semantic -p test_library_compute_forms.py
    • python -m unittest discover -s tests/semantic -p test_vop3_const_mods.py
    • python -I tests/test_text_write_line_endings.py
    • python -m compileall -q tools/rdna2_decode.py tests/test_rdna2_decode.py
    • python -I scripts/check_no_game_data.py tools/rdna2_decode.py tests/test_rdna2_decode.py
    • git diff --check
  • Negative control against origin/main (tools/rdna2_decode.py at 9e7720c): both new test methods fail on origin/main (13 subtest/assertion failures + Unsupported: operand src_239 on POPS translation, and wrong v_frexp_*_f64 outputs on both disasm_bytes 0x1 and direct decode_bytes 0x40180000).
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5495401290 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1959). Originally posted by [ShotTechOp](https://github.com/ShotTechOp) on 2026-11-25T16:46:56Z. --- Claimed in #1608 as `DECODE-F64-LIT-AND-SPECIAL-SRCS`. ### What and why Two bugs in the pure-Python RDNA2 binary decoder (`tools/rdna2_decode.py`) broke parity with `shader_ir.parse_line()` and miscompiled or rejected instructions fed into `tools/rdna2spirv.py`: 1. **GFX10 special source operands `235..239` decoded as `raw` (`src_235`..`src_239`)**: - AMD RDNA2 ISA Table 21 defines source codes `235..239` as `src_shared_base`, `src_shared_limit`, `src_private_base`, `src_private_limit`, and `src_pops_exiting_wave_id` (all already listed in `shader_ir.SPECIAL`). - `_src()` only handled `251..254`, so POPS pixel shaders using `src_pops_exiting_wave_id` (`239`, handled in `tools/rdna2spirv.py:531`) decoded as `{"k": "raw", "t": "src_239"}` and failed translation with `Unsupported: operand src_239`. 2. **Binary64 (`f64`) 32-bit literal sources (`code == 255`) lost their `f64_literal` tag and hex formatting**: - `tools/rdna2_isa_tables.py` already marks binary64 source operands with type `'f64'` across `VOP1`, `VOPC`, and `VOP3` (while keeping non-f64 operands such as `v_ldexp_f64` `SRC1`, `v_cmp_class_f64` `SRC1`, and `v_cvt_f64_i32` `SRC0` typed `'i'`). - Previously `_src(255, ...)` returned plain `{"k": "imm", "v": lit}` without `f64_literal: True` / `literal_hex_digits`, so direct `decode_bytes()` input into `rdna2spirv.f64_source_words()` placed a 32-bit literal such as `0x40180000` (`6.0`) in bits `[31:0]` instead of bits `[63:32]`. - In `_format_operand()`, values `< 100` (such as `0x0`, `0x1`, `0x40`) formatted in decimal (`1`) instead of hex (`0x1`), erasing the distinction between a trailing 32-bit literal (`(0, 1)`) and an inline integer (`(1, 0)`) when `disasm_bytes()` output is parsed by `shader_ir.parse_line()`. ### Changes - **`tools/rdna2_decode.py`**: - Added `_SPECIAL_SRCS` mapping codes `235..239` and `251..254` to their `shader_ir` special operand names. - Threaded `f64=(typ == "f64")` from the `VOP1`, `VOPC`, and `VOP3` decode paths into `_src()`, setting `f64_literal: True` and `literal_hex_digits: len(f"{val:x}")` on `code == 255` literals for `'f64'` sources. - Updated `_format_operand()` to format `f64_literal` immediates in hex (`0x...`) regardless of magnitude so `disasm_bytes()` -> `shader_ir.parse_line()` round-trips bit-identically with `decode_bytes()`. - **`tests/test_rdna2_decode.py`**: - Added `test_gfx10_special_source_operands_235_to_239` (SOP1/VOP1/VOP3 decode + `disasm_bytes` round-trip + end-to-end POPS pixel shader translation & `spirv_asm.assemble` check for both text and direct `decode_bytes` paths). - Added `test_f64_literal_sources_decode_format_and_translate` (VOP1/VOPC/VOP3 decode + small `< 100` hex formatting + VOP3 `neg`/`abs` modifiers + negative controls for non-`f64` operands + end-to-end `rdna2spirv` + `spirv_mini_interp` execution of `v_frexp_exp_i32_f64_e32` and `v_frexp_mant_f64_e32` via both `disasm_bytes` and direct `decode_bytes`). ### Verification - **AI-assisted**: yes. - **Environment**: Windows 11 (Python 3.12.10, CPU-only / `spirv_mini_interp`; no GPU, LLVM, or SPIRV-Tools installed locally). - **Tests run (all GREEN)**: - `python -I tests/test_rdna2_decode.py -v` (21 passed, 1 skipped `llvm-mc not available`) - `python -I tests/test_shader_ir_parse.py` - `python -m unittest discover -s tests/semantic -p test_library_compute_forms.py` - `python -m unittest discover -s tests/semantic -p test_vop3_const_mods.py` - `python -I tests/test_text_write_line_endings.py` - `python -m compileall -q tools/rdna2_decode.py tests/test_rdna2_decode.py` - `python -I scripts/check_no_game_data.py tools/rdna2_decode.py tests/test_rdna2_decode.py` - `git diff --check` - **Negative control against `origin/main` (`tools/rdna2_decode.py` at `9e7720c`)**: both new test methods fail on `origin/main` (13 subtest/assertion failures + `Unsupported: operand src_239` on POPS translation, and wrong `v_frexp_*_f64` outputs on both `disasm_bytes` `0x1` and direct `decode_bytes` `0x40180000`).
kirigayakazima commented 2026-11-28 05:45:07 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-28T05:45:07Z.


#1959 | head d8db285002cd76fa2b8b0bfa084caa68836a896b | python -I tests/test_rdna2_decode.py | red: FAILED (failures=13, errors=1, skipped=1; AssertionError + rdna2spirv.Unsupported) | green: 24/24 OK (skipped=1 pre-existing: test_parity_with_llvm_mc_on_shader_fixtures, 0.072s) | full suite: 513/521 stdlib passed, 0 new failures vs main 8994000b08 | Windows 11, Python 3.14.7, no game files (llvm-mc not installed) | AI-assisted: yes, Antigravity (Gemini)

Details:

  • Red (PR test tests/test_rdna2_decode.py on upstream/main 8994000b08): Ran 24 tests in 0.082s — FAILED (failures=13, errors=1, skipped=1): rdna2spirv.Unsupported: operand src_239 in test_gfx10_special_source_operands_235_to_239, plus 5 AssertionError subtests for special codes 235..239 decoding as src_235..239 instead of src_shared_base/src_shared_limit/src_private_base/src_private_limit/src_pops_exiting_wave_id, and 8 AssertionError checks where f64 32-bit literal operands lacked f64_literal.
  • Green (merged with upstream/main 8994000b08): Ran 24 tests in 0.072s — OK (skipped=1) (test_parity_with_llvm_mc_on_shader_fixtures pre-existing skip: 'llvm-mc not available').
  • Repo checks: scripts/check_no_game_data.py -> 0; python -m compileall -q tools scripts tests -> 0; node --test tests/test_viewer_streaming.cjs -> 0; standalone stdlib tests/test_*.py -> 513/521 passed (33 skipped pytest/helper files; 0 new failures vs 8994000b08, same 8 pre-existing failures).
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7234862504 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1959#issuecomment-7234862504). Originally posted by [kirigayakazima](https://github.com/kirigayakazima) on 2026-11-28T05:45:07Z. --- `#1959 | head d8db285002cd76fa2b8b0bfa084caa68836a896b | python -I tests/test_rdna2_decode.py | red: FAILED (failures=13, errors=1, skipped=1; AssertionError + rdna2spirv.Unsupported) | green: 24/24 OK (skipped=1 pre-existing: test_parity_with_llvm_mc_on_shader_fixtures, 0.072s) | full suite: 513/521 stdlib passed, 0 new failures vs main 8994000b08 | Windows 11, Python 3.14.7, no game files (llvm-mc not installed) | AI-assisted: yes, Antigravity (Gemini)` Details: - **Red** (PR test `tests/test_rdna2_decode.py` on `upstream/main` `8994000b08`): `Ran 24 tests in 0.082s — FAILED (failures=13, errors=1, skipped=1)`: `rdna2spirv.Unsupported: operand src_239` in `test_gfx10_special_source_operands_235_to_239`, plus 5 `AssertionError` subtests for special codes `235..239` decoding as `src_235..239` instead of `src_shared_base`/`src_shared_limit`/`src_private_base`/`src_private_limit`/`src_pops_exiting_wave_id`, and 8 `AssertionError` checks where `f64` 32-bit literal operands lacked `f64_literal`. - **Green** (merged with `upstream/main` `8994000b08`): `Ran 24 tests in 0.072s — OK (skipped=1)` (`test_parity_with_llvm_mc_on_shader_fixtures` pre-existing skip: `'llvm-mc not available'`). - **Repo checks**: `scripts/check_no_game_data.py` -> `0`; `python -m compileall -q tools scripts tests` -> `0`; `node --test tests/test_viewer_streaming.cjs` -> `0`; standalone stdlib `tests/test_*.py` -> `513/521 passed` (`33` skipped pytest/helper files; `0` new failures vs `8994000b08`, same 8 pre-existing failures).
zmasi commented 2026-11-28 13:01:09 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T13:01:09Z.


#1959 | head d8db285002cd76fa2b8b0bfa084caa68836a896b (merged cleanly onto main d48a957bb9988afce424552a3c0c8d01ef12320f) | Windows 11 (10.0.26200), CPython 3.12.10, llvm-mc (gfx1013), spirv-val (1.4.363.1), NVIDIA GeForce RTX 3090 (Vulkan 1.4.341, driver 610.88, shaderFloat64, VK_EXT_fragment_shader_interlock, LEONIDA_VK_VALIDATION=1)

  • Red on main (d48a957bb9988afce424552a3c0c8d01ef12320f): tests/test_rdna2_decode.py fails on main (src_shared_base..src_pops_exiting_wave_id codes 235..239 decode as invalid and f64 32-bit literals omit f64_literal / < 100 hex formatting).
  • Green on PR + main:
    • python -I tests/test_rdna2_decode.py -v: pass (OK).
    • Live llvm-mc -> shader_disasm.disasm(..., backend="python") -> rdna2spirv.py -> spirv-val -> RTX 3090 vk_harness (LEONIDA_VK_VALIDATION=1) round-trip on both ps_f64lit (v_frexp_exp_i32_f64_e32 / v_frexp_mant_f64_e32 with 0x40180000 and 0x1 literals) and ps_pops (src_pops_exiting_wave_id, code 239): 4096/4096 pixels exact ((0x3, 0x0, 0x3fe80000, 0xfffffbef) and (0x0, 0x3f800000, 0x3f800000, 0x3f800000), 0 Khronos validation errors).
    • scripts/check_no_game_data.py and test_text_write_line_endings.py: pass (0 CRLF).

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7239630186 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1959#issuecomment-7239630186). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T13:01:09Z. --- #1959 | head `d8db285002cd76fa2b8b0bfa084caa68836a896b` (merged cleanly onto `main` `d48a957bb9988afce424552a3c0c8d01ef12320f`) | Windows 11 (`10.0.26200`), CPython `3.12.10`, `llvm-mc` (`gfx1013`), `spirv-val` (`1.4.363.1`), NVIDIA GeForce RTX 3090 (Vulkan `1.4.341`, driver `610.88`, `shaderFloat64`, `VK_EXT_fragment_shader_interlock`, `LEONIDA_VK_VALIDATION=1`) - **Red on `main` (`d48a957bb9988afce424552a3c0c8d01ef12320f`)**: `tests/test_rdna2_decode.py` fails on `main` (`src_shared_base`..`src_pops_exiting_wave_id` codes `235..239` decode as invalid and `f64` 32-bit literals omit `f64_literal` / `< 100` hex formatting). - **Green on `PR + main`**: - `python -I tests/test_rdna2_decode.py -v`: pass (`OK`). - Live `llvm-mc` -> `shader_disasm.disasm(..., backend="python")` -> `rdna2spirv.py` -> `spirv-val` -> RTX 3090 `vk_harness` (`LEONIDA_VK_VALIDATION=1`) round-trip on both `ps_f64lit` (`v_frexp_exp_i32_f64_e32` / `v_frexp_mant_f64_e32` with `0x40180000` and `0x1` literals) and `ps_pops` (`src_pops_exiting_wave_id`, code `239`): `4096/4096` pixels exact (`(0x3, 0x0, 0x3fe80000, 0xfffffbef)` and `(0x0, 0x3f800000, 0x3f800000, 0x3f800000)`, `0` Khronos validation errors). - `scripts/check_no_game_data.py` and `test_text_write_line_endings.py`: pass (`0` CRLF). AI-assisted.
OreoFR commented 2026-11-28 21:56:43 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T21:56:43Z.


Verified by OreoFR

  • Base: main 3408969a7 + PR head d8db28500
  • Test: python -I tests/test_rdna2_decode.py ; translator suite
  • Red on main: 13 FAIL + 1 ERROR (rdna2spirv.Unsupported "operand src_239"): the missing function itself
  • Green with the PR: 24 OK; translator suite with no new failure (only test_valu_cvt_f16_int16_mods, which also fails on main)
  • Verdict: READY
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246385642 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1959#issuecomment-7246385642). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-28T21:56:43Z. --- **Verified by OreoFR** - Base: main `3408969a7` + PR head `d8db28500` - Test: `python -I tests/test_rdna2_decode.py ; translator suite` - Red on main: 13 FAIL + 1 ERROR (rdna2spirv.Unsupported "operand src_239"): the missing function itself - Green with the PR: 24 OK; translator suite with no new failure (only test_valu_cvt_f16_int16_mods, which also fails on main) - Verdict: READY - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 AI-assisted (Claude Code, Claude Opus 5.5).
aslan2142 commented 2026-12-01 11:55:29 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T11:55:29Z.

Review: CHANGES_REQUESTED


Reviewed against current main: this branch conflicts with main in tools/rdna2_decode.py and has failing CI. Note that commit ed699ed76 on main has already added special source 239 (src_pops_exiting_wave_id); please rebase onto current main keeping special sources 235..238, the f64 32-bit literal decoding/formatting, and the tests so CI runs cleanly.

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6130756640 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1959#pullrequestreview-6130756640). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T11:55:29Z. **Review:** CHANGES_REQUESTED --- Reviewed against current `main`: this branch conflicts with `main` in `tools/rdna2_decode.py` and has failing CI. Note that commit `ed699ed76` on `main` has already added special source `239` (`src_pops_exiting_wave_id`); please rebase onto current `main` keeping special sources `235..238`, the f64 32-bit literal decoding/formatting, and the tests so CI runs cleanly. *(AI-assisted review.)*
MoonEyes commented 2026-12-02 10:32:14 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T10:32:14Z.


For information: this pull request is carried in #3088, which merges your head (your commits are kept) into current main, resolves the conflicts keeping both sides, and fixes the points raised in review here (details in its description). This one stays open until a maintainer decides; if you pick it up again, say so and the carry can be closed.

AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7342614337 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1959#issuecomment-7342614337). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T10:32:14Z. --- For information: this pull request is carried in #3088, which merges your head (your commits are kept) into current `main`, resolves the conflicts keeping both sides, and fixes the points raised in review here (details in its description). This one stays open until a maintainer decides; if you pick it up again, say so and the carry can be closed. AI-assisted (Claude Code, Claude Opus 5.5)
MoonEyes commented 2026-12-02 11:49:14 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T11:49:14Z.


Closing: this pull request no longer applies to current main (merge conflict in tests/test_rdna2_decode.py, tools/rdna2_decode.py), and open pull requests that have fallen out of step with main are being closed so the list stays workable. Your work is not lost: it is carried in #3088
, which keeps your commits and resolves the conflict on current main.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7344451347 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1959#issuecomment-7344451347). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T11:49:14Z. --- Closing: this pull request no longer applies to current `main` (merge conflict in `tests/test_rdna2_decode.py`, `tools/rdna2_decode.py`), and open pull requests that have fallen out of step with `main` are being closed so the list stays workable. Your work is not lost: it is carried in #3088 , which keeps your commits and resolves the conflict on current `main`. AI-assisted (Claude Code).

Pull request closed

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!1959
No description provided.