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

Merged
lcg007xd-c merged 1 commit from upstream-pr/41 into main 2026-11-25 20:33:08 +00:00
lcg007xd-c commented 2026-11-25 20:09:18 +00:00 (Migrated from github.com)

Imported from uiliannn/VItoriaBr. Originally posted by lcg007xd-c on 2026-11-25T20:09:18Z.


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

<!-- greyfinch-sync:uiliannn/VItoriaBr:issue:6612787931 --> Imported from [uiliannn/VItoriaBr](https://github.com/uiliannn/VItoriaBr/pull/41). Originally posted by [lcg007xd-c](https://github.com/lcg007xd-c) on 2026-11-25T20:09:18Z. --- 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)
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
uiliannn/VItoriaBr!41
No description provided.