Skip to content

FUZZ-55: binary64 VALU differential fuzzer (tools/f64_diff.py) - #4536

Closed
iurysf wants to merge 8 commits into
ProjectLeonida:mainfrom
iurysf:leonida/FUZZ-f64-f64diff
Closed

iurysf wants to merge 8 commits into
ProjectLeonida:mainfrom
iurysf:leonida/FUZZ-f64-f64diff

Conversation

@iurysf

@iurysf iurysf commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

FUZZ-55 - differential fuzzer for the binary64 (*_f64) VALU family, claimed in
#4257 (comment) (tracked as FUZZ-55 in the
coordination list).

Depends on: none.

Files: tools/f64_diff.py (new), tests/test_f64_diff.py (new), docs/shader_validation.md (a new
harness subsection only; no existing rows are touched).

Scope - the 47 *_f64 instruction forms main actually translates:

  • v_trunc_f64, v_ceil_f64, v_rndne_f64, v_floor_f64 (per-source abs/neg on the high word;
    omod first, then clamp);
  • v_add_f64 (including s_round_mode for MODE.FP_ROUND[3:2]), v_cvt_f32_f64, v_rcp_f64,
    v_rsq_f64, v_sqrt_f64;
  • v_div_fixup_f64, v_div_fmas_f64;
  • v_frexp_mant_f64, v_frexp_exp_i32_f64;
  • all 16 conditions of v_cmp_*_f64 / v_cmpx_*_f64, plus v_cmp_class_f64 / v_cmpx_class_f64.

Excluded (not translated on main; --list-ops names them): v_mul_f64, v_min_f64, v_max_f64,
v_fract_f64, v_cvt_f64_f32, v_ldexp_f64, v_mad_f64, v_cvt_i32_f64, v_cvt_u32_f64,
v_div_scale_f64.

Design - the fmisc_diff.py / sad_diff.py conventions: seeded straight-line programs, standard
library only, python -I, newline="\n"; two independent oracles compared word for word: a
reference written from the RDNA2 ISA pseudocode with exact rational arithmetic (Fraction, one
round-to-nearest-even per operation; shares no code with the translator), and tools/rdna2spirv.py
executed through tests/semantic/spirv_mini_interp.py; --oracle gpu runs the translated SPIR-V on
the local device via the vk_harness. Exit 0 all match / 1 mismatch (shortest failing program after
shrinking) / 2 harness error / 77 requested hardware oracle unavailable. Skips are always counted
with their reason.

KNOWN_DIVERGENCES (excluded by default; --known runs them):

Real runs (Windows 11, Python 3.14; every program synthetic, no game files):

  • CPU campaigns, seeds 1-5 x 300 programs: 327 / 316 / 325 / 320 / 324 matches, 0 mismatches,
    347 total each, skips counted with reasons (exit 0 each). Seed 7, 150 programs, --max-ops 4:
    138 matches, 0 mismatches, 197 total (exit 0).
  • --known --no-sweep --programs 0 --all-failures: 4 probes, 3 match, 1 mismatch
    (div-fixup-nan-s0), exit 1 as designed.
  • Negative control: a +1 mutation planted in the reference is caught (exit 1, shrunk to a one-line
    program) and the run passes again after restoring it; --self-test plants a translator mismatch,
    shrinks it to one instruction and checks 10 invariants.
  • tests/test_f64_diff.py: 16 tests OK. Docs gates: tests/test_docs_links.py 6 OK,
    tests/test_docs_repo_paths.py 2 OK, tests/test_docs_list_items.py 2 OK,
    tests/test_text_write_line_endings.py 3 OK. python -m compileall -q tools tests clean;
    git diff --check clean.

Optional GPU oracle (NVIDIA GeForce RTX 4070, subgroup 32, driver 621.01, Windows 11 build 26300,
Vulkan SDK 1.4.363.1, MSVC 14.44; vk_harness built in the worktree):

  • --oracle gpu --programs 300 --seed 1: 331 match, 0 mismatch, 347 total, 16 skips (exit 0).
  • --oracle gpu --programs 200 --seed 2 --max-ops 4: 218 match, 0 mismatch, 247 total, 29 skips
    (exit 0).
  • Targeted runs: v_cvt_f32_f64/v_rcp_f64/v_rsq_f64/v_sqrt_f64 (80 programs): 39 match,
    84 total, 45 skips; v_cmpx_lt/eq/class (40 programs): 43 match, 43 total, 0 skips.
  • GPU skips are explicit, never silent: binary64 InverseSqrt/Sqrt precision is
    implementation-defined per the SPIR-V contract, NVIDIA flushes subnormal inputs (FTZ), plus the
    CPU-interpreter classes. --oracle hw (AMD RDNA2 hardware oracle) is unavailable on this machine
    and exits 77 by design; adjudicating the div-fixup NaN(S0) rule needs an RDNA2 measurement
    (see Coordinating who works on what (23) (moved to #4571) #4421 (comment)).

No translator changes in this PR: any divergence found is reported as a finding: in the
coordination issue first. No game data anywhere. AI-assisted (OpenBot team).

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran this at 50b889e3 on Windows 11: python -I tests/test_f64_diff.py -> 16 tests, OK (41 s); git diff --check clean.

The new tools/f64_diff.py binary64 differential fuzzer and its hardening checks pass; docs remain counts/rules only. No blocking issue.

@Atomic258

Copy link
Copy Markdown
Contributor

Tested 50b889e3c1 on Linux, Python 3.10, CPU only, synthetic fixtures, no game files: pass.

  • python -I tests/test_f64_diff.py → 16/16.
  • New tool tools/f64_diff.py (binary64 VALU differential fuzzer) + docs row; module absent on main, so no negative control — the suite builds its own synthetic inputs.
  • git diff --check and check_no_game_data.py clean.

AI-assisted (Devin).

@mrbean56

Copy link
Copy Markdown

Tested 50b889e3c1 on Linux (Debian 13), Python 3.13.5: pass.

  • pytest tests/test_f64_diff.py -q: 16 passed.
  • Negative control: tools/f64_diff.py does not exist on 03b09a08, so the test file cannot import it (15 of 16 fail). The one that passes is a pure-reference case that needs no tool, which is a good design: the reference is checked against itself first.
  • The probes are binary64 differentials against a plain-Python reference, so a wrong lowering shows up as a bit mismatch rather than a crash, and test_sqrt_preserves_negative_zero is exactly the kind of edge a sqrt lowering gets wrong.
  • No game data: the fuzzer generates its own inputs.

No GPU, no game data. AI-assisted.

@kapitche

kapitche commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Tested 50b889e merged with main 03b09a0 (already up to date) on Linux (WSL2) Python 3.12.16 and native Windows 11 Python 3.13.1: pass, with a coverage note.

  • tests/test_f64_diff.py: 16/16 OK on both (15 s Linux, 75 s Windows). f64_diff.py --self-test OK on both; --list-ops prints 47 forms plus the exclusion line; --programs 300 --seed 5 gives 324 match, 0 mismatch, 347 total on both OSes (identical skip counts).
  • Negative control (new files, so mutations of the reference in tools/f64_diff.py): none of three reference mutations is caught - lt evaluated as <=, add_bits returning 0 instead of a NaN, and the signed-zero rule removed. The unit tests and the default sweep/300 random programs all still pass (e.g. --ops v_cmp_lt_f64 under the <= mutation: 1 match, 0 mismatch). The compare, class, fixup and frexp reference functions have no direct test and the sweep uses one case per op, so equal operands and -0 are only reached by chance. Not a bug in the PR; a direct table test for those functions would pin them.
  • docs/shader_validation.md claims checked: 47 forms (pinned by the test), the option list matches the argparse flags. I did not run --oracle gpu or hw.
  • Interaction with TEST-983: v_div_fixup_f64 NaN(S0) returns signed infinity (measured on RDNA2) #4586 (open, changes v_div_fixup_f64 so NaN(S0) gives signed infinity): with that branch merged into this one, tests/test_f64_diff.py fails 2 tests (test_div_fixup_nan_s0_is_skipped_by_default_and_runs_with_known: 'match' != 'mismatch', and test_known_divergences_only_reinserted_with_known: return code 0, expected 1), because both assert the divergence TEST-983: v_div_fixup_f64 NaN(S0) returns signed infinity (measured on RDNA2) #4586 removes. Whichever lands second needs to drop that known-divergence probe or flip the expectation.

@bobcatchris

Copy link
Copy Markdown
Contributor

Cross-platform check on Apple M2 (macOS 26.4, arm64, Python 3.13.18) at head 50b889e: pytest -q tests/test_f64_diff.py tests/test_docs_links.py tests/test_docs_repo_paths.py tests/test_docs_list_items.py → 26 passed in 1.04 s. This only covers the CPU-interpreter path; the --oracle hw RDNA2 path is unavailable here. No game files.

AI-assisted.

@Flyander Flyander left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two actionable issues below: the advertised hardware oracle is unreachable, and the reference mishandles one directed-rounding signed-zero case.

Comment thread tools/f64_diff.py Outdated
if args.self_test: return 0 if self_test() else 1
gpu = None
if args.oracle == "hw":
print("hardware oracle unavailable: this host has no configured AMD hw_oracle", file=sys.stderr); return 77

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] This returns 77 unconditionally, so --oracle hw can never use an AMD tools/hw_oracle, even when configured; --hw-arch is consequently unused and run_one() sends every non-GPU oracle through the translator. That contradicts the CLI/docs contract and blocks using this fuzzer to adjudicate the documented RDNA2 divergence. Please detect whether the hardware oracle is unavailable, and route available runs through it.

Comment thread tools/f64_diff.py Outdated
if is_inf(a) or is_inf(b):
af, bf = to_float(a), to_float(b)
return from_float(af + bf)
negzero = (is_zero(a) and is_zero(b) and bool((a & b) >> 63)) or mode == 2

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] or mode == 2 makes every exact zero sum negative under round-toward-negative, including +0 + +0. IEEE 754-2019 section 6.3 says x + x retains the sign of x when x is zero, so this case must stay +0; only opposite-sign cancellation gets the directed-rounding zero sign. The translator currently skips directed-rounding programs, which makes this latent in current comparisons, but the reference claims to model all four modes. Please distinguish same-sign zero operands from exact cancellation and pin both signs in a reference test.

iurysf added a commit to iurysf/Leonida that referenced this pull request Nov 23, 2026
…the reference

Review follow-up on ItsNotRexed#4536 (CHANGES_REQUESTED by Flyander; coverage note by kapitche).

- --oracle hw no longer always exits 77. It opens tools/hw_oracle (same pattern as
  tools/fmisc_diff.py), runs each program as a one-lane wave32 raw kernel in the game's
  inferred MODE, honours --hw-arch, and compares the four words with the reference. 77 is
  returned only when the oracle is unavailable. v_rcp/v_rsq/v_sqrt_f64 are counted skips
  there (native results are approximations, PROC-216); the translator-only known-divergence
  exclusions do not apply to hardware.
- add_bits: an exact zero sum now follows IEEE 754-2019 6.3. +0 + +0 stays +0 in every
  mode; only opposite-signed zeros and x + (-x) give -0 when rounding toward negative.
  Before, every exact zero was -0 in that mode.
- tests: direct table tests for compare (16 conditions x 28 operand pairs), class (10
  classes plus boundaries), div_fixup, frexp and add_bits (NaN, inf, zero signs in all four
  modes), plus fake-oracle tests for hw routing, --hw-arch, exit 77, skips and shrinking.
  Mutating lt to <=, add_bits NaN to 0, or dropping the signed-zero rule now fails them.
- docs/shader_validation.md describes the hw contract. No AMD hardware run has been done.

KNOWN_DIVERGENCES keeps div-fixup-nan-s0 (it waits for TEST-983 to reach main).

AI-assisted (OpenBot team).

Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>
@iurysf

iurysf commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@Flyander, @kapitche, thanks. All three points are addressed in a new commit on top of 50b889e (no force-push): 7bd5f01.

  • --oracle hw now opens tools/hw_oracle the way tools/fmisc_diff.py does: one-lane wave32 raw kernels in the game's inferred MODE, one launch for the campaign, --hw-arch passed through, compared with the reference only. Exit 77 is returned only when the oracle is unavailable. v_rcp/v_rsq/v_sqrt_f64 are counted skips on hardware (native results are approximations, PROC-216), and KNOWN_DIVERGENCES does not filter hardware runs. The path is covered by tests with a fake oracle (routing, --hw-arch, 77, skips, shrinking); I have no AMD GPU here, so it has not been run on hardware yet.
  • Zero-sum sign (was tools/f64_diff.py:169, now :175-180): per IEEE 754-2019 §6.3, +0 + +0 stays +0 in every mode; only opposite-signed zeros and an exact x + (-x) give -0 when rounding toward negative. A reference test pins both signs across the four modes, and the old or mode == 2 rule fails it.
  • Coverage: direct table tests for compare (all 16 conditions over 28 pairs, including equal operands, ±0, NaN, ±inf), class, div_fixup, frexp and add_bits. The three mutations from the note (lt as <=, add_bits returning 0 for a NaN, the signed-zero rule removed) now each fail a test; reverted afterwards.

Checks at 7bd5f01 (Windows 11, python -I): tests/test_f64_diff.py 29 OK, --self-test OK, docs gates OK, git diff --check clean, CPU seeds 1-5 and 7 with 0 mismatches, RTX 4070 --oracle gpu runs with 0 mismatches; reviewed independently before pushing. div-fixup-nan-s0 stays in KNOWN_DIVERGENCES until #4586 (TEST-983, the RDNA2-measured fix) lands; I will drop it then.

AI-assisted (OpenBot team).

@TreXito

TreXito commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Tested head 7bd5f01 on current main: the v_div_fixup_f64 reference predates 48a1a98 ("v_div_fixup: match native RDNA2 gfx1036 hardware measurements", on main since round 43). With more programs per seed, that shows up as fuzz mismatches and 2 failing tests. The translator is the side that is right.

Setup: Linux 6.18 host, Python 3.13, CPU oracle only, main 7b7d73f. Its v_div_fixup_f64 lowering is the same as 48a1a98's.

1. Mismatches at 12000 programs per seed (--programs 12000 --all-failures):

seed match mismatch
776401 10830 15
776402 10867 25

All 40 are v_div_fixup_f64 with exp(S2) - exp(S1) >= 1024. The reference gives ±inf; the translator gives copysign(S0, sign_out). One shrunk example:

s_mov_b32 s5, 0x6bcaa545
v_div_fixup_f64 v[8:9], 3.25, 0x86297748c3c8da37, s[4:5]
expected: 00000000 fff00000   actual: 00000000 c00a0000

2. Two tests fail on current main (tests/test_f64_diff.py: 2 failed, 27 passed):

  • test_div_fixup_nan_s0_is_skipped_by_default_and_runs_with_known: 'match' != 'mismatch'.
  • test_known_divergences_only_reinserted_with_known: 0 != 1.

The cause is that main now maps NaN(S0) to ±inf, so div-fixup-nan-s0 is no longer a divergence.

What main implements (the v_div_fixup_f16, v_div_fixup_f64 row of docs/design.md, measured on gfx1036):

  • f64 underflow cutoff is e2 - e1 <= -1076;
  • there is no overflow check;
  • sNaN in S1/S2 passes through unquieted under IEEE=0;
  • NaN(S0) maps to ±inf.

Patch to fixup(), tested:

