Shaders: v_mac_f32 and v_mad_f32 flush the product they round #3210

Open
zzm1234560621-prog wants to merge 4 commits from upstream-pr/3212 into main
zzm1234560621-prog commented 2026-11-26 13:08:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by zzm1234560621-prog on 2026-11-26T13:08:28Z.


What

v_mac_f32 and v_mad_f32 lower to a plain multiply and an add, without the flush the console applies to the product it rounds. A host that flushes sign-preserving then disagrees with the console on the sign of an underflowed product:

in [00800000, 80800000, 00000000, …]   want [00000000]   got [80000000]

+2^-126 × -2^-126 underflows. The console flushes the product to +0; this Intel adapter leaves -0, and the add carries it out. v_mac_legacy_f32 and v_mad_legacy_f32 already agreed, because they go through legacy_mul.

flush_denormal_to_positive_zero is the console's flush: a result whose exponent field is zero and whose mantissa is not becomes +0, while zeros pass through untouched, so the -0 of a true zero product (a negative operand times zero) keeps the sign the multiply gave it.

Applied to the product of v_mac_f32 and of v_mad_f32 / v_madak_f32 / v_madmk_f32. The fused forms (v_fma_f32, v_fmac_f32) already go through FMad and are not touched.

Measured

semantics_tests::arithmetic_matches_the_hardware, Intel Arc (Xe-LPG, driver 32.0.101.6127), Windows 11, Rust 1.98.1, main 63bcca4:

op model mismatches, before after
v_mac_f32 102 of 14,440 0
v_mad_f32 102 of 14,440 0
cargo test -p victory-shader --lib
  297 passed, 5 failed, 3 ignored      (was 296 / 6 / 3)
cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean

Not verified

  • No console hardware: the flush is the one semantics_tests' model encodes ("the product rounded (and flushed) before the add"), which is where the numbers above come from.
  • One adapter. On an AMD or NVIDIA card that already flushes to +0, the added select should be a no-op — the same value out — but I have no such card to confirm it, and WARP's half of the same test is unchanged (it reported 0 mismatches before and after).
  • The cost: two compares and a select per MAD. If that matters for the world's programs, it can be folded into the existing flush machinery rather than added per operation.

No game files. Reported with the rest of this adapter's results in #3196. AI-assisted (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:issue:5510602181 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3212). Originally posted by [zzm1234560621-prog](https://github.com/zzm1234560621-prog) on 2026-11-26T13:08:28Z. --- ## What `v_mac_f32` and `v_mad_f32` lower to a plain multiply and an add, without the flush the console applies to the product it rounds. A host that flushes sign-preserving then disagrees with the console on the sign of an underflowed product: ``` in [00800000, 80800000, 00000000, …] want [00000000] got [80000000] ``` `+2^-126 × -2^-126` underflows. The console flushes the product to **+0**; this Intel adapter leaves **-0**, and the add carries it out. `v_mac_legacy_f32` and `v_mad_legacy_f32` already agreed, because they go through `legacy_mul`. `flush_denormal_to_positive_zero` is the console's flush: a result whose exponent field is zero and whose mantissa is not becomes `+0`, while zeros pass through untouched, so the `-0` of a true zero product (a negative operand times zero) keeps the sign the multiply gave it. Applied to the product of `v_mac_f32` and of `v_mad_f32` / `v_madak_f32` / `v_madmk_f32`. The fused forms (`v_fma_f32`, `v_fmac_f32`) already go through `FMad` and are not touched. ## Measured `semantics_tests::arithmetic_matches_the_hardware`, Intel Arc (Xe-LPG, driver 32.0.101.6127), Windows 11, Rust 1.98.1, `main` `63bcca4`: | op | model mismatches, before | after | |---|---|---| | `v_mac_f32` | 102 of 14,440 | **0** | | `v_mad_f32` | 102 of 14,440 | **0** | ``` cargo test -p victory-shader --lib 297 passed, 5 failed, 3 ignored (was 296 / 6 / 3) cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean ``` ## Not verified - No console hardware: the flush is the one `semantics_tests`' model encodes ("the product rounded (and flushed) before the add"), which is where the numbers above come from. - One adapter. On an AMD or NVIDIA card that already flushes to `+0`, the added select should be a no-op — the same value out — but I have no such card to confirm it, and WARP's half of the same test is unchanged (it reported 0 mismatches before and after). - The cost: two compares and a select per MAD. If that matters for the world's programs, it can be folded into the existing flush machinery rather than added per operation. _No game files. Reported with the rest of this adapter's results in #3196. AI-assisted (Claude)._
AurumCarlos commented 2026-11-26 13:10:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AurumCarlos on 2026-11-26T13:10:23Z.

Review: COMMENTED


Thanks for the clear write-up and the before/after table. The diagnosis matches what the model says, and putting the select between the multiply and the add also has a side benefit: the driver can no longer contract them into an FMA, which the "rounded product" semantics need anyway. A few remarks:

1. The helper only works if the host hasn't flushed the product yet. It decides on the product's bits: exponent 0 and mantissa ≠ 0 → +0. That catches your Intel case, where the multiply leaves a denormal in the register and only the add flushes it. But on a host or driver that flushes at the multiply itself, sign-preserving, the product is already -0 (mantissa 0) when the select sees it. It then passes through as a "true zero" and the add still gives -0. So the fix is tied to where the host flushes, which is what the existing helpers try to avoid ("decided on the bits (the host's own denormal mode varies)" on ftz).

A version that doesn't depend on that would decide from the operands, the way legacy_mul does. A product that comes out with exponent 0 while neither operand has exponent 0 is an underflow, so it becomes +0. One where an operand is zero keeps the multiply's sign. That covers both "the host left a denormal" and "the host already flushed to -0". If you want to keep the current form, it would be worth saying in the doc comment that it assumes the product reaches the select unflushed.

2. Zeros: this differs from write_f's omod path, maybe on purpose. The omod path flushes on e == 0 alone, so a -0 product there becomes +0 too ("a zero or denormal product comes out +0 (measured on RDNA2 with IEEE mode off)"). Here, a true -0 keeps its sign. Your 0-mismatch run suggests the model wants exactly that for MAD, but since the two places now disagree on the sign of a zero product, a short note on why would help the next reader.

3. lower.rs size. This brings lower.rs from 520,563 to 521,545 bytes (+982). #3127 (+3,167), #3158 (+284) and #3192 (+336) are still open and grow the same file, and the four together come to about 525,300, over the 524,288 policy cap. Each passes alone, but whichever lands last will need a trim. Reusing a shared exponent/mantissa test with ftz (the masks and the And/cmp pair are the same) might win some of it back here.

<!-- greyfinch-sync:Marvisak/VIctory:review:6074690974 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3212#pullrequestreview-6074690974). Originally posted by [AurumCarlos](https://github.com/AurumCarlos) on 2026-11-26T13:10:23Z. **Review:** COMMENTED --- Thanks for the clear write-up and the before/after table. The diagnosis matches what the model says, and putting the select between the multiply and the add also has a side benefit: the driver can no longer contract them into an FMA, which the "rounded product" semantics need anyway. A few remarks: **1. The helper only works if the host hasn't flushed the product yet.** It decides on the product's bits: exponent 0 *and* mantissa ≠ 0 → +0. That catches your Intel case, where the multiply leaves a denormal in the register and only the add flushes it. But on a host or driver that flushes at the multiply itself, sign-preserving, the product is already `-0` (mantissa 0) when the select sees it. It then passes through as a "true zero" and the add still gives `-0`. So the fix is tied to *where* the host flushes, which is what the existing helpers try to avoid ("decided on the bits (the host's own denormal mode varies)" on `ftz`). A version that doesn't depend on that would decide from the operands, the way `legacy_mul` does. A product that comes out with exponent 0 while neither operand has exponent 0 is an underflow, so it becomes +0. One where an operand is zero keeps the multiply's sign. That covers both "the host left a denormal" and "the host already flushed to -0". If you want to keep the current form, it would be worth saying in the doc comment that it assumes the product reaches the select unflushed. **2. Zeros: this differs from `write_f`'s omod path, maybe on purpose.** The omod path flushes on `e == 0` alone, so a `-0` product there becomes `+0` too ("a zero or denormal product comes out +0 (measured on RDNA2 with IEEE mode off)"). Here, a true `-0` keeps its sign. Your 0-mismatch run suggests the model wants exactly that for MAD, but since the two places now disagree on the sign of a zero product, a short note on why would help the next reader. **3. `lower.rs` size.** This brings `lower.rs` from 520,563 to 521,545 bytes (+982). #3127 (+3,167), #3158 (+284) and #3192 (+336) are still open and grow the same file, and the four together come to about 525,300, over the 524,288 policy cap. Each passes alone, but whichever lands last will need a trim. Reusing a shared exponent/mantissa test with `ftz` (the masks and the `And`/`cmp` pair are the same) might win some of it back here.
Dukestar69 commented 2026-11-26 13:29:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T13:29:45Z.

Review: APPROVED


Verified on RTX 5090 against origin/main (63bcca4):

  • cargo test -p victory-shader --lib thirty_two_bit_floats -- --test-threads=1: passed.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly flushes denormal intermediate products of v_mac_f32 and v_mad_f32 to +0.0 (while passing signed zeros through).

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6074970124 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3212#pullrequestreview-6074970124). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T13:29:45Z. **Review:** APPROVED --- Verified on RTX 5090 against `origin/main` (`63bcca4`): - `cargo test -p victory-shader --lib thirty_two_bit_floats -- --test-threads=1`: passed. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly flushes denormal intermediate products of `v_mac_f32` and `v_mad_f32` to `+0.0` (while passing signed zeros through). Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
oni-swr commented 2026-11-26 14:01:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-26T13:25:47Z.


WARP test report (head 09c7b82, on top of current main 63bcca4)

Environment: Windows 11, WARP only (VICTORY_WARP=1 and VICTORY_D3D12_WARP=1), Windows SDK 10.0.26100 dxil.dll 1.8.2502.11 via VICTORY_DXIL, rustc/cargo 1.98.1.

  • cargo test -p victory-shader --lib --locked -- --test-threads=1: 298 passed, 4 failed, 3 ignored. This includes semantics_tests::arithmetic_matches_the_hardware and diff_tests::float_semantics_are_the_consoles, both ok.
  • The 4 failures are synthetic_tests::{a_mask_joined_with_data_at_a_uniform_loop_is_its_number, gathers_at_a_level_match_the_hardware, permutes_mask_high_address_bits_and_divergent_branches, permutes_read_the_lane_named_and_zero_from_lanes_left_out} (no pipeline for a wave of 32 / a gather mismatch). The same 4 fail identically on unmodified main, so they are WARP limits (cross-lane, wave-size tests), not caused by this PR.
  • The PR adds no test, so there is no control run to make: nothing fails on main because of it. No test I ran exercises a denormal product through v_mad_f32/v_mac_f32, so the new flush is unverified by the suite.

Diff review: the lowering is a clean select (exponent 0 and mantissa non-zero gives +0), applied to the product only, before the add. v_mad_legacy_f32 is untouched. One thing to check: the in-repo reference model (semantics_tests.rs, mad = add(mul(a,b),c) with out64) keeps the sign of a flushed product (-0), while this PR flushes to +0. The two disagree on a negative denormal product, so -0 + c differs when c is ±0. The existing tests don't reach that case. A test with a negative denormal product, plus the reference model updated to match, would pin the claim down.

Cannot verify here: that the console really drops the sign (no hardware oracle).

AI use: Claude Code (Claude Sonnet 5.5), coordinated by Claude Code (Claude Opus 5.5). Synthetic tests only; no game files, dumps, shader names or retail hashes.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7193339296 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3212#issuecomment-7193339296). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-26T13:25:47Z. --- **WARP test report (head 09c7b82, on top of current main 63bcca4)** Environment: Windows 11, **WARP only** (`VICTORY_WARP=1` and `VICTORY_D3D12_WARP=1`), Windows SDK 10.0.26100 `dxil.dll` 1.8.2502.11 via `VICTORY_DXIL`, rustc/cargo 1.98.1. - `cargo test -p victory-shader --lib --locked -- --test-threads=1`: **298 passed, 4 failed, 3 ignored**. This includes `semantics_tests::arithmetic_matches_the_hardware` and `diff_tests::float_semantics_are_the_consoles`, both ok. - The 4 failures are `synthetic_tests::{a_mask_joined_with_data_at_a_uniform_loop_is_its_number, gathers_at_a_level_match_the_hardware, permutes_mask_high_address_bits_and_divergent_branches, permutes_read_the_lane_named_and_zero_from_lanes_left_out}` (`no pipeline for a wave of 32` / a gather mismatch). The same 4 fail identically on unmodified main, so they are WARP limits (cross-lane, wave-size tests), not caused by this PR. - **The PR adds no test**, so there is no control run to make: nothing fails on main because of it. No test I ran exercises a denormal product through `v_mad_f32`/`v_mac_f32`, so the new flush is unverified by the suite. Diff review: the lowering is a clean select (exponent 0 and mantissa non-zero gives +0), applied to the product only, before the add. `v_mad_legacy_f32` is untouched. One thing to check: the in-repo reference model (`semantics_tests.rs`, `mad` = `add(mul(a,b),c)` with `out64`) keeps the **sign** of a flushed product (-0), while this PR flushes to **+0**. The two disagree on a negative denormal product, so `-0 + c` differs when `c` is ±0. The existing tests don't reach that case. A test with a negative denormal product, plus the reference model updated to match, would pin the claim down. Cannot verify here: that the console really drops the sign (no hardware oracle). AI use: Claude Code (Claude Sonnet 5.5), coordinated by Claude Code (Claude Opus 5.5). Synthetic tests only; no game files, dumps, shader names or retail hashes.
andrewpozdnakov7-jpg commented 2026-11-26 14:01:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T13:52:19Z.


@zzm1234560621-prog I read back the exact FP32 words for v_mac_f32 and v_mad_f32 on 63bcca43 and your 09c7b82, using the same in-process translator and DXIL validator. App-local WARP 1.0.22 gave the same results on both revisions in three runs.

Inputs Both WARP revisions
00800000 × 80800000 + 00000000 (the reported input) 00000000
Same product with addend 80000000 80000000
80800000 × 3f000000 + 80000000 (negative subnormal mathematical product) 80000000
bf800000 × 00000000 + 80000000 (true zero product) 80000000

The normal control and the case with a smallest-normal addend were also unchanged. This covers the proposed input on WARP and leaves the Intel result for hardware verification. The opt-in test can print the same words on Intel with VICTORY_WARP unset.

cargo test --locked -p victory-shader --lib emit::semantics_tests::mad_product_rounding_bit_patterns -- --exact --ignored --nocapture --test-threads=1

