feat: v_cvt_pkrtz_f16_f32 in the RDNA 2 interpreter — 1,210/1,490 #246

Manually merged
github merged 1 commit from gh-pr/246/head into gh-pr/246/base 2026-11-26 05:40:07 +00:00
Owner

@⁠lcg007xd-c on GitHub · 2026-11-25 21:04 UTC · original
lcg007xd-c:feat/rdna2-cvt-pkrtz → main · +109 −19 · 11 files · 1 commits · merged 2026-11-26 00:15 UTC

Change

The reference interpreter now runs v_cvt_pkrtz_f16_f32 in VOP2 (opcode 47) and VOP3. Both encodings raised Untranslated until now.

Source: AMD, "RDNA 2" ISA, November 2020, §12.7 "VOP2 Instructions" (printed p. 135): "D.f16_lo = f32_to_f16(S0.f32); D.f16_hi = f32_to_f16(S1.f32). // Round-toward-zero regardless of current round mode setting in hardware." The ISA notes it is meant for 16-bit compressed exports, so pixel shaders that export f16 colours use it.

It joins rdna2_exec_f16.OPERATIONS (#218) with a small helper, half_toward_zero:

  • It takes the round-to-nearest binary16 (the module's half_bits) and steps one ulp back toward zero when that value lies farther from zero than the exact one. This is exact, because the nearest and toward-zero results are at most one ulp apart.
  • A finite value too large gives ±65504 (0x7BFF), never infinity; ±inf stay ±inf; f32 denormals and values under 2^-24 give ±0.
  • A NaN gives 0x7E00, the module's rule for every f16 result.
  • The sources are f32 words, so VOP3 abs/neg act on bit 31 and an inline float is the f32 value.
  • The result is a whole 32-bit word (WORD_RESULT).
  • Refused by name: VOP3 op_sel on these 32-bit sources, clamp and omod (the existing f16 checks); SDWA/DPP as for every f16 op.

HLSL: not changed. The recompiler still refuses the instruction (tested); its translation can follow with GPU parity tests.

Coverage (rdna2_exec.coverage()): 1,208 → 1,210 of 1,490. All 9 READMEs stay at 81%. Overlap: other open PRs (#230, #232, #241, #244, #245) change the same README number; whichever merges later adds its own delta.

Linked issue: Refs #115 (f16).

Verification

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

python -m pytest                → 1099 passed, 322 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 (no HLSL change).

Oracle and test data

  • New tests/test_rdna2_f16_pkrtz.py (7 tests). It uses a hand-written table of 19 f32 inputs and their toward-zero binary16:

    • cases where round-to-nearest would differ: 1 + 3·2^-11 → 0x3C01 (nearest 0x3C02); 65520 → 0x7BFF (nearest inf); 1.5·2^-24 → 0x0001 (nearest 0x0002);
    • -1e9 → 0xFBFF;
    • ±inf, quiet, signalling and negative NaNs;
    • f32 denormals, values under 2^-24, and the largest f16 denormal.

    Lane i packs inputs i and i + 7. The tests check:

    • VOP2 and VOP3 give the same packed words;
    • VOP3 neg/abs work;
    • inline 1.0 and a literal are read as f32;
    • the op_sel/clamp/omod refusals;
    • the HLSL refusal.
  • Failure case: 6 of the 7 fail on main (the HLSL refusal passes).

Checklist

  • The PR covers a single reviewable behaviour.
  • 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.
  • 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:04 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/246) `lcg007xd-c:feat/rdna2-cvt-pkrtz` → `main` · +109 −19 · 11 files · 1 commits · merged 2026-11-26 00:15 UTC ## Change The reference interpreter now runs `v_cvt_pkrtz_f16_f32` in VOP2 (opcode 47) and VOP3. Both encodings raised `Untranslated` until now. Source: AMD, "RDNA 2" ISA, November 2020, §12.7 "VOP2 Instructions" (printed p. 135): "D.f16_lo = f32_to_f16(S0.f32); D.f16_hi = f32_to_f16(S1.f32). // Round-toward-zero regardless of current round mode setting in hardware." The ISA notes it is meant for 16-bit compressed exports, so pixel shaders that export f16 colours use it. It joins `rdna2_exec_f16.OPERATIONS` (#218) with a small helper, `half_toward_zero`: - It takes the round-to-nearest binary16 (the module's `half_bits`) and steps one ulp back toward zero when that value lies farther from zero than the exact one. This is exact, because the nearest and toward-zero results are at most one ulp apart. - A finite value too large gives ±65504 (`0x7BFF`), never infinity; ±inf stay ±inf; f32 denormals and values under 2^-24 give ±0. - A NaN gives `0x7E00`, the module's rule for every f16 result. - The sources are f32 words, so VOP3 `abs`/`neg` act on bit 31 and an inline float is the f32 value. - The result is a whole 32-bit word (`WORD_RESULT`). - Refused by name: VOP3 `op_sel` on these 32-bit sources, `clamp` and `omod` (the existing f16 checks); SDWA/DPP as for every f16 op. HLSL: not changed. The recompiler still refuses the instruction (tested); its translation can follow with GPU parity tests. Coverage (`rdna2_exec.coverage()`): **1,208 → 1,210 of 1,490**. All 9 READMEs stay at 81%. **Overlap:** other open PRs (#230, #232, #241, #244, #245) change the same README number; whichever merges later adds its own delta. Linked issue: Refs #115 (f16). ## Verification Linux (Arch, Python 3.14.10), no C++ runtime, no GPU (runtime and GPU tests skip), rebased rebased on `main` `9a06443`: ``` python -m pytest → 1099 passed, 322 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 (no HLSL change). ## Oracle and test data - New `tests/test_rdna2_f16_pkrtz.py` (7 tests). It uses a hand-written table of 19 f32 inputs and their toward-zero binary16: - cases where round-to-nearest would differ: `1 + 3·2^-11` → `0x3C01` (nearest `0x3C02`); 65520 → `0x7BFF` (nearest inf); `1.5·2^-24` → `0x0001` (nearest `0x0002`); - -1e9 → `0xFBFF`; - ±inf, quiet, signalling and negative NaNs; - f32 denormals, values under 2^-24, and the largest f16 denormal. Lane i packs inputs i and i + 7. The tests check: - VOP2 and VOP3 give the same packed words; - VOP3 `neg`/`abs` work; - inline 1.0 and a literal are read as f32; - the op_sel/clamp/omod refusals; - the HLSL refusal. - Failure case: 6 of the 7 fail on `main` (the HLSL refusal passes). ## Checklist - [x] The PR covers a single reviewable behaviour. - [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. - [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)
VOP2 47 and its VOP3 form raised Untranslated. D[15:0] and D[31:16] are
S0 and S1 converted to binary16 toward zero, whatever the rounding mode
(ISA section 12.7, p. 135): the nearest value stepped back one ulp when it
lies farther from zero, so a finite value too large gives +-65504 and
never infinity; infinities stay, a NaN gives 0x7E00 (the f16 module's
rule). The sources are f32 words: abs/neg on bit 31, inline floats as
f32. VOP3 op_sel, clamp and omod are refused by name. HLSL not changed
(still refused, tested). README: 1,208 -> 1,210 of 1,490 (81%).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:40:04 +00:00
github manually merged commit 50f0561693 into gh-pr/246/base 2026-11-26 05:40:07 +00:00
Author
Owner

@⁠LooperSalty on GitHub · 2026-11-25 21:56 UTC · original

Thanks — this one is approved, but it now conflicts with main after #242, #244 and #248 were merged (mostly the README RDNA 2 line, plus shared rdna2 files for some). Could you merge or rebase onto main, recount the README line with rdna2_exec.coverage() on the merged tree (all 9 languages), and push? I will merge it as soon as CI is green.

**@⁠LooperSalty** on GitHub · 2026-11-25 21:56 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/246#issuecomment-7175743841) Thanks — this one is approved, but it now conflicts with main after #242, #244 and #248 were merged (mostly the README RDNA 2 line, plus shared rdna2 files for some). Could you merge or rebase onto main, recount the README line with `rdna2_exec.coverage()` on the merged tree (all 9 languages), and push? I will merge it as soon as CI is green.
Author
Owner

@⁠lcg007xd-c on GitHub · 2026-11-25 22:01 UTC · original

Rebased onto main (9a06443), README line recounted with rdna2_exec.coverage() on the merged tree: 1,210 of 1,490 (81%), all 9 languages.

**@⁠lcg007xd-c** on GitHub · 2026-11-25 22:01 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/246#issuecomment-7175833799) Rebased onto `main` (`9a06443`), README line recounted with `rdna2_exec.coverage()` on the merged tree: 1,210 of 1,490 (81%), all 9 languages.
This discussion has been locked. Commenting is limited to contributors.
No description provided.