feat(rdna2-ref): run scalar f16 arithmetic, rounding and conversions #501

Merged
Lewandox merged 1 commit from upstream-pr/501 into main 2026-11-27 15:53:35 +00:00
Lewandox commented 2026-11-27 14:18:15 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by Lewandox on 2026-11-27T14:18:15Z.


Change

Port the 21 non-transcendental scalar half-precision (f16) instructions of emu/rdna2_exec_f16.py to crates/anyxboxx-rdna2-ref (f16.rs, half.rs) across VOP1, VOP2 and VOP3:

  • Arithmetic, FMA and min/max: v_add_f16, v_sub_f16, v_subrev_f16, v_mul_f16, v_fmac_f16, v_fmamk_f16, v_fmaak_f16, v_fma_f16, v_min_f16, v_max_f16, v_ldexp_f16.
  • Rounding, fraction/frexp and conversions: v_floor_f16, v_ceil_f16, v_trunc_f16, v_rndne_f16, v_fract_f16, v_frexp_mant_f16, v_frexp_exp_i16_f16, v_cvt_f16_f32, v_cvt_f32_f16, v_cvt_pkrtz_f16_f32.
  • Matching operand/modifier handling (INLINE_HALVES, op_sel source/destination halves while preserving the untouched VGPR half, abs/neg on bit 15 or bit 31, clamp to [0, 1]) and shared refusals (SDWA/DPP, omod, clamp on word/integer results, op_sel on v_fmac_f16 or 32-bit sources/destinations, v_fmamk_f16/v_fmaak_f16 in VOP3 without a literal, abs/neg or float inline constants on v_ldexp_f16's integer source, op_sel high half on constants).
  • Add these 21 mnemonics to random_program in tests/test_rdna2_ref_parity.py and add dedicated parity tests in tests/test_rdna2_ref_f16_parity.py.

Linked issue: Refs #482 (part 1 of 3)

Verification

cargo +stable-x86_64-pc-windows-gnu test -p anyxboxx-rdna2-ref → 142 passed; 0 failed
cargo +stable-x86_64-pc-windows-gnu clippy -p anyxboxx-rdna2-ref --all-targets -- -D warnings → 0 warnings
cargo +stable-x86_64-pc-windows-gnu fmt --check -p anyxboxx-rdna2-ref → clean
python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools → All checks passed!
python -m pytest tests/test_rdna2_ref_f16_parity.py tests/test_rdna2_ref_parity.py tests/test_readme_sync.py → 57 passed, 1 skipped

(Note: if upstream/main has not yet merged #495/#496 when CI runs, crates/anyxboxx's big_pools_come_after_the_tuned_set_and_before_quality_and_overrides is the pre-existing failure on main.)

Oracle and test data

  • Oracle: PrototypeScarlett/emu/rdna2_exec_f16.py (AMD RDNA 2 ISA sections 12.7, 12.8, 12.12).
  • Test data: synthetic encodings constructed in tests/test_rdna2_ref_f16_parity.py, including an exhaustive 65,536-input sweep over all binary16 bit patterns for all 8 unary operations (v_floor_f16, v_ceil_f16, v_trunc_f16, v_rndne_f16, v_fract_f16, v_frexp_mant_f16, v_frexp_exp_i16_f16, v_cvt_f32_f16), fixed VOP1/VOP2/VOP3 modifier and refusal programs, and 250 seeded multi-instruction programs.
  • Failure case without this change: tests/test_rdna2_ref_f16_parity.py fails because anyxboxx-rdna2-ref refuses all 21 operations with error untranslated.

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 the English and French READMEs (test_readme_sync.py checks it; collected count is 1962, still 1900+).
  • No game, console or SDK file, no key, no dump, no download link.
  • Findings drawn from a title: limited to what rule 2 of AGENTS.md allows; none used here.
  • Code taken from another project: none (emu/rdna2_exec_f16.py is in this repository).

AI assistance: implemented and verified with AI coding assistance.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:issue:5528144984 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/501). Originally posted by [Lewandox](https://github.com/Lewandox) on 2026-11-27T14:18:15Z. --- ## Change Port the 21 non-transcendental scalar half-precision (`f16`) instructions of `emu/rdna2_exec_f16.py` to `crates/anyxboxx-rdna2-ref` (`f16.rs`, `half.rs`) across `VOP1`, `VOP2` and `VOP3`: - Arithmetic, FMA and min/max: `v_add_f16`, `v_sub_f16`, `v_subrev_f16`, `v_mul_f16`, `v_fmac_f16`, `v_fmamk_f16`, `v_fmaak_f16`, `v_fma_f16`, `v_min_f16`, `v_max_f16`, `v_ldexp_f16`. - Rounding, fraction/frexp and conversions: `v_floor_f16`, `v_ceil_f16`, `v_trunc_f16`, `v_rndne_f16`, `v_fract_f16`, `v_frexp_mant_f16`, `v_frexp_exp_i16_f16`, `v_cvt_f16_f32`, `v_cvt_f32_f16`, `v_cvt_pkrtz_f16_f32`. - Matching operand/modifier handling (`INLINE_HALVES`, `op_sel` source/destination halves while preserving the untouched VGPR half, `abs`/`neg` on bit 15 or bit 31, `clamp` to `[0, 1]`) and shared refusals (`SDWA`/`DPP`, `omod`, `clamp` on word/integer results, `op_sel` on `v_fmac_f16` or 32-bit sources/destinations, `v_fmamk_f16`/`v_fmaak_f16` in `VOP3` without a literal, `abs`/`neg` or float inline constants on `v_ldexp_f16`'s integer source, `op_sel` high half on constants). - Add these 21 mnemonics to `random_program` in `tests/test_rdna2_ref_parity.py` and add dedicated parity tests in `tests/test_rdna2_ref_f16_parity.py`. Linked issue: Refs #482 (part 1 of 3) ## Verification ``` cargo +stable-x86_64-pc-windows-gnu test -p anyxboxx-rdna2-ref → 142 passed; 0 failed cargo +stable-x86_64-pc-windows-gnu clippy -p anyxboxx-rdna2-ref --all-targets -- -D warnings → 0 warnings cargo +stable-x86_64-pc-windows-gnu fmt --check -p anyxboxx-rdna2-ref → clean python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools → All checks passed! python -m pytest tests/test_rdna2_ref_f16_parity.py tests/test_rdna2_ref_parity.py tests/test_readme_sync.py → 57 passed, 1 skipped ``` *(Note: if `upstream/main` has not yet merged #495/#496 when CI runs, `crates/anyxboxx`'s `big_pools_come_after_the_tuned_set_and_before_quality_and_overrides` is the pre-existing failure on `main`.)* ## Oracle and test data - Oracle: `PrototypeScarlett/emu/rdna2_exec_f16.py` (AMD RDNA 2 ISA sections 12.7, 12.8, 12.12). - Test data: synthetic encodings constructed in `tests/test_rdna2_ref_f16_parity.py`, including an exhaustive 65,536-input sweep over all binary16 bit patterns for all 8 unary operations (`v_floor_f16`, `v_ceil_f16`, `v_trunc_f16`, `v_rndne_f16`, `v_fract_f16`, `v_frexp_mant_f16`, `v_frexp_exp_i16_f16`, `v_cvt_f32_f16`), fixed `VOP1`/`VOP2`/`VOP3` modifier and refusal programs, and 250 seeded multi-instruction programs. - Failure case without this change: `tests/test_rdna2_ref_f16_parity.py` fails because `anyxboxx-rdna2-ref` refuses all 21 operations with `error untranslated`. ## 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 the English and French READMEs (`test_readme_sync.py` checks it; collected count is 1962, still `1900+`). - [x] No game, console or SDK file, no key, no dump, no download link. - [x] Findings drawn from a title: limited to what rule 2 of `AGENTS.md` allows; none used here. - [x] Code taken from another project: none (`emu/rdna2_exec_f16.py` is in this repository). AI assistance: implemented and verified with AI coding assistance.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
LooperSalty/AnyXboxX!501
No description provided.