feat: implement v_div_fixup_f16 in Python, Rust rdna2-ref, and HLSL #605

Open
mahmudintaginting2024 wants to merge 1 commit from upstream-pr/605 into main
mahmudintaginting2024 commented 2026-12-01 17:38:39 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by mahmudintaginting2024 on 2026-12-01T17:38:39Z.


Change

Implements v_div_fixup_f16 (VOP3 opcode 0x35F) across the Python reference interpreter, the Rust reference interpreter (anyxboxx-rdna2-ref), and the integer-only HLSL/DXIL recompiler.

Per AMD's "RDNA 2" Instruction Set Architecture Reference Guide (30 Nov 2020, SHA-256 22aec03f..., section 12.12, VOP3 863, printed p. 183; OPSEL support per section 6.2.5 Table 21, printed p. 44):

  • Handles S2 NaN (quieted), S1 NaN (quieted), 0/0 and inf/inf (0xFE00), x/0 and inf/y (sign_out ? -INF : +INF), x/inf and 0/y (sign_out ? -0 : +0), and normal sign_out ? -abs(S0) : abs(S0).
  • Supports op_sel[0..2] source half selection, op_sel[3] destination half write (preserving the other 16 bits), abs/neg, and clamp ([0, 1]); refuses omod and high-half constants by name like the other f16conv ops.

Files changed:

  • PrototypeScarlett/emu/rdna2_exec_f16conv.py: add div_fixup_f16 and register v_div_fixup_f16 in OPERATIONS, CLAMP_SATURATES, and DESTINATION_HIGH.
  • PrototypeScarlett/emu/rdna2_hlsl_f16conv.py: add integer-only F16DivFixup(uint s0, uint s1, uint s2) helper and template.
  • crates/anyxboxx-rdna2-ref/src/f16conv.rs: add div_fixup_f16, register in spec(), and add Rust unit test div_fixup_f16_handles_specials_and_quotient_sign.
  • crates/anyxboxx-report/data/rdna2-coverage.txt: regenerated via python tests/test_rust_traduction_parity.py.
  • tests/test_rdna2_exec_f16conv.py, tests/test_rdna2_hlsl_f16conv.py, tests/test_rdna2_ref_f16conv_parity.py: unit tests for all branches/modifiers, wave32/wave64 GPU & WARP parity, and Python vs Rust parity (including seeded random programs).

Verification

python -m pytest -n auto                                                   → 1984 passed in 64.23s
python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools      → All checks passed!
python -m pytest tests/test_rdna2_exec_f16conv.py tests/test_rdna2_hlsl_f16conv.py tests/test_rdna2_ref_f16conv_parity.py → 40 passed (NVIDIA RTX 4060 Laptop GPU)
ANYXBOXX_GPU=warp python -m pytest tests/test_rdna2_hlsl_f16conv.py        → 8 passed
cargo test --release -p anyxboxx-rdna2-ref                                 → ok. 152 passed; 0 failed
cargo clippy --release -p anyxboxx-rdna2-ref --all-targets -- -D warnings  → Finished (0 warnings)
rustfmt --edition 2024 --check crates/anyxboxx-rdna2-ref/src/f16conv.rs    → clean (exit 0)

Oracle and test data

  • Primary source: AMD "RDNA 2" Instruction Set Architecture Reference Guide (section 6.2.5 Table 21 p. 44; section 12.12 VOP3 863 p. 183).
  • HLSL translation verified byte-for-byte against the Python reference interpreter in wave32 and wave64 on both NVIDIA GeForce RTX 4060 Laptop GPU and WARP (ANYXBOXX_GPU=warp), plus vertex and pixel shader compilation.
  • Rust reference interpreter verified byte-for-byte against Python across explicit edge cases and 250 seeded random programs (test_rdna2_ref_f16conv_parity.py).
  • Failure case: test_div_fixup_f16_special_cases_and_modifiers fails with Untranslated on main and passes with this change.

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: test count stays in the 1900+ band (1,984 tests; test_readme_sync.py passes).
  • No game, console or SDK file, no key, no dump, no download link.
  • Findings drawn from a title: none (public AMD RDNA 2 ISA PDF only).
  • Code taken from another project: none.

Note: Co-authored with Gemini Neon (AI assistant).

