Shader tests: the GFX10 decoder against llvm-mc on every opcode (checked-in fixture, no LLVM needed) #87

Open
github-bot wants to merge 1 commit from github-bot/gh-87 into main AGit
Owner

@⁠lcg007xd-c on GitHub · 2026-11-25 22:18 UTC · original
lcg007xd-c:test/llvm-decoder-oracle → main · +7649 −0 · 3 files · 1 commits · open

What

This checks the GFX10 decoder against LLVM's, on every opcode, without needing LLVM to run the tests.

  • The fixture. gfx10/llvm-mc-gfx1030.txt (264 KB, plain text) records what llvm-mc -triple=amdgcn -mcpu=gfx1030 --disassemble makes of one encoding of every opcode of every family. The families are SOP1/2/C/K/P, VOP1/2/3/3P/C, SMEM, DS, MUBUF, MTBUF, MIMG, FLAT/GLOBAL/SCRATCH, VINTRP and EXP. The ALU forms also come with a literal, and VOP3 with a literal in either the first or the third source. That is 7,093 cases, 2,393 of which LLVM decodes.
  • The test. decoder_agrees_with_llvm decodes each case and compares the name (ignoring LLVM's _e32/_e64) and the length in dwords. A wrong length is the bad one, because every later instruction is then read out of step. It takes 0.02 s.
  • Known cases. Today's disagreements are listed in KNOWN, each with a reason, and anything else fails. One pattern is skipped without listing: 0xFF in a source field the instruction doesn't have (e.g. a third source on a two-source op). LLVM reads no literal there and real code never writes one.
  • Regenerating. cargo test -p victory-shader regenerate_llvm_fixture -- --ignored rewrites the fixture. It needs llvm-mc, which can be set with LLVM_MC.

What it found

The 48 listed cases:

  • #69's names. image_sample_cd_g16 (all 8) and image_gather4h have no name; #69 adds them.
  • #70's length. The VOP3 interpolation forms with 0xFF in the attribute field are decoded as having a literal; #70 fixes that.
  • The legacy multiply-adds are named differently. VOP2 0x06 / VOP3 0x106 and VOP3 0x140 are v_mac_legacy_f32 / v_mad_legacy_f32 here, the GFX10.1 names. LLVM's gfx1030 has v_fmac_legacy_f32 / v_fma_legacy_f32 there, the fused forms. Which one the console's GPU implements decides whether these round like an FMA. That is left for whoever owns the lowering. The test only records it.
  • Register-only operands. These have a literal in an operand that must be a register: source 0 of v_movrels*, v_readlane, v_swap* and the permlanes, or the lane mask of v_cndmask and the carry ops. LLVM doesn't read a literal there, and the compiler can't encode one.
  • A test artifact. s_call_b64's branch target lies past the end of the test program.

So nothing in today's decoder misreads real code that I can see. The test is there to keep it that way.

Tests

  • The test passes.
  • I removed the first-source literal check from the VOP3 length rule: 381 cases fail. Removing the third-source check fails 67.
  • The portable CI commands and Windows-target clippy (--target x86_64-pc-windows-msvc) pass locally. The fixture is within the asset policy's size limit.

Not covered: operand text (styles differ from LLVM's), and DS/SMEM/MUBUF encodings beyond the one template each, which LLVM refuses for many opcodes.

🤖 Generated with Claude Code

**@⁠lcg007xd-c** on GitHub · 2026-11-25 22:18 UTC · [original](https://github.com/uiliannn/VItoriaBr/pull/87) `lcg007xd-c:test/llvm-decoder-oracle` → `main` · +7649 −0 · 3 files · 1 commits · open ## What This checks the GFX10 decoder against LLVM's, on every opcode, without needing LLVM to run the tests. - **The fixture.** `gfx10/llvm-mc-gfx1030.txt` (264 KB, plain text) records what `llvm-mc -triple=amdgcn -mcpu=gfx1030 --disassemble` makes of one encoding of every opcode of every family. The families are SOP1/2/C/K/P, VOP1/2/3/3P/C, SMEM, DS, MUBUF, MTBUF, MIMG, FLAT/GLOBAL/SCRATCH, VINTRP and EXP. The ALU forms also come with a literal, and VOP3 with a literal in either the first or the third source. That is 7,093 cases, 2,393 of which LLVM decodes. - **The test.** `decoder_agrees_with_llvm` decodes each case and compares the name (ignoring LLVM's `_e32`/`_e64`) and the length in dwords. A wrong length is the bad one, because every later instruction is then read out of step. It takes 0.02 s. - **Known cases.** Today's disagreements are listed in `KNOWN`, each with a reason, and anything else fails. One pattern is skipped without listing: `0xFF` in a source field the instruction doesn't have (e.g. a third source on a two-source op). LLVM reads no literal there and real code never writes one. - **Regenerating.** `cargo test -p victory-shader regenerate_llvm_fixture -- --ignored` rewrites the fixture. It needs `llvm-mc`, which can be set with `LLVM_MC`. ## What it found The 48 listed cases: - **#69's names.** `image_sample_cd_g16` (all 8) and `image_gather4h` have no name; #69 adds them. - **#70's length.** The VOP3 interpolation forms with `0xFF` in the attribute field are decoded as having a literal; #70 fixes that. - **The legacy multiply-adds are named differently.** VOP2 0x06 / VOP3 0x106 and VOP3 0x140 are `v_mac_legacy_f32` / `v_mad_legacy_f32` here, the GFX10.1 names. LLVM's gfx1030 has `v_fmac_legacy_f32` / `v_fma_legacy_f32` there, the fused forms. Which one the console's GPU implements decides whether these round like an FMA. That is left for whoever owns the lowering. The test only records it. - **Register-only operands.** These have a literal in an operand that must be a register: source 0 of `v_movrels*`, `v_readlane`, `v_swap*` and the permlanes, or the lane mask of `v_cndmask` and the carry ops. LLVM doesn't read a literal there, and the compiler can't encode one. - **A test artifact.** `s_call_b64`'s branch target lies past the end of the test program. So nothing in today's decoder misreads real code that I can see. The test is there to keep it that way. ## Tests - The test passes. - I removed the first-source literal check from the VOP3 length rule: 381 cases fail. Removing the third-source check fails 67. - The portable CI commands and Windows-target clippy (`--target x86_64-pc-windows-msvc`) pass locally. The fixture is within the asset policy's size limit. Not covered: operand text (styles differ from LLVM's), and DS/SMEM/MUBUF encodings beyond the one template each, which LLVM refuses for many opcodes. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
gfx10/llvm-mc-gfx1030.txt holds what `llvm-mc -mcpu=gfx1030
--disassemble` makes of one encoding of every opcode of every encoding
family, with and without a literal (7,093 cases, 2,393 that LLVM
decodes). decoder_agrees_with_llvm decodes each and compares the name
(without _e32/_e64) and the length in dwords: a wrong length puts every
later instruction out of step. Disagreements known today are listed in
KNOWN with why (the image and interpolation names and lengths other PRs
fix, the GFX10.1 names of the legacy multiply-adds, and literals in
register-only operands that LLVM does not read); anything else fails.
0xFF in a source field the instruction does not have is skipped: LLVM
reads no literal there and real code never writes one.

The fixture regenerates with the ignored regenerate_llvm_fixture test,
which runs llvm-mc; the test itself needs no LLVM.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:43:37 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/87/head:github-bot/gh-87'
git switch 'github-bot/gh-87'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-87'
git switch 'github-bot/gh-87'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-87'
git switch 'github-bot/gh-87'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-87'
git switch 'main'
git merge --squash 'github-bot/gh-87'
git switch 'main'
git merge --ff-only 'github-bot/gh-87'
git switch 'main'
git merge 'github-bot/gh-87'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.