startup: lower v_cmp_class_f16 and v_cmpx_class_f16 in gfx2hlsl #1812

Closed
github-bot wants to merge 2 commits from gh-pr/1812/head into gh-pr/1812/base
Owner

@⁠tedin7 on GitHub · 2026-11-24 19:04 UTC · original
tedin7:x2w-frontier-gfx-cmpclass16 → main · +303 −0 · 5 files · 2 commits · closed without merging

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.

**@⁠tedin7** on GitHub · 2026-11-24 19:04 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1812) `tedin7:x2w-frontier-gfx-cmpclass16` → `main` · +303 −0 · 5 files · 2 commits · closed without merging 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:34:50 +00:00
github-bot closed this pull request 2026-11-26 23:34:50 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 19:14 UTC · original

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.

**@⁠tedin7** on GitHub · 2026-11-24 19:14 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1812#issuecomment-7141817804) 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

This discussion has been locked. Commenting is limited to contributors.
No description provided.