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

Open
opened 2026-11-26 21:19:34 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1959
Author: @ShotTechOp
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/decode-f64-lit-and-special-srcs


📝 Commits (1)

  • d8db285 rdna2_decode: decode GFX10 special sources 235..239 and f64 32-bit literals

📊 Changes

2 files changed (+194 additions, -19 deletions)

View changed files

📝 tests/test_rdna2_decode.py (+162 -0)
📝 tools/rdna2_decode.py (+32 -19)

📄 Description

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

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1959 **Author:** [@ShotTechOp](https://github.com/ShotTechOp) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/decode-f64-lit-and-special-srcs` --- ### 📝 Commits (1) - [`d8db285`](https://github.com/ubiquitarianism/leonida/commit/d8db285002cd76fa2b8b0bfa084caa68836a896b) rdna2_decode: decode GFX10 special sources 235..239 and f64 32-bit literals ### 📊 Changes **2 files changed** (+194 additions, -19 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_rdna2_decode.py` (+162 -0) 📝 `tools/rdna2_decode.py` (+32 -19) </details> ### 📄 Description 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`). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#1966
No description provided.