Shaders: a float inline constant in a 64-bit operand is the f64 value #1559

Closed
github-bot wants to merge 1 commit from gh-pr/1559/head into gh-pr/1559/base
Owner

@⁠default-cybe on GitHub · 2026-11-24 19:10 UTC · original
default-cybe:fix/inline-float-const-64bit-operand → main · +93 −9 · 3 files · 1 commits · closed without merging

What

resource::inline64(code) gives the value of an inline constant in a 64-bit operand: integers 128..208 sign-extended, floats 240..248 as f64 bit patterns (0.5, -0.5, 1, -1, 2, -2, 4, -4, and 0x3FC45F30_6DC9C882 for 1/(2 pi)). The SALU 64-bit half closure in emit/lower.rs and src64 now use it.

Why

Per LLVM, a 64-bit source reads codes 240..248 as doubles (LLVM's AMDGPUDisassembler::decodeFPImmed picks getInlineImmVal64 for any 64-bit-wide operand). We took the f32 bits from inline() for the low dword and filled the high dword with the f32's sign (half) or with zero (src64, which sent 240..248 to the zero-extending arm). So:

  • s_mov_b64 s[12:13], 1.0 gave 0x00000000_3f800000, not 0x3ff00000_00000000
  • s_mov_b64 s[12:13], 1/(2pi) gave low dword 0x3e22f983, not 0x6dc9c882
  • s_mov_b64 s[12:13], -1.0 gave high dword 0xffffffff, not 0xbff00000
  • v_lshrrev_b64 v[0:1], 32, -1.0 gave 0, not 0xbff00000
  • v_cmp_eq_u64 against a float constant compared the wrong value

This reaches every user of half (s_mov_b64, s_cselect_b64, s_and/or/xor/... b64, s_lshl/lshr_b64, s_ashr_i64, s_bcnt1_i32_b64, s_ff1_i32_b64, s_cmpu64) and of src64 (v_lshlrev/lshrrev_b64, v_ashrrev_i64, v_cmp_u64/i64). Inline integers behave as before.

Tested

Windows 11 x64, RTX 5070 (driver 32.0.16.1088) and WARP, on main ffe310e plus this commit:

  • New test emit::valu_tests::inline_float_constant_in_a_64_bit_operand_is_the_f64_value. It builds 1-thread GFX10 compute shaders with build_valu_cs: s_mov_b64 (both dwords) for each of codes 240..248, 192 and 208, and s_and_b64 -1, c, v_lshrrev_b64 32, c and v_cmp_eq_u64 c, v[1:2] for codes 243 (-1.0), 248 (1/(2 pi)) and 208 (-16). It runs them with run_cases on the hardware adapter and on WARP. On main it fails with 48 mismatches (24 float checks x 2 devices; the integer codes pass). With the fix it passes on both. The expected values follow LLVM's table; this does not measure AMD hardware.
  • cargo test --workspace: 343 passed, 0 failed, 6 ignored.
  • cargo xtask policy: asset policy: 154 files ok.
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings (the CI command): clean.
  • rustfmt --edition 2024 --check crates/victory-shader/src/emit/valu_tests.rs: clean. cargo fmt --check -p victory-shader reports diffs in lower.rs and resource.rs that are already on main; none are in the lines this commit changes.

Not tested

  • Linux and AMD hardware: not by me. #1458 reports the new test passing at acce0c0 on a Radeon 660M (RDNA2, RADV under Proton). That run checks the emitted DXIL on a second GPU; the expected values still come from LLVM's table.
  • Not run against a game shader.
  • wave.rs constant() (whole-wave simulation of EXEC writes) is not changed. It still treats 240..248 as f32 values; #646 rewrites that function and makes it refuse float constants on s_mov_b64.

Overlap

  • #447 changes the same src64 arm and the half closure (signed 64-bit literals). The two conflict textually; whichever lands second needs a small rebase.
  • #646 (wave.rs constant() refusing float constants on s_mov_b64) is next to this but touches a different file.
  • #416 (v_cvt_f32_f64 via src64) would get the right f64 value for a float constant with this change.
  • #978 (v_cvt_f32_f64) and #1262 (double arithmetic, stacked on #416) each add their own f64 reader that maps codes 240..248 to doubles. They do not change half or src64; if one lands first, its reader and resource::inline64 could share one table.

AI use

Written with Conclave (model cliproxy/claude-opus-5-5), which also ran the commands listed under Tested on my machine, before and after the change. The behaviour comes from public sources (LLVM AMDGPU disassembler).

**@⁠default-cybe** on GitHub · 2026-11-24 19:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/1559) `default-cybe:fix/inline-float-const-64bit-operand` → `main` · +93 −9 · 3 files · 1 commits · closed without merging ## What `resource::inline64(code)` gives the value of an inline constant in a 64-bit operand: integers 128..208 sign-extended, floats 240..248 as f64 bit patterns (0.5, -0.5, 1, -1, 2, -2, 4, -4, and 0x3FC45F30_6DC9C882 for 1/(2 pi)). The SALU 64-bit `half` closure in `emit/lower.rs` and `src64` now use it. ## Why Per LLVM, a 64-bit source reads codes 240..248 as doubles (LLVM's `AMDGPUDisassembler::decodeFPImmed` picks `getInlineImmVal64` for any 64-bit-wide operand). We took the f32 bits from `inline()` for the low dword and filled the high dword with the f32's sign (`half`) or with zero (`src64`, which sent 240..248 to the zero-extending arm). So: - `s_mov_b64 s[12:13], 1.0` gave `0x00000000_3f800000`, not `0x3ff00000_00000000` - `s_mov_b64 s[12:13], 1/(2pi)` gave low dword `0x3e22f983`, not `0x6dc9c882` - `s_mov_b64 s[12:13], -1.0` gave high dword `0xffffffff`, not `0xbff00000` - `v_lshrrev_b64 v[0:1], 32, -1.0` gave `0`, not `0xbff00000` - `v_cmp_eq_u64` against a float constant compared the wrong value This reaches every user of `half` (s_mov_b64, s_cselect_b64, s_and/or/xor/... _b64, s_lshl/lshr_b64, s_ashr_i64, s_bcnt1_i32_b64, s_ff1_i32_b64, s_cmp_*_u64) and of `src64` (v_lshlrev/lshrrev_b64, v_ashrrev_i64, v_cmp_*_u64/i64). Inline integers behave as before. ## Tested Windows 11 x64, RTX 5070 (driver 32.0.16.1088) and WARP, on `main` ffe310e plus this commit: - New test `emit::valu_tests::inline_float_constant_in_a_64_bit_operand_is_the_f64_value`. It builds 1-thread GFX10 compute shaders with `build_valu_cs`: `s_mov_b64` (both dwords) for each of codes 240..248, 192 and 208, and `s_and_b64 -1, c`, `v_lshrrev_b64 32, c` and `v_cmp_eq_u64 c, v[1:2]` for codes 243 (-1.0), 248 (1/(2 pi)) and 208 (-16). It runs them with `run_cases` on the hardware adapter and on WARP. On `main` it fails with 48 mismatches (24 float checks x 2 devices; the integer codes pass). With the fix it passes on both. The expected values follow LLVM's table; this does not measure AMD hardware. - `cargo test --workspace`: 343 passed, 0 failed, 6 ignored. - `cargo xtask policy`: `asset policy: 154 files ok`. - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` (the CI command): clean. - `rustfmt --edition 2024 --check crates/victory-shader/src/emit/valu_tests.rs`: clean. `cargo fmt --check -p victory-shader` reports diffs in `lower.rs` and `resource.rs` that are already on `main`; none are in the lines this commit changes. ## Not tested - Linux and AMD hardware: not by me. #1458 reports the new test passing at `acce0c0` on a Radeon 660M (RDNA2, RADV under Proton). That run checks the emitted DXIL on a second GPU; the expected values still come from LLVM's table. - Not run against a game shader. - `wave.rs` `constant()` (whole-wave simulation of EXEC writes) is not changed. It still treats 240..248 as f32 values; #646 rewrites that function and makes it refuse float constants on `s_mov_b64`. ## Overlap - #447 changes the same `src64` arm and the `half` closure (signed 64-bit literals). The two conflict textually; whichever lands second needs a small rebase. - #646 (wave.rs `constant()` refusing float constants on `s_mov_b64`) is next to this but touches a different file. - #416 (`v_cvt_f32_f64` via `src64`) would get the right f64 value for a float constant with this change. - #978 (`v_cvt_f32_f64`) and #1262 (double arithmetic, stacked on #416) each add their own f64 reader that maps codes 240..248 to doubles. They do not change `half` or `src64`; if one lands first, its reader and `resource::inline64` could share one table. ## AI use Written with Conclave (model `cliproxy/claude-opus-5-5`), which also ran the commands listed under Tested on my machine, before and after the change. The behaviour comes from public sources (LLVM AMDGPU disassembler).
In a 64-bit source (s_mov_b64 and the other SALU b64 ops, the 64-bit
VALU shifts and the u64/i64 compares) the inline constants 240..248 are
f64 bit patterns, as in LLVM's getInlineImmVal64. We used the f32 bits
in the low dword and zero or sign filled the high dword, so
s_mov_b64 s[0:1], 1.0 gave 0x00000000_3f800000, not 0x3ff00000_00000000.

Add resource::inline64 and use it in the SALU 64-bit `half` closure and
in src64. A GPU test checks every float constant and two integer ones
through s_mov_b64, and three of them through s_and_b64, v_lshrrev_b64
and v_cmp_eq_u64.

Committed-by: Conclave (cliproxy/claude-opus-5-5)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:36:26 +00:00
github-bot closed this pull request 2026-11-26 04:36:26 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:42 UTC · original

Automated triage for the maintainers. Closing because another open pull request covers the same change.

See #1577. Float inline constants in 64-bit operands as f64 bits. #1577 contains this change line for line and also follows the constants in resource tracking and s_mov_b64.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

**@⁠Marvisak** on GitHub · 2026-11-25 00:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/1559#issuecomment-7148794512) Automated triage for the maintainers. Closing because another open pull request covers the same change. See #1577. Float inline constants in 64-bit operands as f64 bits. #1577 contains this change line for line and also follows the constants in resource tracking and s_mov_b64. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1559
No description provided.