[PR #1493] [MERGED] rdna2spirv: sign-extend the 32-bit literal of v_cmp(x)_*_i64, v_ashrrev_i64, v_mad_i64_i32 (SHADER-VALU-LITERAL-SEXT) #1520

Closed
opened 2026-11-26 20:21:32 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1493
Author: @QemmHD
Created: 11/25/2026
Status: ✅ Merged
Merged: 11/25/2026
Merged by: @QemmHD

Base: main ← Head: claude/valu-literal-sext


📝 Commits (1)

  • bc2d333 rdna2spirv: sign-extend the 32-bit literal of v_cmp(x)_*_i64, v_ashrrev_i64, v_mad_i64_i32 (SHADER-VALU-LITERAL-SEXT)

📊 Changes

3 files changed (+185 additions, -6 deletions)

View changed files

📝 docs/design.md (+1 -0)
➕ tests/semantic/test_valu_signed_literal64.py (+156 -0)
📝 tools/rdna2spirv.py (+28 -6)

📄 Description

Claimed in the coordination issue as: SHADER-VALU-LITERAL-SEXT (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7149621293)

Related: #978 (OlaiFG7, the scalar half; no conflict, merges cleanly in either order)

What and why

A 32-bit literal used as a signed 64-bit vector operand is now sign-extended (Gen.valu_imm_i64 / Gen.src64_i64), following LLVM's AMDGPU operand-syntax rule ("Conversion of Integer Values"): i64 → {-1,num.i32}, u64/b64 → {0,num.u32}. llvm-mc prints -100 as 0xffffff9c (both spellings encode to the same bytes on gfx1030), and the translator zero-extended that for every 64-bit VALU source, so:

  • v_cmp_lt_i64 5, 0xffffff9c gave 1 instead of 0;
  • v_ashrrev_i64 v[2:3], 4, 0xffffff9c gave 0x0ffffff9:0 instead of 0xfffffff9:0xffffffff;
  • v_mad_i64_i32 …, 1, 1, 0xffffff9c had a high word of 0 instead of 0xffffffff.

Covered: v_cmp(x)_{lt,le,gt,ge,eq,ne,lg}_i64, v_ashrrev_i64 S1 and v_mad_i64_i32 S2. Unchanged by design: the u64/b64 sources (v_cmp_*_u64, v_lshlrev/lshrrev_b64, v_mad_u64_u32 S2, the qsad forms) still zero-extend; f64 literals keep their high-word rule (already correct); inline constants (-16..64) were already full width. src64_data itself is unchanged.

This is the vector half of #978. Found while comparing with VIctory (Marvisak/VIctory 1134418); written anew here.

  • docs/design.md: a contract-table row, confirmed by the LLVM operand-syntax doc, the llvm-mc encodings and #978's precedent. Not measured on hardware.
  • tests/semantic/test_valu_signed_literal64.py: 8 hand-written tests, no game data. Each signed case uses three spellings (decimal, printed hex, explicit SGPR pair), with controls: a positive literal, an inline constant, and the unsigned ops.

Tested

  • New test: 5 of 8 fail on the previous translator (only the hex spelling was wrong); 8 of 8 pass with the fix.
  • Full semantic suite, rebased onto main 0aecc5efa (after #984): 484 files, 6,262 tests, 0 failed.
  • Repository-consistency set: 580 passed, 5 skipped. compileall is clean. Merges cleanly onto current main.
  • Merged locally with #978: clean, and on the merged tree, #978's scalar literal test, this one, test_alu_ashr_i64 and test_alu_mad64 all pass (90 tests). Once both are in, #978's imm64_signed and this PR's valu_imm_i64 do the same thing, so a follow-up could fold them into one.
  • No GPU run or corpus count (no game files). Windows 11, CPU interpreter.

GPUs tested: n/a (translator; CPU interpreter)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly.
  • One topic.
  • No game data, keys or decryption.
  • The new translator rule is in the contract table of docs/design.md, with how it was confirmed.

AI-assisted (Claude Code, Claude Opus 5.5).

🤖 Generated with Claude Code

https://claude.ai/code/session_01SR1Fv7eQNgZjM6miWPKjHf


🔄 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/1493 **Author:** [@QemmHD](https://github.com/QemmHD) **Created:** 11/25/2026 **Status:** ✅ Merged **Merged:** 11/25/2026 **Merged by:** [@QemmHD](https://github.com/QemmHD) **Base:** `main` ← **Head:** `claude/valu-literal-sext` --- ### 📝 Commits (1) - [`bc2d333`](https://github.com/ubiquitarianism/leonida/commit/bc2d333495399fb45c821fa760f3e9d879f1b622) rdna2spirv: sign-extend the 32-bit literal of v_cmp(x)_*_i64, v_ashrrev_i64, v_mad_i64_i32 (SHADER-VALU-LITERAL-SEXT) ### 📊 Changes **3 files changed** (+185 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+1 -0) ➕ `tests/semantic/test_valu_signed_literal64.py` (+156 -0) 📝 `tools/rdna2spirv.py` (+28 -6) </details> ### 📄 Description Claimed in the coordination issue as: SHADER-VALU-LITERAL-SEXT (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7149621293) Related: #978 (OlaiFG7, the scalar half; no conflict, merges cleanly in either order) ### What and why A 32-bit literal used as a **signed** 64-bit vector operand is now sign-extended (`Gen.valu_imm_i64` / `Gen.src64_i64`), following LLVM's AMDGPU operand-syntax rule ("Conversion of Integer Values"): i64 → `{-1,num.i32}`, u64/b64 → `{0,num.u32}`. llvm-mc prints `-100` as `0xffffff9c` (both spellings encode to the same bytes on gfx1030), and the translator zero-extended that for every 64-bit VALU source, so: - `v_cmp_lt_i64 5, 0xffffff9c` gave 1 instead of 0; - `v_ashrrev_i64 v[2:3], 4, 0xffffff9c` gave `0x0ffffff9:0` instead of `0xfffffff9:0xffffffff`; - `v_mad_i64_i32 …, 1, 1, 0xffffff9c` had a high word of 0 instead of `0xffffffff`. Covered: `v_cmp(x)_{lt,le,gt,ge,eq,ne,lg}_i64`, `v_ashrrev_i64` S1 and `v_mad_i64_i32` S2. Unchanged by design: the u64/b64 sources (`v_cmp_*_u64`, `v_lshlrev/lshrrev_b64`, `v_mad_u64_u32` S2, the qsad forms) still zero-extend; f64 literals keep their high-word rule (already correct); inline constants (-16..64) were already full width. `src64_data` itself is unchanged. This is the vector half of #978. Found while comparing with VIctory (Marvisak/VIctory `1134418`); written anew here. - `docs/design.md`: a contract-table row, confirmed by the LLVM operand-syntax doc, the llvm-mc encodings and #978's precedent. Not measured on hardware. - `tests/semantic/test_valu_signed_literal64.py`: 8 hand-written tests, no game data. Each signed case uses three spellings (decimal, printed hex, explicit SGPR pair), with controls: a positive literal, an inline constant, and the unsigned ops. ### Tested - **New test:** 5 of 8 fail on the previous translator (only the hex spelling was wrong); 8 of 8 pass with the fix. - **Full semantic suite**, rebased onto main 0aecc5efa (after #984): 484 files, 6,262 tests, 0 failed. - **Repository-consistency set:** 580 passed, 5 skipped. `compileall` is clean. Merges cleanly onto current main. - **Merged locally with #978:** clean, and on the merged tree, #978's scalar literal test, this one, `test_alu_ashr_i64` and `test_alu_mad64` all pass (90 tests). Once both are in, #978's `imm64_signed` and this PR's `valu_imm_i64` do the same thing, so a follow-up could fold them into one. - No GPU run or corpus count (no game files). Windows 11, CPU interpreter. GPUs tested: n/a (translator; CPU interpreter) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly. - [x] One topic. - [x] No game data, keys or decryption. - [x] The new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. AI-assisted (Claude Code, Claude Opus 5.5). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01SR1Fv7eQNgZjM6miWPKjHf --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:21:32 +01:00
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#1520
No description provided.