tombox-xshader: f16 NaN sign, propagation and default NaN as RDNA2 does #390

Open
github-bot wants to merge 1 commit from github-bot/gh-390 into main AGit
Owner

@⁠SchmashinPrunes on GitHub · 2026-11-25 20:12 UTC · original
SchmashinPrunes:f16-nan-default-path → main · +20 −5 · 2 files · 1 commits · open

@⁠omonkeyz, this is a small follow-up to #389 for the default MODE path. It also came out of comparing the translator with gfx1036 on every lane (#387 harness).

The bug

tb_hadd / tb_hsub / tb_hmul (the f16 add/sub/subrev/mul helpers from #375), and the f16 VOP3 abs/neg source modifiers, left NaN signs and the generated NaN to the host:

  • v_sub_f16(−0, NaN 0x7e00) gives 0xfe00 on gfx1036, but 0x7e00 on both WARP and an RX 9060 XT;
  • v_subrev_f16(NaN, 0) behaves the same way;
  • v_add_f16 with VOP3 neg on a NaN source behaves the same way.

The gfx1036 record (the #387 run, default MODE) gives the rule:

operands gfx1036
0xfe55 + 1.0, 0x7e00 + x the input NaN, payload and sign kept (not quieted)
−0 − 0x7e00 0xfe00: the subtrahend's NaN with its sign flipped
−inf + inf, inf × 0 0xfe00, the generated f16 NaN (the same rule #389 implements for the MODE path)

Change

  • tb_hadd/tb_hsub/tb_hmul propagate an input NaN, src0 first, with the subtrahend's sign flipped in tb_hsub, and return 0xfe00 for an invalid operation.
  • In h16, the f16 VOP3 abs and neg modifiers clear or flip the sign bit instead of using abs() / (-x).

The signalling-NaN passthrough (gfx1036 keeps 0x7c01, while the hosts' f16tof32 quiets it on the operand read) is not covered. That needs operand reads changed across all f16 ops.

Tests

New exec_vop::basic::f16_nan_sign_and_generation_as_rdna2, 8 cases from the gfx1036 record.

run result
WARP, without the hlsl.rs change fails 3 cases: the NaN sign after sub, subrev and VOP3 neg
WARP, tests/exec.rs 190/190
Radeon RX 9060 XT, tests/exec.rs 190/190
isa_sweep target, WARP ok (the 4 existing WARP_KNOWN f64 deviations)
translator vs gfx1036 on every lane, MODE 0xf0, WARP and AMD the qNaN sign differences are gone; what remains in f16 is the signalling-NaN passthrough above, plus the min/max signed-zero cases fixed separately in #388

The PR gate is clean. This touches the same h16 closure as #385 and the prelude next to #388's helpers, so whichever lands second may need a trivial rebase. I'll do it.

🤖 Generated with Claude Code

**@⁠SchmashinPrunes** on GitHub · 2026-11-25 20:12 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/390) `SchmashinPrunes:f16-nan-default-path` → `main` · +20 −5 · 2 files · 1 commits · open @⁠omonkeyz, this is a small follow-up to #389 for the **default** MODE path. It also came out of comparing the translator with gfx1036 on every lane (#387 harness). ### The bug `tb_hadd` / `tb_hsub` / `tb_hmul` (the f16 add/sub/subrev/mul helpers from #375), and the f16 VOP3 `abs`/`neg` source modifiers, left NaN signs and the generated NaN to the host: - `v_sub_f16(−0, NaN 0x7e00)` gives `0xfe00` on gfx1036, but `0x7e00` on both WARP and an RX 9060 XT; - `v_subrev_f16(NaN, 0)` behaves the same way; - `v_add_f16` with VOP3 `neg` on a NaN source behaves the same way. The gfx1036 record (the #387 run, default MODE) gives the rule: | operands | gfx1036 | |---|---| | `0xfe55 + 1.0`, `0x7e00 + x` | the input NaN, payload and sign kept (not quieted) | | `−0 − 0x7e00` | `0xfe00`: the subtrahend's NaN with its sign flipped | | `−inf + inf`, `inf × 0` | `0xfe00`, the generated f16 NaN (the same rule #389 implements for the MODE path) | ### Change - `tb_hadd`/`tb_hsub`/`tb_hmul` propagate an input NaN, src0 first, with the subtrahend's sign flipped in `tb_hsub`, and return `0xfe00` for an invalid operation. - In `h16`, the f16 VOP3 `abs` and `neg` modifiers clear or flip the sign bit instead of using `abs()` / `(-x)`. The signalling-NaN passthrough (gfx1036 keeps `0x7c01`, while the hosts' `f16tof32` quiets it on the operand read) is not covered. That needs operand reads changed across all f16 ops. ### Tests New `exec_vop::basic::f16_nan_sign_and_generation_as_rdna2`, 8 cases from the gfx1036 record. | run | result | |---|---| | WARP, without the `hlsl.rs` change | fails 3 cases: the NaN sign after sub, subrev and VOP3 neg | | WARP, `tests/exec.rs` | 190/190 | | Radeon RX 9060 XT, `tests/exec.rs` | 190/190 | | `isa_sweep` target, WARP | ok (the 4 existing `WARP_KNOWN` f64 deviations) | | translator vs gfx1036 on every lane, MODE 0xf0, WARP and AMD | the qNaN sign differences are gone; what remains in f16 is the signalling-NaN passthrough above, plus the min/max signed-zero cases fixed separately in #388 | The PR gate is clean. This touches the same `h16` closure as #385 and the prelude next to #388's helpers, so whichever lands second may need a trivial rebase. I'll do it. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
At the default MODE, tb_hadd/tb_hsub/tb_hmul left a NaN's sign and the
generated NaN to the host: -0 - NaN gave 0x7e00 on WARP and AMD where
gfx1036 gives 0xfe00. They now propagate an input NaN with its payload
(src0 first, the subtrahend's sign flipped) and return 0xfe00 for an
invalid operation, as recorded on gfx1036. The f16 VOP3 abs and neg
source modifiers clear or flip the sign bit instead of using abs()/(-x),
whose effect on a NaN is host dependent.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:21:12 +00:00
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/390/head:github-bot/gh-390'
git switch 'github-bot/gh-390'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-390'
git switch 'github-bot/gh-390'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-390'
git switch 'github-bot/gh-390'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-390'
git switch 'main'
git merge --squash 'github-bot/gh-390'
git switch 'main'
git merge --ff-only 'github-bot/gh-390'
git switch 'main'
git merge 'github-bot/gh-390'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.