feat: half precision (f16) in the RDNA 2 interpreter (25 encodings) #218

Manually merged
github merged 6 commits from gh-pr/218/head into gh-pr/218/base 2026-11-26 05:38:03 +00:00
Owner

@⁠IxMxAMAR on GitHub · 2026-11-25 16:22 UTC · original
IxMxAMAR:feat/rdna2-f16 → main · +414 −27 · 14 files · 6 commits · merged 2026-11-25 18:32 UTC

Change

Replaces #163, which was closed during the 25 November triage because it conflicted with main after #199 and #151. It is rebased on main (ab55a2a). The code is the same apart from the conflict resolution: the f16 group is wired in next to the instruction groups #151 added, and it shares no instruction name with them.

The RDNA 2 reference interpreter runs 25 more f16 encodings (1,060 → 1,085 of 1,490):

  • v_add, v_sub, v_subrev, v_mul, v_fmac, v_fmamk, v_fmaak, v_max, v_min and v_ldexp_f16, in VOP2 and VOP3;
  • v_fma_f16, in VOP3;
  • v_cvt_f16_f32 and v_cvt_f32_f16, in VOP1 and VOP3.

They live in a new module, emu/rdna2_exec_f16.py, with a few lines in rdna2_exec.py and rdna2_exec_vop3.py.

gfx10 semantics:

  • An f16 write keeps the other half of the VGPR.
  • In VOP3, op_sel picks the half read from each source and the half written.
  • Inline float constants are f16 (1.0 = 0x3C00); integer constants and literals give their low 16 bits.
  • Results are computed in double precision and then rounded once to binary16, to nearest even. Denormals are kept, and every NaN is 0x7E00.

Anything not backed by a source is refused with Untranslated, naming the instruction and the reason:

  • omod;
  • clamp on the f32 result of v_cvt_f32_f16;
  • op_sel on a constant or a 32-bit source;
  • abs/neg on the integer source of v_ldexp_f16;
  • the SDWA/DPP forms of the f16 instructions (refused before the SDWA/DPP path).

README, in all 9 languages:

  • The interpreter line becomes 1,085 of 1,490 (73%). main runs 1,060 today, although its README still says 1,046.
  • The test count becomes 1200+, since this PR takes the suite to 1,223 tests.

The HLSL recompiler is not changed here; its translation follows in the next PR.

Linked issue: Refs #115

Verification

python -m pytest → 937 passed, 286 skipped
python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools → All checks passed!
  • The skips are the tests that need the C++ runtime, the Rust crate or the TomBox DLLs, none of which were built in this checkout.
  • test_readme_sync.py::test_claimed_count_matches_suite passes in the full run (1,223 tests → 1200+).
  • @⁠GravynChips ran the earlier revision on an RTX 4070 SUPER: test_rdna2_f16.py 31/31, plus 65,536 extra FMA cases checked against exact integer arithmetic (comments on #165 and #112).

Oracle and test data

The semantics follow AMD's public "RDNA 2 Instruction Set Architecture"; the 16-bit writes of gfx10 follow LLVM (zeroesHigh16BitsOfDest) and Mesa ACO.

The 31 tests in tests/test_rdna2_f16.py build their own programs, with expected values worked out by hand, and the 9 inline float constants are compared with those of the f32 path. Without this change, emu.rdna2_exec_f16 does not exist and every f16 program raises Untranslated on its instruction. The refusal tests also require the reason in the message.

Checklist

  • The PR covers a single reviewable behaviour (f16 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, never a fake success (unsourced forms are refused with Untranslated).
  • 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.

**@⁠IxMxAMAR** on GitHub · 2026-11-25 16:22 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/218) `IxMxAMAR:feat/rdna2-f16` → `main` · +414 −27 · 14 files · 6 commits · merged 2026-11-25 18:32 UTC ## Change Replaces #163, which was closed during the 25 November triage because it conflicted with `main` after #199 and #151. It is rebased on `main` (`ab55a2a`). The code is the same apart from the conflict resolution: the f16 group is wired in next to the instruction groups #151 added, and it shares no instruction name with them. The RDNA 2 reference interpreter runs 25 more f16 encodings (1,060 → 1,085 of 1,490): - `v_add`, `v_sub`, `v_subrev`, `v_mul`, `v_fmac`, `v_fmamk`, `v_fmaak`, `v_max`, `v_min` and `v_ldexp_f16`, in VOP2 and VOP3; - `v_fma_f16`, in VOP3; - `v_cvt_f16_f32` and `v_cvt_f32_f16`, in VOP1 and VOP3. They live in a new module, `emu/rdna2_exec_f16.py`, with a few lines in `rdna2_exec.py` and `rdna2_exec_vop3.py`. gfx10 semantics: - An f16 write keeps the other half of the VGPR. - In VOP3, `op_sel` picks the half read from each source and the half written. - Inline float constants are f16 (1.0 = 0x3C00); integer constants and literals give their low 16 bits. - Results are computed in double precision and then rounded once to binary16, to nearest even. Denormals are kept, and every NaN is 0x7E00. Anything not backed by a source is refused with `Untranslated`, naming the instruction and the reason: - omod; - clamp on the f32 result of `v_cvt_f32_f16`; - `op_sel` on a constant or a 32-bit source; - abs/neg on the integer source of `v_ldexp_f16`; - the SDWA/DPP forms of the f16 instructions (refused before the SDWA/DPP path). README, in all 9 languages: - The interpreter line becomes 1,085 of 1,490 (73%). `main` runs 1,060 today, although its README still says 1,046. - The test count becomes `1200+`, since this PR takes the suite to 1,223 tests. The HLSL recompiler is not changed here; its translation follows in the next PR. Linked issue: Refs #115 ## Verification ``` python -m pytest → 937 passed, 286 skipped python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools → All checks passed! ``` - The skips are the tests that need the C++ runtime, the Rust crate or the TomBox DLLs, none of which were built in this checkout. - `test_readme_sync.py::test_claimed_count_matches_suite` passes in the full run (1,223 tests → `1200+`). - @⁠GravynChips ran the earlier revision on an RTX 4070 SUPER: `test_rdna2_f16.py` 31/31, plus 65,536 extra FMA cases checked against exact integer arithmetic (comments on #165 and #112). ## Oracle and test data The semantics follow AMD's public "RDNA 2 Instruction Set Architecture"; the 16-bit writes of gfx10 follow LLVM (`zeroesHigh16BitsOfDest`) and Mesa ACO. The 31 tests in `tests/test_rdna2_f16.py` build their own programs, with expected values worked out by hand, and the 9 inline float constants are compared with those of the f32 path. Without this change, `emu.rdna2_exec_f16` does not exist and every f16 program raises `Untranslated` on its instruction. The refusal tests also require the reason in the message. ## Checklist - [x] The PR covers a single reviewable behaviour (f16 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, never a fake success (unsourced forms are refused with `Untranslated`). - [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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:38:02 +00:00
github manually merged commit 2b6ab4642c into gh-pr/218/base 2026-11-26 05:38:03 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.