If reusing it, please retain the Git author or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding it into another commit. AI-assisted with Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7193952960 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3212#issuecomment-7193952960). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-26T13:52:19Z. --- @zzm1234560621-prog I read back the exact FP32 words for `v_mac_f32` and `v_mad_f32` on `63bcca43` and your `09c7b82`, using the same in-process translator and DXIL validator. App-local WARP 1.0.22 gave the same results on both revisions in three runs. | Inputs | Both WARP revisions | | --- | --- | | `00800000 × 80800000 + 00000000` (the reported input) | `00000000` | | Same product with addend `80000000` | `80000000` | | `80800000 × 3f000000 + 80000000` (negative subnormal mathematical product) | `80000000` | | `bf800000 × 00000000 + 80000000` (true zero product) | `80000000` | The normal control and the case with a smallest-normal addend were also unchanged. This covers the proposed input on WARP and leaves the Intel result for hardware verification. The [opt-in test](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/ee7c05374dafbaa9be9f35d014ea5001eaaecc97) can print the same words on Intel with `VICTORY_WARP` unset. ```text cargo test --locked -p victory-shader --lib emit::semantics_tests::mad_product_rounding_bit_patterns -- --exact --ignored --nocapture --test-threads=1 ``` If reusing it, please retain the Git author or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding it into another commit. AI-assisted with Codex.
zzm1234560621-prog commented 2026-11-26 15:02:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by zzm1234560621-prog on 2026-11-26T14:43:21Z.


Both reviews answered with the hardware run the probe was for.

0ed5c35 folds in andrewpozdnakov7-jpg's probe (with the Co-authored-by they asked for), and on this machine the two backends now agree word for word:

Intel Arc (Xe-LPG, driver 32.0.101.6127):
v_mac_f32: [00000000, 80000000, 80000000, 00800000, 80000000, 3f000000]
v_mad_f32: [00000000, 80000000, 80000000, 00800000, 80000000, 3f000000]

WARP, same test:
v_mac_f32: [00000000, 80000000, 80000000, 00800000, 80000000, 3f000000]
v_mad_f32: [00000000, 80000000, 80000000, 00800000, 80000000, 3f000000]

Before the patch, input 1 on hardware was 80000000 where WARP gave 00000000 — that is the mismatch arithmetic_matches_the_hardware was reporting.

To oni-swr's point about the reference model keeping the sign: with the patch, arithmetic_matches_the_hardware passes on both backends over all 14,440 inputs, negative denormal products included, so the model and the lowering do not disagree on the set the suite feeds. Your reading is right that the two would differ on -0 + c if the model flushed sign-preserving and the lowering did not — but the observed words above (rows 2 and 3 are 80000000, i.e. -0) say this driver's product lands on -0 before any select of mine, so the +0 arm is only taken where the product is an actual denormal, which is input 1.

What I cannot claim is the mechanism: whether this driver flushes the product sign-preservingly and my select therefore only fires on input 1, or whether the driver leaves a denormal in all three and something else explains rows 2 and 3. Both readings fit the words. The console is the oracle for the sign, and none of us has one, so I have kept the change to "the suite's model and both backends agree" and left the mechanism out of the commit message.

If the probe is worth keeping past this PR, it should probably stop being #[ignore] and assert the words on any adapter, which would make it a real regression test for the sign question rather than a print. I did not do that here because I do not know which of the two readings the maintainers consider established.

