shader: lower the f64 compares (v_cmp/v_cmpx_*_f64 and class) #100

Open
github-bot wants to merge 2 commits from github-bot/gh-100 into main AGit
Owner

@⁠lcg007xd-c on GitHub · 2026-11-25 22:45 UTC · original
lcg007xd-c:shader-f64-cmp → main · +149 −0 · 2 files · 2 commits · open

What is broken

The f64 compares decode, but compare() in emit/lower.rs has no f64 arm:

Encoding Instructions
VOPC 0x20–0x2F v_cmp_*_f64
VOPC 0x30–0x3F v_cmpx_*_f64
VOPC 0xA8 v_cmp_class_f64
VOPC 0xB8 v_cmpx_class_f64

So a program that uses the result (VCC to a v_cndmask, a branch, or EXEC for v_cmpx) fails with v_cmp_lt_f64 is not supported (and likewise). The earlier coverage run only caught the v_cmpx forms, because a v_cmp whose VCC nobody reads is dead code. I confirmed it through the CPU harness of #62 with v_cmp_lt_f64 feeding v_cndmask_b32.

The change (emit/lower.rs, in compare)

  • f64 predicates: the same predicate table as f32, on the host's doubles.
    • Operand pairs are read with f64_pair (with abs/neg) and joined by MakeDouble, with the DOUBLES flag set.
    • lg is olt | ogt, as the f32 arm does, for the AMD driver reason noted there.
  • f64 class: the f32 class test on the binary64's bits, with no double arithmetic. The exponent (11 bits) and the quiet bit (mantissa bit 51) are in the high dword, and the mantissa test spans both dwords.

Tests

  • emit::lower::tests::f64_compares_translate (every host): v_cmp_lt/lg/neq_f64 and v_cmp_class_f64 feeding v_cndmask_b32, and v_cmpx_gt_f64 writing EXEC before a store, all decode and translate. Without the lower.rs change it fails: v_cmp_lt_f64 [7c420701, d5010000, 01a90280]: GFX10 code at 0x28: v_cmp_lt_f64 is not supported.
  • valu_tests::f64_compares_match_ieee (Windows/GPU): 8 predicates on 6 pairs, against Rust's f64. The pairs are ordered both ways, equal, NaN, ±0 and a one-ulp difference.
  • CPU run: I ran these on Linux through the CPU harness of #62, which runs the emitted DXIL with LLVM's lli. All 16 predicates on all 121 pairs of 11 values (±0, ±inf, NaN, denormal, ±large), against Rust's f64 comparisons, all match. So does v_cmp_class_f64 for every class bit on ±1, ±0, ±denormal, ±inf, a quiet and a signalling NaN.

Run here (Linux, Rust 1.98.1):

  • cargo test -p victory-shader --lib --locked: 188 passed, 0 failed, 2 ignored.
  • Portable clippy and CARGO_FEATURE_PURE=1 cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings: clean.

Not run here: the GPU case, since I have no Windows machine. This needs double-precision shader ops on the host, like #99 and the existing whole-wave f64 sum. The class test itself needs none.

🤖 Generated with Claude Code

**@⁠lcg007xd-c** on GitHub · 2026-11-25 22:45 UTC · [original](https://github.com/uiliannn/VItoriaBr/pull/100) `lcg007xd-c:shader-f64-cmp` → `main` · +149 −0 · 2 files · 2 commits · open ## What is broken The f64 compares decode, but `compare()` in `emit/lower.rs` has no `f64` arm: | Encoding | Instructions | |---|---| | VOPC 0x20–0x2F | `v_cmp_*_f64` | | VOPC 0x30–0x3F | `v_cmpx_*_f64` | | VOPC 0xA8 | `v_cmp_class_f64` | | VOPC 0xB8 | `v_cmpx_class_f64` | So a program that uses the result (VCC to a `v_cndmask`, a branch, or EXEC for `v_cmpx`) fails with `v_cmp_lt_f64 is not supported` (and likewise). The earlier coverage run only caught the `v_cmpx` forms, because a `v_cmp` whose VCC nobody reads is dead code. I confirmed it through the CPU harness of #62 with `v_cmp_lt_f64` feeding `v_cndmask_b32`. ## The change (`emit/lower.rs`, in `compare`) - **`f64` predicates:** the same predicate table as f32, on the host's doubles. - Operand pairs are read with `f64_pair` (with `abs`/`neg`) and joined by `MakeDouble`, with the `DOUBLES` flag set. - `lg` is `olt | ogt`, as the f32 arm does, for the AMD driver reason noted there. - **`f64` class:** the f32 class test on the binary64's bits, with no double arithmetic. The exponent (11 bits) and the quiet bit (mantissa bit 51) are in the high dword, and the mantissa test spans both dwords. ## Tests - **`emit::lower::tests::f64_compares_translate`** (every host): `v_cmp_lt/lg/neq_f64` and `v_cmp_class_f64` feeding `v_cndmask_b32`, and `v_cmpx_gt_f64` writing EXEC before a store, all decode and translate. Without the `lower.rs` change it fails: `v_cmp_lt_f64 [7c420701, d5010000, 01a90280]: GFX10 code at 0x28: v_cmp_lt_f64 is not supported`. - **`valu_tests::f64_compares_match_ieee`** (Windows/GPU): 8 predicates on 6 pairs, against Rust's f64. The pairs are ordered both ways, equal, NaN, ±0 and a one-ulp difference. - **CPU run:** I ran these on Linux through the CPU harness of #62, which runs the emitted DXIL with LLVM's `lli`. All 16 predicates on all 121 pairs of 11 values (±0, ±inf, NaN, denormal, ±large), against Rust's f64 comparisons, all match. So does `v_cmp_class_f64` for every class bit on ±1, ±0, ±denormal, ±inf, a quiet and a signalling NaN. **Run here** (Linux, Rust 1.98.1): - `cargo test -p victory-shader --lib --locked`: 188 passed, 0 failed, 2 ignored. - Portable clippy and `CARGO_FEATURE_PURE=1 cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings`: clean. **Not run here:** the GPU case, since I have no Windows machine. This needs double-precision shader ops on the host, like #99 and the existing whole-wave f64 sum. The class test itself needs none. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
VOPC 0x20..=0x3F and 0xA8/0xB8 decoded, but compare() had no f64 arm,
so a v_cmp_lt_f64 whose result is used failed ("v_cmp_lt_f64 is not
supported"). The f32 predicates now apply to the host's doubles (the
operand pairs, with abs/neg, joined by MakeDouble; DOUBLES flag), lg as
olt|ogt as for f32. v_cmp_class_f64 classifies the binary64's bits as
the f32 class does, the exponent and quiet bit being in the high dword.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:43:58 +00:00
Author
Owner

@⁠lmouz823-lang on GitHub · 2026-11-27 14:58 UTC · original

I can take the native Windows/NVIDIA validation for this PR at exact head 8dbb58ec15295d9da7fba6f4f471b969d2bce43a: f64_compares_translate and f64_compares_match_ieee. I have Windows 11, Rust/MSVC, an RTX 4060 Laptop (8 GiB, driver 610.88), and the SDK DXIL validator. I will verify that the hardware case executes, keep the WARP result separate, and report exact commands, failures or passes, and coverage limits here.

AI-assisted with Codex.

**@⁠lmouz823-lang** on GitHub · 2026-11-27 14:58 UTC · [original](https://github.com/uiliannn/VItoriaBr/pull/100#issuecomment-7221464808) I can take the native Windows/NVIDIA validation for this PR at exact head `8dbb58ec15295d9da7fba6f4f471b969d2bce43a`: `f64_compares_translate` and `f64_compares_match_ieee`. I have Windows 11, Rust/MSVC, an RTX 4060 Laptop (8 GiB, driver 610.88), and the SDK DXIL validator. I will verify that the hardware case executes, keep the WARP result separate, and report exact commands, failures or passes, and coverage limits here. AI-assisted with Codex.
Author
Owner

@⁠lmouz823-lang on GitHub · 2026-11-27 15:02 UTC · original

Native Windows/NVIDIA validation completed on the unchanged PR head 8dbb58ec15295d9da7fba6f4f471b969d2bce43a.

Environment: Windows 11 build 26200, RTX 4060 Laptop 8 GiB, NVIDIA driver 610.88, Rust 1.98.1 MSVC. VICTORY_STRICT_TESTS=1; VICTORY_WARP was unset. VICTORY_DXIL explicitly selected the Windows SDK dxil.dll 1.8.2502.11. The helper's validator-load branch is optional, so this is not a separate validator-loading regression test.

Both exact tests passed, with no ignored tests or device skips:

cargo test --release --locked -p victory-shader --lib emit::lower::tests::f64_compares_translate -- --exact --nocapture --test-threads=1
# 1 passed; 0 failed; 0 ignored

cargo test --release --locked -p victory-shader --lib emit::valu_tests::f64_compares_match_ieee -- --exact --nocapture --test-threads=1
# 1 passed; 0 failed; 0 ignored; 2.66s

The GPU log identified both backends:

VICTORY HOST GPU: NVIDIA GeForce RTX 4060 Laptop GPU (vendor 0x10de)
VICTORY HOST GPU: Microsoft Basic Render Driver (vendor 0x1414)

The existing GPU case checked all 8 predicates × 6 input pairs on each backend, including ordered/reversed/equal values, a NaN operand, signed zero and a one-ulp difference. v_cmp_class_f64 and v_cmpx_gt_f64 were covered by the translation test only; this does not add hardware validation for their class/EXEC behavior or for the other 8 predicates. AMD, the full workspace suite and game execution were not tested.

No source changes were needed; the worktree remains clean. AI-assisted validation with Codex.

**@⁠lmouz823-lang** on GitHub · 2026-11-27 15:02 UTC · [original](https://github.com/uiliannn/VItoriaBr/pull/100#issuecomment-7221546115) Native Windows/NVIDIA validation completed on the unchanged PR head `8dbb58ec15295d9da7fba6f4f471b969d2bce43a`. Environment: Windows 11 build 26200, RTX 4060 Laptop 8 GiB, NVIDIA driver 610.88, Rust 1.98.1 MSVC. `VICTORY_STRICT_TESTS=1`; `VICTORY_WARP` was unset. `VICTORY_DXIL` explicitly selected the Windows SDK `dxil.dll` 1.8.2502.11. The helper's validator-load branch is optional, so this is not a separate validator-loading regression test. Both exact tests passed, with no ignored tests or device skips: ```text cargo test --release --locked -p victory-shader --lib emit::lower::tests::f64_compares_translate -- --exact --nocapture --test-threads=1 # 1 passed; 0 failed; 0 ignored cargo test --release --locked -p victory-shader --lib emit::valu_tests::f64_compares_match_ieee -- --exact --nocapture --test-threads=1 # 1 passed; 0 failed; 0 ignored; 2.66s ``` The GPU log identified both backends: ```text VICTORY HOST GPU: NVIDIA GeForce RTX 4060 Laptop GPU (vendor 0x10de) VICTORY HOST GPU: Microsoft Basic Render Driver (vendor 0x1414) ``` The existing GPU case checked all 8 predicates × 6 input pairs on each backend, including ordered/reversed/equal values, a NaN operand, signed zero and a one-ulp difference. `v_cmp_class_f64` and `v_cmpx_gt_f64` were covered by the translation test only; this does not add hardware validation for their class/EXEC behavior or for the other 8 predicates. AMD, the full workspace suite and game execution were not tested. No source changes were needed; the worktree remains clean. AI-assisted validation with Codex.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/100/head:github-bot/gh-100'
git switch 'github-bot/gh-100'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-100'
git switch 'github-bot/gh-100'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-100'
git switch 'github-bot/gh-100'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-100'
git switch 'main'
git merge --squash 'github-bot/gh-100'
git switch 'main'
git merge --ff-only 'github-bot/gh-100'
git switch 'main'
git merge 'github-bot/gh-100'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.