tombox-xshader: f16 NaNs keep their bits as on RDNA2, signalling ones included (stacked on #390) #392
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
library
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/omonkeyz--xbox-emulator!392
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-392"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@SchmashinPrunes on GitHub · 2026-11-25 21:54 UTC · original
SchmashinPrunes:f16-snan-passthrough→main· +72 −31 · 3 files · 2 commits · open@omonkeyz, this is stacked on #390: the first commit is #390's, so review the second. It finishes the f16 NaN work. gfx1036 passes a signalling NaN through unquieted, and the translator quieted it on both the read (
f16tof32) and the write (tb_f2h).How it was found
The #387 host-vs-silicon comparison treats any f16 NaN as equal to any other, so this didn't show up there. With a bit-exact NaN check added locally (not part of this PR), 21 f16 mnemonics on WARP and 25 on the RX 9060 XT returned different NaN bits from gfx1036 at MODE 0xf0, for example
v_add_f16(0x7c01, 0)gave0x7e01where silicon gives0x7c01. The record shows the f16 ALU ops pass the input NaN through with its exact bits.The rule (gfx1036, default MODE)
v_pk_add/mulv_subrev_f16subrev(0x7e00, 0x7e00)gives0xfe00)v_pk_min/maxv_pk_fma,v_pk_fmac0xfe00even when src2 is a NaN), then src2v_fract_f16(±inf)0xfe00v_cvt_f32_f16(0x7c01)0x7f802000: still a signalling NaNChange
tb_h2fkreads f16 bits into an f32, keeping a signalling NaN signalling.tb_f2hkwrites f16 without forcing the quiet bit. For quiet NaNs it gives exactly whattb_f2hgives.v_cvt_f16_f32keepstb_f2h, because silicon quiets there.tb_hp1/tb_hp2/tb_hpm/tb_hpfimplement the table. Packed-opnegnow flips the sign bit, as #390 did for VOP3.exec_vop/fract.rs: the f16 inf/NaN expectations follow the gfx1036 record instead of a canonical0x7e00. ±inf gives0xfe00, NaNs pass through, and a0x7c01row is added.Tests
New
f16_signalling_nan_passes_through_as_rdna2: 12 gfx1036 vectors.hlsl.rschangetests/exec.rstests/exec.rsisa_sweeptarget, WARPWARP_KNOWNdeviations only)What's left in f16:
v_fma_mixlo/hi_f16, which have their own f32/f16 conversion rules, andv_cvt_pkrtz_f16_f32(qNaN)giving0x7fffon WARP only. #387's comparison (NaNs equal) is unchanged apart from these ops, plus one case that was hidden before: AMD-host SDWA byte-select +abson a denormal. That's the known AMD-host case from #375 and isn't related to this change.A question: f32 and f64 NaN bits
The same bit-exact check shows the same class of difference in f32 and f64, in about 30 mnemonics on each host:
v_add_f32(0x7f800001, 0)gives0x7fc00001, silicon0x7f800001;+qNaNwhere silicon's default is negative:v_fma_f32(inf, 0, c)gives0x7fc00000, silicon0xffc00000;negon a NaN source doesn't flip its sign.Matching silicon there means a NaN check on every f32/f64 add and multiply, which costs speed in every shader, not just ones that produce NaNs. f16 already went through helpers, so the extra cost here is small. Do you want f32/f64 handled the same way? If so, I'll do it as its own PR.
The PR gate is clean. No game or console files are involved.
🤖 Generated with Claude Code
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.