Skip to content

rdna2_decode: an f64 source's literal prints in hex, apart from the inline integer (SHADER-890) - #5115

Open
hmodymac8-droid wants to merge 1 commit into
ItsNotRexed:mainfrom
hmodymac8-droid:fix/shader-890-f64-literal-hex
Open

hmodymac8-droid wants to merge 1 commit into
ItsNotRexed:mainfrom
hmodymac8-droid:fix/shader-890-f64-literal-hex

Conversation

@hmodymac8-droid

Copy link
Copy Markdown

Claimed in #5032: #5032 (comment) (SHADER-890, tupacfan04's finding)

What and why

tools/rdna2_decode.py printed every immediate below 100 in decimal (_format_operand). That made the literal dword of an f64 source look the same as an inline integer: the finder's encoding came out as v_add_f64 v[4:5], 1, 1, while LLVM prints v_add_f64 v[4:5], 0x1, 1.

On an f64 source the two mean different things:

  • the literal is bits 63:32,
  • the inline integer is the whole value.

shader_ir.parse_line marks an f64 source as a literal only from the 0x spelling (f64_literal), so the Python backend gave the translator an inline constant where the code had a literal.

Change

  • _src: a literal (code 255) on a 64-bit operand (n == 2) gets lit64: True.
  • format_insn / _format_operand: that literal prints in hex when the opcode is an f64 one ("_f64" in op), as LLVM's printImmediate64 does for a non-inline FP64 value.
  • Unchanged: a 32-bit literal is the whole value either way, and LLVM prints a small one in decimal, so it keeps decimal (v_add_f32_e64 v4, 1, 1). The same goes for 64-bit integer operands, which LLVM also prints in decimal when the value is inline-sized. The decoded dicts of 32-bit literals are unchanged too, since the existing tests compare them exactly.

Test

tests/test_rdna2_decode.py gains test_small_f64_literal_prints_in_hex_like_llvm. The finder's encoding now prints v_add_f64 v[4:5], 0x1, 1, and shader_ir flags only the first source as f64_literal. A 32-bit literal 1 still prints as 1, and its dict stays {"k": "imm", "v": 1}. On main 3faac557 the new test fails, and with the change it passes.

Tested

Synthetic encodings only, no game files, no GPU. On Windows 11, Python 3.13.5:

  • python -I tests/test_rdna2_decode.py: OK (10 tests, 1 skipped: the llvm-mc parity test, since llvm-mc isn't installed here)
  • python -I tests/test_shader_disasm.py: OK
  • python -I tests/test_shader_ir.py: OK
  • python -m compileall -q on both files: clean
  • git diff --check: clean

AI-assisted (Claude Code).

🤖 Generated with Claude Code

…nline integer (SHADER-890)

The decoder printed every immediate below 100 in decimal, so the literal
dword of an f64 source came out the same as an inline integer:
`v_add_f64 v[4:5], 1, 1` for a literal 1 and an inline 1. On an f64
source the two differ (the literal is bits 63:32, the inline integer the
whole value), LLVM prints the literal in hex (`0x1`), and shader_ir only
marks an f64 source as a literal from that spelling, so the Python
backend handed the translator an inline constant where the code had a
literal.

_src marks a literal on a 64-bit operand (`lit64`), and format_insn
prints it in hex when the opcode is an f64 one. 32-bit literals, 64-bit
integer operands and the decoded operand dicts of 32-bit literals are
unchanged.

tests/test_rdna2_decode.py: the finder's encoding now prints
`v_add_f64 v[4:5], 0x1, 1` and shader_ir flags only the first source as
an f64 literal (fails on main); a 32-bit literal 1 still prints as `1`.

Found by tupacfan04. Synthetic encodings only; no game files.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@kacper-serewis kacper-serewis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Integrated #5115 cb6bcea with #5104 3ceecb6 in private scratch. Six hand-encoded ordinary f64 equality compares distinguished inline 1 from literal dword 1 through formatting, parsing, translation and CPU interpretation, including e64 right-hand operands. All six focused compare tests passed. Across 26,503 cached listings there were no static f64 compares, and all 468 source operands at the identified f64 sites were registers. Applicability of the literal case comes from the synthetic tests. AI-assisted, CPU only.

@MichaelL401

Copy link
Copy Markdown
Contributor

Tested cb6bcead on Linux, CPU only (no GPU), Python 3.12.16: pass.

  • python -I tests/test_rdna2_decode.py: OK (1 skipped). Negative control: with main's tools/rdna2_decode.py, the same suite gives 1 failure.

Code read: only a literal (code 255) read as a 64-bit operand is marked lit64, and only an _f64 op prints it in hex, so inline integers, 32-bit literals and _f64 ops with a 32-bit source (e.g. v_cvt_f64_f32) print as before.

AI-assisted (Claude).

@thehollowedone

Copy link
Copy Markdown

Independent Windows check of cb6bcead with CPython 3.12.8 and conda-forge llvm-mc 23.1.6 (AMDGPU enabled). Tested the published patch on 3faac557 in a scratch copy.

  • test_shader_disasm.py and test_shader_ir.py passed all 57 tests. The decoder suite passed nine tests, including the new regression, and ran the LLVM fixture parity test.
  • The parity test fails identically on the base and PR in ps_w64_a_discard.asm at exp null (target vs special), the existing issue addressed by TEST-1010: rdna2_decode: exp null is a special operand, as shader_ir parses it #4697.
  • Direct LLVM disassembly confirms v_add_f64 v[4:5], 0x1, 1 and v_cvt_f32_f64_e64 v4, 0x1. The patched decoder and parser preserved the f64 literal versus inline-integer distinction in 24 synthetic decodes across addition and both conversion directions. The new regression fails with the base decoder.

CPU only, using synthetic instructions. AI-assisted.

@Atomic258

Copy link
Copy Markdown
Contributor

Tested cb6bcea on Windows Server 2022, CPython 3.13.12: pass

  • python -I tests/test_rdna2_decode.py -> Ran 10 tests, OK (skipped=1)
  • Negative control (tools/rdna2_decode.py swapped to upstream/main): FAILED (failures=1)

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

@kotekompotek

Copy link
Copy Markdown

Independent Windows CPU verification on cb6bcead:

  • python -m pytest tests/test_rdna2_decode.py --basetemp D:\temp\pytest_tmp -q: 9 passed, 1 skipped in 0.59s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants