tools: valu_literal64_probe measures how a 32-bit VALU literal is extended in a 64-bit integer operand (HW-VALU-LITERAL64-EXT) #1800

Merged
mcpeacebir-lang merged 1 commit from upstream-pr/1800 into main 2026-11-28 10:49:05 +00:00
mcpeacebir-lang commented 2026-11-25 12:17:30 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by mcpeacebir-lang on 2026-11-25T12:17:30Z.


Claimed in the coordination issue as: HW-VALU-LITERAL64-EXT (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7162001706). Result: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7162059499

What and why

The "32-bit literal source of a signed 64-bit vector op" row of docs/design.md ends with "Not measured on hardware". It gives the translator's rule for a 32-bit VALU literal in a 64-bit integer operand: sign-extend in an i64 operand, zero-extend in a u64/b64 one (Gen.valu_imm_i64, SHADER-VALU-LITERAL-SEXT). That rule comes from LLVM's assembler documentation. A literal is one dword, so where the hardware takes the high dword from is what decides it.

I measured it on an RX 7800 XT and posted the result in #1608. Every result follows the row. This pull request turns that run into a tool, so the row can cite it and someone with a gfx103x card can measure RDNA2 with one command.

tools/valu_literal64_probe.py runs through tools/hw_oracle:

  • 21 op forms:
    • v_cmp_{lt,gt}_{i64,u64}: e64 with the literal as src0 and as src1, and e32;
    • v_cmpx_{lt,gt}_{i64,u64};
    • v_ashrrev_i64, v_lshrrev_b64 and v_lshlrev_b64;
    • v_mad_i64_i32 and v_mad_u64_u32.
  • Literals: 0xffffff9c, 0x80000000 and 0x7fffffff. The last one is a control that both models agree on.
  • One lane per kernel, in wave32 and wave64.
  • The VGPR operand is chosen so the two models (sign- or zero-extended high dword) give different results. A unit test checks that for every case.
  • It prints, per wave size, how many results follow the row's rule, and names any result that does not.

Exit codes:

  • 0: every result follows the rule.
  • 1: a result does not, or the report cannot be written.
  • 2: harness or CLI error.
  • 77: no oracle, or a family other than gfx10/gfx11.

--waves, --json and --self-test follow cndmask_hw_probe.py (#1784) and dpp_hw_probe.py (#1773).

The row now gives the gfx1101 measurement and says RDNA2 is not measured. No translator change. New files plus one row of docs/design.md.

Tested

  • python -I tests/test_valu_literal64_probe.py: 20 tests, 19 OK and 1 skipped (the llvm-mc check). With LEONIDA_AMD_CLANG set to the clang from rocm-sdk-core==10.0.0 (AMD LLVM 23.0.0git), all 20 are OK. The llvm-mc check assembles every kernel body for gfx1030 (GFX10 spelling) and gfx1101, in wave32 and wave64. It also checks that each literal is encoded as that one dword.
  • python -I tools/valu_literal64_probe.py --self-test: OK.
  • On the GPU, on main 0d80bc5df:
    $ python -I tools/valu_literal64_probe.py --json report.json
    device: gfx1101
    wave32: 63/63 follow the rule (i64 sign-extends, u64/b64 zero-extends); 20 match only sext, 22 only zext, 21 controls
    wave64: 63/63 follow the rule (i64 sign-extends, u64/b64 zero-extends); 20 match only sext, 22 only zext, 21 controls
    result: every literal is extended as the row says
    
  • Checks on the changed files:
    • scripts/check_no_game_data.py: clean.
    • compileall and git diff --check: clean.
    • tests/test_ci_registration.py, tests/test_text_write_line_endings.py and every tests/test_docs_*.py: OK.
  • test_runner_calls_all_tests.py, test_tool_stdout_encoding.py and test_runtime_paths.py are red on main already (#1673). None of their failures names these files.

Not run: RDNA2 itself (no gfx103x card here), which is what the tool is for. Nothing in the translator suite changes.

GPUs tested: AMD Radeon RX 7800 XT (gfx1101, RDNA3), AMD driver 32.0.32029.2010, Windows 11, through tools/hw_oracle (amdhip64_7.dll, AMD clang from rocm-sdk-core==10.0.0).

AI-assisted: yes (Claude Code, Claude Opus 5.5)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change; the existing row gains its hardware measurement)

🤖 Generated with Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5491164414 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1800). Originally posted by [mcpeacebir-lang](https://github.com/mcpeacebir-lang) on 2026-11-25T12:17:30Z. --- Claimed in the coordination issue as: HW-VALU-LITERAL64-EXT (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7162001706). Result: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7162059499 ### What and why The "32-bit literal source of a signed 64-bit vector op" row of `docs/design.md` ends with "Not measured on hardware". It gives the translator's rule for a 32-bit VALU literal in a 64-bit integer operand: sign-extend in an i64 operand, zero-extend in a u64/b64 one (`Gen.valu_imm_i64`, SHADER-VALU-LITERAL-SEXT). That rule comes from LLVM's assembler documentation. A literal is one dword, so where the hardware takes the high dword from is what decides it. I measured it on an RX 7800 XT and posted the result in #1608. Every result follows the row. This pull request turns that run into a tool, so the row can cite it and someone with a gfx103x card can measure RDNA2 with one command. `tools/valu_literal64_probe.py` runs through `tools/hw_oracle`: - 21 op forms: - `v_cmp_{lt,gt}_{i64,u64}`: e64 with the literal as src0 and as src1, and e32; - `v_cmpx_{lt,gt}_{i64,u64}`; - `v_ashrrev_i64`, `v_lshrrev_b64` and `v_lshlrev_b64`; - `v_mad_i64_i32` and `v_mad_u64_u32`. - Literals: `0xffffff9c`, `0x80000000` and `0x7fffffff`. The last one is a control that both models agree on. - One lane per kernel, in wave32 and wave64. - The VGPR operand is chosen so the two models (sign- or zero-extended high dword) give different results. A unit test checks that for every case. - It prints, per wave size, how many results follow the row's rule, and names any result that does not. Exit codes: - 0: every result follows the rule. - 1: a result does not, or the report cannot be written. - 2: harness or CLI error. - 77: no oracle, or a family other than gfx10/gfx11. `--waves`, `--json` and `--self-test` follow `cndmask_hw_probe.py` (#1784) and `dpp_hw_probe.py` (#1773). The row now gives the gfx1101 measurement and says RDNA2 is not measured. No translator change. New files plus one row of `docs/design.md`. ### Tested - `python -I tests/test_valu_literal64_probe.py`: 20 tests, 19 OK and 1 skipped (the llvm-mc check). With `LEONIDA_AMD_CLANG` set to the clang from `rocm-sdk-core==10.0.0` (AMD LLVM 23.0.0git), all 20 are OK. The llvm-mc check assembles every kernel body for gfx1030 (GFX10 spelling) and gfx1101, in wave32 and wave64. It also checks that each literal is encoded as that one dword. - `python -I tools/valu_literal64_probe.py --self-test`: OK. - On the GPU, on `main` `0d80bc5df`: ``` $ python -I tools/valu_literal64_probe.py --json report.json device: gfx1101 wave32: 63/63 follow the rule (i64 sign-extends, u64/b64 zero-extends); 20 match only sext, 22 only zext, 21 controls wave64: 63/63 follow the rule (i64 sign-extends, u64/b64 zero-extends); 20 match only sext, 22 only zext, 21 controls result: every literal is extended as the row says ``` - Checks on the changed files: - `scripts/check_no_game_data.py`: clean. - `compileall` and `git diff --check`: clean. - `tests/test_ci_registration.py`, `tests/test_text_write_line_endings.py` and every `tests/test_docs_*.py`: OK. - `test_runner_calls_all_tests.py`, `test_tool_stdout_encoding.py` and `test_runtime_paths.py` are red on `main` already (#1673). None of their failures names these files. Not run: RDNA2 itself (no gfx103x card here), which is what the tool is for. Nothing in the translator suite changes. GPUs tested: AMD Radeon RX 7800 XT (gfx1101, RDNA3), AMD driver 32.0.32029.2010, Windows 11, through `tools/hw_oracle` (`amdhip64_7.dll`, AMD clang from `rocm-sdk-core==10.0.0`). AI-assisted: yes (Claude Code, Claude Opus 5.5) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change; the existing row gains its hardware measurement) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
GeorgiyDemo commented 2026-11-25 12:50:01 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by GeorgiyDemo on 2026-11-25T12:50:01Z.


Tested 98d9e147a on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against main 98c2f7777 (Python GPU probe; hardware oracle not run):

  • pytest 9.2.0 on tests/test_valu_literal64_probe.py: 19 passed, 1 skipped, 95 subtests passed at this head.
  • On main the file fails at collection (the new probe module/helpers do not exist), so there is no before/after beyond "new probe".
  • Not run: the native AMD measurement itself; the skip is the hardware-dependent test.

AI-assisted; synthetic fixtures only, no game data.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7162919813 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1800#issuecomment-7162919813). Originally posted by [GeorgiyDemo](https://github.com/GeorgiyDemo) on 2026-11-25T12:50:01Z. --- Tested `98d9e147a` on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against `main` `98c2f7777` (Python GPU probe; hardware oracle not run): - pytest 9.2.0 on `tests/test_valu_literal64_probe.py`: **19 passed, 1 skipped, 95 subtests passed** at this head. - On `main` the file fails at collection (the new probe module/helpers do not exist), so there is no before/after beyond "new probe". - Not run: the native AMD measurement itself; the skip is the hardware-dependent test. AI-assisted; synthetic fixtures only, no game data.
sodove commented 2026-11-28 10:11:15 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by sodove on 2026-11-28T10:11:15Z.


#1800 | head ea765a73910f4f0d1dfd1eee96fce339bc53baef | python3 -I tests/test_valu_literal64_probe.py -v | red: import error before any test ran (new module absent) | green: 20 passed | Import-only red → pass

The new probe module is absent on main, so the test file stopped at import. After merging, all 20 tests ran, including assembly with LLVM 21.1.8. This run used the synthetic test oracle.

Pinned main 33db04a7010e81c40a7a6a15624525aa0c4a3a58, merged into this PR head. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Full suite: not run. AI-assisted: OpenAI Codex. Batch claim.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7237728932 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1800#issuecomment-7237728932). Originally posted by [sodove](https://github.com/sodove) on 2026-11-28T10:11:15Z. --- #1800 | head `ea765a73910f4f0d1dfd1eee96fce339bc53baef` | `python3 -I tests/test_valu_literal64_probe.py -v` | red: import error before any test ran (new module absent) | green: 20 passed | **Import-only red → pass** The new probe module is absent on main, so the test file stopped at import. After merging, all 20 tests ran, including assembly with LLVM 21.1.8. This run used the synthetic test oracle. Pinned main `33db04a7010e81c40a7a6a15624525aa0c4a3a58`, merged into this PR head. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Full suite: not run. AI-assisted: OpenAI Codex. [Batch claim](https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7237628300).
DadaCap commented 2026-11-28 10:49:07 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-28T10:49:07Z.


Merged, thank you @mcpeacebir-lang!

What it does: tools: valu_literal64_probe measures how a 32-bit VALU literal is extended in a 64-bit integer operand (HW-VALU-LITERAL64-EXT)

How it was checked: sodove tested this PR at head ea765a739 on main 33db04a70: the PR's own test fails on main and passes with this PR merged in (his result is linked from the batch summary in #1608). We then re-ran the same test locally on Windows 11 and got the same verdict: on main, red (import error: probe module is new); with the PR, green (20 OK, 1 skip).

On main the test fails only because the new probe module does not exist yet, which is expected for a new tool; its llvm-mc case was skipped on our machine (no AMD clang set up).

CI: the red jobs on this PR fail the same way on main, or on the older main it was built on (the cs_dpp_cmp.asm translator fixture, since fixed on main, and the Windows runner's Visual Studio setup), so none comes from this change.

Merged one by one with 20 other PRs of the same reviewed batch, pinned to the tested head.

AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238141900 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1800#issuecomment-7238141900). Originally posted by [DadaCap](https://github.com/DadaCap) on 2026-11-28T10:49:07Z. --- Merged, thank you @mcpeacebir-lang! **What it does:** tools: valu_literal64_probe measures how a 32-bit VALU literal is extended in a 64-bit integer operand (HW-VALU-LITERAL64-EXT) **How it was checked:** sodove tested this PR at head `ea765a739` on main `33db04a70`: the PR's own test fails on main and passes with this PR merged in (his result is linked from the batch summary in #1608). We then re-ran the same test locally on Windows 11 and got the same verdict: on main, red (import error: probe module is new); with the PR, green (20 OK, 1 skip). On main the test fails only because the new probe module does not exist yet, which is expected for a new tool; its llvm-mc case was skipped on our machine (no AMD clang set up). **CI:** the red jobs on this PR fail the same way on main, or on the older main it was built on (the `cs_dpp_cmp.asm` translator fixture, since fixed on main, and the Windows runner's Visual Studio setup), so none comes from this change. Merged one by one with 20 other PRs of the same reviewed batch, pinned to the tested head. AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.
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!1800
No description provided.