Skip to content

rdna2_isa_tables: add gfx1013 VOP3 0x16b v_mul_lo_i32 (BUILD-1529) - #5641

Closed
kotekompotek wants to merge 1 commit into
ProjectLeonida:mainfrom
kotekompotek:work/build-1529-gfx1013-0x16b
Closed

kotekompotek wants to merge 1 commit into
ProjectLeonida:mainfrom
kotekompotek:work/build-1529-gfx1013-0x16b

Conversation

@kotekompotek

Copy link
Copy Markdown

Implements BUILD-1529 (claimed in #4933):

  • Adds VOP3 opcode 0x16b (v_mul_lo_i32, gfx1013) to VOP3 in tools/rdna2_isa_tables.py.
  • Verified locally:
    • python -m pytest tests/test_rdna2_decode.py --basetemp D:\temp\pytest_tmp -q: 8 passed, 1 skipped in 0.80s
    • git diff --check (clean)

@mrbean56

Copy link
Copy Markdown

Verified 5cddba2238 externally: the entry is correct.

  • llvm-mc -arch=amdgcn -mcpu=gfx1013 -show-encoding on v_mul_lo_i32 v0, v1, v2 gives [0x00,0x00,0x6b,0xd5,...], i.e. VOP3 opcode 0x6b, between v_mul_hi_u32 (0x6a) and v_mul_hi_i32 (0x6c) exactly as the table now has it. gfx1010 gives the same word; gfx1030 rejects the instruction ("not supported on this GPU"), so the entry is gfx10.1-only and belongs to the union table this file already keeps for gfx1013.
  • pytest tests/test_isa_coverage.py -q: 16 passed, 4 skipped.
  • There is no new test that decodes a word with 0x16b; a two-line rdna2_decode case would keep the entry from being dropped later, but that is a nice-to-have, the encoding is verified.

No GPU, no game data. AI-assisted.

@tahffo68hk-hash

Copy link
Copy Markdown
Contributor

This overlaps the earlier BUILD-1529 patch in bobcatchris/Leonida#3, claimed in #4933. I trial-merged 5cddba22 with current main 561b65a8 on Windows and checked the synthetic words d56b000d 000226ff bf800000 bf810000 (a VOP3 with a literal followed by s_endpgm).

The table entry fixes gfx1013, but the trial merge also decodes v_mul_lo_i32 on both gfx1030 and gfx1036, with zero invalid instructions. This opcode is GFX10.1-only. The earlier patch checks the target after determining the encoding length, including the literal. Its negative control verifies that gfx1030/gfx1036 reject the VOP3 and resume at s_endpgm at byte 12. Current main already passes mcpu into this path, so the target check and regression can be reused here. CPU only, synthetic inputs, AI-assisted.

这与先前在 #4933 认领的 BUILD-1529 补丁 bobcatchris/Leonida#3 重叠。我在 Windows 试合并了 5cddba22 和当前 main 561b65a8,测试合成指令字 d56b000d 000226ff bf800000 bf810000,其中带字面量的 VOP3 后面紧跟 s_endpgm。

表项修复了 gfx1013,但试合并版本在 gfx1030 和 gfx1036 上也解出 v_mul_lo_i32,非法指令计数为零。此操作码仅限 GFX10.1。先前的补丁先确定含字面量的指令长度,再检查目标架构。它的负对照验证 gfx1030/gfx1036 拒绝该 VOP3,从字节 12 的 s_endpgm 恢复。当前 main 已把 mcpu 传到这里,可以复用该目标检查和回归测试。仅 CPU 和合成输入,AI 辅助。

@Luqueze

Luqueze commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Code read of 5cddba22 against main dde82f27 (no checkout, nothing run): entry correct, two changes suggested.

  • The entry is right: 0x16b sits between v_mul_hi_u32 (0x16a) and v_mul_hi_i32 (0x16c) with the same operand template as v_mul_lo_u32, matching the llvm-mc check above.
  • Agree with the target point above: _decode_one returns the entry for every mcpu, so decode_bytes(..., mcpu="gfx1030") and gfx1036 decode v_mul_lo_i32 where LLVM rejects it (docs/design.md:480). rdna2_decode.py:932 already keys 0x140 on mcpu.startswith("gfx101"). The same check for 0x16b, applied after the literal length is known, would keep gfx103x listings honest.
  • Decoding alone doesn't make the op usable yet: rdna2spirv.py:9878 handles v_mul_lo_u32 only, so a gfx1013 shader with this op still ends in Unsupported at translation. rdna2spirv: v_mul_lo_i32 (GFX10.1-only VOP3 0x16b) #3504 adds the lowering (and a GPU fixture) but conflicts with main now. Worth a line in the description saying the two go together.
  • A test in tests/test_rdna2_decode.py would pin it: the word decodes as v_mul_lo_i32 on gfx1013 and is refused on gfx1030.

AI-assisted (Claude Code).

@ps1ke

ps1ke commented Nov 23, 2026

Copy link
Copy Markdown

Tested 5cddba223 on Linux x86-64 (Arch, Python 3.14, LLVM 23.1.3), CPU only, no GPU, no game files: pass for the table entry.

  • Checked the opcode against LLVM: v_mul_lo_i32 v0, v1, v2 assembles with -mcpu=gfx1013 to 00 00 6b d5 01 05 02 02 (VOP3 opcode 0x16b) and is rejected on gfx1030 ("instruction not supported on this GPU"). Operand shape (VDST/SRC0/SRC1, 1 dword, integer) matches the neighbouring v_mul_lo_u32 (0x169).
  • tests/test_rdna2_decode.py: 8 pass, 1 fails (test_parity_with_llvm_mc_on_shader_fixtures, an op_sel:[0,1,0,0] vs op_sel:[0,1] difference on cs_w32_permlane_fi.asm); the same test fails on current main with LLVM 23.1.3, so it is not from this change.

AI-assisted (Claude Code).

@lucas-lachaud

Copy link
Copy Markdown

Tested 5cddba2 on AMD BC-250 (gfx1013, Cyan Skillfish), Linux libdrm hw_oracle with #6179, Mesa 26.2.7, kernel 7.3.3, Fedora 44: the new row matches LLVM 22 llvm-mc -mcpu=gfx1013 (VOP3 0x16b, VDST/SRC0/SRC1). rdna2_decode now prints the same text as llvm-mc for 16 test encodings (VGPR, SGPR, SGPR+SGPR, literal and inline-constant operands); without this PR they decode as invalid. tests/semantic gives the same results with and without the PR (5,930 pass; the 4 failures in test_image_atomics_guard and test_image_store_d16 are already on main).

On hardware, though, v_mul_lo_i32 does not multiply. Over 5,440 (a, b) pairs (edge values incl. 0, ±1, INT32_MIN/MAX, 0xFFFFFFFF, overflowing and mixed-sign products, plus 4,608 seeded random pairs) × 8 operand forms × wave32/wave64 = 87,040 checks, it wrote 0 every time: it overwrites a pre-filled destination, so it is not a no-op. The same happens with the raw .long encoding and with s_nop padding. The control v_mul_lo_u32 (0x169) matched (a*b) & 0xFFFFFFFF on all 87,040. No GPU resets. So the decoder row is right, but on this gfx1013 silicon a translation to a plain OpIMul (#3504) would not match the hardware; whether the console's gfx1013 behaves the same is unknown. A run on an RX 5000 card (gfx1010/1011/1012) would show whether this is GFX10.1-wide; I can share the probe.

AI-assisted (Claude Code).

@isfcrctfs isfcrctfs left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Read at the PR head (5cddba22) against current origin/main (6dda063).

  • Audit (audit.py pr 5641): clean.
  • Entry verified independently: llvm-mc -triple=amdgcn -mcpu=gfx1013 assembles v_mul_lo_i32 v1, s0, s1 to 01 00 6b d5 ... (VOP3 opcode 0x16b, VDST/SRC0/SRC1, one dword each), and rejects it for gfx1030 ("instruction not supported on this GPU"). Decoding the hand-built word (0x35 << 26) | (0x16b << 16) | 1 with the PR prints v_mul_lo_i32 v1, s0, s1; with the PR's base tables the same word is counted invalid (invalid == 2), so the change is observable and is not a duplicate key.
  • python3 -I tests/test_rdna2_decode.py: 9 tests, 8 OK, 1 skipped.

The table entry itself is correct. Two gaps, both raised above:

  1. Nothing pins the row: the decode suite passes identically before and after, so a later table edit can drop 0x16b silently. A case in tests/test_rdna2_decode.py with this one word would fix that.
  2. Target gate: current main already gates the other gfx1013-only VOP3 entries (tools/rdna2_decode.py:932, if opc == 0x140 and mcpu.startswith("gfx101")). decode_bytes defaults to mcpu="gfx1013" and has no such check for 0x16b, so mcpu="gfx1030"/"gfx1036" decode it where LLVM rejects it. The same pattern, applied after the literal length is known, would keep wrong-target listings honest. A test asserting accepted on gfx1013 and rejected on gfx1030 covers both.

Decoding alone does not make the op translatable: tools/rdna2spirv.py has no v_mul_lo_i32 rule, so it still ends in Unsupported, as docs/design.md says.

AI-assisted

@fadi-abu-basem-25

Copy link
Copy Markdown
Contributor

Tested 5cddba2 applied on main 867d922, Windows 11, Python 3.14.6, no GPU: pass. python -I tests/test_rdna2_decode.py: 16 tests OK (1 skipped).

The encoding matches LLVM: VOP3Instructions.td has defm V_MUL_LO_I32 : VOP3_Real_gfx10<0x16b>; inside let SubtargetPredicate = isGFX10Before1030, so 0x16b is v_mul_lo_i32 on GFX10.1 (gfx1010 to gfx1013, gfx1013 included) and does not exist on gfx1030 and later. The operand row matches its neighbours 0x169, 0x16a and 0x16c.

A follow-up, not for this PR: tools/rdna2spirv.py has a rule for v_mul_lo_u32 (line 9878 at 867d922) but none for v_mul_lo_i32, so a listing that uses it still stops at the translator. If it's ever needed, the v_mul_lo_u32 rule fits: the low 32 bits of the product are the same signed or unsigned.

AI-assisted review (Claude Code).

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.

9 participants