startup: lower v_cmp_class_f16 and v_cmpx_class_f16 in gfx2hlsl #1805

Closed
tedin7 wants to merge 2 commits from upstream-pr/1812 into main
tedin7 commented 2026-11-24 19:04:32 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T19:04:32Z.


Related to #1723 and #870 (no Fixes). v_cmp_class_f16 and v_cmpx_class_f16 had no lowering in tools/startup/gfx2hlsl.py.

Change

The instruction tests whether the binary16 value in the low half of SRC0 falls in one of ten classes named by the mask in SRC1: bit 0 signalling NaN, 1 quiet NaN, 2 -inf, 3 -normal, 4 -denormal, 5 -0, 6 +0, 7 +denormal, 8 +normal, 9 +inf. class_f16 (reached through op_v_cmp_class_f16 and op_v_cmpx_class_f16) reads the encoding, so a denormal stays a denormal whatever the denormal mode and a NaN keeps its signalling bit. The _e32 and _e64 spellings, a vector-condition, scalar or exec destination and a narrowed EXEC follow compare(). The abs and neg that the instruction encodes act on the sign bit of the half (abs clears it, then neg flips it). Refused: op_sel, clamp and any other modifier, a source that is not a register (inline float, literal), unbalanced |, a wrong operand count and the SDWA spelling.

The new code sits in its own methods and does not touch compare() or common(), where #1798 lowers v_cmp_class_f32; the two do not share a helper.

Tests

tests/startup_gfx2hlsl_cmp_class_f16_check.py, registered in CMakeLists.txt (startup_gfx2hlsl_cmp_class_f16) and in .github/workflows/windows.yml:

  • Eight forms (e32, e64, scalar destination, cmpx e32 and e64, -v1, |v1|, -|v1|) are compiled as C++ from the emitted statements and run over all 65,536 binary16 values and 25 masks (the ten single class bits, none, all, mixed and bits above 9) against a reference that classifies through Python's binary16 conversion. Six planted faults in the emitted text must each be detected.
  • Translation controls (EXEC narrowing, cmpx, scalar destination mask, inline -1 mask) and eight refusals.
  • binary <llvm-mc>: five spellings assemble to recorded encodings (value in SRC0, mask in SRC1).

Verified (Linux)

  • The check passes; binary llvm-mc-19 passes (gfx1013).
  • Four mutations of gfx2hlsl.py, each failing the check, original restored: signalling bit read from the wrong mantissa bit, denormal threshold off by one, mask test changed from & to |, neg flipping the wrong bit.
  • git diff --check origin/main...HEAD, tests/docs_links_check.py, tests/bidi_controls_check.py: pass.
  • git merge-tree: no conflicts with main, #1755, #1778, #1796, #1798, #1699. #1783 already conflicts with main on its own.

Not verified

No draw on a GPU and no HLSL compiler run: the C++ stand-in treats uint as unsigned, which matches the HLSL semantics used (no signed or float arithmetic is involved).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6589283104 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1812). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T19:04:32Z. --- Related to #1723 and #870 (no `Fixes`). `v_cmp_class_f16` and `v_cmpx_class_f16` had no lowering in `tools/startup/gfx2hlsl.py`. ### Change The instruction tests whether the binary16 value in the low half of SRC0 falls in one of ten classes named by the mask in SRC1: bit 0 signalling NaN, 1 quiet NaN, 2 -inf, 3 -normal, 4 -denormal, 5 -0, 6 +0, 7 +denormal, 8 +normal, 9 +inf. `class_f16` (reached through `op_v_cmp_class_f16` and `op_v_cmpx_class_f16`) reads the encoding, so a denormal stays a denormal whatever the denormal mode and a NaN keeps its signalling bit. The `_e32` and `_e64` spellings, a vector-condition, scalar or exec destination and a narrowed EXEC follow `compare()`. The `abs` and `neg` that the instruction encodes act on the sign bit of the half (abs clears it, then neg flips it). Refused: `op_sel`, `clamp` and any other modifier, a source that is not a register (inline float, literal), unbalanced `|`, a wrong operand count and the SDWA spelling. The new code sits in its own methods and does not touch `compare()` or `common()`, where #1798 lowers `v_cmp_class_f32`; the two do not share a helper. ### Tests `tests/startup_gfx2hlsl_cmp_class_f16_check.py`, registered in `CMakeLists.txt` (`startup_gfx2hlsl_cmp_class_f16`) and in `.github/workflows/windows.yml`: - Eight forms (e32, e64, scalar destination, cmpx e32 and e64, `-v1`, `|v1|`, `-|v1|`) are compiled as C++ from the emitted statements and run over all 65,536 binary16 values and 25 masks (the ten single class bits, none, all, mixed and bits above 9) against a reference that classifies through Python's binary16 conversion. Six planted faults in the emitted text must each be detected. - Translation controls (EXEC narrowing, cmpx, scalar destination mask, inline `-1` mask) and eight refusals. - `binary <llvm-mc>`: five spellings assemble to recorded encodings (value in SRC0, mask in SRC1). ### Verified (Linux) - The check passes; `binary llvm-mc-19` passes (gfx1013). - Four mutations of `gfx2hlsl.py`, each failing the check, original restored: signalling bit read from the wrong mantissa bit, denormal threshold off by one, mask test changed from `&` to `|`, neg flipping the wrong bit. - `git diff --check origin/main...HEAD`, `tests/docs_links_check.py`, `tests/bidi_controls_check.py`: pass. - `git merge-tree`: no conflicts with `main`, #1755, #1778, #1796, #1798, #1699. #1783 already conflicts with `main` on its own. ### Not verified No draw on a GPU and no HLSL compiler run: the C++ stand-in treats `uint` as `unsigned`, which matches the HLSL semantics used (no signed or float arithmetic is involved). AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-24 20:00:44 +00:00
tedin7 commented 2026-11-24 20:01:17 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T19:14:51Z.


Closing this draft for now to help keep the open PR queue manageable; the branch stays preserved on the fork so it can be reopened once the queue clears.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7141817804 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1812#issuecomment-7141817804). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T19:14:51Z. --- Closing this draft for now to help keep the open PR queue manageable; the branch stays preserved on the fork so it can be reopened once the queue clears.

Pull request closed

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
R0Y00/Xbox2Windows!1805
No description provided.