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

Open
SchmashinPrunes wants to merge 1 commit from upstream-pr/388 into main
SchmashinPrunes commented 2026-11-25 18:37:12 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by SchmashinPrunes on 2026-11-25T18:37:12Z.


@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

<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:5497029487 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/388). Originally posted by [SchmashinPrunes](https://github.com/SchmashinPrunes) on 2026-11-25T18:37:12Z. --- @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)
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/388:upstream-pr/388'
git switch 'upstream-pr/388'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/388'
git switch 'upstream-pr/388'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/388'
git switch 'upstream-pr/388'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/388'
git switch 'main'
git merge --squash 'upstream-pr/388'
git switch 'main'
git merge --ff-only 'upstream-pr/388'
git switch 'main'
git merge 'upstream-pr/388'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
omonkeyz/xbox-emulator!388
No description provided.