AI-assisted (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7195226837 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3212#issuecomment-7195226837). Originally posted by [zzm1234560621-prog](https://github.com/zzm1234560621-prog) on 2026-11-26T14:43:21Z. --- Both reviews answered with the hardware run the probe was for. **`0ed5c35`** folds in andrewpozdnakov7-jpg's probe (with the `Co-authored-by` they asked for), and on this machine the two backends now agree word for word: ``` Intel Arc (Xe-LPG, driver 32.0.101.6127): v_mac_f32: [00000000, 80000000, 80000000, 00800000, 80000000, 3f000000] v_mad_f32: [00000000, 80000000, 80000000, 00800000, 80000000, 3f000000] WARP, same test: v_mac_f32: [00000000, 80000000, 80000000, 00800000, 80000000, 3f000000] v_mad_f32: [00000000, 80000000, 80000000, 00800000, 80000000, 3f000000] ``` Before the patch, input 1 on hardware was `80000000` where WARP gave `00000000` — that is the mismatch `arithmetic_matches_the_hardware` was reporting. To oni-swr's point about the reference model keeping the sign: with the patch, `arithmetic_matches_the_hardware` passes on both backends over all 14,440 inputs, negative denormal products included, so the model and the lowering do not disagree on the set the suite feeds. Your reading is right that the two would differ on `-0 + c` if the model flushed sign-preserving and the lowering did not — but the observed words above (rows 2 and 3 are `80000000`, i.e. `-0`) say this driver's product lands on `-0` *before* any select of mine, so the `+0` arm is only taken where the product is an actual denormal, which is input 1. What I cannot claim is the mechanism: whether this driver flushes the product sign-preservingly and my select therefore only fires on input 1, or whether the driver leaves a denormal in all three and something else explains rows 2 and 3. Both readings fit the words. The console is the oracle for the sign, and none of us has one, so I have kept the change to "the suite's model and both backends agree" and left the mechanism out of the commit message. If the probe is worth keeping past this PR, it should probably stop being `#[ignore]` and assert the words on any adapter, which would make it a real regression test for the sign question rather than a print. I did not do that here because I do not know which of the two readings the maintainers consider established. _AI-assisted (Claude)._
zzm1234560621-prog commented 2026-11-26 15:02:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by zzm1234560621-prog on 2026-11-26T14:48:01Z.


One correction with numbers, since it changes what the model already covers: the negative-denormal-product cases are in the 14,440, not outside them.

arithmetic_probes feeds the accumulate and mad probes triples(F32_EDGES, F32_EDGES, F32_THIRD), which is fully cartesian — 38 × 38 × 10 = 14,440, the count in the summary line. And the sets contain the operands in question:

  • F32_EDGES has 0x8080_0000 (±smallest normal, line 673) and 0x3F00_0000 (0.5, line 676);
  • F32_THIRD has 0x0000_0000 and 0x8000_0000 (lines 708–709).

So [0x8080_0000, 0x3F00_0000, 0x0000_0000] and […, 0x8000_0000] — the negative denormal product with a +0 and with a -0 addend — are both fed to v_mac_f32 and v_mad_f32 by arithmetic_matches_the_hardware, and with this patch it passes on both backends. That test compares against mad/out64, so the model and the hardware agree on those inputs; the model is not keeping a sign the lowering contradicts.

Which also fits the words from andrewpozdnakov7-jpg's probe on the same machine: rows 2 and 3 (-0 addend) come out 80000000 on hardware and WARP alike, i.e. plain IEEE addition of a -0 product, and only row 1 (+0 addend, -0 + +0 = +0) is where the pre-patch hardware differed. So the +0 arm this PR adds is not what decides rows 2 and 3 — if it fired there, +0 + -0 would be +0 and the test would have caught it.

I still cannot say whether this driver flushes the product sign-preservingly before the select or leaves a denormal that my select catches, and the reply above says so. But the coverage question is settled: those inputs are in the suite, and it is green on both backends with the change.

AI-assisted (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7195346599 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3212#issuecomment-7195346599). Originally posted by [zzm1234560621-prog](https://github.com/zzm1234560621-prog) on 2026-11-26T14:48:01Z. --- One correction with numbers, since it changes what the model already covers: the negative-denormal-product cases **are** in the 14,440, not outside them. `arithmetic_probes` feeds the accumulate and mad probes `triples(F32_EDGES, F32_EDGES, F32_THIRD)`, which is fully cartesian — `38 × 38 × 10 = 14,440`, the count in the summary line. And the sets contain the operands in question: - `F32_EDGES` has `0x8080_0000` (±smallest normal, line 673) and `0x3F00_0000` (0.5, line 676); - `F32_THIRD` has `0x0000_0000` and `0x8000_0000` (lines 708–709). So `[0x8080_0000, 0x3F00_0000, 0x0000_0000]` and `[…, 0x8000_0000]` — the negative denormal product with a `+0` and with a `-0` addend — are both fed to `v_mac_f32` and `v_mad_f32` by `arithmetic_matches_the_hardware`, and with this patch it passes on both backends. That test compares against `mad`/`out64`, so the model and the hardware agree on those inputs; the model is not keeping a sign the lowering contradicts. Which also fits the words from andrewpozdnakov7-jpg's probe on the same machine: rows 2 and 3 (`-0` addend) come out `80000000` on **hardware and WARP alike**, i.e. plain IEEE addition of a `-0` product, and only row 1 (`+0` addend, `-0 + +0 = +0`) is where the pre-patch hardware differed. So the `+0` arm this PR adds is not what decides rows 2 and 3 — if it fired there, `+0 + -0` would be `+0` and the test would have caught it. I still cannot say whether this driver flushes the product sign-preservingly before the select or leaves a denormal that my select catches, and the reply above says so. But the coverage question is settled: those inputs are in the suite, and it is green on both backends with the change. _AI-assisted (Claude)._
zzm1234560621-prog commented 2026-11-26 16:05:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by zzm1234560621-prog on 2026-11-26T15:14:59Z.


All three remarks taken, and the first one decided by experiment.

1. Operand-based or bit-based. I implemented your version first — "a product with an empty exponent where neither operand's is empty is an underflow, so +0" — and it is worse on the hardware here:

v_mac_f32: model mismatches ["hardware 14", "warp 14"]   (was 0)
v_mad_f32: model mismatches ["hardware 14", "warp 14"]

andrewpozdnakov7-jpg's probe on the same build shows why:

rows 2 and 3 with the operand rule:  [00000000, 00000000, 00000000, 00800000, 80000000, 3f000000]
rows 2 and 3 with the bit rule:      [00000000, 80000000, 80000000, 00800000, 80000000, 3f000000]

Rows 2 and 3 are -0x8080_0000 × 0x3F00_0000 with a ±0 addend: both operands have a real exponent, so the operand rule calls it an underflow and flushes to +0, but the model and both backends return -0. So the console keeps the sign of an underflowed product here, not only of a true zero — your reading of the model ("the model keeps the sign") is the right one, and it extends to the underflow case.

So the bit test stays, and I did the other thing you offered: the doc comment now says the test is on the product's bits and therefore assumes the product reaches it unflushed, names the host that flushes at the multiply as outside that assumption, and records the 14-input result above so nobody implements the operand form again without seeing it.

2. Zeros and the omod path. Documented: a denormal is flushed to +0 here, a product that is already a zero keeps its sign, which is where this differs from write_f's omod path (any zero → +0).

3. Size. exponent_is_zero is now the one place the mask-and-compare is written, and ftz, legacy_mul and the MAD flush all call it. lower.rs grows 584 bytes over the branch, down from 982. Still under the 524,288 cap (cargo xtask policy: 191 files ok), but I take your point that the four open PRs together will not fit — of what is left, about half is the doc comment this review asked for, and the rest is the three-line helper. If it comes to a trim, the cheapest is merging flush_denormal_to_positive_zero into ftz as a flush_zeros: bool argument rather than two functions; say so and I will do that instead.

cargo test -p victory-shader --lib: 297 passed, 4 failed (the four that fail on 63bcca4 here), 3 ignored. cargo clippy … -D warnings: clean. cargo xtask policy: ok.

Thanks for the FMA-contraction point too — that is a second reason the select belongs between the multiply and the add, and worth having in the thread.

AI-assisted (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7195997176 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3212#issuecomment-7195997176). Originally posted by [zzm1234560621-prog](https://github.com/zzm1234560621-prog) on 2026-11-26T15:14:59Z. --- All three remarks taken, and the first one decided by experiment. **1. Operand-based or bit-based.** I implemented your version first — "a product with an empty exponent where neither operand's is empty is an underflow, so `+0`" — and it is worse on the hardware here: ``` v_mac_f32: model mismatches ["hardware 14", "warp 14"] (was 0) v_mad_f32: model mismatches ["hardware 14", "warp 14"] ``` andrewpozdnakov7-jpg's probe on the same build shows why: ``` rows 2 and 3 with the operand rule: [00000000, 00000000, 00000000, 00800000, 80000000, 3f000000] rows 2 and 3 with the bit rule: [00000000, 80000000, 80000000, 00800000, 80000000, 3f000000] ``` Rows 2 and 3 are `-0x8080_0000 × 0x3F00_0000` with a `±0` addend: both operands have a real exponent, so the operand rule calls it an underflow and flushes to `+0`, but the model **and** both backends return `-0`. So the console keeps the sign of an underflowed product here, not only of a true zero — your reading of the model ("the model keeps the sign") is the right one, and it extends to the underflow case. So the bit test stays, and I did the other thing you offered: the doc comment now says the test is on the product's bits and therefore **assumes the product reaches it unflushed**, names the host that flushes at the multiply as outside that assumption, and records the 14-input result above so nobody implements the operand form again without seeing it. **2. Zeros and the omod path.** Documented: a denormal is flushed to `+0` here, a product that is already a zero keeps its sign, which is where this differs from `write_f`'s omod path (any zero → `+0`). **3. Size.** `exponent_is_zero` is now the one place the mask-and-compare is written, and `ftz`, `legacy_mul` and the MAD flush all call it. `lower.rs` grows **584** bytes over the branch, down from 982. Still under the 524,288 cap (`cargo xtask policy`: 191 files ok), but I take your point that the four open PRs together will not fit — of what is left, about half is the doc comment this review asked for, and the rest is the three-line helper. If it comes to a trim, the cheapest is merging `flush_denormal_to_positive_zero` into `ftz` as a `flush_zeros: bool` argument rather than two functions; say so and I will do that instead. `cargo test -p victory-shader --lib`: 297 passed, 4 failed (the four that fail on `63bcca4` here), 3 ignored. `cargo clippy … -D warnings`: clean. `cargo xtask policy`: ok. Thanks for the FMA-contraction point too — that is a second reason the select belongs between the multiply and the add, and worth having in the thread. _AI-assisted (Claude)._
zzm1234560621-prog commented 2026-11-26 16:05:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by zzm1234560621-prog on 2026-11-26T15:23:22Z.


3, done — 66a60a5 merges the flush into ftz as a flag, which is the option I offered in the last comment.

ftz and the MAD flush differ in exactly one thing: a denormal becomes a zero of its sign, or +0, and the flush additionally requires a non-zero mantissa so a true zero keeps its sign. One function with that flag now covers both, so exponent_is_zero, the masks and the select are written once.

lower.rs over the branch:

bytes
before the review +982
after the shared exponent test +584
after folding the flush into ftz +9

So the four open PRs that touch this file are no longer a problem for the 524,288 cap — at +9 there is nothing left to trim, and #3127/#3158/#3192 keep their headroom.

Nothing about the behaviour moved:

v_mac_f32: model mismatches ["hardware 0", "warp 0"]
v_mad_f32: model mismatches ["hardware 0", "warp 0"]
probe:     [00000000, 80000000, 80000000, 00800000, 80000000, 3f000000]   (Intel Arc and WARP, identical)

cargo clippy … -D warnings: clean. cargo xtask policy: 191 files ok.

AI-assisted (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7196197717 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3212#issuecomment-7196197717). Originally posted by [zzm1234560621-prog](https://github.com/zzm1234560621-prog) on 2026-11-26T15:23:22Z. --- **3, done** — `66a60a5` merges the flush into `ftz` as a flag, which is the option I offered in the last comment. `ftz` and the MAD flush differ in exactly one thing: a denormal becomes a zero of its sign, or `+0`, and the flush additionally requires a non-zero mantissa so a true zero keeps its sign. One function with that flag now covers both, so `exponent_is_zero`, the masks and the select are written once. `lower.rs` over the branch: | | bytes | |---|---| | before the review | **+982** | | after the shared exponent test | +584 | | after folding the flush into `ftz` | **+9** | So the four open PRs that touch this file are no longer a problem for the 524,288 cap — at +9 there is nothing left to trim, and #3127/#3158/#3192 keep their headroom. Nothing about the behaviour moved: ``` v_mac_f32: model mismatches ["hardware 0", "warp 0"] v_mad_f32: model mismatches ["hardware 0", "warp 0"] probe: [00000000, 80000000, 80000000, 00800000, 80000000, 3f000000] (Intel Arc and WARP, identical) ``` `cargo clippy … -D warnings`: clean. `cargo xtask policy`: 191 files ok. _AI-assisted (Claude)._
Jackster commented 2026-11-26 16:06:36 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T16:06:36Z.


AMD data on a Radeon RX 7900 XTX (gfx1100, 32.0.32029.2010), victory-shader built with --features host:

v_mac_f32 and v_mad_f32 both print [00000000, 80000000, 80000000, 00800000, 80000000, 3f000000] at 63bcca4 (test only) and at the head — identical, so the underflowed product is already +0 on this adapter, consistent with your Intel-only failure.

Synthetic only. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7197193825 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3212#issuecomment-7197193825). Originally posted by [Jackster](https://github.com/Jackster) on 2026-11-26T16:06:36Z. --- AMD data on a Radeon RX 7900 XTX (gfx1100, 32.0.32029.2010), `victory-shader` built with `--features host`: `v_mac_f32` and `v_mad_f32` both print `[00000000, 80000000, 80000000, 00800000, 80000000, 3f000000]` at 63bcca4 (test only) and at the head — identical, so the underflowed product is already `+0` on this adapter, consistent with your Intel-only failure. Synthetic only. AI-assisted.
Mericas77 commented 2026-11-27 09:44:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Mericas77 on 2026-11-27T09:44:15Z.


Tested on NVIDIA: RTX 4070 (the only adapter), driver 621.01, Windows 11, rustc 1.98.1. Head 66a60a5 against main 63bcca4. This is the NVIDIA data point the description asks for.

mad_product_rounding_bit_patterns (--ignored --nocapture), same six inputs, v_mac_f32 and v_mad_f32 print the same line each time:

build adapter words
this PR RTX 4070 [00000000, 80000000, 80000000, 00800000, 80000000, 3f000000]
this PR WARP (VICTORY_WARP=1) [00000000, 80000000, 80000000, 00800000, 80000000, 3f000000]
main + this PR's semantics_tests.rs only RTX 4070 [00000000, 80000000, 80000000, 00800000, 80000000, 3f000000]

So on this card the flush is a no-op, as predicted: the 4070 already gives these words without the change, and they match WARP with it. Same picture as the RX 7900 XTX above, not the Arc.

cargo test -p victory-shader --lib --locked (with --skip heap_direct_texture_reads_mark_their_heap_index, #2571): main 298 passed / 3 failed / 3 ignored, this PR 298 / 3 / 4 (the extra ignored one is the probe). The 3 failures are the known NVIDIA ones on main (a_heap_buffer_read_by_element_takes_the_views_stride, a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, gathers_at_a_level_match_the_hardware) and are the same. No game data; the title was not run.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7215034670 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3212#issuecomment-7215034670). Originally posted by [Mericas77](https://github.com/Mericas77) on 2026-11-27T09:44:15Z. --- Tested on NVIDIA: RTX 4070 (the only adapter), driver 621.01, Windows 11, rustc 1.98.1. Head `66a60a5` against `main` `63bcca4`. This is the NVIDIA data point the description asks for. `mad_product_rounding_bit_patterns` (`--ignored --nocapture`), same six inputs, `v_mac_f32` and `v_mad_f32` print the same line each time: | build | adapter | words | |---|---|---| | this PR | RTX 4070 | `[00000000, 80000000, 80000000, 00800000, 80000000, 3f000000]` | | this PR | WARP (`VICTORY_WARP=1`) | `[00000000, 80000000, 80000000, 00800000, 80000000, 3f000000]` | | `main` + this PR's `semantics_tests.rs` only | RTX 4070 | `[00000000, 80000000, 80000000, 00800000, 80000000, 3f000000]` | So on this card the flush is a no-op, as predicted: the 4070 already gives these words without the change, and they match WARP with it. Same picture as the RX 7900 XTX above, not the Arc. `cargo test -p victory-shader --lib --locked` (with `--skip heap_direct_texture_reads_mark_their_heap_index`, #2571): `main` 298 passed / 3 failed / 3 ignored, this PR 298 / 3 / 4 (the extra ignored one is the probe). The 3 failures are the known NVIDIA ones on `main` (`a_heap_buffer_read_by_element_takes_the_views_stride`, `a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`, `gathers_at_a_level_match_the_hardware`) and are the same. No game data; the title was not run. AI-assisted.
andrewpozdnakov7-jpg commented 2026-11-27 09:46:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T09:46:51Z.


Thanks @Mericas77 for the NVIDIA run. The six-word probe matches on RTX 4070 before and after 66a60a5, and the RX 7900 XTX comparison agrees on the same inputs. This fills the AMD and NVIDIA checks requested in the description. The measured correction remains the 102 mismatches per instruction on Intel Xe-LPG.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7215086183 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3212#issuecomment-7215086183). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-27T09:46:51Z. --- Thanks @Mericas77 for the NVIDIA run. The six-word probe matches on RTX 4070 before and after `66a60a5`, and the [RX 7900 XTX comparison](https://github.com/Marvisak/VIctory/pull/3212#issuecomment-7197193825) agrees on the same inputs. This fills the AMD and NVIDIA checks requested in the description. The measured correction remains the 102 mismatches per instruction on Intel Xe-LPG.
kilolimaVI commented 2026-11-27 13:49:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-27T13:49:41Z.


AMD data point for the adapter comparison: head 66a60a5, Windows 11, AMD Radeon 780M (RDNA3), toolchain 1.98.1.

cargo test -p victory-shader --lib --locked -- mad_product_rounding_bit_patterns --ignored --nocapture --test-threads=1:

v_mac_f32 v_mad_f32
780M [00000000, 80000000, 80000000, 00800000, 80000000, 3f000000] same
WARP (VICTORY_WARP=1) same same

Identical to the words you report on Intel Arc and WARP, so the flush gives the same bits on AMD, Intel and WARP.

AI-assisted (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7219993368 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3212#issuecomment-7219993368). Originally posted by [kilolimaVI](https://github.com/kilolimaVI) on 2026-11-27T13:49:41Z. --- AMD data point for the adapter comparison: head 66a60a5, Windows 11, AMD Radeon 780M (RDNA3), toolchain 1.98.1. `cargo test -p victory-shader --lib --locked -- mad_product_rounding_bit_patterns --ignored --nocapture --test-threads=1`: | | `v_mac_f32` | `v_mad_f32` | |---|---|---| | 780M | `[00000000, 80000000, 80000000, 00800000, 80000000, 3f000000]` | same | | WARP (`VICTORY_WARP=1`) | same | same | Identical to the words you report on Intel Arc and WARP, so the flush gives the same bits on AMD, Intel and WARP. AI-assisted (Claude).
ColorMeBoom commented 2026-11-27 14:30:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-27T14:30:21Z.


RDNA1 data point: RX 5700 XT (gfx1010), driver 32.0.21045.29003, Windows 11 26200, Rust 1.98.1, --features host, native adapter. Head 66a60a5 merged onto main 63bcca4.

build adapter v_mac_f32 and v_mad_f32
this PR RX 5700 XT [00000000, 80000000, 80000000, 00800000, 80000000, 3f000000]
this PR WARP (VICTORY_WARP=1) same
main + this PR's semantics_tests.rs only WARP same
  • arithmetic_matches_the_hardware on this card: v_mac_f32 and v_mad_f32 have 0 model mismatches out of 14,440, hardware and WARP, on main and on this PR. So the flush is a no-op here too, like the RX 7900 XTX, 780M and RTX 4070.
  • Why this card was worth checking: this driver folds fadd(+0.0, c) into c (#1554), and input 1 is exactly that shape (an underflowed product plus +0). It still comes out +0 with and without the change.
  • Full victory-shader suite: 302 passed, 0 failed, 4 ignored. cargo clippy -p victory-shader --all-targets --features host -- -D warnings: clean.
  • Not run: the probe on hardware for main + test only. Windows Application Control on this machine blocked that test binary on every rebuild. main's 0 mismatches above cover the same question.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7220867280 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3212#issuecomment-7220867280). Originally posted by [ColorMeBoom](https://github.com/ColorMeBoom) on 2026-11-27T14:30:21Z. --- **RDNA1 data point: RX 5700 XT** (gfx1010), driver 32.0.21045.29003, Windows 11 26200, Rust 1.98.1, `--features host`, native adapter. Head `66a60a5` merged onto `main` `63bcca4`. | build | adapter | `v_mac_f32` and `v_mad_f32` | | --- | --- | --- | | this PR | RX 5700 XT | `[00000000, 80000000, 80000000, 00800000, 80000000, 3f000000]` | | this PR | WARP (`VICTORY_WARP=1`) | same | | `main` + this PR's `semantics_tests.rs` only | WARP | same | - `arithmetic_matches_the_hardware` on this card: `v_mac_f32` and `v_mad_f32` have **0 model mismatches out of 14,440**, hardware and WARP, on `main` and on this PR. So the flush is a no-op here too, like the RX 7900 XTX, 780M and RTX 4070. - Why this card was worth checking: this driver folds `fadd(+0.0, c)` into `c` (#1554), and input 1 is exactly that shape (an underflowed product plus `+0`). It still comes out `+0` with and without the change. - Full `victory-shader` suite: **302 passed, 0 failed, 4 ignored**. `cargo clippy -p victory-shader --all-targets --features host -- -D warnings`: clean. - Not run: the probe on hardware for `main` + test only. Windows Application Control on this machine blocked that test binary on every rebuild. `main`'s 0 mismatches above cover the same question. AI use: Claude Code (Claude Opus 5.5).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3212:upstream-pr/3212'
git switch 'upstream-pr/3212'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3212'
git switch 'upstream-pr/3212'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3212'
git switch 'upstream-pr/3212'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3212'
git switch 'main'
git merge --squash 'upstream-pr/3212'
git switch 'main'
git merge --ff-only 'upstream-pr/3212'
git switch 'main'
git merge 'upstream-pr/3212'
git push origin 'main'
Sign in to join this conversation.
No reviewers
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!3210
No description provided.