Shaders: a signed 64-bit operand sign-extends its 32-bit literal (port of VIctory#447) #41

Manually merged
github merged 1 commit from gh-pr/41/head into gh-pr/41/base 2026-11-26 03:42:14 +00:00
Owner

@⁠lcg007xd-c on GitHub · 2026-11-25 20:09 UTC · original
lcg007xd-c:port/i64-literal-sign-extend → main · +43 −1 · 2 files · 1 commits · merged 2026-11-25 20:33 UTC

Port of Marvisak/VIctory#447 by Dufftwt, cherry-picked with -x, so the commit keeps its author. VItoriaBr's issue #4 lists it as a sync candidate, and no PR claims it.

What it fixes

A 32-bit literal in a signed 64-bit operand is sign-extended on the hardware (LLVM's AMDGPU operand rules), but the lowering zero-extends every literal. So v_cmp_lt_i64 v[1:2], -100 currently compares against 4294967196, and s_ashr_i64 of a negative literal shifts in zeros. On main, the zero-extend is at crates/victory-shader/src/emit/lower.rs:8066.

The change touches both places a 64-bit operand is built, the vector path and the scalar high-half path. Unsigned and bit operands keep the zero-extension. The diff is 12 lines plus upstream's test, valu_tests::signed_64_bit_operands_sign_extend_their_literal.

Tested (Linux, Rust 1.98.1)

  • The picked commit applies to main without conflicts.
  • cargo test -p victory-shader --lib --locked: 186 passed, 0 failed, 2 ignored.
  • cargo clippy -p victory-shader --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings: clean.

Not run here: the hardware test. valu_tests is Windows-only, and I have no Windows machine, so the Windows CI job runs it.

🤖 Generated with Claude Code

**@⁠lcg007xd-c** on GitHub · 2026-11-25 20:09 UTC · [original](https://github.com/uiliannn/VItoriaBr/pull/41) `lcg007xd-c:port/i64-literal-sign-extend` → `main` · +43 −1 · 2 files · 1 commits · merged 2026-11-25 20:33 UTC Port of [Marvisak/VIctory#447](https://github.com/Marvisak/VIctory/pull/447) by Dufftwt, cherry-picked with `-x`, so the commit keeps its author. VItoriaBr's issue #4 lists it as a sync candidate, and no PR claims it. ## What it fixes A 32-bit literal in a signed 64-bit operand is sign-extended on the hardware (LLVM's AMDGPU operand rules), but the lowering zero-extends every literal. So `v_cmp_lt_i64 v[1:2], -100` currently compares against `4294967196`, and `s_ashr_i64` of a negative literal shifts in zeros. On `main`, the zero-extend is at `crates/victory-shader/src/emit/lower.rs:8066`. The change touches both places a 64-bit operand is built, the vector path and the scalar high-half path. Unsigned and bit operands keep the zero-extension. The diff is 12 lines plus upstream's test, `valu_tests::signed_64_bit_operands_sign_extend_their_literal`. ## Tested (Linux, Rust 1.98.1) - The picked commit applies to `main` without conflicts. - `cargo test -p victory-shader --lib --locked`: 186 passed, 0 failed, 2 ignored. - `cargo clippy -p victory-shader --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings`: clean. **Not run here:** the hardware test. `valu_tests` is Windows-only, and I have no Windows machine, so the Windows CI job runs it. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A literal is 32 bits; in a 64-bit operand the hardware sign-extends it
when the operand is signed (i64) and zero-extends it otherwise (LLVM's
AMDGPU operand rules). Every literal was zero-extended, so
v_cmp_lt_i64 v[1:2], -100 compared with 4294967196, and so did the
other i64 compares, v_ashrrev_i64 and s_ashr_i64.

Literals of operands of i64 instructions are now sign-extended, in the
vector and the scalar paths.

(cherry picked from commit 7d049431de9b12873d801de2b8a54ab4007fcde9)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:42:12 +00:00
github manually merged commit 4c39f8c4c3 into gh-pr/41/base 2026-11-26 03:42:14 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.