Skip to content

startup: v_cmp_class_f16 has no lowering (binary16 class compare) #1855

Done

Description

@triggered02

Found in the refusal census (#870). 1 refused shader:

v_cmp_class_f16_e64 s14, 0x7c01, v0    -> REFUSED: v_cmp_class_f16

Problem

The binary16 class comparison had no lowering. The binary32 form is handled by the class-compare branch (PR #1798), but the half form needs a different helper: the value is the raw binary16 bit pattern in the low half of the operand word, the ten class bits follow the half format (exponent 5 bits, mantissa 10, quiet bit 0x0200), and an abs/neg modifier acts on bit 15 rather than bit 31.

Fix

tools/pixel_aot.py already carried the binary16 helper; it is ported into Pipeline.common() as class16, and the class-compare branch dispatches on the mnemonic:

if base in ('v_cmp_class_f32', 'v_cmpx_class_f32', 'v_cmp_class_f16', 'v_cmpx_class_f16'):
    f16 = base.endswith('_f16')
...
    cond = '(class16(%s) & %s) != 0u' % (bits, self.u(mask))   # f16

Measured on the branch:

form before after
v_cmp_class_f16_e64 s14, 0x7c01, v0 refused s14 = (((class16(0x00007c01u) & v0) != 0u) ? 1u : 0u);
v_cmpx_class_f16_e64 vcc_lo, v0, -1 refused exec = (((class16(v0) & 0xffffffffu) != 0u) ? 1u : 0u);
v_cmpx_class_f16_e32 v0, v5 refused exec = (((class16(v0) & v5) != 0u) ? 1u : 0u);

The abs/neg modifier forms lower to class16((v0 & 0x7fffu)) and class16((v0 ^ 0x8000u)). A float-printed operand is refused by name, because it would otherwise be lowered as its binary32 bit pattern.

Test

startup_gfx2hlsl_cmp_class_f16 builds VOPC-in-VOP3 encodings from the checked-in decoder's layout, decodes them, then translates. Ten checks: the census form, both exec-mask shapes, the abs/neg handling on bit 15, the float-operand refusal, and — value-level — a Python binary16 classifier (written from the IEEE half layout) compared against the emitted helper body evaluated over all 65,536 binary16 patterns.

dev:     3/3 (cmp_class, cmp_class_f16, startup_translator)
release: startup_gfx2hlsl_cmp_class_f16 Passed 3.18 s

Fail-first, three genuine class-bit mutations (all fail the value-level check while the text checks pass):

swap -inf/+inf bits        -> FAIL
swap quiet/signaling NaN   -> FAIL
swap -subnormal/+subnormal -> FAIL

Depends on #1798

This branch is based on startup/cmp-class (#1798) because the class-compare branch and class32 helper are not on main yet. Merge #1798 first; after that this PR's diff is only the class16 helper, the mnemonic dispatch and the new test.

What this does not establish

  • That the emitted HLSL compiles or computes the right predicate on a device — the test compares values from the emitted text; DXC/WARP were not run here.
  • v_cmp_class_f64 and the arithmetic/compare f16 forms that are not class comparisons are out of scope.

AI-assisted (Claude Code).

Activity

  1. ChazY11 commented on Nov 25, 2026

    @ChazY11
    Contributor

    Claiming this

    Environment: x64 Windows 11 build 26300.9974, MSVC 19.44, Windows SDK 10.0.26100, DXC 10.0.26100 (x64), Python 3.13, physical GPU (RTX 5080 Laptop, 32.0.15.8142) and the in-box WARP.

    State of main at 6218beb2, checked rather than assumed:

    tools/startup/gfx2hlsl.py  class32  present
    tools/startup/gfx2hlsl.py  class16  absent
    tools/startup/gfx2hlsl.py  v_cmp_class_f16  absent      -> the census form is still refused
    tools/pixel_aot.py         class16  present            -> the helper to port
    

    so the dependency you list (#1798, the class32 helper and the class-compare branch) has landed and this is now only the half form.

    What I will do

    1. Port class16 from tools/pixel_aot.py into Pipeline.common() unchanged (the ten class bits from bits [15:0], quiet bit 0x0200), listed next to class32.
    2. Dispatch the half mnemonics in the class-compare branch:
      if name in ('v_cmp_class_f32', 'v_cmpx_class_f32', 'v_cmp_class_f16', 'v_cmpx_class_f16'):
          f16 = name.endswith('_f16')
          cond = '(class16(%s) & %s) != 0u' % (bits, self.u(mask)) if f16 else ...
      with bits being the operand's raw word, not self.f(value), so an inline 0x7c01 reaches the helper as 0x00007c01u and not as a
      binary32 float.
    3. abs/neg on the half act on bit 15 ((v0 & 0x7fffu), (v0 ^ 0x8000u)), not bit 31, and are applied to the raw word before the helper.
    4. Refuse by name an operand that prints as a float, since lowering it would take its binary32 bit pattern.
    5. Test, in the shape this file already uses: build the VOPC-in-VOP3 encodings from the checked-in decoder's layout, decode, translate, then assert
      the emitted text for the census form, both exec shapes, the abs/neg handling and the float-operand refusal — and, value level, a Python
      binary16 classifier written from the IEEE half layout compared against the emitted helper body evaluated over all 65,536 halves.

    Negative controls I will run before claiming the fixture is worth anything: three class-bit mutations (swap -inf/+inf, swap quiet/signaling NaN,
    swap -subnormal/+subnormal) must each fail the value-level check while the text checks still pass.

    Scope boundaries I will keep

    • No v_cmp_class_f64, no f16 arithmetic or ordering compares: they are not class compares.
    • No shader-key special case and no fixed register number, per the same rule you set on Shader: prove the packed screen-position input for a fullscreen composite #1629.
    • I will not claim that the emitted HLSL computes the right predicate on a device. The value check evaluates the helper text in Python; if you want a
      DXC/WARP pass over it, say so and I will add a draw fixture rather than implying the translation was executed.

    Nothing else of mine touches these lines: my only open changes are #2053 (an AGENTS.md list fix) and #2063 (a test that pins handler refusal
    behaviour), neither of which edits gfx2hlsl.py.

    AI-assisted.

  2. added 2 commits that reference this issue on Nov 25, 2026
  3. R0Y00 commented on Nov 25, 2026

    @R0Y00
    Owner

    The encoded 0x7c01 literal now lowers on main via #2092 (8e17f8f). The source-built controls cover that decoded literal, e32/e64 and both execution-mask shapes, and check the emitted binary16 helper against all 65,536 input bit patterns. The slice accepts the tested plain operands and rejects ambiguous immediates and half SDWA. Any additional SDWA coverage can follow in #2020. These checks establish the translator behavior for the reported refusal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions