feat: v_fract_f16, v_frexp_mant_f16 and v_frexp_exp_i16_f16 in the RDNA 2 interpreter — 1,214/1,490 #247

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

@⁠lcg007xd-c on GitHub · 2026-11-25 21:07 UTC · original
lcg007xd-c:feat/rdna2-f16-fract-frexp → main · +122 −18 · 11 files · 1 commits · merged 2026-11-26 00:15 UTC

Change

The reference interpreter now runs three more f16 VOP1 ops, in VOP1 and VOP3, 6 encodings that raised Untranslated until now. They mirror the interpreter's f32 forms (_fract, _frexp_mantissa, _frexp_exponent):

Op Result
v_fract_f16 S0 + -floor(S0) (ISA), at most 0x3BFF, the largest f16 under 1.0, as v_fract_f32 stops at 0x3F7FFFFF (#209). So fract(-2^-24) is 0x3BFF, not 1.0. NaN for ±inf and NaN; fract(-0) = +0; DX semantics, fract(-1.2) = 0.8
v_frexp_mant_f16 m in S0 = m × 2^e, 0.5 ≤ |m| < 1, sign kept. ±0, ±inf and NaN give S0 unchanged (ISA pseudo-code: D.f16 = S0.f16)
v_frexp_exp_i16_f16 e as a 16-bit two's-complement integer; 0 for ±0, ±inf and NaN

A denormal is normalised: 0x0001 = 0.5 × 2^-23 gives -23, 0x03FF gives -14. That is what math.frexp does in the f32 forms here, and what LLVM does when it folds amdgcn_frexp_mant/exp with APFloat frexp (AMDGPUInstCombineIntrinsic.cpp). It is not measured on hardware.

The existing f16 rules apply: a low-half write keeps the high half, op_sel reads or writes the high half, and abs/neg act on bit 15. One new refusal: VOP3 clamp on the integer result of v_frexp_exp_i16_f16. The f16 [0, 1] clamp would otherwise be applied to an integer; a new INTEGER_RESULT set marks it.

Source: AMD, "RDNA 2" ISA, November 2020, §12.8 "VOP1 Instructions", opcodes 89, 90 and 95 (printed p. 147-148).

HLSL: not changed. The recompiler still refuses these ops (tested).

Coverage (rdna2_exec.coverage()): 1,208 → 1,214 of 1,490. All 9 READMEs stay at 81%. Overlap: other open PRs change the same README number. In emu/rdna2_exec_f16.py this PR adds its lines at the end of OPERATIONS and after _is_nan, away from where #245 and #246 add theirs, so the code parts merge cleanly.

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                → 1103 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_fract_frexp.py (11 tests). A hand-written table gives the three results for each of 13 inputs:

    • 1.5, -1.2, -5.0, 1.0 and 65504;
    • ± the smallest denormal, and the largest denormal;
    • ±0, ±inf and a NaN.

    The tests:

    • VOP1 for each op (the high half kept);
    • VOP3 op_sel reading and writing the high half;
    • VOP3 neg, and inline 1.0;
    • the clamp refusal;
    • the HLSL refusals.
  • Failure case: 8 of the 11 fail on main (the HLSL refusals pass).

Checklist

  • The PR covers a single reviewable behaviour. (Three exact f16 unary ops, mirroring their f32 forms.)
  • 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:07 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/247) `lcg007xd-c:feat/rdna2-f16-fract-frexp` → `main` · +122 −18 · 11 files · 1 commits · merged 2026-11-26 00:15 UTC ## Change The reference interpreter now runs three more f16 VOP1 ops, in VOP1 and VOP3, 6 encodings that raised `Untranslated` until now. They mirror the interpreter's f32 forms (`_fract`, `_frexp_mantissa`, `_frexp_exponent`): | Op | Result | | --- | --- | | `v_fract_f16` | `S0 + -floor(S0)` (ISA), at most `0x3BFF`, the largest f16 under 1.0, as `v_fract_f32` stops at `0x3F7FFFFF` (#209). So `fract(-2^-24)` is `0x3BFF`, not 1.0. NaN for ±inf and NaN; `fract(-0) = +0`; DX semantics, `fract(-1.2) = 0.8` | | `v_frexp_mant_f16` | m in `S0 = m × 2^e`, 0.5 ≤ \|m\| < 1, sign kept. ±0, ±inf and NaN give S0 unchanged (ISA pseudo-code: `D.f16 = S0.f16`) | | `v_frexp_exp_i16_f16` | e as a 16-bit two's-complement integer; 0 for ±0, ±inf and NaN | A denormal is normalised: `0x0001` = 0.5 × 2^-23 gives `-23`, `0x03FF` gives `-14`. That is what `math.frexp` does in the f32 forms here, and what LLVM does when it folds `amdgcn_frexp_mant/exp` with `APFloat` `frexp` (`AMDGPUInstCombineIntrinsic.cpp`). It is not measured on hardware. The existing f16 rules apply: a low-half write keeps the high half, `op_sel` reads or writes the high half, and `abs`/`neg` act on bit 15. One new refusal: VOP3 `clamp` on the integer result of `v_frexp_exp_i16_f16`. The f16 `[0, 1]` clamp would otherwise be applied to an integer; a new `INTEGER_RESULT` set marks it. Source: AMD, "RDNA 2" ISA, November 2020, §12.8 "VOP1 Instructions", opcodes 89, 90 and 95 (printed p. 147-148). HLSL: not changed. The recompiler still refuses these ops (tested). Coverage (`rdna2_exec.coverage()`): **1,208 → 1,214 of 1,490**. All 9 READMEs stay at 81%. **Overlap:** other open PRs change the same README number. In `emu/rdna2_exec_f16.py` this PR adds its lines at the end of `OPERATIONS` and after `_is_nan`, away from where #245 and #246 add theirs, so the code parts merge cleanly. 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 → 1103 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_fract_frexp.py` (11 tests). A hand-written table gives the three results for each of 13 inputs: - 1.5, -1.2, -5.0, 1.0 and 65504; - ± the smallest denormal, and the largest denormal; - ±0, ±inf and a NaN. The tests: - VOP1 for each op (the high half kept); - VOP3 `op_sel` reading and writing the high half; - VOP3 `neg`, and inline 1.0; - the clamp refusal; - the HLSL refusals. - Failure case: 8 of the 11 fail on `main` (the HLSL refusals pass). ## Checklist - [x] The PR covers a single reviewable behaviour. (Three exact f16 unary ops, mirroring their f32 forms.) - [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)
VOP1 89, 90 and 95 and their VOP3 forms (6 encodings) raised
Untranslated. They follow the interpreter's f32 forms:
- fract = S0 + -floor(S0), at most 0x3BFF (largest f16 under 1.0, as
  v_fract_f32 bounds to 0x3F7FFFFF), NaN for +-inf and NaN, fract(-0) =
  +0;
- frexp splits S0 = m * 2^e with 0.5 <= |m| < 1; +-0, +-inf and NaN give
  S0 and exponent 0 (ISA pseudo-code); a denormal is normalised, as
  LLVM's AMDGPUInstCombineIntrinsic folds amdgcn_frexp_exp with APFloat.
The exponent is a 16-bit integer written to one half; VOP3 clamp on it is
refused by name. ISA: AMD RDNA 2, section 12.8 (p. 147-148). HLSL not
changed (still refused, tested). README: 1,208 -> 1,214 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:10 +00:00
github manually merged commit f75b107099 into gh-pr/247/base 2026-11-26 05:40:12 +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/247#issuecomment-7175744339) 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,214 of 1,490 (81%), all 9 languages.

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