Skip to content

startup: lower v_cmp_class_f16 and v_cmpx_class_f16 in gfx2hlsl - #1812

Closed
tedin7 wants to merge 2 commits into
R0Y00:mainfrom
tedin7:x2w-frontier-gfx-cmpclass16
Closed

tedin7 wants to merge 2 commits into
R0Y00:mainfrom
tedin7:x2w-frontier-gfx-cmpclass16

Conversation

@tedin7

@tedin7 tedin7 commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

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)

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

tedin7 commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator Author

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 tedin7 closed this Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant