Skip to content

Translator: f16 rounding — integer f16 narrowing and single-rounded f16 FMAs (SHADER-55, SHADER-56) - #575

Merged
ItsNotRexed merged 3 commits into
ProjectLeonida:mainfrom
IAmNotSiob:shader-55-56
Nov 22, 2026
Merged

ItsNotRexed merged 3 commits into
ProjectLeonida:mainfrom
IAmNotSiob:shader-55-56

Conversation

@IAmNotSiob

@IAmNotSiob IAmNotSiob commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Two parts, one per commit. Items: SHADER-55 and SHADER-56 (both claimed in #374). Closes #513.

(Part 1 was the mini-interpreter NaN fix for #509. I dropped it because #533 / TEST-67 already does that. The f16 tests here export zero-high-half words, so they don't depend on it.)

Part 1: f16 narrowing with integer ops (SHADER-56, #513)

Drivers fold PackHalf2x16 → UnpackHalf2x16 to a no-op, so the next f16 op saw the unrounded f32 value:

Gen.f16_bits converts using only integer ops. It rounds to nearest even, or toward zero with ±65504 for pkrtz. It keeps f16 denormals, gives ±0 for f32 denormal inputs, and turns NaN into a quiet NaN. It's used by f16_out (every f16 VOP1/2/3 result), v_pk_*_f16, v_cvt_f16_f32, f16 sin/cos, v_interp_p2_f16, v_fma_mix* and f16_rtz.

Not touched: image/buffer d16 packing (#489's area), and f16_roundtrip for 16-bit interpolants (#512's OpQuantizeToF16). OpQuantizeToF16 flushes f16 denormals, so I didn't use it for arithmetic.

Test: tests/semantic/test_f16_int_convert.py checks RTE and RTZ against Python's binary16 on ties, the subnormal and overflow boundaries, ±0, ±inf and NaN, plus a seeded sweep over every f32 exponent from 2⁻²⁷ to 2¹⁸. It also asserts that the f16 ALU sites emit no PackHalf2x16. tests/spirv_interp.py gains OpU{Less,Greater}ThanEqual and OpFUnordNotEqual.

Part 2: f16 FMAs round once (SHADER-55)

v_fma_f16, v_fmac_f16 and v_pk_fma_f16 were Fma (rounded to f32) followed by narrowing, which is a double rounding. @BetterJdue's RX 6700 measurement in #374 shows the hardware is a correctly rounded f16 FMA (0 mismatches in 12,612 cases). fma_f16_odd does it in four steps:

  1. x*y is exact in f32: 22 significant bits, and the result stays inside the f32 normal range.
  2. TwoSum gives the f32 sum and its exact error. The ops carry NoContraction.
  3. If the error is non-zero and the sum is even, step one f32 ulp toward the error. That makes the sum the round-to-odd f32 of the exact result.
  4. f16_bits then rounds that correctly to f16, because round-to-odd at 24 bits is innocuous for ≤ 22-bit targets.

omod and clamp keep this valid, since they're exact power-of-two scaling and clamping to representable bounds. v_fma_mix* with f32 sources still uses Fma, and the design row says so.

Test: tests/semantic/test_f16_fma_rounding.py compares against an exact Fraction reference. It uses random triples plus triples built so that a*b lands exactly on an f16 halfway point and c is below half an f32 ulp. f32-first rounding gets those wrong about half the time. Negative control: with main's tools/, 107 subtests fail. All pass here.

Tested

Overlap: #494 adds a fract parameter to f16_out and will conflict on a few lines. Whichever lands second rebases, and I'll do it if it's this one. After this merges, #476's README note about skipping the f16 FMAs can go.

AI-assisted (Claude Code): it wrote the changes and tests, and ran everything above.

…ADER-56, ItsNotRexed#513)

Drivers fold PackHalf2x16 -> UnpackHalf2x16 to a no-op, so a following f16 op saw the unrounded f32 (ItsNotRexed#513:
v_pk_add_f16 -> v_pk_mul_f16 1 ulp off under --wave64-emulate on NVIDIA; v_cvt_pkrtz_f16_f32 rounding to
nearest on llvmpipe). Gen.f16_bits converts with integer ops (RTE, or RTZ with +-65504 for pkrtz) and is used
by f16_out, v_cvt_f16_f32, v_pk_*_f16, f16 sin/cos, v_interp_p2_f16, v_fma_mix* and f16_rtz.
tests/spirv_interp.py gains OpU{Less,Greater}ThanEqual and OpFUnordNotEqual.
v_fma_f16, v_fmac_f16 and v_pk_fma_f16 used GLSL Fma (rounded to f32) and then narrowed, a double rounding;
an RX 6700 matches a correctly rounded f16 FMA in 12,612/12,612 cases (ProjectLeonida#374). fma_f16_odd: exact f32 product,
TwoSum, round-to-odd at f32, then f16_bits. Design row for f16 rounding.
@IAmNotSiob IAmNotSiob changed the title Translator: f16 rounding — integer f16 narrowing and single-rounded f16 FMAs (SHADER-55, SHADER-56), interpreter NaN bits (#509) Translator: f16 rounding — integer f16 narrowing and single-rounded f16 FMAs (SHADER-55, SHADER-56) Nov 22, 2026
@dcastell1

Copy link
Copy Markdown
Contributor

TEST-82 on an RTX 5090 (Blackwell), Windows 11 Pro 10.0.26300.9974, NVIDIA 621.24 / Vulkan 1.4.357, MSVC 14.44, llvm-mc 21.1.8 (WSL), SPIRV-Tools 2025.1, vk_compute_test built at 91b36cf:

                                   native            --emulate
main (ee97b84)                     100/100 match     200/200 match
#575 (5c8cc4f)                     100/100 match     200/200 match

valu_fuzz.py --family f16 --programs 100 --seed 1 --wave both, 0 mismatched, 0 untranslated, 0 harness errors in all four runs; the native runs skip the 100 wave64 programs because the 5090 has 32-wide subgroups. The --show 1:34:32 and 1:49:32 programs are covered by that seed and match on both trees, so I could not reproduce the NVIDIA mismatch reported tonight on this machine/driver; the PR is at least a clean no-regression on the 5090, not a demonstrated before/after fix here.

No game files were used.

@esteban-dcp

esteban-dcp commented Nov 22, 2026 •

Copy link
Copy Markdown

TEST-82: tested 5c8cc4f against the f16 fuzz mismatches, on two GPUs, Linux 7.3.5 (CachyOS): pass.

python -I tools/valu_fuzz.py --family f16 --programs 200 --seed 1 --wave both [--emulate], each GPU pinned with VK_LOADER_DRIVERS_SELECT (device line checked), VK_LOADER_LAYERS_DISABLE=~implicit~. Test programs built from main at ee97b84 (the "main" column) and from this branch.

GPU mode main this PR
AMD Radeon 740M (RDNA3, RADV, Mesa 26.3.1), subgroup 32..64 native, wave32+wave64 221/400 400/400
same --emulate 140/400 400/400
NVIDIA RTX 4050 Laptop (Ada), driver 620.73.04, subgroup 32 native (wave64 skipped) 198/200 200/200
same --emulate 398/400 400/400

0 harness errors, 0 not translated. On main the RADV mismatches were spread over v_pk_fma_f16, v_pk_mul_f16, v_fmac_f16, v_mul_f16, v_fma_f16 and v_add_f16; the 2 NVIDIA ones were v_mul_f16 and v_cvt_f32_f16. All gone with this PR.

For comparison, #551 (8ad2ed5) on the same runs: RADV 396/400 native and 388/400 emulated, NVIDIA 200/200 and 400/400. Its remaining RADV mismatches are mostly v_cvt_f16_f32 (23 of the 32 mismatching op lines native, 83 of 98 emulated), plus a few v_lshrrev_b16/v_mul_lo_u16/v_pk_min_f16 lines (I did not check whether those are downstream of the cvt).

@zneel

zneel commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 5c8cc4f with the f16 fuzzer on the AMD proprietary Windows driver, which the RADV and NVIDIA runs above don't cover: pass.

AMD Radeon RX 9070 XT (RDNA4), driver 26.11.2 (Vulkan 2.0.416), Windows 11 Pro 10.0.26300, runtime built from main ee97b84 (this PR only changes the translator), native Windows llvm-mc 21.1.8.

python -I tools/valu_fuzz.py --family f16 --programs 50 --seed 1 --wave both [--emulate]:

native (wave32 + wave64) --emulate
main ee97b84 30/100 30/100
this PR 100/100 100/100
#551 8ad2ed5, for comparison 93/100 93/100

On main, a lone v_cvt_f16_f32 comes out 1 ulp smaller in magnitude in 448 of 448 differing halves. Across all f16 float ops it's 6,560 of 7,232. This is consistent with this driver rounding PackHalf2x16 toward zero, as reported in #166. #551's remaining mismatches are mostly v_cvt_f16_f32_e32 (52 words), whose branch still calls PackHalf2x16 at 8ad2ed5. The other 4 words are v_pk_min_f16, which I didn't trace (likely an earlier result carried forward). Only the f16 fuzzer was run on this head. AI-assisted (Claude Code); I checked the results.

@IAmNotSiob

Copy link
Copy Markdown
Collaborator Author

nice, thx for running it on the windows driver :)

@tylerstraub

Copy link
Copy Markdown
Contributor

Replying to @zneel.

One detail for the requested rebase: the new main at c432cdc includes #551 (merge 298a69d). I checked the translator at that tip: the integer pack helper is present, but v_cvt_f16_f32 still emits PackHalf2x16. That makes the explicit conversion a useful regression case to keep when reconciling the two changes. The 93/100 row above measures #551 at 8ad2ed5; the integrated main tip still needs its own measurement before using it as the new baseline. Conversion on the merge-round tip

AI-assisted.

@WHOISJARDAS

Copy link
Copy Markdown
Contributor

Tested 5c8cc4f on AMD: RX 9070 XT (RDNA4), AMD proprietary 26.11.2 (LLPC), Windows 11. I used the f16 fuzzer (--programs 100), with wave64 and wave32 per program:

seed main (91b36cf) #551 this PR
1 63/200 191/200 200/200
2 192/200 198/200
3 185/200 196/200

--emulate gives the same counts.

So on AMD this PR fixes the round-toward-zero PackHalf2x16 (numbers in #551) at every site the fuzzer reaches. The 6 programs left are not about rounding:

Both go away when the module declares OpExecutionMode %main SignedZeroInfNanPreserve 32 and its capability. I added just those two lines to the SPIR-V this PR emits for the six programs:

My reading, a hypothesis: without the execution mode the driver's compiler may assume there are no NaNs or −0. A NaN result is then undefined, and through the integer narrowing it reaches the store, which gets dropped. #494 mentions this execution mode but leaves it out; I've claimed adding it in #374. With it, this PR is clean on AMD.

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

# Conflicts:
#	docs/design.md
#	tests/spirv_interp.py
#	tools/rdna2spirv.py
@IAmNotSiob

Copy link
Copy Markdown
Collaborator Author

rebased onto main (6f4bd2a). #551 landed in the same spots so i kept this PR's f16 path (it covers every site, #551 only some) and dropped the two helpers that ended up unused. semantic tests 814 OK, regen_fixtures --check clean :)

@zneel

zneel commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Measured the two tips asked about above, same GPU and settings as my earlier comment (RX 9070 XT, AMD 26.11.2, Windows 11; valu_fuzz.py --family f16 --programs 50 --seed 1 --wave both, native and --emulate give the same counts; vk_compute_test built at ee97b84):

native --emulate
main c432cdc (with #551 merged) 93/100 93/100
this PR rebased, 6f4bd2a 100/100 100/100

So the merged main behaves like #551 alone did: the 7 programs left are the same shape, 52 words from v_cvt_f16_f32_e32 and 4 from v_pk_min_f16. The rebase keeps the fix. AI-assisted (Claude Code).

@dea7hsmiless

Copy link
Copy Markdown
Contributor

Tested 6f4bd2a on an RTX 3070 (Ampere, 32-wide subgroups), NVIDIA 621.24, Windows 11 26300, Vulkan 1.4.357, MSVC 19.44, LLVM 21.1.8 (WSL Ubuntu 24.04, gfx1013), Vulkan SDK 1.4.363.0.

python -I tools/valu_fuzz.py --family f16 --programs 50 --seed 1 --wave both [--emulate]:

native --emulate
main 91b36cf 48/50 match, 2 mismatched 98/100 match, 2 mismatched
this PR 50/50 match, 0 mismatched 100/100 match, 0 mismatched

The two base mismatches are seed-1 programs 34 and 49: v_mul_f16_e64 low bit and v_cvt_f32_f16_e32. Same seed and program count before/after; 50 native wave64 programs skip because the GPU has no 64-wide subgroup. No game files.

@IAmNotSiob

Copy link
Copy Markdown
Collaborator Author

nice, thx for the ampere run :)

@VictorJulianiR

Copy link
Copy Markdown
Contributor

TEST-82 supplemental check on the rebased 6f4bd2a and its c432cdc baseline. On the GitHub-hosted macOS arm64 Apple Paravirtual device with MoltenVK 1.4.2, 99 of 100 matched on each revision. There were zero skips, untranslated programs or harness errors. The generated seed-1 f16 wave32 inputs were byte-identical across revisions. The driver reports subgroup sizes 4–32 and does not advertise required-subgroup-size selection for compute. Full comparison

The sole mismatch was --show 1:23:32 on both revisions. I replayed every prefix. Initialization through the first 13 operations matched the oracle. Adding operation 14, v_mul_f16, produced the same difference on all 64 invocations on both revisions. Register v27 was 0x40000000, versus 0x40008000 in the oracle: the low half was positive zero instead of negative zero. All prefix shaders passed spirv-val. Prefix readbacks and hashes

This leaves one reproducible signed-zero difference on this backend and shows no newly mismatching programs from the PR. The requested RDNA2 and NVIDIA replays are separate. AI-assisted, synthetic inputs.

@BetterJdue

Copy link
Copy Markdown
Contributor

TEST-82, RDNA2 part: tested 5c8cc4f on an AMD Radeon RX 6700 (gfx1031, RDNA2): pass. The f16 fuzz mismatches on main are gone, native and emulated.

python -I tools/valu_fuzz.py --family f16 --programs 100 --seed 1 --wave both [--emulate], same runtime build for both trees:

Tree native --emulate
main b8f6c74 63/200 match, 137 mismatched 63/200 match, 137 mismatched
#575 5c8cc4f 200/200 match, 0 mismatched 200/200 match, 0 mismatched

No programs skipped, untranslated or with harness errors in any of the four runs.

Setup: AMD Windows driver 26.11.2 (Vulkan 1.4.315), Windows 11 Pro 26300, Vulkan SDK 1.4.363.0, llvm-mc 21.1.8 (scripts/build_llvm_mc.ps1), runtime built with scripts/build_runtime.ps1 from main b8f6c74, Python 3.15.2. Subgroup 32..64. Synthetic fuzz programs only, no game files.

AI-assisted (Claude); the runs were on my GPU.

@espaciointoficial-sys

Copy link
Copy Markdown

Tested 6f4bd2a on NVIDIA GeForce RTX 4070 SUPER (Ada), driver 621.35, Windows 11, for TEST-82. f16 fuzzer, 100 programs, no --skip-op (FMAs included):

42c9c9a (main before #551) main (c432cdc) this PR (6f4bd2a)
seed 1, wave32 native 98/100 100/100 100/100
seed 1, --emulate 198/200 200/200 200/200
seeds 2 and 3, wave32 native — 100/100 each 100/100 each

The two mismatches before #551 are exactly --show 1:34:32 (v_mul_f16_e64, got 0x43f627c5, want 0x43f627c4) and 1:49:32 (v_cvt_f32_f16_e32, got 0xc248c408, want 0xc248c000). On current main they are already gone through #551, and this PR keeps them fixed with the FMAs included. No regression on Ada. Native wave64 skipped (no 64-wide subgroups).

No game files. AI-assisted (Claude Code): it ran the fuzzer and wrote this comment.

@dea7hsmiless

Copy link
Copy Markdown
Contributor

Heads-up from the RTX 3070 runs: on current main c432cdc, the seed-1 f16 run that failed on 91b36cf is now clean without this PR.

valu_fuzz.py --family f16 --programs 50 --seed 1 --wave both:

  • 91b36cf: 48/50 native, 98/100 emulated (programs 34 and 49: v_mul_f16_e64, v_cvt_f32_f16_e32)
  • c432cdc (current main): 50/50 native, 100/100 emulated

The FMA-specific value tests here probably still cover behavior the fuzzer does not, so I am not saying the PR is redundant. Just flagging that this fuzzer seed no longer reproduces on main, in case another merge covered part of the same rounding path. No game files.

@VeTkN

VeTkN commented Nov 22, 2026

Copy link
Copy Markdown

Tested 6f4bd2a on RTX 5070 (Blackwell), NVIDIA 621.01, Windows 11 Pro (10.0.26200): pass.

valu_fuzz.py --family f16 --programs 200 --seed 1/2/3 --wave both [--emulate]
                     native (wave32)     --emulate
main c432cdc         200/200 per seed    400/400 per seed
this PR 6f4bd2a      200/200 per seed    400/400 per seed

0 mismatched, 0 untranslated, 0 harness errors in all 12 runs; native wave64 skipped (no 64-wide subgroups). Same as the Ada and Ampere runs above, now on Blackwell. No game files.

AI-assisted (Claude): it wrote the test script and this entry; I ran it on this machine.

@Proudnoob4

Copy link
Copy Markdown
Contributor

Tested 6f4bd2a on NVIDIA GeForce RTX 4080, driver 621.01, Vulkan 1.4.357, subgroup 32..32, Windows 10 22H2: pass, no change against main c432cdc.

main c432cdc this PR
scripts/run_gpu_tests.py (native) 59/85, 26 skipped (no 64-wide subgroup) 59/85, 26 skipped
scripts/run_gpu_tests.py (LEONIDA_W64_EMULATE=1) 85/85 85/85
tools/valu_fuzz.py --family f16 --seed 1 --wave 32 50/50 50/50
tools/valu_fuzz.py --family f16 --seed 1 --emulate 100/100 100/100
  • tests/semantic: 814 OK; test_f16_fma_rounding 4, test_f16_int_convert 5, test_mutations 2, all OK.
  • Test programs built at main c432cdc (MSVC 14.44, Vulkan SDK 1.4.363.1), llvm-mc 23.1.4 (native MSYS2).

Counts only. AI-assisted (Claude Code in OpenCode): it ran these on this machine.

@IAmNotSiob

Copy link
Copy Markdown
Collaborator Author

thx for the 4080 run :)

@dougmb

dougmb commented Nov 22, 2026

Copy link
Copy Markdown

f16 fuzz before and after this PR on an NVIDIA RTX 3060, Linux: no regression. main already matches on this driver, so this run can't show the fix.

GPU:      NVIDIA GeForce RTX 3060 (Ampere), subgroup 32..32
Driver:   NVIDIA 620.73.04 (Linux proprietary), Vulkan 1.4.357
OS:       Arch Linux, kernel 6.18.64-1-lts
Tools:    LLVM 23.1.4 (llvm-mc), SPIRV-Tools v2026.4, Python 3.14.10; the same vk_compute_test build for both sides
Commits:  main c432cdc vs this PR 6f4bd2a
valu_fuzz --family f16 main #575
seed 1, 100 programs, native (wave32) 100/100 100/100
seed 1, 100 programs, --emulate 200/200 200/200
seed 2, 200 programs, native (wave32) 200/200 200/200
seed 2, 200 programs, --emulate 400/400 400/400

Native wave64 is skipped because NVIDIA has no 64-wide subgroup. There were no harness errors, and nothing failed to translate.

Driver comparison: seed-1 programs 34 and 49 mismatch on the Windows NVIDIA drivers in #166, 610.88 and 621.24. They match on main with Linux 615.78.08 (my run in #166) and 620.73.04 (this run). On this card, whether main hits the double rounding depends on the driver. That fits SHADER-56: some drivers fold the PackHalf2x16 → UnpackHalf2x16 round trip and others don't. A before/after on a Windows NVIDIA driver is what would show the fix on NVIDIA. @tswic-highdesert's RADV run in #166 already shows it on AMD.

python -m unittest discover -s tests/semantic: 805 tests OK on main and 814 tests OK on this PR.

AI-assisted (Claude Code). Only synthetic fuzzer programs were used; no game files.

@IAmNotSiob

Copy link
Copy Markdown
Collaborator Author

ty for the 3060 run ^^

@phalstead

Copy link
Copy Markdown

TEST-82 on an NVIDIA RTX 4080 (Ada, AD103), driver 621.24, Windows 11 Pro 10.0.26200, Vulkan 1.4.357, subgroup 32..32. Each tree was built and run on its own (vk_compute_test from that tree; MSVC 19.51, llvm-mc 21.1.8 native with AMDGPU, SPIRV-Tools v2026.4).

python -I tools/valu_fuzz.py --family f16 --programs 50 --seed 1 --wave both [--emulate]:

f16, seed 1 native --emulate
ee97b84 (original base) 48/50, 2 mismatched 98/100, the same 2
5c8cc4f (original head) 50/50, 0 100/100, 0
c432cdc (current main, with #551) 50/50, 0 100/100, 0
6f4bd2a (rebased head) 50/50, 0 100/100, 0

The two base mismatches are --show 1:34:32 (v_mul_f16_e64, 0x43f627c5 vs 0x43f627c4) and 1:49:32 (v_cvt_f32_f16_e32). On 6f4bd2a, seed 2 is 50/50 native and 100/100 emulated; --family mem is 100/100 emulated; lds_fuzz.py --seed 1 is 93/100 with the same seven ds_bpermute_b32 inactive-lane mismatches as main (#253), so no change there.

Rebase note: the conflict against main is gone; 6f4bd2a is mergeable/clean. As @dea7hsmiless saw on Ampere, current main c432cdc is already clean for this f16 seed on Ada too (see also @Proudnoob4's 4080 run). The PR still covers narrowing sites #551 does not (@tylerstraub's v_cvt_f16_f32 note) and introduces no regression in these runs.

AI-assisted (OpenCode); results checked by hand. No game files.

@0xTehuti

Copy link
Copy Markdown
Contributor

Tested 6f4bd2a on NVIDIA GeForce RTX 2070 SUPER (Turing, SM 7.5), driver 595.79, Windows 11, for TEST-82.

python -I tools/valu_fuzz.py --family f16 --seed 1 --programs 100 --build "D:/Workspaces/Leonida/runtime/build" [--emulate]:

Tree Native wave32 Emulated (--emulate)
main (c432cdc) 95/100 match (5 mismatched) 195/200 match (5 mismatched)
#575 (6f4bd2a) 100/100 match (0 mismatched) 200/200 match (0 mismatched)

Mismatch Details & Resolution

On main (c432cdc), 5 programs mismatched on Turing due to v_cvt_f16_f32 / v_pk_min_f16 narrowing and rounding differences:

Native wave64 tests skipped as expected (Turing compute subgroups are 32-wide). Zero untranslated shaders or harness errors across all runs.

Additional Checks

  • python -I -m unittest discover -s tests/semantic: 814/814 passed (OK).

Synthetic fuzz programs only, no game files. AI-assisted.

@ItsNotRexed
ItsNotRexed merged commit 2452a5b into ProjectLeonida:main Nov 22, 2026
9 checks passed
@rafaelpssz

Copy link
Copy Markdown
Collaborator

Tested 6f4bd2a on an NVIDIA GeForce RTX 3060 (Ampere), driver 616.64, Windows 11 Pro 10.0.26200, subgroup 32, for TEST-82. valu_fuzz.py --family f16 --seed 1, 50 programs, --wave both, no --skip-op (FMAs included):

42c9c9a (main before #551) main c432cdc this PR 6f4bd2a
wave32 native 48/50 50/50 50/50
--emulate 98/100 100/100 100/100
program 1:34:32 mismatch match match
program 1:49:32 mismatch match match

Before #551 the two mismatches are 1:34:32 (v_mul_f16_e64 v27, v28, v34: got 0x43f627c5, want 0x43f627c4, every thread) and 1:49:32 (v_cvt_f32_f16_e32 v31, v34: got 0xc248c408, want 0xc248c000; v34 comes from the preceding v_pk_fma_f16). They're already gone on main through #551; this PR keeps them fixed and adds no regression here. Native wave64 skipped (no 64-wide subgroups). The PR merges cleanly and changes no runtime/ files, so the same vk_compute_test build ran all three trees. No game files.

@Pierre-Kookis

Copy link
Copy Markdown
Contributor

AMD data point for the record (tested the merged head, 6f4bd2a). On an AMD Windows driver, main c432cdc did fail the f16 fuzzer, and #575 fixes it.

Setup: Windows 11. AMD Radeon Graphics (Ryzen 7 7800X3D iGPU, RDNA2), driver 32.0.21043.5001, subgroup 32..64. RTX 4070 Ti SUPER, driver 610.88, subgroup 32. Test programs from main c432cdc (llvm-mingw clang), llvm-mc 23.1.6, SPIRV-Tools 2026.4.

valu_fuzz.py --family f16, seed 1:

main c432cdc #575
AMD native, --wave both 93/100, 7 mismatched 100/100
NVIDIA native, --wave 32 50/50 50/50
NVIDIA --emulate 100/100 100/100

On main, every AMD mismatch is the low half written by v_cvt_f16_f32_e32, 1 ULP low. For example, 0x...a001 comes back where 0x...a002 is expected, and the error propagates into later v_pk_*_f16 ops. With --skip-op v_cvt_f16_f32, main gets 100/100 on AMD. This fits PackHalf2x16 rounding being implementation-defined, which the AMD Windows driver apparently doesn't round to nearest even, so the seed can look clean on NVIDIA and still fail on AMD.

run_gpu_tests.py with #575: AMD 80/85 (5 skipped, mesh), NVIDIA 59/85 (26 skipped, wave64), NVIDIA emulated 85/85. No failures.

(AI-assisted run, counts only.)

WHOISJARDAS added a commit to WHOISJARDAS/Leonida that referenced this pull request Nov 22, 2026
… and -0

RDNA2 float ops return NaN, +-inf and -0 as computed. Without float controls,
Vulkan lets the driver assume none of them occur, and AMD's compiler does. On
an RX 9070 XT (26.11.2), x != x NaN checks fold to false and -0 products come
back +0. With integer f16 narrowing (ProjectLeonida#575), NaN results are never stored.

- rdna2spirv.py: every module declares the SignedZeroInfNanPreserve capability
  and OpExecutionMode SignedZeroInfNanPreserve 32. The index entry lists the
  property it needs (float_controls). --no-float-controls leaves both out.
- vk_pipeline_check: reads float_controls and skips a shader on a device
  without shaderSignedZeroInfNanPreserveFloat32.
- GPU test cs_signed_zero_nan (check.py, run_gpu_tests.py): without the mode,
  out[4..7] are 0 on AMD; with it, all eight words match.
- tests/test_translate.py: covers the mode, the index entry and the opt-out.
- docs/design.md: a "Float controls" contract row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
WHOISJARDAS added a commit to WHOISJARDAS/Leonida that referenced this pull request Nov 22, 2026
… and -0

RDNA2 float ops return NaN, +-inf and -0 as computed. Without float controls,
Vulkan lets the driver assume none of them occur, and AMD's compiler does. On
an RX 9070 XT (26.11.2), x != x NaN checks fold to false and -0 products come
back +0. With integer f16 narrowing (ProjectLeonida#575), NaN results are never stored.

- rdna2spirv.py: every module declares the SignedZeroInfNanPreserve capability
  and OpExecutionMode SignedZeroInfNanPreserve 32. The index entry lists the
  property it needs (float_controls). --no-float-controls leaves both out.
- vk_pipeline_check: reads float_controls and skips a shader on a device
  without shaderSignedZeroInfNanPreserveFloat32.
- GPU test cs_signed_zero_nan (check.py, run_gpu_tests.py): without the mode,
  out[4..7] are 0 on AMD; with it, all eight words match.
- tests/test_translate.py: covers the mode, the index entry and the opt-out.
- docs/design.md: a "Float controls" contract row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
WHOISJARDAS added a commit to WHOISJARDAS/Leonida that referenced this pull request Nov 22, 2026
… and -0

RDNA2 float ops return NaN, +-inf and -0 as computed. Without float controls,
Vulkan lets the driver assume none of them occur, and AMD's compiler does. On
an RX 9070 XT (26.11.2), x != x NaN checks fold to false and -0 products come
back +0. With integer f16 narrowing (ProjectLeonida#575), NaN results are never stored.

- rdna2spirv.py: every module declares the SignedZeroInfNanPreserve capability
  and OpExecutionMode SignedZeroInfNanPreserve 32. The index entry lists the
  property it needs (float_controls). --no-float-controls leaves both out.
- vk_pipeline_check: reads float_controls and skips a shader on a device
  without shaderSignedZeroInfNanPreserveFloat32.
- GPU test cs_signed_zero_nan (check.py, run_gpu_tests.py): without the mode,
  out[4..7] are 0 on AMD; with it, all eight words match.
- tests/test_translate.py: covers the mode, the index entry and the opt-out.
- docs/design.md: a "Float controls" contract row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
WHOISJARDAS added a commit to WHOISJARDAS/Leonida that referenced this pull request Nov 22, 2026
… and -0

RDNA2 float ops return NaN, +-inf and -0 as computed. Without float controls,
Vulkan lets the driver assume none of them occur, and AMD's compiler does. On
an RX 9070 XT (26.11.2), x != x NaN checks fold to false and -0 products come
back +0. With integer f16 narrowing (ProjectLeonida#575), NaN results are never stored.

- rdna2spirv.py: every module declares the SignedZeroInfNanPreserve capability
  and OpExecutionMode SignedZeroInfNanPreserve 32. The index entry lists the
  property it needs (float_controls). --no-float-controls leaves both out.
- vk_pipeline_check: reads float_controls and skips a shader on a device
  without shaderSignedZeroInfNanPreserveFloat32.
- GPU test cs_signed_zero_nan (check.py, run_gpu_tests.py): without the mode,
  out[4..7] are 0 on AMD; with it, all eight words match.
- tests/test_translate.py: covers the mode, the index entry and the opt-out.
- docs/design.md: a "Float controls" contract row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

--wave64-emulate: packed f16 result reaches the next op unrounded (1 ULP off) on NVIDIA