startup: v_cmp_class_f32 has no lowering (2 of the remaining loading-screen shader refusals) #1790

Closed
opened 2026-11-24 18:49:33 +00:00 by triggered02 · 0 comments
triggered02 commented 2026-11-24 18:49:33 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T18:49:33Z.


Found in the refusal census (#870). 2 refused shaders, both the binary32 class comparison:

v_cmp_class_f32_e64 s32, -1, v4    -> REFUSED: v_cmp_class_f32
v_cmp_class_f32_e32 vcc_lo, -1, v0 -> REFUSED: v_cmp_class_f32

tools/pixel_aot.py already implemented this for the pixel AOT path, so the ten-class helper is ported from there rather than reinvented.

1. Problem

The class comparison tests which binary32 class a value falls in against a mask. Nothing in tools/startup/gfx2hlsl.py lowered it.

2. Change

A helper in the shader preamble (same ten class bits, in encoding order: signaling NaN, quiet NaN, -inf, -normal, -denormal, -0, +0, +denormal, +normal, +inf):

uint class32(float value) {
    uint bits = asuint(value), magnitude = bits & 0x7fffffffu;
    bool negative = bits >= 0x80000000u;
    if (magnitude > 0x7f800000u) return (bits & 0x00400000u) != 0u ? 0x2u : 0x1u;
    if (magnitude == 0x7f800000u) return negative ? 0x4u : 0x200u;
    if (magnitude >= 0x00800000u) return negative ? 0x8u : 0x100u;
    if (magnitude != 0u) return negative ? 0x10u : 0x80u;
    return negative ? 0x20u : 0x40u;
}

and a branch in compare() that lowers the predicate to (class32(value) & mask) != 0u, reading the mask as an integer operand and the value as a float:

v_cmp_class_f32_e64 vcc_lo, -1, v4  -> vcc = (((class32(F(v4)) & 0xffffffffu) != 0u) ? 1u : 0u);
v_cmpx_class_f32_e64 vcc_lo, -1, v4 -> exec = (...);   (and clears the straight-line EXEC assumption)

The census -1 mask is the inline constant for "every class"; a literal mask (0x00000300u = +normal|+inf) and a register mask follow the same path.

3. Test

startup_gfx2hlsl_cmp_class builds VOPC-in-VOP3 encodings from the checked-in decoder's layout (prefix 0b110101, opcode [25:16], scalar destination w0[7:0], sources in w1), decodes them, then translates. Nine checks: both spellings decode and lower, the non-exec form writes VCC, the v_cmpx_ form writes EXEC and clears exec_known, a literal mask and a register mask reach the helper, and the helper is present in the common preamble with the quiet/signaling NaN distinction.

dev:     13/13 startup_gfx2hlsl* + startup_translator passed
release: startup_gfx2hlsl_cmp_class Passed 0.14 s

Fail-first: changing & to | in the class test fails a register mask is read as an integer; renaming the helper fails the class helper is emitted in the common preamble.

4. What this does not establish

  • That the class bits match LLVM's ClassFlags on hardware — they are ported from pixel_aot.py and unchanged by this PR; the census mask (-1) does not exercise individual bits.
  • v_cmp_class_f16/_f64, v_cmpx_class_f16, and DXC/draw results are out of scope.

Note for the merge

#1755 changes compare()'s signature to take mods; this branch is based on main before it, so the two touch the same function and will need a trivial conflict resolution (keep both: the mods argument and this class branch).

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6589024229 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1797). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-24T18:49:33Z. --- Found in the refusal census (#870). **2** refused shaders, both the binary32 class comparison: ``` v_cmp_class_f32_e64 s32, -1, v4 -> REFUSED: v_cmp_class_f32 v_cmp_class_f32_e32 vcc_lo, -1, v0 -> REFUSED: v_cmp_class_f32 ``` `tools/pixel_aot.py` already implemented this for the pixel AOT path, so the ten-class helper is ported from there rather than reinvented. ## 1. Problem The class comparison tests which binary32 class a value falls in against a mask. Nothing in `tools/startup/gfx2hlsl.py` lowered it. ## 2. Change A helper in the shader preamble (same ten class bits, in encoding order: signaling NaN, quiet NaN, -inf, -normal, -denormal, -0, +0, +denormal, +normal, +inf): ```hlsl uint class32(float value) { uint bits = asuint(value), magnitude = bits & 0x7fffffffu; bool negative = bits >= 0x80000000u; if (magnitude > 0x7f800000u) return (bits & 0x00400000u) != 0u ? 0x2u : 0x1u; if (magnitude == 0x7f800000u) return negative ? 0x4u : 0x200u; if (magnitude >= 0x00800000u) return negative ? 0x8u : 0x100u; if (magnitude != 0u) return negative ? 0x10u : 0x80u; return negative ? 0x20u : 0x40u; } ``` and a branch in `compare()` that lowers the predicate to `(class32(value) & mask) != 0u`, reading the mask as an integer operand and the value as a float: ``` v_cmp_class_f32_e64 vcc_lo, -1, v4 -> vcc = (((class32(F(v4)) & 0xffffffffu) != 0u) ? 1u : 0u); v_cmpx_class_f32_e64 vcc_lo, -1, v4 -> exec = (...); (and clears the straight-line EXEC assumption) ``` The census `-1` mask is the inline constant for "every class"; a literal mask (`0x00000300u` = +normal|+inf) and a register mask follow the same path. ## 3. Test `startup_gfx2hlsl_cmp_class` builds VOPC-in-VOP3 encodings from the checked-in decoder's layout (prefix `0b110101`, opcode `[25:16]`, scalar destination `w0[7:0]`, sources in `w1`), decodes them, then translates. Nine checks: both spellings decode and lower, the non-exec form writes VCC, the `v_cmpx_` form writes EXEC and clears `exec_known`, a literal mask and a register mask reach the helper, and the helper is present in the common preamble with the quiet/signaling NaN distinction. ``` dev: 13/13 startup_gfx2hlsl* + startup_translator passed release: startup_gfx2hlsl_cmp_class Passed 0.14 s ``` Fail-first: changing `&` to `|` in the class test fails *a register mask is read as an integer*; renaming the helper fails *the class helper is emitted in the common preamble*. ## 4. What this does not establish - That the class bits match LLVM's `ClassFlags` on hardware — they are ported from `pixel_aot.py` and unchanged by this PR; the census mask (`-1`) does not exercise individual bits. - `v_cmp_class_f16`/`_f64`, `v_cmpx_class_f16`, and DXC/draw results are out of scope. ## Note for the merge #1755 changes `compare()`'s signature to take `mods`; this branch is based on main before it, so the two touch the same function and will need a trivial conflict resolution (keep both: the `mods` argument and this class branch). AI-assisted (Claude Code).
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#1790
No description provided.