feat: half-precision compares (v_cmp[x]_*_f16, v_cmp[x]_class_f16) in the HLSL recompiler #250

Merged
lcg007xd-c merged 1 commit from upstream-pr/250 into main 2026-11-26 00:15:06 +00:00
lcg007xd-c commented 2026-11-25 21:27:51 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by lcg007xd-c on 2026-11-25T21:27:51Z.


Change

The HLSL recompiler now translates the 68 f16 compare encodings that #244 added to the interpreter: v_cmp[x]_{f,lt,…,tru}_f16 and v_cmp[x]_class_f16, in VOPC and VOP3, for wave32 and wave64. Until now it refused them.

The code is a new module, emu/rdna2_hlsl_cmpf16.py (about 50 lines), with one branch each in the VOPC and VOP3 paths of rdna2_hlsl.py and rdna2_hlsl_wave64.py:

  • Sources: read as for the other f16 instructions (rdna2_hlsl_f16._operand): a register's low half, an inline float as binary16 (0x3C00), a literal's low half. VOP3 abs/neg act on bit 15 (rdna2_hlsl_f16._modified).
  • Predicates: both halves are widened with the existing F16ToF32, which is exact (an f16 denormal is a normal f32), and the existing f32 conditions are reused (compare_condition), so NaN is tested apart as in #134.
  • Class: v_cmp_class_f16 reads the f16 bits through a new ClassF16 helper, because widening would make a signalling NaN quiet and a denormal normal.
  • Refused like the interpreter: op_sel, clamp, omod, and abs/neg on the class mask. The f16 compares are routed before the SDWA path, so their SDWA/DPP forms are refused by name too.

Linked issue: Refs #115 (f16).

Verification

Linux (Arch, Python 3.14.10), no C++ runtime, no GPU:

python -m pytest                → 1091 passed, 323 skipped
python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools → All checks passed!

GPU parity: Windows CI only. CI run 45704586464 (WARP): tests/test_rdna2_hlsl_cmpf16.py 11 passed, the 4 GPU tests included; whole suite 1411 passed, 3 skipped. Not run on an AMD or NVIDIA card.

Locally: I have no Windows, dxc or WARP; the Windows CI job runs them. On the CPU I checked that:

  • every GPU program translates (wave32 and wave64);
  • with the GPU runner stubbed to return the interpreter's memory, each test builds and its own asserts hold;
  • the generated text uses F16ToF32, IsNanF32, ClassF16 and Ballot64 where expected.

Oracle and test data

  • New tests/test_rdna2_hlsl_cmpf16.py:

    • CPU tests: the widening and the class helper in the text; inline 1.0 as 0x3C00; a literal's low half; abs/neg on bit 15; refusals of SDWA, op_sel, clamp and abs/neg on the mask; wave64 using Ballot64.
    • GPU parity, byte for byte against the interpreter:
      • every predicate, as v_cmp and v_cmpx, in VOPC and VOP3, under a partial EXEC (68 masks, in two programs);
      • inline constants, a literal and modifiers;
      • wave64 with a partial 64-bit EXEC.

    The inputs are the hand-labelled pairs of #244 (±0, quiet and signalling NaN, ± denormals, ±inf, neighbours), one value per class against single class bits, and pseudo-random words, all with junk high halves.

  • The interpreter tests of #244 that asserted the HLSL refusal are removed, since the recompiler now translates these instructions.

