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

Open
github-bot wants to merge 4 commits from github-bot/gh-3212 into main AGit
Owner

@⁠zzm1234560621-prog on GitHub · 2026-11-26 13:08 UTC · original
zzm1234560621-prog:shaders/mad-product-flush → main · +70 −21 · 2 files · 4 commits · open

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).

**@⁠zzm1234560621-prog** on GitHub · 2026-11-26 13:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/3212) `zzm1234560621-prog:shaders/mad-product-flush` → `main` · +70 −21 · 2 files · 4 commits · open ## 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)._
The console rounds a MAD's product and flushes a denormal result to **+0**,
the sign dropped. The lowering multiplied plainly and added, so a host that
flushes sign-preserving disagrees with it: on Intel Xe-LPG the two ops miss
the model on 102 of the 14,440 inputs `semantics_tests` feeds them, all of
them `want 00000000 got 80000000`. `v_mac_legacy_f32` and `v_mad_legacy_f32`
already matched, because they go through `legacy_mul`.

`flush_denormal_to_positive_zero` is that flush as the hardware leaves it: a
result whose exponent is zero and whose mantissa is not becomes +0, while
zeros pass through, so the -0 of a true zero product (a negative operand
times zero) stays as the multiply gave it.

arithmetic_matches_the_hardware, Intel Arc (Xe-LPG, driver 32.0.101.6127),
main `63bcca4`:

  v_mac_f32:  model mismatches 102 -> 0
  v_mad_f32:  model mismatches 102 -> 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 13:13:07 +00:00
Author
Owner

@⁠AurumCarlos on GitHub · 2026-11-26 13:10 UTC · original · reviewed

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.

**@⁠AurumCarlos** on GitHub · 2026-11-26 13:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/3212#pullrequestreview-6074690974) · **reviewed** 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.
Author
Owner

@⁠oni-swr on GitHub · 2026-11-26 13:25 UTC · original

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.

**@⁠oni-swr** on GitHub · 2026-11-26 13:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/3212#issuecomment-7193339296) **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.
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 13:29 UTC · original · approved these changes

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).

**@⁠Dukestar69** on GitHub · 2026-11-26 13:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/3212#pullrequestreview-6074970124) · **approved these changes** 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).
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-26 13:52 UTC · original

@⁠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.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-26 13:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/3212#issuecomment-7193952960) @⁠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.
Folds in andrewpozdnakov7-jpg's probe (ee7c053) so the flush can be compared
on any adapter: six inputs through `v_mac_f32` and `v_mad_f32`, printing the
FP32 words, including a negative denormal product with a +0 and a -0 addend
and a true zero product.

On this machine the two backends now agree word for word, where before the
patch the first input came back `80000000` on hardware and `00000000` on
WARP:

  v_mac_f32:  [00000000, 80000000, 80000000, 00800000, 80000000, 3f000000]
  v_mad_f32:  [00000000, 80000000, 80000000, 00800000, 80000000, 3f000000]
  (Intel Arc Xe-LPG and WARP, identical)

Co-authored-by: andrewpozdnakov7-jpg <[email protected]>
Author
Owner

@⁠zzm1234560621-prog on GitHub · 2026-11-26 14:43 UTC · original

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** on GitHub · 2026-11-26 14:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/3212#issuecomment-7195226837) 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)._
Author
Owner

@⁠zzm1234560621-prog on GitHub · 2026-11-26 14:48 UTC · original

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** on GitHub · 2026-11-26 14:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/3212#issuecomment-7195346599) 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)._
Review from AurumCarlos on #3212, three remarks:

- The "zero or a denormal" test was written out in `ftz`, in `legacy_mul`
  and again in the MAD flush. It is now `exponent_is_zero`, and the three
  call it.
- The MAD flush decides on the product's bits, so it assumes the product
  reaches it unflushed. The doc comment now says that, and says why the
  operand-based form does not replace it: deciding from the operands turns
  an underflowed negative product into `+0`, which misses the model on 14
  of the 14,440 inputs — on hardware and WARP alike — and flips two of the
  probe's words from `-0` to `+0` where the model and both backends say
  `-0`.
- It also says why a true `-0` product keeps its sign here where the output
  multipliers turn any zero into `+0`.

`lower.rs` grows 584 bytes over the branch, down from 982.
Author
Owner

@⁠zzm1234560621-prog on GitHub · 2026-11-26 15:14 UTC · original

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** on GitHub · 2026-11-26 15:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/3212#issuecomment-7195997176) 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)._
`ftz` and the MAD product flush differ in one thing only: a denormal becomes
a zero of its sign, or `+0`, and the flush also asks for a non-zero mantissa
so that a true zero keeps its sign. One function with that flag covers both,
so `exponent_is_zero`, the masks and the select are written once.

`lower.rs` grows **9** bytes over the branch (982 before the review, 584
after the first pass), which keeps the four open PRs that touch this file
inside the 524,288 policy cap.

cargo test -p victory-shader --lib: 297 passed, 4 failed, 3 ignored — the
four that fail on `63bcca4` on this adapter.
cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean.
cargo xtask policy: 191 files ok.
The MAD probe's words are unchanged: [00000000, 80000000, 80000000, 00800000,
80000000, 3f000000] on Intel Arc and on WARP.
Author
Owner

@⁠zzm1234560621-prog on GitHub · 2026-11-26 15:23 UTC · original

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).

**@⁠zzm1234560621-prog** on GitHub · 2026-11-26 15:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/3212#issuecomment-7196197717) **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)._
Author
Owner

@⁠Jackster on GitHub · 2026-11-26 16:06 UTC · original · edited 2026-11-26 16:08 UTC

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.

**@⁠Jackster** on GitHub · 2026-11-26 16:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/3212#issuecomment-7197193825) · edited 2026-11-26 16:08 UTC 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.
This pull request can be merged automatically.
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/3212/head:github-bot/gh-3212'
git switch 'github-bot/gh-3212'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3212'
git switch 'github-bot/gh-3212'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3212'
git switch 'github-bot/gh-3212'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3212'
git switch 'main'
git merge --squash 'github-bot/gh-3212'
git switch 'main'
git merge --ff-only 'github-bot/gh-3212'
git switch 'main'
git merge 'github-bot/gh-3212'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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!3212
No description provided.