Shaders: v_max_f16/v_min_f16/v_max3_f16/v_min3_f16 have no negative-zero ordering test #802

Closed
opened 2026-11-26 04:13:59 +00:00 by github-bot · 4 comments
Owner

@⁠kss306 on GitHub · 2026-11-24 11:11 UTC · original

max_and_min_order_negative_zero_below_positive_zero in valu_tests.rs checks that v_max_f32/v_min_f32/v_max3_f32/v_min3_f32 order −0 below +0 as RDNA2 requires. The f16 equivalents (v_max_f16, v_min_f16, v_max3_f16, v_min3_f16) go through the same max_min() helper (fixed by #448) but are never covered by any test.

Affected instructions

Instruction VOP3 opcode Tested f32 sibling
v_max_f16 0x111 v_max_f32 (0x110) ✓
v_min_f16 0x10E v_min_f32 (0x10F) ✓
v_max3_f16 0x354 v_max3_f32 (0x154) ✓
v_min3_f16 0x351 v_min3_f32 (0x151) ✓

Implementation evidence

lower.rs, max_min() at line 1377, is the single helper for all float min/max variants. For f16 inputs the caller widens them from f16 to f32 via half_fsrc() before entering max_min(), so the helper operates on f32-widened values. RDNA2's f16 −0 (0x8000) widens to f32 −0 (0x8000_0000), so the magnitude AND with 0x7FFF_FFFF correctly detects the two-zeros case in widened space.

PR #448 explicitly states the fix covers "v_max_f32, v_min_f32, their three-operand and f16 forms". The implementation is correct; the f16 test was never added.

The f16 path in valu16_op() (lower.rs around line 4344):

"v_max_f16" => self.max_min(true, a, b),
_ => self.max_min(false, a, b),   // catches v_min_f16

And the three-operand f16 forms (lower.rs around line 4377):

"v_max3_f16" => { let t = self.max_min(true, a, b); self.max_min(true, t, acc) }
"v_min3_f16" => { let t = self.max_min(false, a, b); self.max_min(false, t, acc) }

Missing test

valu_tests.rs fn max_and_min_order_negative_zero_below_positive_zero() (line 311) covers only f32 opcodes (0x110, 0x10F, 0x154, 0x151). The f16 opcodes 0x111, 0x10E, 0x354, 0x351 do not appear in the test.

The test helpers for f16 bit patterns are already present in the file (f16_to_f32, is_f16_nan), and f16 −0 (0x8000) is already used in v_cmp_lg_is_false_for_nan. Adding the f16 cases requires only a second ops array.

Suggested test addition

Extend max_and_min_order_negative_zero_below_positive_zero with an f16 block:

// f16: -0 = 0x8000, +0 = 0x0000. The low 16 bits of v0 hold the f16 result.
let (pz16, nz16) = (0x0000_u32, 0x8000_u32);
let cases16 = [
    [nz16, pz16, nz16, 0],
    [pz16, nz16, nz16, 0],
    [nz16, pz16, pz16, 0],
    [pz16, nz16, pz16, 0],
];
let ops16 = [
    ("v_max_f16",  0x111, pz16),
    ("v_min_f16",  0x10E, nz16),
    ("v_max3_f16", 0x354, pz16),
    ("v_min3_f16", 0x351, nz16),
];
for (name, op, want) in ops16 {
    let shader = build_valu_cs(&vop3(op, 0, vgpr(1), vgpr(2), vgpr(3)));
    run_cases(&shader, &cases16, |backend, _, inp, got| {
        // compare low 16 bits only (f16 result sits in the low half)
        assert_eq!(got & 0xFFFF, want, "{backend}: {name} {inp:x?}");
    });
}

No game data needed; the test skips when no SM 6.6 device is available and runs on WARP.

AI-assisted: found with Kiro (Claude) and independently confirmed by five separate analysis passes without cross-contamination; no hardware run, no game data.

**@⁠kss306** on GitHub · 2026-11-24 11:11 UTC · [original](https://github.com/Marvisak/VIctory/issues/802) `max_and_min_order_negative_zero_below_positive_zero` in `valu_tests.rs` checks that `v_max_f32`/`v_min_f32`/`v_max3_f32`/`v_min3_f32` order −0 below +0 as RDNA2 requires. The f16 equivalents (`v_max_f16`, `v_min_f16`, `v_max3_f16`, `v_min3_f16`) go through the same `max_min()` helper (fixed by #448) but are never covered by any test. ## Affected instructions | Instruction | VOP3 opcode | Tested f32 sibling | |---|---|---| | `v_max_f16` | 0x111 | `v_max_f32` (0x110) ✓ | | `v_min_f16` | 0x10E | `v_min_f32` (0x10F) ✓ | | `v_max3_f16` | 0x354 | `v_max3_f32` (0x154) ✓ | | `v_min3_f16` | 0x351 | `v_min3_f32` (0x151) ✓ | ## Implementation evidence `lower.rs`, `max_min()` at line 1377, is the single helper for all float min/max variants. For f16 inputs the caller widens them from f16 to f32 via `half_fsrc()` before entering `max_min()`, so the helper operates on f32-widened values. RDNA2's f16 −0 (`0x8000`) widens to f32 −0 (`0x8000_0000`), so the magnitude AND with `0x7FFF_FFFF` correctly detects the two-zeros case in widened space. PR #448 explicitly states the fix covers "v_max_f32, v_min_f32, their three-operand and f16 forms". The implementation is correct; the f16 test was never added. The f16 path in `valu16_op()` (`lower.rs` around line 4344): ```rust "v_max_f16" => self.max_min(true, a, b), _ => self.max_min(false, a, b), // catches v_min_f16 ``` And the three-operand f16 forms (`lower.rs` around line 4377): ```rust "v_max3_f16" => { let t = self.max_min(true, a, b); self.max_min(true, t, acc) } "v_min3_f16" => { let t = self.max_min(false, a, b); self.max_min(false, t, acc) } ``` ## Missing test `valu_tests.rs` `fn max_and_min_order_negative_zero_below_positive_zero()` (line 311) covers only f32 opcodes (`0x110`, `0x10F`, `0x154`, `0x151`). The f16 opcodes `0x111`, `0x10E`, `0x354`, `0x351` do not appear in the test. The test helpers for f16 bit patterns are already present in the file (`f16_to_f32`, `is_f16_nan`), and f16 −0 (`0x8000`) is already used in `v_cmp_lg_is_false_for_nan`. Adding the f16 cases requires only a second `ops` array. ## Suggested test addition Extend `max_and_min_order_negative_zero_below_positive_zero` with an f16 block: ```rust // f16: -0 = 0x8000, +0 = 0x0000. The low 16 bits of v0 hold the f16 result. let (pz16, nz16) = (0x0000_u32, 0x8000_u32); let cases16 = [ [nz16, pz16, nz16, 0], [pz16, nz16, nz16, 0], [nz16, pz16, pz16, 0], [pz16, nz16, pz16, 0], ]; let ops16 = [ ("v_max_f16", 0x111, pz16), ("v_min_f16", 0x10E, nz16), ("v_max3_f16", 0x354, pz16), ("v_min3_f16", 0x351, nz16), ]; for (name, op, want) in ops16 { let shader = build_valu_cs(&vop3(op, 0, vgpr(1), vgpr(2), vgpr(3))); run_cases(&shader, &cases16, |backend, _, inp, got| { // compare low 16 bits only (f16 result sits in the low half) assert_eq!(got & 0xFFFF, want, "{backend}: {name} {inp:x?}"); }); } ``` No game data needed; the test skips when no SM 6.6 device is available and runs on WARP. **AI-assisted:** found with Kiro (Claude) and independently confirmed by five separate analysis passes without cross-contamination; no hardware run, no game data.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:13:59 +00:00
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-24 11:51 UTC · original

I added a synthetic regression test for all four f16 min/max forms. The two-source VOP3 encodings are 0x139 for v_max_f16 and 0x13a for v_min_f16. The three-source encodings are 0x354 and 0x351 as reported. The test checks the decoded instruction names before comparing the low 16 bits of the readback.

All eight sign combinations passed for each instruction on both the hardware D3D12 adapter and WARP. That includes the two cases where only the third operand's sign differs. The full VALU test group passed (14 tests), along with Clippy, formatting for the changed file, and the asset policy check.

The single test-only commit is available for review or cherry-pick. 53e1c74

**@⁠fuzeofficlal** on GitHub · 2026-11-24 11:51 UTC · [original](https://github.com/Marvisak/VIctory/issues/802#issuecomment-7130636112) I added a synthetic regression test for all four f16 min/max forms. The two-source VOP3 encodings are `0x139` for `v_max_f16` and `0x13a` for `v_min_f16`. The three-source encodings are `0x354` and `0x351` as reported. The test checks the decoded instruction names before comparing the low 16 bits of the readback. All eight sign combinations passed for each instruction on both the hardware D3D12 adapter and WARP. That includes the two cases where only the third operand's sign differs. The full VALU test group passed (14 tests), along with Clippy, formatting for the changed file, and the asset policy check. The single test-only commit is available for review or cherry-pick. [`53e1c74`](https://github.com/fuzeofficlal/VIctory/commit/53e1c7482146d9f3e3bc83f2377c9f1817cbe12e)
Author
Owner

@⁠towiice on GitHub · 2026-11-24 11:58 UTC · original

Implemented and verified on hardware. Note on opcode mapping: in GFX10 VOP3 encoding, VOP2 instructions map at base 0x100, so v_max_f16 (VOP2 0x039) is 0x139, and v_min_f16 (VOP2 0x03A) is 0x13A (whereas 0x111 / 0x10E are unknown/unmapped VOP3 opcodes). v_max3_f16 (0x354) and v_min3_f16 (0x351) are native VOP3.

The extended test is implemented on:
https://github.com/towiice/VIctory/tree/test/valu-integer-min3-max3-med3 (commit 89fa58e)

Hardware Test Results:

  • Hardware: NVIDIA GeForce GTX 1650 SUPER (Turing TU116, 4 GB VRAM, 32-wide subgroups / wave32, driver 610.88), Windows 11 x64 (26H2 / 10.0.26300), DXC v1.9.2609, toolchain stable-x86_64-pc-windows-gnullvm.
  • Test command: cargo +stable-x86_64-pc-windows-gnullvm test -p victory-shader --lib max_and_min -- --nocapture
  • Result: 1 passed, 0 failed (5.17 s). All four f16 operations correctly order -0 (0x8000) below +0 (0x0000) on both hardware GPU and WARP.
**@⁠towiice** on GitHub · 2026-11-24 11:58 UTC · [original](https://github.com/Marvisak/VIctory/issues/802#issuecomment-7130782287) Implemented and verified on hardware. Note on opcode mapping: in GFX10 VOP3 encoding, VOP2 instructions map at base `0x100`, so `v_max_f16` (VOP2 `0x039`) is `0x139`, and `v_min_f16` (VOP2 `0x03A`) is `0x13A` (whereas `0x111` / `0x10E` are unknown/unmapped VOP3 opcodes). `v_max3_f16` (`0x354`) and `v_min3_f16` (`0x351`) are native VOP3. The extended test is implemented on: https://github.com/towiice/VIctory/tree/test/valu-integer-min3-max3-med3 (commit `89fa58e`) **Hardware Test Results:** - Hardware: NVIDIA GeForce GTX 1650 SUPER (Turing TU116, 4 GB VRAM, 32-wide subgroups / wave32, driver 610.88), Windows 11 x64 (26H2 / 10.0.26300), DXC v1.9.2609, toolchain `stable-x86_64-pc-windows-gnullvm`. - Test command: `cargo +stable-x86_64-pc-windows-gnullvm test -p victory-shader --lib max_and_min -- --nocapture` - Result: **1 passed, 0 failed** (5.17 s). All four f16 operations correctly order -0 (`0x8000`) below +0 (`0x0000`) on both hardware GPU and WARP.
Author
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-24 11:59 UTC · original

Added the requested synthetic hardware test max_and_min_f16_order_negative_zero_below_positive_zero covering v_max_f16, v_min_f16, v_max3_f16, and v_min3_f16 across all -0.0 (0x8000) / +0.0 (0x0000) orderings plus non-zero high-half garbage bits.

(Note: in RDNA2 VOP3 encoding, the VOP2 forms v_max_f16 (0x039) and v_min_f16 (0x03a) sit at 0x139 and 0x13a rather than 0x111/0x10e listed in the OP table — 0x111 is v_min_i32 and 0x10e does not decode. Verified against victory-shader's decoder and live hardware.)

External PRs are currently collaborators_only, so the verified commit (combined with #799 and #800 in crates/victory-shader/src/emit/valu_tests.rs, based on main ffe310e) is ready on my fork:

Verification (Windows 11 Pro 26100, AMD Radeon RX 9060 XT driver 32.0.32029.2010 + WARP, Rust 1.98.1):

  • rustfmt --edition 2024 --check crates/victory-shader/src/emit/valu_tests.rs: PASS
  • cargo xtask policy: PASS (154 files ok)
  • cargo clippy --workspace --all-targets --locked -- -D warnings (default + --features diagnostics): PASS
  • cargo test -p victory-shader --locked -- valu_tests: 16/16 PASS (verified on both RX 9060 XT and WARP via run_cases)
  • cargo test --workspace --locked: PASS (0 failed)

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

**@⁠geiyiliyabumo** on GitHub · 2026-11-24 11:59 UTC · [original](https://github.com/Marvisak/VIctory/issues/802#issuecomment-7130803314) Added the requested synthetic hardware test `max_and_min_f16_order_negative_zero_below_positive_zero` covering `v_max_f16`, `v_min_f16`, `v_max3_f16`, and `v_min3_f16` across all `-0.0` (`0x8000`) / `+0.0` (`0x0000`) orderings plus non-zero high-half garbage bits. *(Note: in RDNA2 VOP3 encoding, the VOP2 forms `v_max_f16` (`0x039`) and `v_min_f16` (`0x03a`) sit at **`0x139`** and **`0x13a`** rather than `0x111`/`0x10e` listed in the OP table — `0x111` is `v_min_i32` and `0x10e` does not decode. Verified against `victory-shader`'s decoder and live hardware.)* External PRs are currently `collaborators_only`, so the verified commit (combined with #799 and #800 in `crates/victory-shader/src/emit/valu_tests.rs`, based on `main` `ffe310e`) is ready on my fork: - Branch: https://github.com/geiyiliyabumo/VIctory/tree/test/valu-f32-class-int3-f16-zero - Commit: https://github.com/geiyiliyabumo/VIctory/commit/9a173fc **Verification (Windows 11 Pro 26100, AMD Radeon RX 9060 XT driver `32.0.32029.2010` + WARP, Rust `1.98.1`):** - `rustfmt --edition 2024 --check crates/victory-shader/src/emit/valu_tests.rs`: PASS - `cargo xtask policy`: PASS (`154 files ok`) - `cargo clippy --workspace --all-targets --locked -- -D warnings` (default + `--features diagnostics`): PASS - `cargo test -p victory-shader --locked -- valu_tests`: **16/16 PASS** (verified on both RX 9060 XT and WARP via `run_cases`) - `cargo test --workspace --locked`: PASS (0 failed) *AI-assisted; synthetic tests only, no game files.*
Author
Owner

@⁠Altorru on GitHub · 2026-11-24 12:17 UTC · original

The f16 block is in max_and_min_order_negative_zero_below_positive_zero and covers v_max_f16, v_min_f16, v_max3_f16 and v_min3_f16. One correction to the issue text: the two-operand forms are VOP2 0x039/0x03a in this decoder, not VOP3 0x111/0x10E, so the test builds them as VOP2 and the three-operand forms as VOP3. Implemented in fork PR Altorru/VIctory#1 (upstream PR creation is collaborator-only), commit bb3a37b. Windows CI passed: cargo test --workspace on https://github.com/Altorru/VIctory/actions/runs/45391712656, where the new test ran on WARP. No game data.

**@⁠Altorru** on GitHub · 2026-11-24 12:17 UTC · [original](https://github.com/Marvisak/VIctory/issues/802#issuecomment-7131240654) The f16 block is in max_and_min_order_negative_zero_below_positive_zero and covers v_max_f16, v_min_f16, v_max3_f16 and v_min3_f16. One correction to the issue text: the two-operand forms are VOP2 0x039/0x03a in this decoder, not VOP3 0x111/0x10E, so the test builds them as VOP2 and the three-operand forms as VOP3. Implemented in fork PR Altorru/VIctory#1 (upstream PR creation is collaborator-only), commit bb3a37b. Windows CI passed: cargo test --workspace on https://github.com/Altorru/VIctory/actions/runs/45391712656, where the new test ran on WARP. No game data.
This discussion has been locked. Commenting is limited to contributors.
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#802
No description provided.