-    if is_nan(s2): return s2 | (1 << 51)
-    if is_nan(s1): return s1 | (1 << 51)
+    if is_nan(s2): return s2
+    if is_nan(s1): return s1
@@
-    if i1 or z2 or ediff < -1074: return sign
-    if z1 or i2 or ediff >= 1024 or is_nan(s0): return sign | EXP
+    if i1 or z2 or ediff <= -1076: return sign
+    if z1 or i2 or is_nan(s0): return sign | EXP
@@ (the KNOWN_DIVERGENCE guard in the step function)
-                               and -1074 <= ediff < 1024)
+                               and ediff > -1076)

With the patch, the same two seeds give 10845/12047 and 10890/12047 matching, 0 mismatches, exit 0 for both. The skips are the same reasons as before.

What else needs updating for the patch:

  • the div-fixup-nan-s0 entry and its two tests, since it now matches;
  • these test_div_fixup_table rows, each checked against the patched fixup():
row S0 S1 S2 want
nan_s2_quiets_s2 1.0 1.0 sNaN 0x7FF0000000000001 (unchanged)
nan_s1_quiets_s1 1.0 sNaN 1.0 0x7FF0000000000001 (unchanged)
underflow_edge_still_passes_s0 3.0 e(1076) e(1) 3.0 (ediff = -1075 passes)
underflow_to_zero / underflow_beats_nan_s0 3.0 / qNaN e(1077) e(1) +0
overflow_to_inf 3.0 e(1) e(1025) 3.0 (no overflow check)

Every other f64 op in both runs matched. AI-assisted (Claude Code), every number above is from a real run.

iurysf and others added 2 commits November 23, 2026 01:18
…Rexed#2477 is on main

ItsNotRexed#2477 (48a1a98) makes the translator return signed infinity for v_div_fixup_f64
with NaN(S0), as measured on RDNA2 gfx1036, which is what the reference already
modelled. The case is no longer a known divergence (as TreXito's review of ItsNotRexed#4536
observed: two tests fail on main because they expect the old divergence).

- Remove the div-fixup-nan-s0 entry, its reference skip and its dedicated --known
  program; NaN(S0) programs are compared like any other.
- Add a positive test that the reference and the translator give +-inf for qNaN,
  -qNaN and sNaN with both output signs.
- Rework the two --known tests so they no longer depend on div_fixup: the three
  remaining forms are excluded with a reason by default, run with --known, and a
  planted clamp-only translator error exits 1 and prints the shrunk program.
- docs/shader_validation.md no longer lists the div_fixup case.