Made with AI assistance (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:LooperSalty/AnyXboxX:issue:6614102216 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/250). Originally posted by [lcg007xd-c](https://github.com/lcg007xd-c) on 2026-11-25T21:27:51Z. --- ## Change The HLSL recompiler now translates the 68 f16 compare encodings that #244 added to the interpreter: `v_cmp[x]_{f,lt,…,tru}_f16` and `v_cmp[x]_class_f16`, in VOPC and VOP3, for wave32 and wave64. Until now it refused them. The code is a new module, `emu/rdna2_hlsl_cmpf16.py` (about 50 lines), with one branch each in the VOPC and VOP3 paths of `rdna2_hlsl.py` and `rdna2_hlsl_wave64.py`: - **Sources**: read as for the other f16 instructions (`rdna2_hlsl_f16._operand`): a register's low half, an inline float as binary16 (`0x3C00`), a literal's low half. VOP3 `abs`/`neg` act on bit 15 (`rdna2_hlsl_f16._modified`). - **Predicates**: both halves are widened with the existing `F16ToF32`, which is exact (an f16 denormal is a normal f32), and the existing f32 conditions are reused (`compare_condition`), so NaN is tested apart as in #134. - **Class**: `v_cmp_class_f16` reads the f16 bits through a new `ClassF16` helper, because widening would make a signalling NaN quiet and a denormal normal. - **Refused like the interpreter**: `op_sel`, `clamp`, `omod`, and `abs`/`neg` on the class mask. The f16 compares are routed before the SDWA path, so their SDWA/DPP forms are refused by name too. Linked issue: Refs #115 (f16). ## Verification Linux (Arch, Python 3.14.10), no C++ runtime, no GPU: ``` python -m pytest → 1091 passed, 323 skipped python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools → All checks passed! ``` **GPU parity: Windows CI only.** CI run 45704586464 (WARP): `tests/test_rdna2_hlsl_cmpf16.py` 11 passed, the 4 GPU tests included; whole suite 1411 passed, 3 skipped. Not run on an AMD or NVIDIA card. Locally: I have no Windows, `dxc` or WARP; the Windows CI job runs them. On the CPU I checked that: - every GPU program translates (wave32 and wave64); - with the GPU runner stubbed to return the interpreter's memory, each test builds and its own asserts hold; - the generated text uses `F16ToF32`, `IsNanF32`, `ClassF16` and `Ballot64` where expected. ## Oracle and test data - New `tests/test_rdna2_hlsl_cmpf16.py`: - CPU tests: the widening and the class helper in the text; inline 1.0 as `0x3C00`; a literal's low half; abs/neg on bit 15; refusals of SDWA, op_sel, clamp and abs/neg on the mask; wave64 using `Ballot64`. - GPU parity, byte for byte against the interpreter: - every predicate, as `v_cmp` and `v_cmpx`, in VOPC and VOP3, under a partial EXEC (68 masks, in two programs); - inline constants, a literal and modifiers; - wave64 with a partial 64-bit EXEC. The inputs are the hand-labelled pairs of #244 (±0, quiet and signalling NaN, ± denormals, ±inf, neighbours), one value per class against single class bits, and pseudo-random words, all with junk high halves. - The interpreter tests of #244 that asserted the HLSL refusal are removed, since the recompiler now translates these instructions. Made with AI assistance (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
LooperSalty commented 2026-11-25 21:56:51 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-25T21:56:51Z.


Thanks — this one is approved, but it now conflicts with main after #242, #244 and #248 were merged (mostly the README RDNA 2 line, plus shared rdna2 files for some). Could you merge or rebase onto main, recount the README line with rdna2_exec.coverage() on the merged tree (all 9 languages), and push? I will merge it as soon as CI is green.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7175742178 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/250#issuecomment-7175742178). Originally posted by [LooperSalty](https://github.com/LooperSalty) on 2026-11-25T21:56:51Z. --- Thanks — this one is approved, but it now conflicts with main after #242, #244 and #248 were merged (mostly the README RDNA 2 line, plus shared rdna2 files for some). Could you merge or rebase onto main, recount the README line with `rdna2_exec.coverage()` on the merged tree (all 9 languages), and push? I will merge it as soon as CI is green.
lcg007xd-c commented 2026-11-25 22:01:18 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by lcg007xd-c on 2026-11-25T22:01:18Z.


Rebased onto main (9a06443); the only conflict was the rdna2_hlsl_wave64.py import line next to #248's LDS_ADD_TID. No README change in this one.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7175834692 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/250#issuecomment-7175834692). Originally posted by [lcg007xd-c](https://github.com/lcg007xd-c) on 2026-11-25T22:01:18Z. --- Rebased onto `main` (`9a06443`); the only conflict was the `rdna2_hlsl_wave64.py` import line next to #248's `LDS_ADD_TID`. No README change in this one.
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
LooperSalty/AnyXboxX!250
No description provided.