Shaders: v_mov_b32 and v_cndmask_b32 apply abs/neg via float ops, flushing denormals and quieting sNaN (fix on a fork) #883

Open
opened 2026-11-24 13:23:24 +00:00 by AscilCH · 4 comments
AscilCH commented 2026-11-24 13:23:24 +00:00 (Migrated from github.com)
Contributor

Imported from Marvisak/VIctory. Originally posted by AscilCH on 2026-11-24T13:23:24Z.


Pull requests are currently restricted to collaborators, so I am sharing this bug report and verified fix from a clean fork branch off main (ffe310e).

Bug

In crates/victory-shader/src/emit/lower.rs, the typeless _b32 instructions v_mov_b32 and v_cndmask_b32 route source operands through fsrc() (which emits dx.op.unary.f32(FAbs) and fsub -0.0, x) whenever abs or neg modifiers are set:

  • v_mov_b32 (lower.rs:3897-3904): routes v.abs != 0 || v.neg != 0 through f(self, 0) and float(self, a).
  • v_cndmask_b32 (lower.rs:4163-4167): routes v.abs != 0 || v.neg != 0 through (f(self, 0), f(self, 1)) and float(self, r).

On RDNA2 (GFX10.3), both v_mov_b32 and v_cndmask_b32 are typeless _b32 instructions (ReadsModeReg = 0 in LLVM AMDGPU) whose abs and neg input modifiers operate strictly bitwise on bit 31 (& 0x7FFF_FFFF / ^ 0x8000_0000) — they do not flush denormals to zero or quiet signalling NaNs. On D3D12 hosts (where f32 arithmetic flushes subnormals and quiets sNaNs), emitting float FAbs / fsub -0.0, x corrupts subnormal values and sNaN payloads.

Reproduction (Before Fix)

With synthetic RDNA2 compute shaders lowered to DXIL and executed on hardware (NVIDIA RTX 3050 6GB Laptop GPU, driver 32.0.16.1742, Windows 11 10.0.26300.0):

hardware: v_mov_b32_e64(-0x00000001) = 0x80000000, want 0x80000001
hardware: v_cndmask_b32_e64(-0x00000001, |0x3f800000|, 0) = 0x80000000, want 0x80000001

Fix

  • Added Lower::src_bits in crates/victory-shader/src/emit/lower.rs to read a raw 32-bit operand (preserving DPP self.src0 and SDWA select_bits) and apply abs (& 0x7FFF_FFFF) and neg (^ 0x8000_0000) bitwise.
  • Updated v_mov_b32 to use src_bits(inst, 0) and write via int(self, a), converting to float via as_float + float(self, a) only when v.clamp || v.omod != 0.
  • Updated v_cndmask_b32 to read both operands via src_bits and write via int(self, r).
  • Added two hardware + WARP + dxil.dll tests in crates/victory-shader/src/emit/valu_tests.rs:
    • emit::valu_tests::v_mov_b32_modifiers_are_bitwise (VOP3 neg, abs, -|x|, SDWA neg, and clamp/mul:2 across normals, ±0.0, ±inf, ±denormal, ±sNaN, and ±qNaN payloads)
    • emit::valu_tests::v_cndmask_b32_modifiers_are_bitwise (VOP3 mixed neg/abs, -|x| + neg, and one-sided neg with unmodified src1 across the same value set)

Verification

Tested on Windows 11 (10.0.26300.0), NVIDIA RTX 3050 6GB Laptop GPU (driver 32.0.16.1742), WARP, and Windows SDK dxil.dll (10.0.26100.0):

  • rustfmt --edition 2024 --check on valu_tests.rs and modified lines of lower.rs: clean
  • cargo xtask policy: 154 files ok
  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean
  • cargo test -p victory-shader --locked -- --skip v_med3_f32_matches_rdna2_with_nan: 121 passed, 0 failed, 1 ignored
  • cargo test --workspace --locked -- --skip v_med3_f32_matches_rdna2_with_nan: all workspace crates passed (0 failed; pre-existing NVIDIA #726 test skipped)

AI-assisted; synthetic tests only, no game files.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6582769928 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/883). Originally posted by [AscilCH](https://github.com/AscilCH) on 2026-11-24T13:23:24Z. --- Pull requests are currently restricted to collaborators, so I am sharing this bug report and verified fix from a clean fork branch off `main` (`ffe310e`). - **Branch:** https://github.com/AscilCH/VIctory/tree/fix/bitwise-abs-neg-mov-cndmask - **Commit:** https://github.com/AscilCH/VIctory/commit/cacf6ad1ec743fe4a1111c84baa9f6114040976c ### Bug In `crates/victory-shader/src/emit/lower.rs`, the typeless `_b32` instructions `v_mov_b32` and `v_cndmask_b32` route source operands through `fsrc()` (which emits `dx.op.unary.f32(FAbs)` and `fsub -0.0, x`) whenever `abs` or `neg` modifiers are set: - `v_mov_b32` (`lower.rs:3897-3904`): routes `v.abs != 0 || v.neg != 0` through `f(self, 0)` and `float(self, a)`. - `v_cndmask_b32` (`lower.rs:4163-4167`): routes `v.abs != 0 || v.neg != 0` through `(f(self, 0), f(self, 1))` and `float(self, r)`. On RDNA2 (GFX10.3), both `v_mov_b32` and `v_cndmask_b32` are typeless `_b32` instructions (`ReadsModeReg = 0` in LLVM AMDGPU) whose `abs` and `neg` input modifiers operate strictly bitwise on bit 31 (`& 0x7FFF_FFFF` / `^ 0x8000_0000`) — they do not flush denormals to zero or quiet signalling NaNs. On D3D12 hosts (where f32 arithmetic flushes subnormals and quiets sNaNs), emitting float `FAbs` / `fsub -0.0, x` corrupts subnormal values and sNaN payloads. ### Reproduction (Before Fix) With synthetic RDNA2 compute shaders lowered to DXIL and executed on hardware (NVIDIA RTX 3050 6GB Laptop GPU, driver `32.0.16.1742`, Windows 11 `10.0.26300.0`): ```text hardware: v_mov_b32_e64(-0x00000001) = 0x80000000, want 0x80000001 hardware: v_cndmask_b32_e64(-0x00000001, |0x3f800000|, 0) = 0x80000000, want 0x80000001 ``` ### Fix - Added `Lower::src_bits` in `crates/victory-shader/src/emit/lower.rs` to read a raw 32-bit operand (preserving DPP `self.src0` and SDWA `select_bits`) and apply `abs` (`& 0x7FFF_FFFF`) and `neg` (`^ 0x8000_0000`) bitwise. - Updated `v_mov_b32` to use `src_bits(inst, 0)` and write via `int(self, a)`, converting to float via `as_float` + `float(self, a)` only when `v.clamp || v.omod != 0`. - Updated `v_cndmask_b32` to read both operands via `src_bits` and write via `int(self, r)`. - Added two hardware + WARP + `dxil.dll` tests in `crates/victory-shader/src/emit/valu_tests.rs`: - `emit::valu_tests::v_mov_b32_modifiers_are_bitwise` (VOP3 `neg`, `abs`, `-|x|`, SDWA `neg`, and `clamp`/`mul:2` across normals, `±0.0`, `±inf`, `±denormal`, `±sNaN`, and `±qNaN` payloads) - `emit::valu_tests::v_cndmask_b32_modifiers_are_bitwise` (VOP3 mixed `neg`/`abs`, `-|x|` + `neg`, and one-sided `neg` with unmodified `src1` across the same value set) ### Verification Tested on Windows 11 (`10.0.26300.0`), NVIDIA RTX 3050 6GB Laptop GPU (driver `32.0.16.1742`), WARP, and Windows SDK `dxil.dll` (`10.0.26100.0`): - `rustfmt --edition 2024 --check` on `valu_tests.rs` and modified lines of `lower.rs`: clean - `cargo xtask policy`: `154 files ok` - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: clean - `cargo test -p victory-shader --locked -- --skip v_med3_f32_matches_rdna2_with_nan`: `121 passed, 0 failed, 1 ignored` - `cargo test --workspace --locked -- --skip v_med3_f32_matches_rdna2_with_nan`: all workspace crates passed (`0 failed`; pre-existing NVIDIA `#726` test skipped) *AI-assisted; synthetic tests only, no game files.*
LAKSHYA-cmd-tech commented 2026-11-24 14:04:54 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by LAKSHYA-cmd-tech on 2026-11-24T13:50:15Z.


Verified and merged downstream in PR #25. Passing bitwise modifiers through bit 31 preserves subnormal values and sNaN payloads on D3D12 hardware for both v_mov_b32 and v_cndmask_b32.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7133409735 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/883#issuecomment-7133409735). Originally posted by [LAKSHYA-cmd-tech](https://github.com/LAKSHYA-cmd-tech) on 2026-11-24T13:50:15Z. --- Verified and merged downstream in PR #25. Passing bitwise modifiers through bit 31 preserves subnormal values and sNaN payloads on D3D12 hardware for both v_mov_b32 and v_cndmask_b32.
DenRakEiw commented 2026-11-24 15:03:52 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-24T14:08:35Z.


Independent verification of cacf6ad (AscilCH/VIctory@fix/bitwise-abs-neg-mov-cndmask, fast-forward on main ffe310e) on Windows 11 x64 (Rust 1.98.1 MSVC) with NVIDIA GeForce RTX 5090 (Blackwell) and WARP:

  • cargo test -p victory-shader valu_tests: 15 passed, 0 failed (no skips needed; v_mov_b32_modifiers_are_bitwise, v_cndmask_b32_modifiers_are_bitwise, and v_med3_f32_matches_rdna2_with_nan all pass on both RTX 5090 and WARP)
  • Negative control (lower.rs reverted to ffe310e, new tests kept): both v_mov_b32_modifiers_are_bitwise and v_cndmask_b32_modifiers_are_bitwise fail as expected (-0x00000001 flushed to 0x80000000 instead of 0x80000001)
  • cargo clippy -p victory-shader --all-targets: 0 warnings
  • cargo xtask policy: ok

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7133906071 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/883#issuecomment-7133906071). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-24T14:08:35Z. --- Independent verification of `cacf6ad` (`AscilCH/VIctory@fix/bitwise-abs-neg-mov-cndmask`, fast-forward on `main` `ffe310e`) on Windows 11 x64 (Rust 1.98.1 MSVC) with **NVIDIA GeForce RTX 5090** (Blackwell) and **WARP**: - `cargo test -p victory-shader valu_tests`: **15 passed, 0 failed** (no skips needed; `v_mov_b32_modifiers_are_bitwise`, `v_cndmask_b32_modifiers_are_bitwise`, and `v_med3_f32_matches_rdna2_with_nan` all pass on both RTX 5090 and WARP) - **Negative control** (`lower.rs` reverted to `ffe310e`, new tests kept): both `v_mov_b32_modifiers_are_bitwise` and `v_cndmask_b32_modifiers_are_bitwise` fail as expected (`-0x00000001` flushed to `0x80000000` instead of `0x80000001`) - `cargo clippy -p victory-shader --all-targets`: **0 warnings** - `cargo xtask policy`: ok AI-assisted (Gemini 4 Neon).
Marvisak commented 2026-11-25 07:03:23 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T06:50:29Z.


Automated triage for the maintainers.

Half of this is still on current main. In crates/victory-shader/src/emit/lower.rs, the v_mov_b32 arm still sends any abs/neg through the float source path (f(self, 0) then float), so a denormal or signalling NaN can be changed. v_cndmask_b32 is already fixed there: it now applies abs/neg as And/Xor on the sign bit ("Sign-bit moves on the bits a select passes through"). I found no open pull request for the v_mov_b32 part. Pull requests are open to everyone now, so please open one for cacf6ad (or only its v_mov_b32 half and the tests) against current main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7155213901 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/883#issuecomment-7155213901). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T06:50:29Z. --- <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-24T14:08:35Z at=2026-11-25T06:50:28Z --> Automated triage for the maintainers. Half of this is still on current `main`. In `crates/victory-shader/src/emit/lower.rs`, the `v_mov_b32` arm still sends any `abs`/`neg` through the float source path (`f(self, 0)` then `float`), so a denormal or signalling NaN can be changed. `v_cndmask_b32` is already fixed there: it now applies `abs`/`neg` as `And`/`Xor` on the sign bit ("Sign-bit moves on the bits a select passes through"). I found no open pull request for the `v_mov_b32` part. Pull requests are open to everyone now, so please open one for `cacf6ad` (or only its `v_mov_b32` half and the tests) against current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
Lyrnc commented 2026-11-26 18:52:23 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by Lyrnc on 2026-11-26T18:52:23Z.


Hardware check of the claim here, on gfx1036 (RDNA2). It holds: abs and neg on v_mov_b32 and v_cndmask_b32 only move bit 31. The measurement also shows something no fix here covers: v_mov_b32 ignores clamp and the output modifier. main and #2548 both apply them as float operations.

Setup.

  • Hardware: the Radeon iGPU of a Ryzen 7 9800X3D, gfx1036, AMD driver 32.0.21042.62, Windows 11. A HIP kernel (assembled by the driver's amd_comgr) runs the raw words below, one input row per lane.
  • Mode: IEEE off, f32 denormals flushed (the console's mode). As controls, f32 denormals kept (all forms), and IEEE on (the clamp/omod forms).
  • Inputs: 20 patterns, 10 rows each, 200 rows per form: ±0, ±1, ±inf, the smallest and largest denormals of both signs, 0x00400000, ±FLT_MIN, quiet and signalling NaNs with payloads. v_cndmask_b32 picks per row between that pattern and a small denormal.
  • Translator: the same words through build_valu_cs, on that Radeon and on an RTX 5080 (driver 610.88), one adapter at a time with a local switch.

PC RDNA2 silicon, not the console's GPU. No game data.

gfx1036 results. The same with f32 denormals flushed or kept, and the clamp/omod rows also with IEEE on:

  • v_mov_b32_e64 with neg, abs, or -|x|: the source with bit 31 flipped, cleared or set. Nothing else changes: -0x00000001 gives 0x80000001, |0xff800001| gives 0x7f800001, and 0xffc00000 stays 0xffc00000 under -|x|.
  • v_mov_b32_e64 with clamp, mul:2, mul:4 or div:2: the source, unchanged. Examples: -1.0 clamp → 0xbf800000, 1.0 mul:2 → 0x3f800000, 0.5 mul:4 → 0x3f000000, -0 clamp → 0x80000000, 0x7f800001 clamp → 0x7f800001.
  • v_mov_b32_e64 -v clamp: the negation applies and the clamp doesn't: 1.0 → 0xbf800000.
  • v_cndmask_b32_e64: neg/abs on either source are the same sign-bit moves on the selected value. clamp and mul:2 are ignored there too (-1.0, 2.0 and 0x80000001 come through unchanged).

Translator, rows that differ from the hardware (of 200):

form main 63bcca4, Radeon main, RTX 5080 #2548 (f3809a8), Radeon #2548, RTX 5080
-v 0 0 0 0
|v| 0 120 0 0
-|v| 0 120 0 0
clamp 170 170 170 170
mul:2 / div:2 100 170 100 170
-v clamp 170 170 170 170
v_cndmask_b32 neg/abs, either source 0 0 0 0

The 120 on the 5080 are the denormals flushed to ±0 and the NaNs rewritten, as this issue describes. The AMD driver happens to keep them through the float path. #2548 fixes those on both hosts.

The clamp and multiplier rows still differ with #2548. It sends v_mov_b32 through write_f when clamp or omod is set, and its test asserts that: -(-0.25) clamp mul:2 should be 0.5. On the hardware that instruction gives 0x3e800000 (0.25).

A fix stacked on #2548 is on Lyrnc:fix/v-mov-b32-ignores-clamp-omod. It writes the moved bits whatever clamp/omod say. It adds a GPU test from the rows above that fails on main and on #2548, and changes #2548's float-modifier case to the hardware's value. I'll open it as a PR once #2548 is settled, or fold it in if fuzeofficlal prefers.

AI use: Claude Code (Claude Opus 5.5) wrote the probe and ran it on the GPUs above; the numbers come from those runs.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7200944888 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/883#issuecomment-7200944888). Originally posted by [Lyrnc](https://github.com/Lyrnc) on 2026-11-26T18:52:23Z. --- Hardware check of the claim here, on gfx1036 (RDNA2). It holds: `abs` and `neg` on `v_mov_b32` and `v_cndmask_b32` only move bit 31. The measurement also shows something no fix here covers: **`v_mov_b32` ignores `clamp` and the output modifier.** `main` and #2548 both apply them as float operations. **Setup.** - **Hardware:** the Radeon iGPU of a Ryzen 7 9800X3D, **gfx1036**, AMD driver 32.0.21042.62, Windows 11. A HIP kernel (assembled by the driver's amd_comgr) runs the raw words below, one input row per lane. - **Mode:** IEEE off, f32 denormals flushed (the console's mode). As controls, f32 denormals kept (all forms), and IEEE on (the `clamp`/`omod` forms). - **Inputs:** 20 patterns, 10 rows each, 200 rows per form: `±0`, `±1`, `±inf`, the smallest and largest denormals of both signs, `0x00400000`, `±FLT_MIN`, quiet and signalling NaNs with payloads. `v_cndmask_b32` picks per row between that pattern and a small denormal. - **Translator:** the same words through `build_valu_cs`, on that Radeon and on an RTX 5080 (driver 610.88), one adapter at a time with a local switch. PC RDNA2 silicon, not the console's GPU. No game data. **gfx1036 results.** The same with f32 denormals flushed or kept, and the `clamp`/`omod` rows also with IEEE on: - **`v_mov_b32_e64` with `neg`, `abs`, or `-|x|`:** the source with bit 31 flipped, cleared or set. Nothing else changes: `-0x00000001` gives `0x80000001`, `|0xff800001|` gives `0x7f800001`, and `0xffc00000` stays `0xffc00000` under `-|x|`. - **`v_mov_b32_e64` with `clamp`, `mul:2`, `mul:4` or `div:2`:** the source, unchanged. Examples: `-1.0 clamp → 0xbf800000`, `1.0 mul:2 → 0x3f800000`, `0.5 mul:4 → 0x3f000000`, `-0 clamp → 0x80000000`, `0x7f800001 clamp → 0x7f800001`. - **`v_mov_b32_e64 -v clamp`:** the negation applies and the clamp doesn't: `1.0 → 0xbf800000`. - **`v_cndmask_b32_e64`:** `neg`/`abs` on either source are the same sign-bit moves on the selected value. `clamp` and `mul:2` are ignored there too (`-1.0`, `2.0` and `0x80000001` come through unchanged). **Translator, rows that differ from the hardware (of 200):** | form | `main` `63bcca4`, Radeon | `main`, RTX 5080 | #2548 (`f3809a8`), Radeon | #2548, RTX 5080 | |---|---|---|---|---| | `-v` | 0 | 0 | 0 | 0 | | `\|v\|` | 0 | **120** | 0 | 0 | | `-\|v\|` | 0 | **120** | 0 | 0 | | `clamp` | **170** | **170** | **170** | **170** | | `mul:2` / `div:2` | **100** | **170** | **100** | **170** | | `-v clamp` | **170** | **170** | **170** | **170** | | `v_cndmask_b32` `neg`/`abs`, either source | 0 | 0 | 0 | 0 | The 120 on the 5080 are the denormals flushed to `±0` and the NaNs rewritten, as this issue describes. The AMD driver happens to keep them through the float path. #2548 fixes those on both hosts. The `clamp` and multiplier rows still differ with #2548. It sends `v_mov_b32` through `write_f` when `clamp` or `omod` is set, and its test asserts that: `-(-0.25) clamp mul:2` should be `0.5`. On the hardware that instruction gives `0x3e800000` (`0.25`). A fix stacked on #2548 is on [`Lyrnc:fix/v-mov-b32-ignores-clamp-omod`](https://github.com/Lyrnc/VIctory/tree/fix/v-mov-b32-ignores-clamp-omod). It writes the moved bits whatever `clamp`/`omod` say. It adds a GPU test from the rows above that fails on `main` and on #2548, and changes #2548's float-modifier case to the hardware's value. I'll open it as a PR once #2548 is settled, or fold it in if fuzeofficlal prefers. AI use: Claude Code (Claude Opus 5.5) wrote the probe and ran it on the GPUs above; the numbers come from those runs.
Sign in to join this conversation.
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
Marvisak/VIctory#883
No description provided.