<!-- greyfinch-sync:LooperSalty/AnyXboxX:issue:5591086866 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/605). Originally posted by [mahmudintaginting2024](https://github.com/mahmudintaginting2024) on 2026-12-01T17:38:39Z. --- ## Change Implements `v_div_fixup_f16` (VOP3 opcode `0x35F`) across the Python reference interpreter, the Rust reference interpreter (`anyxboxx-rdna2-ref`), and the integer-only HLSL/DXIL recompiler. Per AMD's *"RDNA 2" Instruction Set Architecture* Reference Guide (30 Nov 2020, SHA-256 `22aec03f...`, section 12.12, VOP3 863, printed p. 183; `OPSEL` support per section 6.2.5 Table 21, printed p. 44): - Handles `S2` NaN (quieted), `S1` NaN (quieted), `0/0` and `inf/inf` (`0xFE00`), `x/0` and `inf/y` (`sign_out ? -INF : +INF`), `x/inf` and `0/y` (`sign_out ? -0 : +0`), and normal `sign_out ? -abs(S0) : abs(S0)`. - Supports `op_sel[0..2]` source half selection, `op_sel[3]` destination half write (preserving the other 16 bits), `abs`/`neg`, and `clamp` (`[0, 1]`); refuses `omod` and high-half constants by name like the other `f16conv` ops. Files changed: - `PrototypeScarlett/emu/rdna2_exec_f16conv.py`: add `div_fixup_f16` and register `v_div_fixup_f16` in `OPERATIONS`, `CLAMP_SATURATES`, and `DESTINATION_HIGH`. - `PrototypeScarlett/emu/rdna2_hlsl_f16conv.py`: add integer-only `F16DivFixup(uint s0, uint s1, uint s2)` helper and template. - `crates/anyxboxx-rdna2-ref/src/f16conv.rs`: add `div_fixup_f16`, register in `spec()`, and add Rust unit test `div_fixup_f16_handles_specials_and_quotient_sign`. - `crates/anyxboxx-report/data/rdna2-coverage.txt`: regenerated via `python tests/test_rust_traduction_parity.py`. - `tests/test_rdna2_exec_f16conv.py`, `tests/test_rdna2_hlsl_f16conv.py`, `tests/test_rdna2_ref_f16conv_parity.py`: unit tests for all branches/modifiers, wave32/wave64 GPU & WARP parity, and Python vs Rust parity (including seeded random programs). ## Verification ``` python -m pytest -n auto → 1984 passed in 64.23s python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools → All checks passed! python -m pytest tests/test_rdna2_exec_f16conv.py tests/test_rdna2_hlsl_f16conv.py tests/test_rdna2_ref_f16conv_parity.py → 40 passed (NVIDIA RTX 4060 Laptop GPU) ANYXBOXX_GPU=warp python -m pytest tests/test_rdna2_hlsl_f16conv.py → 8 passed cargo test --release -p anyxboxx-rdna2-ref → ok. 152 passed; 0 failed cargo clippy --release -p anyxboxx-rdna2-ref --all-targets -- -D warnings → Finished (0 warnings) rustfmt --edition 2024 --check crates/anyxboxx-rdna2-ref/src/f16conv.rs → clean (exit 0) ``` ## Oracle and test data - Primary source: AMD *"RDNA 2" Instruction Set Architecture* Reference Guide (section 6.2.5 Table 21 p. 44; section 12.12 VOP3 863 p. 183). - HLSL translation verified byte-for-byte against the Python reference interpreter in wave32 and wave64 on both NVIDIA GeForce RTX 4060 Laptop GPU and WARP (`ANYXBOXX_GPU=warp`), plus vertex and pixel shader compilation. - Rust reference interpreter verified byte-for-byte against Python across explicit edge cases and 250 seeded random programs (`test_rdna2_ref_f16conv_parity.py`). - Failure case: `test_div_fixup_f16_special_cases_and_modifiers` fails with `Untranslated` on `main` and passes with this change. ## 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: test count stays in the `1900+` band (1,984 tests; `test_readme_sync.py` passes). - [x] No game, console or SDK file, no key, no dump, no download link. - [x] Findings drawn from a title: none (public AMD RDNA 2 ISA PDF only). - [x] Code taken from another project: none. _Note: Co-authored with **Gemini Neon** (AI assistant)._
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/605:upstream-pr/605'
git switch 'upstream-pr/605'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/605'
git switch 'upstream-pr/605'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/605'
git switch 'upstream-pr/605'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/605'
git switch 'main'
git merge --squash 'upstream-pr/605'
git switch 'main'
git merge --ff-only 'upstream-pr/605'
git switch 'main'
git merge 'upstream-pr/605'
git push origin 'main'
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!605
No description provided.