startup: lower v_cmp_class_f16 and v_cmpx_class_f16 (issue #1855) #2085

Merged
ChazY11 merged 3 commits from upstream-pr/2092 into main 2026-11-25 00:32:21 +00:00
ChazY11 commented 2026-11-25 00:10:04 +00:00 (Migrated from github.com)

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


What

Lowers v_cmp_class_f16 and v_cmpx_class_f16 in tools/startup/gfx2hlsl.py, closing the census refusal in #1855:

v_cmp_class_f16_e64 s14, 0x7c01, v0    -> REFUSED

tools/pixel_aot.py already carried the ten-class half helper, so this ports it into Pipeline.common() as class16, next to class32, and
dispatches the half mnemonics in the class-compare branch.

The two things that make the half form different

  1. The classes follow bits [15:0], not the binary32 layout: exponent 5 bits, mantissa 10, quiet bit 0x0200. The value is therefore the raw
    operand word
    , never self.f(value) — converting would test the wrong bit pattern, and an inline 0x7c01 would arrive as a binary32 float.
  2. abs/neg act on bit 15, so they are applied to the raw word before the helper: (v0 & 0x7fffu) and (v0 ^ 0x8000u). The decoder prints an
    absolute source as |v4| and a negated one as -v4, so both spellings are accepted alongside abs(...).

A float-printed operand is refused by name, because lowering it would take its binary32 pattern as if it were a half:

v_cmp_class_f16_e64 s14, 1.0, v0  -> Unsupported: source 1.0: f16 class compares need the raw half

Emitted forms

v_cmp_class_f16_e64 s14, 0x7c01, v0   -> s14 = (((class16(0x00007c01u) & v0) != 0u) ? 1u : 0u);
v_cmpx_class_f16_e64 vcc_lo, v0, -1   -> exec = (((class16(v0) & 0xffffffffu) != 0u) ? 1u : 0u);
v_cmpx_class_f16_e32 v0, v5           -> exec = (((class16(v0) & v5) != 0u) ? 1u : 0u);
v_cmp_class_f16_e64 s14, |v0|, v1     -> s14 = (((class16((v0 & 0x7fffu)) & v1) != 0u) ? 1u : 0u);
v_cmp_class_f16_e64 s14, -v0, v1      -> s14 = (((class16((v0 ^ 0x8000u)) & v1) != 0u) ? 1u : 0u);

Test

tests/startup_gfx2hlsl_cmp_class_f16_check.py builds the VOPC-in-VOP3 encodings from the checked-in decoder's layout (tools/disasm_rdna2.py,
opcodes 0x8f and 0x9f), decodes them, translates, and checks the emitted text for each form above. Then it does the value-level check: a binary16
classifier written from the IEEE half layout, compared against the emitted helper body evaluated over all 65,536 halves.

out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_cmp_class_f16_check.py
the emitted helper agrees with the binary16 classifier on all 65536 halves: ok
startup gfx2hlsl half class compare checks: ok          exit 0

Registered as startup_gfx2hlsl_cmp_class_f16 beside startup_gfx2hlsl_cmp_class in CMakeLists.txt — the same place, and the same
CMake-only route, as the binary32 sibling it mirrors.

Fail-first controls, six of them

Each reverts or breaks one clause, and each fails on the assertion that covers it while the other text checks still pass:

control fails
swap -inf/+inf bits the 65,536-half agreement
swap quiet/signaling NaN bits the 65,536-half agreement
swap -subnormal/+subnormal bits the 65,536-half agreement
abs mask 0x7fffu → the float 0x7fffffffu "an absolute half clears bit 15"
neg xor 0x8000u → the float 0x80000000u "a negated half flips bit 15"
the value goes through self.f() "the value is the raw half word, not a converted float"

The first three are the ones the issue asked for, and they fail at the value level rather than the text level — which is the point: a wrong class
bit produces plausible-looking HLSL.

Whole family still green

All 28 tests/startup_gfx2hlsl_*_check.py exit 0 on this branch, including the binary32 sibling startup_gfx2hlsl_cmp_class_check.py, which shares
the branch this change edits.

What this does not establish

That the emitted HLSL compiles or computes the right predicate on a device. The value check evaluates the helper text in Python; DXC and WARP were not
run for this change. If you want that, it should be a draw fixture, and I would add it as a separate change rather than implying this one was
executed.

Also unchanged and still shared with the binary32 path: a pair operand (v[0:1]) is accepted and the low word is used. That predates this change — the
binary32 compare does the same — so I left it alone rather than mixing a second behaviour into this PR.

Refs #1855. AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6594071974 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2092). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-25T00:10:04Z. --- ## What Lowers `v_cmp_class_f16` and `v_cmpx_class_f16` in `tools/startup/gfx2hlsl.py`, closing the census refusal in #1855: ```text v_cmp_class_f16_e64 s14, 0x7c01, v0 -> REFUSED ``` `tools/pixel_aot.py` already carried the ten-class half helper, so this ports it into `Pipeline.common()` as `class16`, next to `class32`, and dispatches the half mnemonics in the class-compare branch. ## The two things that make the half form different 1. **The classes follow bits [15:0]**, not the binary32 layout: exponent 5 bits, mantissa 10, quiet bit `0x0200`. The value is therefore the **raw operand word**, never `self.f(value)` — converting would test the wrong bit pattern, and an inline `0x7c01` would arrive as a binary32 float. 2. **`abs`/`neg` act on bit 15**, so they are applied to the raw word before the helper: `(v0 & 0x7fffu)` and `(v0 ^ 0x8000u)`. The decoder prints an absolute source as `|v4|` and a negated one as `-v4`, so both spellings are accepted alongside `abs(...)`. A float-printed operand is refused by name, because lowering it would take its binary32 pattern as if it were a half: ```text v_cmp_class_f16_e64 s14, 1.0, v0 -> Unsupported: source 1.0: f16 class compares need the raw half ``` ## Emitted forms ```text v_cmp_class_f16_e64 s14, 0x7c01, v0 -> s14 = (((class16(0x00007c01u) & v0) != 0u) ? 1u : 0u); v_cmpx_class_f16_e64 vcc_lo, v0, -1 -> exec = (((class16(v0) & 0xffffffffu) != 0u) ? 1u : 0u); v_cmpx_class_f16_e32 v0, v5 -> exec = (((class16(v0) & v5) != 0u) ? 1u : 0u); v_cmp_class_f16_e64 s14, |v0|, v1 -> s14 = (((class16((v0 & 0x7fffu)) & v1) != 0u) ? 1u : 0u); v_cmp_class_f16_e64 s14, -v0, v1 -> s14 = (((class16((v0 ^ 0x8000u)) & v1) != 0u) ? 1u : 0u); ``` ## Test `tests/startup_gfx2hlsl_cmp_class_f16_check.py` builds the VOPC-in-VOP3 encodings from the checked-in decoder's layout (`tools/disasm_rdna2.py`, opcodes `0x8f` and `0x9f`), decodes them, translates, and checks the emitted text for each form above. Then it does the value-level check: a binary16 classifier written from the IEEE half layout, compared against the **emitted helper body evaluated over all 65,536 halves**. ```powershell out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_cmp_class_f16_check.py the emitted helper agrees with the binary16 classifier on all 65536 halves: ok startup gfx2hlsl half class compare checks: ok exit 0 ``` Registered as `startup_gfx2hlsl_cmp_class_f16` beside `startup_gfx2hlsl_cmp_class` in `CMakeLists.txt` — the same place, and the same CMake-only route, as the binary32 sibling it mirrors. ## Fail-first controls, six of them Each reverts or breaks one clause, and each fails on the assertion that covers it while the other text checks still pass: | control | fails | |---|---| | swap `-inf`/`+inf` bits | the 65,536-half agreement | | swap quiet/signaling NaN bits | the 65,536-half agreement | | swap `-subnormal`/`+subnormal` bits | the 65,536-half agreement | | `abs` mask `0x7fffu` → the float `0x7fffffffu` | "an absolute half clears bit 15" | | `neg` xor `0x8000u` → the float `0x80000000u` | "a negated half flips bit 15" | | the value goes through `self.f()` | "the value is the raw half word, not a converted float" | The first three are the ones the issue asked for, and they fail at the value level rather than the text level — which is the point: a wrong class bit produces plausible-looking HLSL. ## Whole family still green All 28 `tests/startup_gfx2hlsl_*_check.py` exit 0 on this branch, including the binary32 sibling `startup_gfx2hlsl_cmp_class_check.py`, which shares the branch this change edits. ## What this does not establish That the emitted HLSL compiles or computes the right predicate on a device. The value check evaluates the helper text in Python; DXC and WARP were not run for this change. If you want that, it should be a draw fixture, and I would add it as a separate change rather than implying this one was executed. Also unchanged and still shared with the binary32 path: a pair operand (`v[0:1]`) is accepted and the low word is used. That predates this change — the binary32 compare does the same — so I left it alone rather than mixing a second behaviour into this PR. Refs #1855. AI-assisted.
upstream-sync closed this pull request 2026-11-25 01:01:36 +00:00
tedin7 commented 2026-11-25 01:01:37 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Review of head 4b15ae0930 (comment only).

Scope: tools/startup/gfx2hlsl.py lowers v_cmp_class_f16 / v_cmpx_class_f16 through a new class16 helper on the raw half word. abs/neg act on bit 15. A float-printed operand is refused. CMakeLists.txt only registers the new test. tests/startup_gfx2hlsl_cmp_class_f16_check.py builds its instruction bytes from the decoder field layout, with no copied vendor text. Clean-room looks fine.

P1: 0. P2: 0.

Commands executed locally (Linux, in a worktree of this head):

  • python3 -B tests/startup_gfx2hlsl_cmp_class_f16_check.py PASS (including the 65536-half classifier agreement check)
  • python3 -B tests/startup_gfx2hlsl_cmp_class_check.py PASS (binary32 sibling)
  • python3 tests/docs_links_check.py PASS
  • python3 tests/bidi_controls_check.py PASS
  • git diff --check origin/main...HEAD clean
  • git merge-tree --write-tree --name-only origin/main HEAD no conflicts

Mutations (reverted afterwards):

  • Normal-half threshold 0x0400u -> 0x0800u in class16: killed (the 65536-half agreement check reports MISMATCH).
  • Negation ^ 0x8000u -> ^ 0x80000000u: killed (a negated half flips bit 15 reports MISMATCH).

Windows CI was still pending when this was written.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6049545189 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2092#pullrequestreview-6049545189). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T00:13:48Z. **Review:** COMMENTED --- Review of head 4b15ae0930e6872c7b3bc52258d0183bfa6fd9d2 (comment only). Scope: `tools/startup/gfx2hlsl.py` lowers `v_cmp_class_f16` / `v_cmpx_class_f16` through a new `class16` helper on the raw half word. `abs`/`neg` act on bit 15. A float-printed operand is refused. `CMakeLists.txt` only registers the new test. `tests/startup_gfx2hlsl_cmp_class_f16_check.py` builds its instruction bytes from the decoder field layout, with no copied vendor text. Clean-room looks fine. P1: 0. P2: 0. Commands executed locally (Linux, in a worktree of this head): - `python3 -B tests/startup_gfx2hlsl_cmp_class_f16_check.py` PASS (including the 65536-half classifier agreement check) - `python3 -B tests/startup_gfx2hlsl_cmp_class_check.py` PASS (binary32 sibling) - `python3 tests/docs_links_check.py` PASS - `python3 tests/bidi_controls_check.py` PASS - `git diff --check origin/main...HEAD` clean - `git merge-tree --write-tree --name-only origin/main HEAD` no conflicts Mutations (reverted afterwards): - Normal-half threshold `0x0400u` -> `0x0800u` in `class16`: killed (the 65536-half agreement check reports MISMATCH). - Negation `^ 0x8000u` -> `^ 0x80000000u`: killed (`a negated half flips bit 15` reports MISMATCH). Windows CI was still pending when this was written. AI-assisted; commands listed were executed locally.
ChazY11 commented 2026-11-25 01:02:04 +00:00 (Migrated from github.com)

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


Thanks — that is a more useful review than the CI alone would have been, and two things in it are new to me.

Windows CI finished since your comment

Assemble and translate gfx1013 fixtures        pass 2m8s
Build and test on Windows                      pass 3m44s
Run platform-independent Python checks (Linux) pass 37s

so the platforms are green in both directions, not just the Linux side you ran.

Your 0x0400 → 0x0800 mutation is the better version of what I ran

I mutated the three category bits the issue listed (-inf/+inf, quiet/signaling NaN, -subnormal/+subnormal) and separately caught the abs/neg mixups,
but I did not mutate the normal/denormal boundary itself — which is the one threshold that has no name in the issue, and the one where a wrong
exponent bias would hide: an off-by-one there turns every denormal into a normal and the class table still "looks right" for the values a fixture
usually picks. It is killed by the 65,536-half sweep, which is the point of sweeping all of them rather than sampling.

The one behavioural gap I know about, stated so it is not a surprise later

A pair operand is accepted and the low word is used:

v_cmp_class_f16_e64 s14, v[0:1], v1   -> s14 = (((class16(v0) & v1) != 0u) ? 1u : 0u);
v_cmp_class_f32_e64 s14, v[0:1], v1   -> s14 = (((class32(F(v0)) & v1) != 0u) ? 1u : 0u);

The binary32 path does the same thing, so it predates this PR and I left it alone rather than mixing a second behaviour in. If you would rather the half
form refuse a 64-bit source — an f16 operand is 16 bits, so a pair is arguably malformed — that is a two-line change and I will add it here, but it
would then differ from v_cmp_class_f32 until that one is changed too.

What is still unestablished, in your terms

Nothing in the test says the emitted HLSL computes the right predicate on a device. If you want that closed before merge, say so and I will add the draw
fixture as a separate PR rather than widening this one; the value check evaluates the helper text in Python, and I would rather that stay labelled as
what it is.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7148360405 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2092#issuecomment-7148360405). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-25T00:17:48Z. --- Thanks — that is a more useful review than the CI alone would have been, and two things in it are new to me. ## Windows CI finished since your comment ```text Assemble and translate gfx1013 fixtures pass 2m8s Build and test on Windows pass 3m44s Run platform-independent Python checks (Linux) pass 37s ``` so the platforms are green in both directions, not just the Linux side you ran. ## Your `0x0400` → `0x0800` mutation is the better version of what I ran I mutated the three category bits the issue listed (`-inf/+inf`, quiet/signaling NaN, `-subnormal/+subnormal`) and separately caught the `abs`/`neg` mixups, but I did not mutate the **normal/denormal boundary** itself — which is the one threshold that has no name in the issue, and the one where a wrong exponent bias would hide: an off-by-one there turns every denormal into a normal and the class table still "looks right" for the values a fixture usually picks. It is killed by the 65,536-half sweep, which is the point of sweeping all of them rather than sampling. ## The one behavioural gap I know about, stated so it is not a surprise later A pair operand is accepted and the low word is used: ```text v_cmp_class_f16_e64 s14, v[0:1], v1 -> s14 = (((class16(v0) & v1) != 0u) ? 1u : 0u); v_cmp_class_f32_e64 s14, v[0:1], v1 -> s14 = (((class32(F(v0)) & v1) != 0u) ? 1u : 0u); ``` The binary32 path does the same thing, so it predates this PR and I left it alone rather than mixing a second behaviour in. If you would rather the half form refuse a 64-bit source — an f16 operand is 16 bits, so a pair is arguably malformed — that is a two-line change and I will add it here, but it would then differ from `v_cmp_class_f32` until that one is changed too. ## What is still unestablished, in your terms Nothing in the test says the emitted HLSL computes the right predicate on a device. If you want that closed before merge, say so and I will add the draw fixture as a separate PR rather than widening this one; the value check evaluates the helper text in Python, and I would rather that stay labelled as what it is. AI-assisted.
R0Y00 commented 2026-11-25 01:02:05 +00:00 (Migrated from github.com)

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


I added the reproduction notes and kept this slice to the e32/e64 raw-half forms. The census literal reaches the helper unchanged, ambiguous signed inline values and floating class masks are refused, and half SDWA stays outside this patch. The 65,536-value check, decoded operands and refusal controls passed, along with the existing f32 class and SDWA checks. The SDWA work in #2020 can remain a separate follow-up.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7148550923 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2092#issuecomment-7148550923). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T00:28:44Z. --- I added the reproduction notes and kept this slice to the e32/e64 raw-half forms. The census literal reaches the helper unchanged, ambiguous signed inline values and floating class masks are refused, and half SDWA stays outside this patch. The 65,536-value check, decoded operands and refusal controls passed, along with the existing f32 class and SDWA checks. The SDWA work in #2020 can remain a separate follow-up.
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!2085
No description provided.