feat: v_floor/ceil/trunc/rndne_f16 in the RDNA 2 interpreter — 1,216/1,490 #245

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

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

Change

The reference interpreter now runs the four f16 rounding ops in VOP1 and VOP3, 8 encodings that raised Untranslated until now: v_floor_f16, v_ceil_f16, v_trunc_f16 and v_rndne_f16.

They join rdna2_exec_f16.OPERATIONS (#218) through a small helper, half_round:

  • the result is the integral value of S0, exact in binary16, with the sign of S0 kept, as the interpreter's f32 forms do (_signed_round: IEEE 754 roundToIntegral, trunc(-0.5) = -0, ceil(-0.5) = -0);
  • v_rndne_f16 rounds ties to even (2.5 → 2, -2.5 → -2);
  • infinities are unchanged, and a NaN gives 0x7E00 (the rule of every f16 result in this module).

The existing f16 rules apply unchanged:

  • VOP1 writes the low half and keeps the high half;
  • VOP3 op_sel reads or writes the high half;
  • abs/neg act on bit 15;
  • clamp limits the result to [0, 1];
  • SDWA/DPP are refused.

Source: AMD, "RDNA 2" ISA, November 2020, §12.8 "VOP1 Instructions", opcodes 91-94 (printed p. 148). Note that the ISA pseudo-code of V_RNDNE_F16 (floor(S0 + 0.5), minus 1 on an even tie) gives +0 for -0.5. This PR keeps the sign, as v_rndne_f32 does here (_round_even, copysign) and as LLVM's constant folding of rint does. Neither case is measured; say if you prefer the pseudo-code.

HLSL: not changed. The recompiler still refuses these ops (tested). The translation can follow with GPU parity tests, as #219 did after #218.

Coverage (rdna2_exec.coverage()): 1,208 → 1,216 of 1,490. All 9 READMEs go from 81% to 82%. Overlap: #230, #232, #241 and #244 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                → 1106 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_rounding.py (14 tests). A hand-written table of 16 inputs lists all four results for each:

    • ±1.5 and ±2.5 (ties to even);
    • ±0.5, 0.75 and -0;
    • ± the smallest denormal;
    • 4094 and 65504 (already whole);
    • ±inf;
    • a signalling NaN and a negative NaN.

    The tests:

    • VOP1 for each op (the high half kept);
    • VOP3 with op_sel reading and writing the high half;
    • VOP3 neg, abs and clamp;
    • inline 1.0 (0x3C00) and a literal's low half;
    • HLSL still refusing each op.
  • Failure case: 10 of the 14 fail on main (the 4 that pass are the HLSL refusals).

Checklist

  • The PR covers a single reviewable behaviour. (f16 rounding to integral, 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.
  • 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:02 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/245) `lcg007xd-c:feat/rdna2-f16-rounding` → `main` · +121 −18 · 11 files · 1 commits · merged 2026-11-26 00:15 UTC ## Change The reference interpreter now runs the four f16 rounding ops in VOP1 and VOP3, 8 encodings that raised `Untranslated` until now: `v_floor_f16`, `v_ceil_f16`, `v_trunc_f16` and `v_rndne_f16`. They join `rdna2_exec_f16.OPERATIONS` (#218) through a small helper, `half_round`: - the result is the integral value of S0, exact in binary16, with the sign of S0 kept, as the interpreter's f32 forms do (`_signed_round`: IEEE 754 roundToIntegral, `trunc(-0.5) = -0`, `ceil(-0.5) = -0`); - `v_rndne_f16` rounds ties to even (2.5 → 2, -2.5 → -2); - infinities are unchanged, and a NaN gives `0x7E00` (the rule of every f16 result in this module). The existing f16 rules apply unchanged: - VOP1 writes the low half and keeps the high half; - VOP3 `op_sel` reads or writes the high half; - `abs`/`neg` act on bit 15; - `clamp` limits the result to [0, 1]; - SDWA/DPP are refused. Source: AMD, "RDNA 2" ISA, November 2020, §12.8 "VOP1 Instructions", opcodes 91-94 (printed p. 148). Note that the ISA pseudo-code of V_RNDNE_F16 (`floor(S0 + 0.5)`, minus 1 on an even tie) gives +0 for -0.5. This PR keeps the sign, as `v_rndne_f32` does here (`_round_even`, `copysign`) and as LLVM's constant folding of `rint` does. Neither case is measured; say if you prefer the pseudo-code. HLSL: not changed. The recompiler still refuses these ops (tested). The translation can follow with GPU parity tests, as #219 did after #218. Coverage (`rdna2_exec.coverage()`): **1,208 → 1,216 of 1,490**. All 9 READMEs go from 81% to 82%. **Overlap:** #230, #232, #241 and #244 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 → 1106 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_rounding.py` (14 tests). A hand-written table of 16 inputs lists all four results for each: - ±1.5 and ±2.5 (ties to even); - ±0.5, 0.75 and -0; - ± the smallest denormal; - 4094 and 65504 (already whole); - ±inf; - a signalling NaN and a negative NaN. The tests: - VOP1 for each op (the high half kept); - VOP3 with `op_sel` reading and writing the high half; - VOP3 `neg`, `abs` and `clamp`; - inline 1.0 (0x3C00) and a literal's low half; - HLSL still refusing each op. - Failure case: 10 of the 14 fail on `main` (the 4 that pass are the HLSL refusals). ## Checklist - [x] The PR covers a single reviewable behaviour. (f16 rounding to integral, 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. - [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 four f16 rounding ops (VOP1 91-94 and their VOP3 forms, 8 encodings)
raised Untranslated. They join rdna2_exec_f16.OPERATIONS: the integral
value of S0 (exact in binary16), sign kept as the f32 forms do (IEEE 754
roundToIntegral: trunc(-0.5) = -0), infinities unchanged, NaN -> 0x7E00;
v_rndne rounds ties to even. The existing f16 rules apply: low half
written and high half kept, op_sel, abs/neg on bit 15, clamp to [0, 1].
ISA: AMD RDNA 2, section 12.8 (p. 148). HLSL not changed: it still
refuses them (tested). README: 1,208 -> 1,216 of 1,490 (82%).

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:59 +00:00
github manually merged commit 5dc98ea455 into gh-pr/245/base 2026-11-26 05:40:01 +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/245#issuecomment-7175742775) 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,216 of 1,490 (82%), all 9 languages.

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