tombox-xshader: order -0 below +0 in float min/max, as RDNA2 does #388

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

@⁠SchmashinPrunes on GitHub · 2026-11-25 18:37 UTC · original
SchmashinPrunes:minmax-signed-zero → main · +35 −12 · 2 files · 1 commits · open

@⁠omonkeyz, this came out of running the ISA sweep on RDNA2 silicon (#385/#387). I compared the translator's output with the gfx1036 output on every lane, including lanes the sweep models leave undefined.

The bug

Float min/max of equal zeros: v_min_f32, v_max_f32, v_min3/max3/med3_f32, the f16 forms and v_pk_min/max_f16. The translator emitted HLSL min/max, which leaves the choice between +0 and −0 to the host.

On gfx1036, −0 orders below +0:

op operands gfx1036
v_min_f32 +0, −0 (either order) −0
v_max_f32 +0, −0 (either order) +0
v_min3_f32 (2^32, −0, +0) −0
v_max3_f32 (+0, −0, −0.5) +0
v_med3_f32 (−0, +0, −1) −0

The f16 forms behave the same. How the translator compared:

  • On both hosts: v_min_f32, v_max_f32, v_max_f16 and v_med3_f16 returned the wrong zero, on WARP and on an RX 9060 XT.
  • WARP only: v_min3/max3/med3_f32, v_min_f16, v_min3/max3_f16 and v_pk_min/max_f16 were wrong on WARP and matched on AMD, because both followed their host.

These are among the most used float ops in the title corpus (v_max3_f32 about 24k uses, v_med3_f32 about 7.7k).

Change

  • New tb_fmin / tb_fmax in the prelude. They return the host min/max unless the operands compare equal. In that case they combine the signs: OR for min, AND for max. That only matters for ±0. NaN handling is unchanged.
  • Every float min/max site uses them.
  • f16 v_med3 now takes the same NaN branch as v_med3_f32: the min3 of the inputs when any input is NaN. gfx1036 returns that too, for example (NaN, +0, −54.5) gives −54.5.
  • v_min/max_f64 is unchanged. No f64 signed-zero difference showed up.

Tests

New exec_vop::basic::float_min_max_order_signed_zeros_as_rdna2: 14 cases over 10 mnemonics, taken from the gfx1036 outputs.

run result
WARP, tests/exec.rs 190/190
Radeon RX 9060 XT (TOMBOX_EXEC_HW=1), tests/exec.rs 190/190
translator vs gfx1036 output on every lane (the #387 harness), initial MODE 0xf0 and 0xc0, WARP and AMD every min/max/min3/max3/med3/pk_min/pk_max mnemonic now agrees, except the f32 omod cases (#386) and one f16 SDWA signalling-NaN case, which is in the MODE-path follow-up

The PR gate is clean.

🤖 Generated with Claude Code

**@⁠SchmashinPrunes** on GitHub · 2026-11-25 18:37 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/388) `SchmashinPrunes:minmax-signed-zero` → `main` · +35 −12 · 2 files · 1 commits · open @⁠omonkeyz, this came out of running the ISA sweep on RDNA2 silicon (#385/#387). I compared the translator's output with the gfx1036 output on every lane, including lanes the sweep models leave undefined. ### The bug Float min/max of equal zeros: `v_min_f32`, `v_max_f32`, `v_min3/max3/med3_f32`, the f16 forms and `v_pk_min/max_f16`. The translator emitted HLSL `min`/`max`, which leaves the choice between +0 and −0 to the host. On gfx1036, **−0 orders below +0**: | op | operands | gfx1036 | |---|---|---| | `v_min_f32` | +0, −0 (either order) | −0 | | `v_max_f32` | +0, −0 (either order) | +0 | | `v_min3_f32` | (2^32, −0, +0) | −0 | | `v_max3_f32` | (+0, −0, −0.5) | +0 | | `v_med3_f32` | (−0, +0, −1) | −0 | The f16 forms behave the same. How the translator compared: - **On both hosts:** `v_min_f32`, `v_max_f32`, `v_max_f16` and `v_med3_f16` returned the wrong zero, on WARP and on an RX 9060 XT. - **WARP only:** `v_min3/max3/med3_f32`, `v_min_f16`, `v_min3/max3_f16` and `v_pk_min/max_f16` were wrong on WARP and matched on AMD, because both followed their host. These are among the most used float ops in the title corpus (`v_max3_f32` about 24k uses, `v_med3_f32` about 7.7k). ### Change - New `tb_fmin` / `tb_fmax` in the prelude. They return the host `min`/`max` unless the operands compare equal. In that case they combine the signs: OR for min, AND for max. That only matters for ±0. NaN handling is unchanged. - Every float min/max site uses them. - f16 `v_med3` now takes the same NaN branch as `v_med3_f32`: the `min3` of the inputs when any input is NaN. gfx1036 returns that too, for example `(NaN, +0, −54.5)` gives −54.5. - `v_min/max_f64` is unchanged. No f64 signed-zero difference showed up. ### Tests New `exec_vop::basic::float_min_max_order_signed_zeros_as_rdna2`: 14 cases over 10 mnemonics, taken from the gfx1036 outputs. | run | result | |---|---| | WARP, `tests/exec.rs` | 190/190 | | Radeon RX 9060 XT (`TOMBOX_EXEC_HW=1`), `tests/exec.rs` | 190/190 | | translator vs gfx1036 output on every lane (the #387 harness), initial MODE 0xf0 and 0xc0, WARP and AMD | every min/max/min3/max3/med3/pk_min/pk_max mnemonic now agrees, except the f32 omod cases (#386) and one f16 SDWA signalling-NaN case, which is in the MODE-path follow-up | The PR gate is clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
v_min/max/min3/max3/med3 (f32, f16) and v_pk_min/max_f16 used HLSL
min/max, whose choice between equal zeros is up to the host: WARP and
an RX 9060 XT disagree with each other, and both disagree with gfx1036
on some forms. On gfx1036 min(+0, -0) is -0 and max is +0. tb_fmin and
tb_fmax keep the host result except for equal operands, where they
combine the signs. f16 med3 also takes the f32 path's NaN branch
(min3 when an input is NaN), which gfx1036 follows too.

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:09 +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/388/head:github-bot/gh-388'
git switch 'github-bot/gh-388'

Merge

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