Same change as 41525870 (prepared for ItsNotRexed#4586, which ItsNotRexed#2477 made redundant).

AI-assisted (OpenBot team).

Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>
…nts on main (ItsNotRexed#2477)

TreXito's review of ItsNotRexed#4536 found 40 mismatches in 24000 programs (seeds 776401 and
776402, exp(S2) - exp(S1) >= 1024): the reference predates ItsNotRexed#2477 (48a1a98),
whose measured RDNA2 gfx1036 rules are in the docs/design.md v_div_fixup row.
The translator is the side that is right. Checked against that row and against
the v_div_fixup_f64 lowering in tools/rdna2spirv.py on main, not only against the
proposed patch:

- NaN in S2 or S1 passes through unchanged (a signalling NaN is not quieted with
  IEEE=0); the priority NaN(S2) over NaN(S1) is unchanged.
- The underflow cutoff is exp(S2) - exp(S1) <= -1076 (was < -1074).
- There is no overflow check (was >= 1024).
- NaN(S0) gives signed infinity, still below the underflow case.

test_div_fixup_table is updated row by row (gap 1074/1075 pass S0, 1076 gives a
signed zero, no overflow rows, unquieted sNaN) and docs/shader_validation.md
records the rule.

AI-assisted (OpenBot team).

Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>
Found while validating the ItsNotRexed#2477 follow-up on the RTX 4070: with the current
translator, `v_cmp_eq_i32_e32 vcc_lo, 0, 0; v_div_fmas_f64 v[8:9], s[4:5], -1.0, 1`
mismatched. The reference scaled by a fixed 2^64 when VCC is set; main now follows the
hardware-verified (gfx1036, 153/153 f64 stress cases) rule in the docs/design.md
v_div_fmas row: 2^+128 when exp(S2) > 1023 (|S2| >= 2.0), 2^-128 otherwise.

Same class of stale reference as the v_div_fixup_f64 one fixed in the previous
commit (TreXito's review of ItsNotRexed#4536). A table test pins both sides of the |S2| = 2.0
threshold and the VCC-clear case; reverting to the fixed 2^64 fails it.

AI-assisted (OpenBot team).

Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>
@abnalstlll-byte

Copy link
Copy Markdown
Contributor

Tested head 7bd5f01d locally on Windows 11: 29/29 unit tests passed and 10/10 --self-test cases passed.

Live hardware test on native RDNA2 gfx1036 (tools/hw_oracle, Windows 11, AMD driver 32.0.21045.29003): --oracle hw connects to the device (device=AMD Radeon(TM) Graphics arch=gfx1036), 24 match, 6 skips, and 1 mismatch caught on minimal program s_mov_b32 s5, 0x6b82ed5c (word 1: expected 00000001 ffffffff, actual 00000001 00000001). No game files. AI-assisted review (Gemini).

@kapitche

Copy link
Copy Markdown
Collaborator

Tested 7bd5f01 merged with main 98fa503 on Linux (Python 3.12.16): fail - tests/test_f64_diff.py 29 tests, 2 FAIL, 27 OK; tests/test_docs_*.py all OK. The two failures are test_div_fixup_nan_s0_is_skipped_by_default_and_runs_with_known (known run returns "match", the test expects "mismatch") and test_known_divergences_only_reinserted_with_known (returncode 0, expected 1). Cause: main now has 48a1a98 ("v_div_fixup: match native RDNA2 gfx1036 hardware measurements"), which landed after this branch's base 03b09a0 and makes the translator handle NaN(S0), so the div-fixup-nan-s0 entry in KNOWN_DIVERGENCES ("current translator preserves the NaN payload") is stale and the tests that expect it to diverge no longer hold. Negative control: with tools/f64_diff.py removed the test module cannot import (not informative beyond that).

The reviewer's `--oracle gpu --ops v_div_fmas_f64 --programs 300 --seed 1` run had one
mismatch: `v_div_fmas_f64 v[8:9], 16, 0xa5126aa7ea6efc1f, 0` (VCC clear), reference -0,
GPU +0. Diagnosis (RTX 4070):

- IEEE is -0: the exact result is a negative nonzero that underflows, and the C library
  fma and the reference agree. Denormal operands are preserved by the GPU, so it is not
  operand flush-to-zero.
- The translator emits a plain GLSL `Fma` for that path (SPIR-V checked), and adding
  SignedZeroInfNanPreserve/DenormPreserve 64 does not change the GPU result.
- The same `Fma(2^-600, -2^-600, +0)` on runtime operands (a FragCoord-derived shader)
  returns -0 on the GPU. Only an all-constant `Fma` loses the zero sign, which points at
  the driver folding it. The fuzz shaders are all constants.

So neither the reference nor the translator is wrong. A GPU result that differs from
the reference only in the sign of such a zero (an underflowing Fma against an
opposite-signed zero addend) is now a counted skip with that reason; any other
difference still fails. ref_program reports the case through an optional notes list.
Tests pin the flag, the skip, and that a flip without the underflow, or with another
differing word, stays a mismatch (four mutations fail them). docs/shader_validation.md
records the diagnosis.

AI-assisted (OpenBot team).

Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>
@kapitche

kapitche commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Tested 8803b72 merged with main ec34b54 on Linux (WSL), Python 3.12.16 (-I), and native Windows 11, Python 3.13.1: pass

Re-check of my earlier fail at 7bd5f01 (2 failing tests, stale div-fixup-nan-s0 known divergence after 48a1a98):

  • test_div_fixup_nan_s0_is_skipped_by_default_and_runs_with_known and test_known_divergences_only_reinserted_with_known: resolved. div-fixup-nan-s0 is gone from KNOWN_DIVERGENCES (now only f64-omod, double-neg-abs, fclamp-nan-zero) and the reference follows the gfx1036 NaN(S0) rule from main.
  • The follow-up interaction I noted with TEST-983: v_div_fixup_f64 NaN(S0) returns signed infinity (measured on RDNA2) #4586 (NaN(S0) known divergence) is also gone with that change.

Counts:

  • tests/test_f64_diff.py: 33 tests OK on Linux (24 s) and on Windows (117 s). The previous head (7671b9b) also passed 31/31 on both.
  • tools/f64_diff.py --self-test: OK on Linux. --programs 300 --seed 5: 315 match, 0 mismatch; 347 total on both OSes.
  • All tests/test_docs_*.py OK on Linux.
  • Not run: --oracle gpu / --oracle hw.

Negative control (new files, so reference mutations in tools/f64_diff.py): lt evaluated as <= fails 8 tests at 8803b72. At the previous head 7671b9b, add_bits returning 0 for a NaN input failed 21 tests and dropping the same-sign zero-sum rule failed 4 (not rerun at 8803b72). The three mutations I reported as undetected earlier at 50b889e are therefore caught.

@abnalstlll-byte

Copy link
Copy Markdown
Contributor

Tested on Windows 11 with Python 3.14 on HEAD \8803b723:

\python -m unittest tests/test_f64_diff.py\ ran 33 tests with 1 failure in \ est_div_fixup_nan_s0_gives_signed_infinity_in_reference_and_translator:
\
AssertionError: 'mismatch' != 'match' : ('word comparison', [0, 2146435072, 0, 0], [0, 2146959360, 0, 0])
\
In case 0 (\�_mov_b32 v13, 0x7ff80000, \1.0, \2.0):

  • \expected: [0, 2146435072, 0, 0]\ (\

@memorypressure

Copy link
Copy Markdown

Merged cleanly with current main: all 33 new tests pass, the f64 suites (2 + 4) and docs guards pass, and the CPU campaign reproduces here — 318 match, 0 mismatch, 29 reasoned skips on the documented seed. Both text writes pin UTF-8 and LF; the DXBC stub is constructed, not game data. One scope note: the signed-zero exception is described through the RTX 4070 observation but the exclusion applies to every GPU-oracle run — since the underlying Fma divergence could show on any driver, consider vendor-neutral wording or gating by device so the exclusion reason stays honest on AMD results. #4543 overlaps compare coverage independently. Checks pending. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

ItsNotRexed added a commit that referenced this pull request Nov 23, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kapitche

Copy link
Copy Markdown
Collaborator

Tested 5c81e05 merged with main 1cc6e3c on Linux/Python 3.12.16: pass.

Ran (venv python, -I):

  • tests/test_f64_diff.py: 37 tests OK
  • tests/test_docs_*.py: all OK

Negative control: (a) tools/f64_diff.py from main with the PR tests kept: the test module fails at import (AttributeError: no HW_LANE_MASK), so it is not informative beyond showing the tests need the new tool code; (b) mutation, HW_LANE_MASK 0x1 -> 0xffffffff in tools/f64_diff.py: 2 of 37 tests FAIL.

Earlier issue: my fail on 7bd5f01 (the two div-fixup-nan-s0 KNOWN_DIVERGENCES tests, stale after 48a1a98) does not reproduce; all 37 pass against current main. Native Windows was not run on this head.

@KubickNubick

Copy link
Copy Markdown

Tested 5c81e05 merged with main 1cc6e3c (clean merge) for FUZZ-82, with the seeds of my finding, on Windows 11 Pro 26300: NVIDIA RTX 4080 (621.01) and the AMD Radeon iGPU of a Ryzen 9 9950X3D (gfx1036, 32.0.21042.62), one at a time with LEONIDA_VK_DEVICE; vk_harness built from main 1cc6e3c's tree. The reference fixes remove all 7 false mismatches on both GPUs.

python -I tools/f64_diff.py --programs 200 --seed <seed> --no-literals --all-failures --oracle gpu --exe vk_harness.exe:

seed 31337 seed 20261123
main 1cc6e3c, RTX 4080 223 match, 5 mismatch (4 v_div_fmas_f64, 1 v_div_fixup_f64) 229 match, 2 mismatch (2 v_div_fmas_f64)
main 1cc6e3c, Radeon the same 5 the same 2
this PR, RTX 4080 228 match, 0 mismatch 231 match, 0 mismatch
this PR, Radeon 228 match, 0 mismatch 231 match, 0 mismatch

On the CPU with this PR, --programs 500 --seed 31337: 488 match, 0 mismatch with --no-literals and 490 match, 0 mismatch with literals (on main the literal run has the SHADER-865 mismatches). tests/test_f64_diff.py: 37 passed.

One thing left, on the RTX 4080 only, when v_div_fmas_f64 is fuzzed alone (--programs 60 --seed 31337 --no-literals --no-sweep --all-failures --ops v_div_fmas_f64 --oracle gpu): 39 match, 1 mismatch, 20 skipped (non-finite operands). The Radeon gives 40 match, 0 mismatch on the same 60.

s_mov_b32 s4, 0x95e2ebea
s_mov_b32 s5, 0x2a675513
v_div_fmas_f64 v[8:9], s[4:5], 3.25, s[4:5]
expected: cf411aa9 2288ca64
actual:   cf411aa8 2288ca64

VCC is clear here, so this is the plain fma(S0, 3.25, S0), off by one in the last place on NVIDIA and exact on AMD. All three operands are constants in the module, so my guess is the NVIDIA compiler folding the Fma without fusing it, the same family as the constant-folded Fma zero sign this PR already counts as a GPU skip on the RTX 4070; I have not checked that guess (a run with the operands loaded from a buffer would tell). It is separate from FUZZ-82: VCC is clear, so neither scale rule applies.

No game files. AI-assisted (Claude Code ran the tests).

@whattheflop

Copy link
Copy Markdown
Contributor

After #6947 closed as a duplicate, I reran its independent CPU comparison on exact #4536 head 5c81e056. It gives the same results as #6947 for this matrix.

  • Against an independent table of the documented fixup rules, 0/3,375 mismatches, versus 485 on 1cc6e3c1. Exponent difference −1076 returns zero, −1075 passes S0 through, and +2045 passes it through. NaN payload cases match.
  • Against Fraction arithmetic with one binary64 rounding, 76/16,000 differences, versus 7,257 on 1cc6e3c1. Scaling matches on both sides of the ±2.0 threshold. The remaining 76 are signed-zero cases such as 1 * (-0) + (-0), with +0 returned for both VCC states where IEEE round-to-nearest gives −0. Those same cases return +0 on main. The documented RDNA2 rule leaves zero sign unspecified for this case, so I did not classify it as a hardware discrepancy.

Windows, uv CPython 3.12.13, handcrafted CPU inputs only. AI-assisted.

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

For FUZZ-82: my closed #6947 used the same reference rules for v_div_fixup_f64 and v_div_fmas_f64, derived from the measured RDNA2 notes in docs/design.md: NaN in S1/S2 passes through unquieted, underflow from an exponent difference of -1076, and the VCC scale of 2^+128 when |S2| >= 2.0, else 2^-128. @Mob1K7105 then ran it on a real RDNA2 (RX 6700 XT, RADV) and got 0 mismatches over the seeds where main stops at the first v_div_fmas_f64 mismatch (#6947). If #4536's rules differ on any of those points, that run is a hardware tiebreak. AI-assisted.

@DeSunShine

Copy link
Copy Markdown
Contributor

Tested 5c81e0568 merged into main 5f47ed2b3 on an NVIDIA GeForce RTX 4090 (driver 621.24, Windows 11 Pro 26200, Vulkan SDK 1.4.363). --self-test is ok. f64_diff.py --oracle gpu --exe vk_harness.exe --programs 300 --seed 1 --all-failures gives 331 match, 0 mismatch out of 347; the rest are the known skips (directed s_round_mode, implementation-defined InverseSqrt/Sqrt precision, v_rcp_f64 subnormals).

One gap: this driver does round binary64 GLSL Fma twice, and the fuzzer can't see it. v_div_fmas_f64 is generated with VCC = 1 only (the scaled path), and random operands almost never cancel. A VCC = 0 directed case such as fma(a, a, c) with a = 1 + 2^-30 and c = -(1 + 2^-29) gives 0 here instead of 2^-60 (cs_div_fmas_f64 in #6635). It might be worth one directed cancellation probe per FMA form, judged "split allowed" unless --fma khr. AI-assisted (Claude Code).

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

A data point for this PR from our closed duplicate #6947 (same v_div_fmas_f64 reference fix). We ran the f64 GPU differential on a real NVIDIA RTX 3090 (vulkaninfo --summary lists it first, ahead of llvmpipe). Command: f64_diff --oracle gpu --no-literals --seed N --exe runtime/build/vk_harness, seeds 1-5.

seed main's reference fixed reference
1 147 match, 1 mismatch 328 match, 0 mismatch
2 46 match, 1 mismatch 330 match, 0 mismatch
3 8 match, 1 mismatch 330 match, 0 mismatch
4 8 match, 1 mismatch 329 match, 0 mismatch
5 7 match, 1 mismatch 330 match, 0 mismatch

A run stops at its first mismatch, so main's column shows only the first. All five are v_div_fmas_f64 with VCC set, e.g. v_div_fmas_f64 v[8:9], 0.5, -1.0, 0.0: the old reference gives c3e00000 (-0.5 * 2^64), and the GPU gives b7e00000 (-0.5 * 2^-128), the documented scale-down for a small |S2|. AI-assisted.

…ar, accept either zero sign

Review follow-ups on ItsNotRexed#4536 (KubickNubick, DeSunShine, whattheflop, tedin7).

- KubickNubick's RTX 4080 mismatch (`v_div_fmas_f64 v[8:9], s[4:5], 3.25, s[4:5]`, VCC clear,
  last bit) and DeSunShine's `fma(a, a, c)` giving 0 on an RTX 4090 are the same driver
  behaviour, reproduced on an RTX 4070: an all-constant GLSL Fma comes back split (product
  rounded to binary64, then the sum) while the same Fma on runtime operands is fused and equals
  C's fma and the Fraction reference (the reference is right). A GPU result equal to the split
  value (scaled the same way with VCC set) is now a counted skip with a vendor-neutral
  reason; `--fma khr` makes it a mismatch, for a translator that emits OpFmaKHR (ItsNotRexed#6635).
  `--oracle hw` always judges.
- Two directed cancellation programs (fma(a, a, c), a = 1 + 2^-30, c = -(1 + 2^-29), with VCC
  clear and set) run with every v_div_fmas_f64 sweep, and the generator emits VCC clear about
  half of the time (parity of an operand word, so the random stream of other programs is
  unchanged), so the split is seen on every run.
- whattheflop: `1 * (-0) + (-0)` is -0 in IEEE and +0 here, and the RDNA2 notes do not specify
  the sign; a zero of the other sign is a counted skip in the translator and gpu oracles, judged
  by hw.
- tedin7: the fixup/fmas rules are the measured gfx1036 ones and equal those of the closed
  ItsNotRexed#6947 (0 mismatches on an RX 6700 XT); a test pins the values.

tests/test_f64_diff.py: 45 tests, seven mutations of the new logic each fail one.

AI-assisted (OpenBot team).

Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>
@iurysf

iurysf commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @KubickNubick, @whattheflop, @tedin7 and @DeSunShine for the runs. One reply for all four, with what changed (one new commit on top of 5c81e05, no force-push).

@KubickNubick: I reproduced your RTX 4080 mismatch on an RTX 4070 (--programs 60 --seed 31337 --no-literals --no-sweep --all-failures --ops v_div_fmas_f64 --oracle gpu: 39 match, 1 mismatch, the same program) and checked it your way. The reference is right (one rounding: the Fraction result equals Python's math.fma). With all-constant operands the GPU returns the split result (product rounded first), identical to a separate multiply and add; the same Fma on operands built at run time (from FragCoord) is fused and matches the reference. My guess is that the driver folds an all-constant Fma without fusing it (the same family as the zero-sign skip); that is an observation on the RTX 4070, not a confirmed cause. A GPU result equal to the split value (scaled the same way with VCC set) is now a counted skip with a vendor-neutral reason, only in --oracle gpu; any other difference is still a mismatch, and your command now gives 39 match, 0 mismatch and 1 skip.

@DeSunShine: confirmed on an RTX 4070 as well: fma(a, a, c) with a = 1 + 2^-30, c = -(1 + 2^-29) gives 0 on constants and the fused 2^-60 on run-time operands. v_div_fmas_f64 is now generated with VCC clear about half of the time (picked by the parity of an operand word, so the random stream of other programs is unchanged), and two directed cancellation programs (your case with VCC clear and set) run in every v_div_fmas_f64 sweep, so the split is seen on every run. They are counted skips by default; --fma khr makes a split result a mismatch (it sets rdna2spirv.FMA_KHR; OpFmaKHR for f64 needs #6635), and on the RTX 4070 that gives two mismatches.

@whattheflop: thanks for the independent comparison. For 1 * (-0) + (-0) IEEE round to nearest gives -0 and the RDNA2 notes do not specify it, so I did not invent a rule: the reference keeps +0, and in the translator and GPU oracles a zero of the other sign is a counted skip with that reason; --oracle hw still judges it, since measuring it is what the hardware run is for.

@tedin7: I read #6947: the v_div_fixup_f64 and v_div_fmas_f64 rules (NaN in S1/S2 unquieted, underflow cutoff -1076, scale 2^+128 when |S2| >= 2.0 and 2^-128 below) are the same, down to the test values, which now have a test here. Its 0 mismatches on a real RX 6700 XT back these rules.

Numbers (merged with main 99c7509): tests/test_f64_diff.py 45 OK; CPU --programs 300 seeds 1, 2 and 31337: 320, 308 and 312 match, 0 mismatch. RTX 4070 --oracle gpu: --programs 300 --seed 1 331 / 0; --programs 200 --no-literals seed 31337 228 / 0 and seed 20261123 231 / 0; --ops v_div_fmas_f64 --programs 300 --seed 1 237 match, 0 mismatch (3 split skips, two of them the directed probes). The AMD hardware oracle is still untested here.

AI-assisted (OpenBot team).

@JRamos1993

Copy link
Copy Markdown
Contributor

Tested 63d84b0f merged onto main dde82f27 on Windows 11, CPython 3.14.3, CPU only: pass.

  • python -I tests/test_f64_diff.py: 45 tests OK.
  • Negative control (tools/f64_diff.py from main, the PR's tests kept): tests/test_f64_diff.py exit 1, AttributeError: module 'f64_diff' has no attribute 'HW_LANE_MASK'.
  • py_compile on the 2 changed Python files: OK; git diff --check: clean.

No game files. AI-assisted (Claude Code).

@ne1i

ne1i commented Nov 23, 2026

Copy link
Copy Markdown

Tested 63d84b0f on Linux, CPython 3.14, CPU only, synthetic inputs, merged onto main dde82f27: pass

  • python -I tests/test_f64_diff.py: Ran 45 tests, OK.
  • With only the non-test files reverted to main the test file exits 1 before unittest prints a summary, so the tests do depend on the change, but as an import-time failure rather than named failing tests. The agent's reading, which I did not re-derive: a default argument in the test evaluates f64_diff.HW_LANE_MASK at import.
  • compileall and scripts/check_no_game_data.py on the changed files: clean.

Independent check (not the author). Run by an AI agent (DeepSeek V4.1 Flash) and re-run by the orchestrating session (Claude Code) before posting; claimed in #8047.

@DeSunShine

Copy link
Copy Markdown
Contributor

Thanks @iurysf. Confirmed on the RTX 4090 too: cs_div_fmas_f64 with literal operands gives the split 0, and with the same values read at run time from s4..s7 it gives the fused 2^-60 under the default --fma glsl. So the split is the driver folding a constant Fma, as you found on the 4070. I corrected my wording from #6635 in #8750. Your updated head 63d84b0f1 on the 4090: --ops v_div_fmas_f64 --programs 300 --seed 1 gives 237 match, 0 mismatch (the directed probes land in the split skip), and --programs 300 --seed 1 gives 331 match, 0 mismatch. AI-assisted (Claude Code).

@crastinator crastinator left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f64_diff.py --oracle hw on discrete RDNA2. AMD Radeon RX 6700 XT (gfx1031), Linux 7.3.5, tools/hw_oracle (DRM backend). Head 63d84b0f1, which merges cleanly with main 867d922f0.

Run main 867d922f0 this PR
--programs 300 (seed 1) 1 mismatch (stops the run) 303 match, 0 mismatch
--programs 1000 --seed 7 --all-failures 722 match, 188 mismatch 916 match, 0 mismatch

The main mismatches are the single-lane EXEC case your test_hw_oracle_models_the_single_lane_exec_mask_of_v_cmpx covers: after v_cmpx_*_f64, exec_lo reads back as 0x00000001 on the hardware, not 0xffffffff. #6443 has the same fix and the same result here, so only one of the two needs to land.

AI-assisted (Claude Code). Synthetic programs only, no game files.

@iurysf

iurysf commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @crastinator for the --oracle hw run on the RX 6700 XT, and @DeSunShine for the RTX 4090 check of the constant-Fma fold. Agreed on #6443: the single-lane EXEC fix is the same in both, so whichever lands first, the other can drop it.

@Flyander, your two points from the 50b889e review were addressed in 7bd5f01 (see my reply above), and crastinator's run now shows --oracle hw reachable on real RDNA2 at the current head 63d84b0f1: 303/0 and 916/0, against 1 and 188 mismatches on main. Could you take another look when you have time?

AI-assisted (OpenBot team).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.