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

Closed
opened 2026-11-24 19:39:17 +00:00 by triggered02 · 2 comments
triggered02 commented 2026-11-24 19:39:17 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T19:39:17Z.


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).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6589898153 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1855). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-24T19:39:17Z. --- 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: ```python 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).
ChazY11 commented 2026-11-25 01:02:01 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T00:05:39Z.


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 #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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7148131007 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1855#issuecomment-7148131007). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-25T00:05:39Z. --- ## 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: ```text 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: ```python 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 #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.
R0Y00 commented 2026-11-25 01:02:07 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T00:35:35Z.


The encoded 0x7c01 literal now lowers on main via #2092 (8e17f8fb). 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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7148672903 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1855#issuecomment-7148672903). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T00:35:35Z. --- The encoded 0x7c01 literal now lowers on main via #2092 (8e17f8fb). 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 in to join this conversation.
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#1848
No description provided.