feat: half-precision compares (v_cmp[x]_*_f16, v_cmp[x]_class_f16) in the RDNA 2 interpreter — 1,206/1,490 #244

Manually merged
github merged 1 commit from gh-pr/244/head into gh-pr/244/base 2026-11-26 05:39:56 +00:00
Owner

@⁠lcg007xd-c on GitHub · 2026-11-25 21:00 UTC · original
lcg007xd-c:feat/rdna2-f16-compares → main · +277 −35 · 14 files · 1 commits · merged 2026-11-25 21:46 UTC

Change

The reference interpreter now runs the 34 half-precision compares in VOPC and VOP3, 68 encodings that raised Untranslated until now: v_cmp[x]_{f,lt,eq,le,gt,lg,ge,o,u,nge,nlg,ngt,nle,neq,nlt,tru}_f16 and v_cmp[x]_class_f16. The code is a new module, emu/rdna2_exec_cmpf16.py (about 95 lines), plus one dispatch line each in rdna2_exec.py and rdna2_exec_vop3.py.

Semantics
Values S0[15:0] and S1[15:0] as binary16; the high halves are ignored. The 16 predicates are the f32 ones (FLOAT_TESTS): ordered tests are false on NaN and their n* negations true, -0 == +0, denormals are compared by value
Class v_cmp_class_f16 tests the IEEE class of S0 against the bits S1[9:0]: bit 0 sNaN … bit 9 +inf. rdna2_exec_cmp64.float_class gets the 16-bit format (5, 10)
Sources Read as for the other f16 instructions (rdna2_exec_f16._source, #218): a register's low half, an inline float as binary16 (1.0 = 0x3C00), an inline integer or a literal as its low 16 bits. S1 of class also reads an inline float as binary16, following the ISA's note: "the S1 has a format of f16 since floating point literal constants are interpreted as 16 bit value for this opcode"
Mask Written whole, so inactive lanes are cleared (ISA §3.9). v_cmp writes VCC (VOPC) or its SGPR (VOP3); v_cmpx writes EXEC only
Modifiers VOP3 abs/neg act on bit 15 of a float source

Refused by name (rule 3), as not documented or not measured:

  • VOP3 op_sel (ISA §6.2.5: OPSEL is not for VOPC in the VOP3 encoding; same rule as the i16/u16 compares of #226);
  • clamp and omod;
  • abs/neg on the class mask S1;
  • the SDWA and DPP forms, which are refused for every f16 instruction (#218).

HLSL: not changed. The recompiler still refuses these instructions, which a test pins. Its translation can follow in a separate PR with GPU parity tests, the way #218 and #219 were split.

Coverage of the reference interpreter (rdna2_exec.coverage()): 1,138 → 1,206 of 1,490 encodings. All 9 READMEs go from 76% to 81% (rounded to nearest, as in #218: 1,085 → 73%). With main at 400e590 the suite collects 1,405 tests, so the 9 READMEs now say 1400+. Overlap: #230, #232 and #241 change the same README number; whichever merges later adds its own delta in a one-line rebase.

Linked issue: Refs #115 (f16).

Verification

Linux (Arch, Python 3.14.10), no C++ runtime, no GPU (runtime and GPU tests skip), rebased on main 400e590:

python -m pytest                → 1086 passed, 319 skipped
python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools → All checks passed!

The suite is green on this machine since #237 and #238 merged.

Not run: the Windows CI job and GPU/WARP. There is no HLSL change; the HLSL refusal is tested on the CPU.

Oracle and test data

  • New tests/test_rdna2_exec_cmpf16.py (48 tests). Expected masks come from a hand-labelled relation of 12 (S0, S1) pairs, with junk high halves that a 32-bit compare would see. The pairs cover:

    • 1 < 2 and equal values;
    • -0 == +0;
    • a quiet NaN, a signalling NaN in S1, and NaN against NaN;
    • ± the smallest denormal against 0;
    • ±inf against ±65504;
    • adjacent values.

    The tests:

    • every predicate in VOPC under a partial EXEC (inactive lanes cleared) and in VOP3 to an SGPR (VCC untouched);
    • v_cmpx in VOPC and VOP3, writing EXEC only;
    • inline 1.0 against f16 1.0 and against f32 1.0 (low half 0); a literal's low half; const(0);
    • VOP3 abs/neg on bit 15;
    • v_cmp_class_f16 with one value per class against each single mask bit (unused bits 10 and 11 included), with const(3), with inline 1.0 as the mask (0x3C00: no class bit), and with neg on S0;
    • the refusals: op_sel, clamp, omod, abs on the mask, SDWA;
    • the HLSL refusal.
  • Failure case: 46 of the 48 fail on main. The 2 that pass are the HLSL refusals.

  • Not measured on hardware: no RDNA 2 GPU was available here. The semantics follow the ISA text and the existing f32/f16 rules of the interpreter.

Checklist

  • The PR covers a single reviewable behaviour. (f16 compares in the interpreter.)
  • A test fails without this change and passes with it.
  • The commands and results of each check are given above.
  • An unimplemented function returns an error (E_NOTIMPL), never a fake success. (Unsourced forms raise Untranslated naming the instruction.)
  • README: the same change in all 9 languages (test_readme_sync.py checks it).
  • No game, console or SDK file, no key, no dump, no download link.
  • Findings drawn from a title: none.
  • Code taken from another project: none.

Made with AI assistance (Claude Code).

🤖 Generated with Claude Code

**@⁠lcg007xd-c** on GitHub · 2026-11-25 21:00 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/244) `lcg007xd-c:feat/rdna2-f16-compares` → `main` · +277 −35 · 14 files · 1 commits · merged 2026-11-25 21:46 UTC ## Change The reference interpreter now runs the **34 half-precision compares in VOPC and VOP3**, 68 encodings that raised `Untranslated` until now: `v_cmp[x]_{f,lt,eq,le,gt,lg,ge,o,u,nge,nlg,ngt,nle,neq,nlt,tru}_f16` and `v_cmp[x]_class_f16`. The code is a new module, `emu/rdna2_exec_cmpf16.py` (about 95 lines), plus one dispatch line each in `rdna2_exec.py` and `rdna2_exec_vop3.py`. | | Semantics | | --- | --- | | Values | S0[15:0] and S1[15:0] as binary16; the high halves are ignored. The 16 predicates are the f32 ones (`FLOAT_TESTS`): ordered tests are false on NaN and their `n*` negations true, -0 == +0, denormals are compared by value | | Class | `v_cmp_class_f16` tests the IEEE class of S0 against the bits S1[9:0]: bit 0 sNaN … bit 9 +inf. `rdna2_exec_cmp64.float_class` gets the 16-bit format (5, 10) | | Sources | Read as for the other f16 instructions (`rdna2_exec_f16._source`, #218): a register's low half, an inline float as binary16 (1.0 = 0x3C00), an inline integer or a literal as its low 16 bits. S1 of class also reads an inline float as binary16, following the ISA's note: "the S1 has a format of f16 since floating point literal constants are interpreted as 16 bit value for this opcode" | | Mask | Written whole, so inactive lanes are cleared (ISA §3.9). `v_cmp` writes VCC (VOPC) or its SGPR (VOP3); `v_cmpx` writes EXEC only | | Modifiers | VOP3 `abs`/`neg` act on bit 15 of a float source | Refused by name (rule 3), as not documented or not measured: - VOP3 `op_sel` (ISA §6.2.5: OPSEL is not for VOPC in the VOP3 encoding; same rule as the i16/u16 compares of #226); - `clamp` and `omod`; - `abs`/`neg` on the class mask S1; - the SDWA and DPP forms, which are refused for every f16 instruction (#218). HLSL: not changed. The recompiler still refuses these instructions, which a test pins. Its translation can follow in a separate PR with GPU parity tests, the way #218 and #219 were split. Coverage of the reference interpreter (`rdna2_exec.coverage()`): **1,138 → 1,206 of 1,490** encodings. All 9 READMEs go from 76% to 81% (rounded to nearest, as in #218: 1,085 → 73%). With `main` at `400e590` the suite collects 1,405 tests, so the 9 READMEs now say `1400+`. **Overlap:** #230, #232 and #241 change the same README number; whichever merges later adds its own delta in a one-line rebase. Linked issue: Refs #115 (f16). ## Verification Linux (Arch, Python 3.14.10), no C++ runtime, no GPU (runtime and GPU tests skip), rebased on `main` `400e590`: ``` python -m pytest → 1086 passed, 319 skipped python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools → All checks passed! ``` The suite is green on this machine since #237 and #238 merged. Not run: the Windows CI job and GPU/WARP. There is no HLSL change; the HLSL refusal is tested on the CPU. ## Oracle and test data - New `tests/test_rdna2_exec_cmpf16.py` (48 tests). Expected masks come from a hand-labelled relation of 12 (S0, S1) pairs, with junk high halves that a 32-bit compare would see. The pairs cover: - 1 < 2 and equal values; - -0 == +0; - a quiet NaN, a signalling NaN in S1, and NaN against NaN; - ± the smallest denormal against 0; - ±inf against ±65504; - adjacent values. The tests: - every predicate in VOPC under a partial EXEC (inactive lanes cleared) and in VOP3 to an SGPR (VCC untouched); - `v_cmpx` in VOPC and VOP3, writing EXEC only; - inline 1.0 against f16 1.0 and against f32 1.0 (low half 0); a literal's low half; `const(0)`; - VOP3 `abs`/`neg` on bit 15; - `v_cmp_class_f16` with one value per class against each single mask bit (unused bits 10 and 11 included), with `const(3)`, with inline 1.0 as the mask (0x3C00: no class bit), and with `neg` on S0; - the refusals: op_sel, clamp, omod, abs on the mask, SDWA; - the HLSL refusal. - Failure case: 46 of the 48 fail on `main`. The 2 that pass are the HLSL refusals. - Not measured on hardware: no RDNA 2 GPU was available here. The semantics follow the ISA text and the existing f32/f16 rules of the interpreter. ## Checklist - [x] The PR covers a single reviewable behaviour. (f16 compares in the interpreter.) - [x] A test fails without this change and passes with it. - [x] The commands and results of each check are given above. - [x] An unimplemented function returns an error (`E_NOTIMPL`), never a fake success. (Unsourced forms raise `Untranslated` naming the instruction.) - [x] README: the same change in all 9 languages (`test_readme_sync.py` checks it). - [x] No game, console or SDK file, no key, no dump, no download link. - [x] Findings drawn from a title: none. - [x] Code taken from another project: none. Made with AI assistance (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The 34 f16 compares, in VOPC and VOP3 (68 encodings), raised Untranslated.
New module emu/rdna2_exec_cmpf16.py:
- S0[15:0] and S1[15:0] are binary16 values compared with the 16
  predicates of the f32 compares (ordered false on NaN, n* forms true,
  -0 == +0, denormals by value); v_cmp_class_f16 tests the IEEE class of
  S0 against the mask S1 (float_class gains the 16-bit format).
- Sources are read like the other f16 instructions: a register's low half,
  an inline float as binary16 (1.0 = 0x3C00), an inline integer or a
  literal as its low 16 bits. S1 of class also reads an inline float as
  binary16, per the ISA's note on V_CMP_CLASS_F16.
- The mask is written whole (inactive lanes cleared): VCC or EXEC in VOPC,
  the SGPR destination or EXEC in VOP3; VOP3 abs/neg act on bit 15.
- Refused by name: VOP3 op_sel (ISA section 6.2.5), clamp and omod, abs/neg
  on the class mask, and the SDWA/DPP forms (as for every f16 op).

Sources: AMD RDNA 2 ISA (November 2020) section 12.9 (p. 156-161), section
3.9 (p. 19-20), section 6.2.5 (p. 44). The HLSL recompiler is not changed
and still refuses these instructions (tested). README: 1,138 -> 1,206 of
1,490 (76% -> 81%) in the 9 languages.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:39:54 +00:00
github manually merged commit ff121581a0 into gh-pr/244/base 2026-11-26 05:39:56 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.