Shaders: v_cmp_class_f32 (VOPC 0x088) has no synthetic hardware test #799

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

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

v_cmp_class_f32 (VOPC opcode 0x088) is fully implemented in crates/victory-shader/src/emit/lower.rs but has no synthetic hardware test in crates/victory-shader/src/emit/valu_tests.rs. Its sibling v_cmp_class_f16 (VOPC 0x08f) has an exhaustive test added in #140.

Implementation evidence

lower.rs, compare() at line 5097, handles both types in one branch:

"f32" | "f16" if op == "class" => {
    let f16 = ty == "f16";
    let x = if f16 {
        // half_src() extracts 16-bit operand
    } else {
        let x = self.fsrc(inst, 0)?;   // f32-specific path
        self.as_int(x)
    };
    let (exp_sh, sign_sh, exp_mask, mant_mask, quiet_bit) = if f16 {
        (10, 15, 0x1F, 0x03FF, 0x0200)
    } else {
        (23, 31, 0xFF, 0x7F_FFFF, 0x40_0000)   // f32 constants, never tested
    };

The f32 path uses distinct constants (exp_sh=23, mant_mask=0x7F_FFFF, quiet_bit=0x40_0000) that differ from f16 and are only reachable when ty == "f32".

Missing test

valu_tests.rs contains fn v_cmp_class_f16_matches_rdna2() (line 868) which covers all 10 IEEE-754 binary16 classes using vop3(0x08f, ...). Opcode 0x088 (v_cmp_class_f32) does not appear anywhere in the test file.

Suggested test

Add fn v_cmp_class_f32_matches_rdna2() to valu_tests.rs mirroring the f16 test:

#[test]
fn v_cmp_class_f32_matches_rdna2() {
    // v_cmp_class_f32_e64 s6, v1, v2 (VOP3 encoding of VOPC 0x088)
    // v_cndmask_b32_e64 v0, 0, 1, s6
    let cmp = build_valu_cs(&[
        vop3(0x088, 6, vgpr(1), vgpr(2), 0)[0],
        vop3(0x088, 6, vgpr(1), vgpr(2), 0)[1],
        vop3(0x101, 0, 0x80, 0x81, sgpr(6))[0],
        vop3(0x101, 0, 0x80, 0x81, sgpr(6))[1],
    ]);

    // All 10 IEEE-754 binary32 classes: bit k corresponds to class k.
    // quiet_bit = 0x40_0000 (bit 22).
    let classes: &[(u32, u32)] = &[
        (0x7F80_0001, 0), // +sNaN  (quiet bit clear, mantissa != 0)
        (0xFF80_0001, 0), // -sNaN
        (0x7FC0_0000, 1), // +qNaN  (quiet bit set)
        (0xFFC0_0001, 1), // -qNaN
        (0xFF80_0000, 2), // -inf
        (0xBF80_0000, 3), // -normal (-1.0)
        (0x8000_0001, 4), // -denormal
        (0x8000_0000, 5), // -0.0
        (0x0000_0000, 6), // +0.0
        (0x0000_0001, 7), // +denormal
        (0x3F80_0000, 8), // +normal (+1.0)
        (0x7F80_0000, 9), // +inf
    ];
    let mut cases = Vec::new();
    for &(bits, cls) in classes {
        cases.push(([bits, 1u32 << cls, 0, 0], 1u32));
        cases.push(([bits, 0x3FF & !(1u32 << cls), 0, 0], 0u32));
    }
    let inputs: Vec<[u32; 4]> = cases.iter().map(|c| c.0).collect();
    run_cases(&cmp, &inputs, |backend, i, inp, got| {
        let want = cases[i].1;
        assert_eq!(got, want, "{backend}: v_cmp_class_f32({bits:#010x}, {cls:#05x}) = {got}, want {want}");
    });
}

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

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:10 UTC · [original](https://github.com/Marvisak/VIctory/issues/799) `v_cmp_class_f32` (VOPC opcode 0x088) is fully implemented in `crates/victory-shader/src/emit/lower.rs` but has no synthetic hardware test in `crates/victory-shader/src/emit/valu_tests.rs`. Its sibling `v_cmp_class_f16` (VOPC 0x08f) has an exhaustive test added in #140. ## Implementation evidence `lower.rs`, `compare()` at line 5097, handles both types in one branch: ```rust "f32" | "f16" if op == "class" => { let f16 = ty == "f16"; let x = if f16 { // half_src() extracts 16-bit operand } else { let x = self.fsrc(inst, 0)?; // f32-specific path self.as_int(x) }; let (exp_sh, sign_sh, exp_mask, mant_mask, quiet_bit) = if f16 { (10, 15, 0x1F, 0x03FF, 0x0200) } else { (23, 31, 0xFF, 0x7F_FFFF, 0x40_0000) // f32 constants, never tested }; ``` The f32 path uses distinct constants (`exp_sh=23`, `mant_mask=0x7F_FFFF`, `quiet_bit=0x40_0000`) that differ from f16 and are only reachable when `ty == "f32"`. ## Missing test `valu_tests.rs` contains `fn v_cmp_class_f16_matches_rdna2()` (line 868) which covers all 10 IEEE-754 binary16 classes using `vop3(0x08f, ...)`. Opcode `0x088` (`v_cmp_class_f32`) does not appear anywhere in the test file. ## Suggested test Add `fn v_cmp_class_f32_matches_rdna2()` to `valu_tests.rs` mirroring the f16 test: ```rust #[test] fn v_cmp_class_f32_matches_rdna2() { // v_cmp_class_f32_e64 s6, v1, v2 (VOP3 encoding of VOPC 0x088) // v_cndmask_b32_e64 v0, 0, 1, s6 let cmp = build_valu_cs(&[ vop3(0x088, 6, vgpr(1), vgpr(2), 0)[0], vop3(0x088, 6, vgpr(1), vgpr(2), 0)[1], vop3(0x101, 0, 0x80, 0x81, sgpr(6))[0], vop3(0x101, 0, 0x80, 0x81, sgpr(6))[1], ]); // All 10 IEEE-754 binary32 classes: bit k corresponds to class k. // quiet_bit = 0x40_0000 (bit 22). let classes: &[(u32, u32)] = &[ (0x7F80_0001, 0), // +sNaN (quiet bit clear, mantissa != 0) (0xFF80_0001, 0), // -sNaN (0x7FC0_0000, 1), // +qNaN (quiet bit set) (0xFFC0_0001, 1), // -qNaN (0xFF80_0000, 2), // -inf (0xBF80_0000, 3), // -normal (-1.0) (0x8000_0001, 4), // -denormal (0x8000_0000, 5), // -0.0 (0x0000_0000, 6), // +0.0 (0x0000_0001, 7), // +denormal (0x3F80_0000, 8), // +normal (+1.0) (0x7F80_0000, 9), // +inf ]; let mut cases = Vec::new(); for &(bits, cls) in classes { cases.push(([bits, 1u32 << cls, 0, 0], 1u32)); cases.push(([bits, 0x3FF & !(1u32 << cls), 0, 0], 0u32)); } let inputs: Vec<[u32; 4]> = cases.iter().map(|c| c.0).collect(); run_cases(&cmp, &inputs, |backend, i, inp, got| { let want = cases[i].1; assert_eq!(got, want, "{backend}: v_cmp_class_f32({bits:#010x}, {cls:#05x}) = {got}, want {want}"); }); } ``` The test skips gracefully when no SM 6.6 device is available and runs on WARP. No game data needed. **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

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

Added v_cmp_class_f32_matches_rdna2 (all 10 binary32 classes plus abs/neg modifier cases) along with a fix for v_cmp_class_f32 flushing denormals / quieting sNaNs under abs/neg in #830 (github.com/AndyLatimer/VIctory@e08e6f4664, verified on native Windows 11 hardware GPU + WARP + dxil.dll).

**@⁠AndyLatimer** on GitHub · 2026-11-24 11:47 UTC · [original](https://github.com/Marvisak/VIctory/issues/799#issuecomment-7130545784) Added `v_cmp_class_f32_matches_rdna2` (all 10 binary32 classes plus `abs`/`neg` modifier cases) along with a fix for `v_cmp_class_f32` flushing denormals / quieting sNaNs under `abs`/`neg` in #830 (https://github.com/AndyLatimer/VIctory/commit/e08e6f46641ff8ced92b94313f1e143a3ac9fe42, verified on native Windows 11 hardware GPU + WARP + `dxil.dll`).
Author
Owner

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

Added the requested synthetic hardware test v_cmp_class_f32_matches_rdna2 (VOPC 0x088 in VOP3) covering all 10 IEEE-754 binary32 classes (including signed sNaN/qNaN, subnormals, signed zeros, normals, infinities), individual bit masks, combined masks (0x1F8, 0x060, 0x003), zero mask, and ignored high bits (0xFFFF_FC00).

External PRs are currently collaborators_only, so the verified commit (combined with #800 and #802 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:58 UTC · [original](https://github.com/Marvisak/VIctory/issues/799#issuecomment-7130798927) Added the requested synthetic hardware test `v_cmp_class_f32_matches_rdna2` (VOPC `0x088` in VOP3) covering all 10 IEEE-754 binary32 classes (including signed sNaN/qNaN, subnormals, signed zeros, normals, infinities), individual bit masks, combined masks (`0x1F8`, `0x060`, `0x003`), zero mask, and ignored high bits (`0xFFFF_FC00`). External PRs are currently `collaborators_only`, so the verified commit (combined with #800 and #802 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

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

Independently reproduced the abs/neg modifier bug noted in #830 on NVIDIA hardware and prepared a clean standalone commit on main (ffe310e):

Summary

  • crates/victory-shader/src/emit/lower.rs (compare): Unifies f16 and f32 v_cmp_class_* / v_cmpx_class_* to read raw operand bits (self.src0 / operand + sdwa_src) and apply abs (& 0x7FFF_FFFF) before neg (^ 0x8000_0000) bitwise rather than via self.fsrc(), matching RDNA2 ISA semantics.
  • crates/victory-shader/src/emit/valu_tests.rs (v_cmp_class_f32_matches_rdna2): Covers all 10 IEEE-754 binary32 classes plus neg, abs, and combined abs+neg (-|x|) on normals, zeros, sNaNs, and denormals.

Verification (Windows 11, NVIDIA GeForce RTX 3050 6GB Laptop driver 32.0.16.1742 + WARP + dxil.dll 10.0.26100.0, Rust 1.98.1)

  • Before fix (ffe310e): v_cmp_class_f32_matches_rdna2 failed on RTX 3050 hardware with v_cmp_class_f32(-0x00000001, 0x010) = 0, want 1 (negating +denormal through fsrc() flushed it to -0.0 under DXIL FTZ).
  • After fix (8eb2e3f):
    • cargo test -p victory-shader --locked v_cmp_class: 2/2 PASS on RTX 3050 hardware, WARP, and dxil.dll validation
    • cargo xtask policy: PASS (154 files ok)
    • cargo clippy --workspace --all-targets --locked -- -D warnings (default + --all-features): PASS (0 warnings)
    • cargo test --workspace --locked -- --skip v_med3_f32_matches_rdna2_with_nan: PASS (excluding only the known pre-existing NVIDIA #726 failure)

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

**@⁠AscilCH** on GitHub · 2026-11-24 12:17 UTC · [original](https://github.com/Marvisak/VIctory/issues/799#issuecomment-7131228827) Independently reproduced the `abs`/`neg` modifier bug noted in #830 on NVIDIA hardware and prepared a clean standalone commit on `main` (`ffe310e`): - **Branch:** https://github.com/AscilCH/VIctory/tree/fix/v-cmp-class-f32-modifiers-and-tests - **Commit:** https://github.com/AscilCH/VIctory/commit/8eb2e3fa4abef3e3ca377a8d3c881b797716d25a ### Summary - **`crates/victory-shader/src/emit/lower.rs` (`compare`)**: Unifies `f16` and `f32` `v_cmp_class_*` / `v_cmpx_class_*` to read raw operand bits (`self.src0` / `operand` + `sdwa_src`) and apply `abs` (`& 0x7FFF_FFFF`) before `neg` (`^ 0x8000_0000`) bitwise rather than via `self.fsrc()`, matching RDNA2 ISA semantics. - **`crates/victory-shader/src/emit/valu_tests.rs` (`v_cmp_class_f32_matches_rdna2`)**: Covers all 10 IEEE-754 binary32 classes plus `neg`, `abs`, and combined `abs+neg` (`-|x|`) on normals, zeros, `sNaN`s, and denormals. ### Verification (Windows 11, NVIDIA GeForce RTX 3050 6GB Laptop driver `32.0.16.1742` + WARP + `dxil.dll` `10.0.26100.0`, Rust `1.98.1`) - **Before fix (`ffe310e`):** `v_cmp_class_f32_matches_rdna2` failed on RTX 3050 hardware with `v_cmp_class_f32(-0x00000001, 0x010) = 0, want 1` (negating `+denormal` through `fsrc()` flushed it to `-0.0` under DXIL FTZ). - **After fix (`8eb2e3f`):** - `cargo test -p victory-shader --locked v_cmp_class`: **2/2 PASS** on RTX 3050 hardware, WARP, and `dxil.dll` validation - `cargo xtask policy`: **PASS** (`154 files ok`) - `cargo clippy --workspace --all-targets --locked -- -D warnings` (default + `--all-features`): **PASS** (0 warnings) - `cargo test --workspace --locked -- --skip v_med3_f32_matches_rdna2_with_nan`: **PASS** (excluding only the known pre-existing NVIDIA `#726` failure) *AI-assisted; synthetic tests only, no game files.*
Author
Owner

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

Adding an NVIDIA Turing hardware verification data point (GTX 1650 SUPER, 4 GB VRAM, wave32, driver 610.88, Windows 11 26300, stable-x86_64-pc-windows-gnullvm):

  • Implemented v_cmp_class_f32_matches_rdna2 (all 10 IEEE-754 binary32 classes, complement masks, zero mask, and ignored high bits 0xFFFF_FC00) on https://github.com/towiice/VIctory/tree/test/valu-f32-class-and-s-bfe-u32 (commit fb441bf).
  • cargo +stable-x86_64-pc-windows-gnullvm test -p victory-shader --lib v_cmp_class_f32_matches_rdna2: 1 passed, 0 failed (2.43 s, both hardware GPU and WARP).
**@⁠towiice** on GitHub · 2026-11-24 12:17 UTC · [original](https://github.com/Marvisak/VIctory/issues/799#issuecomment-7131232204) Adding an NVIDIA Turing hardware verification data point (`GTX 1650 SUPER`, 4 GB VRAM, wave32, driver `610.88`, Windows 11 26300, `stable-x86_64-pc-windows-gnullvm`): - Implemented `v_cmp_class_f32_matches_rdna2` (all 10 IEEE-754 binary32 classes, complement masks, zero mask, and ignored high bits `0xFFFF_FC00`) on https://github.com/towiice/VIctory/tree/test/valu-f32-class-and-s-bfe-u32 (commit `fb441bf`). - `cargo +stable-x86_64-pc-windows-gnullvm test -p victory-shader --lib v_cmp_class_f32_matches_rdna2`: **1 passed, 0 failed** (2.43 s, both hardware GPU and WARP).
Author
Owner

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

v_cmp_class_f32_matches_rdna2 adds all ten IEEE-754 binary32 classes (sNaN vs qNaN via the bit-22 quiet bit, both zeros, both denormals, both infinities). 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/799#issuecomment-7131239492) v_cmp_class_f32_matches_rdna2 adds all ten IEEE-754 binary32 classes (sNaN vs qNaN via the bit-22 quiet bit, both zeros, both denormals, both infinities). 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.
Author
Owner

@⁠studiostephe on GitHub · 2026-11-24 12:21 UTC · original

The suggested test, with the neg-modifier case the f32 path also needs.

compare()'s f32 branch (lower.rs, "f32" | "f16" if op == "class") takes src0 through fsrc(), which applies the neg modifier — so unlike the f16 branch (which handles it in-line), the f32 test needs its own neg probe. 0x7F80_0001 (+sNaN) negated is -sNaN: still class 0.

Patch (on main ffe310e)

diff --git a/crates/victory-shader/src/emit/valu_tests.rs b/crates/victory-shader/src/emit/valu_tests.rs
index b4ee77d..e7a2d85 100644
--- a/crates/victory-shader/src/emit/valu_tests.rs
+++ b/crates/victory-shader/src/emit/valu_tests.rs
@@ -937,3 +937,71 @@ fn v_cmp_class_f16_matches_rdna2() {
         );
     });
 }
+
+#[test]
+fn v_cmp_class_f32_matches_rdna2() {
+    // v_cmp_class_f32_e64 s6, v1, v2 (VOP3 encoding of VOPC 0x088);
+    // v_cndmask_b32_e64 v0, 0, 1, s6.
+    let cmp = build_valu_cs(&[
+        vop3(0x088, 6, vgpr(1), vgpr(2), 0)[0],
+        vop3(0x088, 6, vgpr(1), vgpr(2), 0)[1],
+        vop3(0x101, 0, 0x80, 0x81, sgpr(6))[0],
+        vop3(0x101, 0, 0x80, 0x81, sgpr(6))[1],
+    ]);
+    // Same with neg on src0 (bit 29 of w1): the f32 path applies it.
+    let [w0, mut w1] = vop3(0x088, 6, vgpr(1), vgpr(2), 0);
+    w1 |= 1 << 29; // neg[0] = 1
+    let cmp_neg = build_valu_cs(&[
+        w0,
+        w1,
+        vop3(0x101, 0, 0x80, 0x81, sgpr(6))[0],
+        vop3(0x101, 0, 0x80, 0x81, sgpr(6))[1],
+    ]);
+
+    // All 10 IEEE-754 binary32 classes: bit k corresponds to class k.
+    // quiet_bit = 0x40_0000 (bit 22).
+    let classes: &[(u32, u32)] = &[
+        (0x7F80_0001, 0), // +sNaN (quiet bit clear, mantissa != 0)
+        (0xFF80_0001, 0), // -sNaN
+        (0x7FC0_0000, 1), // +qNaN (quiet bit set)
+        (0xFFC0_0001, 1), // -qNaN
+        (0xFF80_0000, 2), // -inf
+        (0xBF80_0000, 3), // -normal (-1.0)
+        (0x8000_0001, 4), // -denormal
+        (0x8000_0000, 5), // -0.0
+        (0x0000_0000, 6), // +0.0
+        (0x0000_0001, 7), // +denormal
+        (0x3F80_0000, 8), // +normal (+1.0)
+        (0x7F80_0000, 9), // +inf
+    ];
+    let mut cases = Vec::new();
+    for &(bits, cls) in classes {
+        // Exact class bit -> true; complement of class bit across all 10 bits -> false.
+        cases.push(([bits, 1u32 << cls, 0, 0], 1u32));
+        cases.push(([bits, 0x3FF & !(1u32 << cls), 0, 0], 0u32));
+    }
+    let inputs: Vec<[u32; 4]> = cases.iter().map(|c| c.0).collect();
+    run_cases(&cmp, &inputs, |backend, i, inp, got| {
+        let want = cases[i].1;
+        assert_eq!(
+            got, want,
+            "{backend}: v_cmp_class_f32({:#010x}, {:#05x}) = {got}, want {want}",
+            inp[0], inp[1],
+        );
+    });
+
+    // neg flips the sign bit: 0x7F800001 (+sNaN) negated is -sNaN, still class 0.
+    let neg_cases: &[([u32; 4], u32)] = &[
+        ([0x7F80_0001, 1 << 0, 0, 0], 1),
+        ([0x7F80_0001, 1 << 1, 0, 0], 0),
+    ];
+    let neg_in: Vec<[u32; 4]> = neg_cases.iter().map(|c| c.0).collect();
+    run_cases(&cmp_neg, &neg_in, |backend, i, inp, got| {
+        let want = neg_cases[i].1;
+        assert_eq!(
+            got, want,
+            "{backend}: v_cmp_class_f32(-{:#010x}, {:#05x}) = {got}, want {want}",
+            inp[0], inp[1],
+        );
+    });
+}

Verified

  • The module is #[cfg(all(test, windows))] (host GPU harness), so it cannot run on this machine. Cross-compiled it instead: cargo check -p victory-shader --profile test --target x86_64-pc-windows-msvc with the repo's pinned 1.98.1 — clean, no warnings. rustfmt --edition 2024 --check clean.
  • Expected values independently checked by re-implementing the f32 class logic of compare() in Python over every case in the test (24 class cases + the neg probe): all match.
  • Encoding cross-checked against the working f16 test: vop3(0x088, ...) for VOPC 0x088 (opcodes.rs:539), same v_cndmask extraction via 0x101.

So: compiles for the Windows test profile, and the semantics are verified against the lowering line by line — but the GPU run itself (hardware and warp backends) happens in CI / on a Windows box.

AI use: written and verified by qwen3.8_27b running locally on an M1 Mac. No game data used.

**@⁠studiostephe** on GitHub · 2026-11-24 12:21 UTC · [original](https://github.com/Marvisak/VIctory/issues/799#issuecomment-7131324963) The suggested test, with the neg-modifier case the f32 path also needs. `compare()`'s f32 branch (`lower.rs`, `"f32" | "f16" if op == "class"`) takes src0 through `fsrc()`, which applies the `neg` modifier — so unlike the f16 branch (which handles it in-line), the f32 test needs its own neg probe. `0x7F80_0001` (+sNaN) negated is -sNaN: still class 0. ## Patch (on `main` `ffe310e`) ```diff diff --git a/crates/victory-shader/src/emit/valu_tests.rs b/crates/victory-shader/src/emit/valu_tests.rs index b4ee77d..e7a2d85 100644 --- a/crates/victory-shader/src/emit/valu_tests.rs +++ b/crates/victory-shader/src/emit/valu_tests.rs @@ -937,3 +937,71 @@ fn v_cmp_class_f16_matches_rdna2() { ); }); } + +#[test] +fn v_cmp_class_f32_matches_rdna2() { + // v_cmp_class_f32_e64 s6, v1, v2 (VOP3 encoding of VOPC 0x088); + // v_cndmask_b32_e64 v0, 0, 1, s6. + let cmp = build_valu_cs(&[ + vop3(0x088, 6, vgpr(1), vgpr(2), 0)[0], + vop3(0x088, 6, vgpr(1), vgpr(2), 0)[1], + vop3(0x101, 0, 0x80, 0x81, sgpr(6))[0], + vop3(0x101, 0, 0x80, 0x81, sgpr(6))[1], + ]); + // Same with neg on src0 (bit 29 of w1): the f32 path applies it. + let [w0, mut w1] = vop3(0x088, 6, vgpr(1), vgpr(2), 0); + w1 |= 1 << 29; // neg[0] = 1 + let cmp_neg = build_valu_cs(&[ + w0, + w1, + vop3(0x101, 0, 0x80, 0x81, sgpr(6))[0], + vop3(0x101, 0, 0x80, 0x81, sgpr(6))[1], + ]); + + // All 10 IEEE-754 binary32 classes: bit k corresponds to class k. + // quiet_bit = 0x40_0000 (bit 22). + let classes: &[(u32, u32)] = &[ + (0x7F80_0001, 0), // +sNaN (quiet bit clear, mantissa != 0) + (0xFF80_0001, 0), // -sNaN + (0x7FC0_0000, 1), // +qNaN (quiet bit set) + (0xFFC0_0001, 1), // -qNaN + (0xFF80_0000, 2), // -inf + (0xBF80_0000, 3), // -normal (-1.0) + (0x8000_0001, 4), // -denormal + (0x8000_0000, 5), // -0.0 + (0x0000_0000, 6), // +0.0 + (0x0000_0001, 7), // +denormal + (0x3F80_0000, 8), // +normal (+1.0) + (0x7F80_0000, 9), // +inf + ]; + let mut cases = Vec::new(); + for &(bits, cls) in classes { + // Exact class bit -> true; complement of class bit across all 10 bits -> false. + cases.push(([bits, 1u32 << cls, 0, 0], 1u32)); + cases.push(([bits, 0x3FF & !(1u32 << cls), 0, 0], 0u32)); + } + let inputs: Vec<[u32; 4]> = cases.iter().map(|c| c.0).collect(); + run_cases(&cmp, &inputs, |backend, i, inp, got| { + let want = cases[i].1; + assert_eq!( + got, want, + "{backend}: v_cmp_class_f32({:#010x}, {:#05x}) = {got}, want {want}", + inp[0], inp[1], + ); + }); + + // neg flips the sign bit: 0x7F800001 (+sNaN) negated is -sNaN, still class 0. + let neg_cases: &[([u32; 4], u32)] = &[ + ([0x7F80_0001, 1 << 0, 0, 0], 1), + ([0x7F80_0001, 1 << 1, 0, 0], 0), + ]; + let neg_in: Vec<[u32; 4]> = neg_cases.iter().map(|c| c.0).collect(); + run_cases(&cmp_neg, &neg_in, |backend, i, inp, got| { + let want = neg_cases[i].1; + assert_eq!( + got, want, + "{backend}: v_cmp_class_f32(-{:#010x}, {:#05x}) = {got}, want {want}", + inp[0], inp[1], + ); + }); +} ``` ## Verified - The module is `#[cfg(all(test, windows))]` (host GPU harness), so it cannot run on this machine. Cross-compiled it instead: `cargo check -p victory-shader --profile test --target x86_64-pc-windows-msvc` with the repo's pinned `1.98.1` — clean, no warnings. `rustfmt --edition 2024 --check` clean. - Expected values independently checked by re-implementing the f32 class logic of `compare()` in Python over every case in the test (24 class cases + the neg probe): all match. - Encoding cross-checked against the working f16 test: `vop3(0x088, ...)` for VOPC 0x088 (opcodes.rs:539), same `v_cndmask` extraction via 0x101. So: compiles for the Windows test profile, and the semantics are verified against the lowering line by line — but the GPU run itself (`hardware` and `warp` backends) happens in CI / on a Windows box. _AI use: written and verified by qwen3.8_27b running locally on an M1 Mac. No game data used._
Author
Owner

@⁠Beeak on GitHub · 2026-11-24 13:08 UTC · original

Added a standalone synthetic test for v_cmp_class_f32 (VOPC 0x088) in crates/victory-shader/tests/v_cmp_class_f32_test.rs (based on main ffe310e).

Since external PRs are restricted on upstream, the verified branch and PR are on my fork:

Summary

  • build_v_cmp_class_f32_cs: builds a synthetic 1-thread GFX10 compute shader executing v_cmp_class_f32_e32 vcc_lo, v1, v2 (VOPC 0x088), converting vcc_lo via v_cndmask_b32_e64 v0, 0, 1, vcc_lo, and storing the result to a raw UAV; lowers through ir::build -> structure::structure -> resource::track -> io::raise -> emit::emit and validates DXIL via emit::validator::Validator when dxil.dll is present.
  • v_cmp_class_f32_lowers_and_validates: verifies lowering, DXIL emission, and validation.
  • v_cmp_class_f32_matches_rdna2 (#[cfg(windows)]): executes 47 synthetic (f32_bits, mask, expected) cases across all 10 IEEE-754 binary32 classes (+sNaN/-sNaN, +qNaN/-qNaN, -inf, -normal, -subnormal, -0.0, +0.0, +subnormal, +normal, +inf), covering exact bit masks (1 << cls), 10-bit complements (0x3FF & !(1 << cls)), combined masks (0x003 NaN, 0x204 +/-inf, 0x060 +/-0.0), empty mask (0x000), and ignored upper bits (0xFFFF_FC00) on SM 6.6 hardware GPU and WARP (respecting VICTORY_D3D12_WARP / VICTORY_WARP=1).

Verification (Windows, rustc 1.98.1, SM 6.6 hardware GPU + WARP)

  • cargo test -p victory-shader --test v_cmp_class_f32_test: 2 passed, 0 failed, 0 ignored
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean
  • cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings: clean
  • rustfmt --edition 2024 --check crates/victory-shader/tests/v_cmp_class_f32_test.rs: clean
  • cargo xtask policy: asset policy: 155 files ok

All input data was synthetic. No game files were used. AI-assisted with Cline.

**@⁠Beeak** on GitHub · 2026-11-24 13:08 UTC · [original](https://github.com/Marvisak/VIctory/issues/799#issuecomment-7132398152) Added a standalone synthetic test for `v_cmp_class_f32` (VOPC `0x088`) in `crates/victory-shader/tests/v_cmp_class_f32_test.rs` (based on `main` `ffe310e`). Since external PRs are restricted on upstream, the verified branch and PR are on my fork: - **Fork PR:** https://github.com/Beeak/VIctory/pull/2 - **Branch:** https://github.com/Beeak/VIctory/tree/tests/v-cmp-class-f32 - **Commit:** https://github.com/Beeak/VIctory/commit/420a3b002b8d6e91510f8ffa76d07e35da846fdf ### Summary - `build_v_cmp_class_f32_cs`: builds a synthetic 1-thread GFX10 compute shader executing `v_cmp_class_f32_e32 vcc_lo, v1, v2` (VOPC `0x088`), converting `vcc_lo` via `v_cndmask_b32_e64 v0, 0, 1, vcc_lo`, and storing the result to a raw UAV; lowers through `ir::build` -> `structure::structure` -> `resource::track` -> `io::raise` -> `emit::emit` and validates DXIL via `emit::validator::Validator` when `dxil.dll` is present. - `v_cmp_class_f32_lowers_and_validates`: verifies lowering, DXIL emission, and validation. - `v_cmp_class_f32_matches_rdna2` (`#[cfg(windows)]`): executes 47 synthetic `(f32_bits, mask, expected)` cases across all 10 IEEE-754 binary32 classes (`+sNaN`/`-sNaN`, `+qNaN`/`-qNaN`, `-inf`, `-normal`, `-subnormal`, `-0.0`, `+0.0`, `+subnormal`, `+normal`, `+inf`), covering exact bit masks (`1 << cls`), 10-bit complements (`0x3FF & !(1 << cls)`), combined masks (`0x003` NaN, `0x204` `+/-inf`, `0x060` `+/-0.0`), empty mask (`0x000`), and ignored upper bits (`0xFFFF_FC00`) on SM 6.6 hardware GPU and WARP (respecting `VICTORY_D3D12_WARP` / `VICTORY_WARP=1`). ### Verification (Windows, `rustc 1.98.1`, SM 6.6 hardware GPU + WARP) - `cargo test -p victory-shader --test v_cmp_class_f32_test`: **2 passed, 0 failed, 0 ignored** - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`: clean - `cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings`: clean - `rustfmt --edition 2024 --check crates/victory-shader/tests/v_cmp_class_f32_test.rs`: clean - `cargo xtask policy`: `asset policy: 155 files ok` All input data was synthetic. No game files were used. AI-assisted with Cline.
Author
Owner

@⁠jules47800 on GitHub · 2026-11-25 01:25 UTC · original

Covered on main since 328eec1 (2026-11-24). class_compares_match_the_hardware in crates/victory-shader/src/emit/semantics_tests.rs runs v_cmp_class_f32 (VOPC 0x88) over the f32 edge values. It uses each of the ten class bits plus the masks 0x3FF, 0x3 and 0x204, checked against a class() model that does not flush denormals. It passes on an RX 6600 XT and on WARP at 42363ab. The test request is met. The abs/neg modifier bug is a separate issue, #830 (PR #1327).

**@⁠jules47800** on GitHub · 2026-11-25 01:25 UTC · [original](https://github.com/Marvisak/VIctory/issues/799#issuecomment-7149527364) Covered on main since `328eec1` (2026-11-24). `class_compares_match_the_hardware` in `crates/victory-shader/src/emit/semantics_tests.rs` runs `v_cmp_class_f32` (VOPC 0x88) over the f32 edge values. It uses each of the ten class bits plus the masks 0x3FF, 0x3 and 0x204, checked against a `class()` model that does not flush denormals. It passes on an RX 6600 XT and on WARP at `42363ab`. The test request is met. The `abs`/`neg` modifier bug is a separate issue, #830 (PR #1327).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 03:53 UTC · original

Automated triage for the maintainers.

Fixed in main. Commit 328eec1 (2026-11-24) added class_compares_match_the_hardware in crates/victory-shader/src/emit/semantics_tests.rs. It runs v_cmp_class_f32 (VOPC 0x88) on the hardware and WARP over the f32 edge values, each class bit and combined masks. That is the test this issue asks for.

The abs/neg modifier bug found while writing the test is a separate defect, tracked in #830 with open PR #1327. Please send fork branches for it there or as PRs.

This issue will be closed in 48 hours unless the reporter replies or a maintainer removes the triage: proposed close label.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 03:53 UTC · [original](https://github.com/Marvisak/VIctory/issues/799#issuecomment-7152339404) <!-- victory-issue-triage v1 verdict=proposed-close seen=2026-11-25T01:25:16Z at=2026-11-25T03:53:44Z --> Automated triage for the maintainers. Fixed in `main`. Commit 328eec1 (2026-11-24) added `class_compares_match_the_hardware` in `crates/victory-shader/src/emit/semantics_tests.rs`. It runs `v_cmp_class_f32` (VOPC 0x88) on the hardware and WARP over the f32 edge values, each class bit and combined masks. That is the test this issue asks for. The `abs`/`neg` modifier bug found while writing the test is a separate defect, tracked in #830 with open PR #1327. Please send fork branches for it there or as PRs. This issue will be closed in 48 hours unless the reporter replies or a maintainer removes the `triage: proposed close` label. --- _Generated by [Claude Code](https://claude.ai/code)_
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#799
No description provided.