feat: implement v_sad_u16 in Python, Rust rdna2-ref, and HLSL #604

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

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


Change

Implements v_sad_u16 (VOP3 opcode 0x15C) across the Python reference interpreter, the Rust reference interpreter (anyxboxx-rdna2-ref), and the HLSL/DXIL recompiler.

Per AMD's "RDNA 2" Instruction Set Architecture Reference Guide (30 Nov 2020, SHA-256 22aec03f..., section 12.12, printed p. 171):

ABSDIFF(x, y) := (x > y ? x - y : y - x) // UNSIGNED comparison
D.u  = S2.u;
D.u += ABSDIFF(S0.u[31:16], S1.u[31:16]);
D.u += ABSDIFF(S0.u[15:0],  S1.u[15:0]).
  • PrototypeScarlett/emu/rdna2_exec_vop3.py: add _sad_u16 and VECTOR3["v_sad_u16"] (VOP3 integer clamp continues to raise Untranslated per INTEGER_CLAMP).
  • crates/anyxboxx-rdna2-ref/src/vop3.rs: add v_sad_u16 to integer_names, sad_shorts, compute, and unit test sad_u16_sums_unsigned_halfword_differences_and_accumulates.
  • PrototypeScarlett/emu/rdna2_hlsl_helpers.py & rdna2_hlsl_ops.py: add SadU16(uint a, uint b) helper and (SadU16({a}, {b}) + {c}) translation.
  • crates/anyxboxx-report/data/rdna2-coverage.txt: regenerated via python tests/test_rust_traduction_parity.py (VOP3: 425 -> 426 / 438; total 1,365 / 1,490).
  • tests/test_rdna2_exec_vop3_more.py & tests/test_rdna2_ref_parity.py: unit tests, HLSL/GPU/WARP byte-for-byte parity, and Python vs Rust wave32/wave64 parity including clamp refusal.

Verification

python -m pytest -n auto                                                   → 1986 passed in 36.71s
python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools      → All checks passed!
ANYXBOXX_GPU=warp python -m pytest tests/test_rdna2_exec_vop3_more.py -k sad_u16 → 2 passed
python -m pytest tests/test_rdna2_exec_vop3_more.py -k sad_u16             → 2 passed (NVIDIA RTX 4060 Laptop GPU)
cargo test --release -p anyxboxx-rdna2-ref                                 → ok. 152 passed; 0 failed
cargo test --release -p anyxboxx                                           → ok. 28 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/vop3.rs       → clean (exit 0)

Oracle and test data

  • Primary source: AMD "RDNA 2" Instruction Set Architecture Reference Guide (section 12.12, printed p. 171).
  • HLSL translation verified byte-for-byte against the Python reference interpreter on both NVIDIA GeForce RTX 4060 Laptop GPU and WARP (ANYXBOXX_GPU=warp).
  • Rust reference interpreter verified byte-for-byte against Python across wave32 and wave64 (test_v_sad_u16_parity).
  • Failure case: test_sad_u16_sums_unsigned_halfword_differences, test_sad_u16_hlsl_and_gpu_parity, and test_v_sad_u16_parity fail with Untranslated on main and pass 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,986 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:5590967611 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/604). Originally posted by [mahmudintaginting2024](https://github.com/mahmudintaginting2024) on 2026-12-01T17:31:13Z. --- ## Change Implements `v_sad_u16` (VOP3 opcode `0x15C`) across the Python reference interpreter, the Rust reference interpreter (`anyxboxx-rdna2-ref`), and the HLSL/DXIL recompiler. Per AMD's *"RDNA 2" Instruction Set Architecture* Reference Guide (30 Nov 2020, SHA-256 `22aec03f...`, section 12.12, printed p. 171): ``` ABSDIFF(x, y) := (x > y ? x - y : y - x) // UNSIGNED comparison D.u = S2.u; D.u += ABSDIFF(S0.u[31:16], S1.u[31:16]); D.u += ABSDIFF(S0.u[15:0], S1.u[15:0]). ``` - `PrototypeScarlett/emu/rdna2_exec_vop3.py`: add `_sad_u16` and `VECTOR3["v_sad_u16"]` (VOP3 integer `clamp` continues to raise `Untranslated` per `INTEGER_CLAMP`). - `crates/anyxboxx-rdna2-ref/src/vop3.rs`: add `v_sad_u16` to `integer_names`, `sad_shorts`, `compute`, and unit test `sad_u16_sums_unsigned_halfword_differences_and_accumulates`. - `PrototypeScarlett/emu/rdna2_hlsl_helpers.py` & `rdna2_hlsl_ops.py`: add `SadU16(uint a, uint b)` helper and `(SadU16({a}, {b}) + {c})` translation. - `crates/anyxboxx-report/data/rdna2-coverage.txt`: regenerated via `python tests/test_rust_traduction_parity.py` (`VOP3`: 425 -> 426 / 438; total 1,365 / 1,490). - `tests/test_rdna2_exec_vop3_more.py` & `tests/test_rdna2_ref_parity.py`: unit tests, HLSL/GPU/WARP byte-for-byte parity, and Python vs Rust wave32/wave64 parity including `clamp` refusal. ## Verification ``` python -m pytest -n auto → 1986 passed in 36.71s python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools → All checks passed! ANYXBOXX_GPU=warp python -m pytest tests/test_rdna2_exec_vop3_more.py -k sad_u16 → 2 passed python -m pytest tests/test_rdna2_exec_vop3_more.py -k sad_u16 → 2 passed (NVIDIA RTX 4060 Laptop GPU) cargo test --release -p anyxboxx-rdna2-ref → ok. 152 passed; 0 failed cargo test --release -p anyxboxx → ok. 28 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/vop3.rs → clean (exit 0) ``` ## Oracle and test data - Primary source: AMD *"RDNA 2" Instruction Set Architecture* Reference Guide (section 12.12, printed p. 171). - HLSL translation verified byte-for-byte against the Python reference interpreter on both NVIDIA GeForce RTX 4060 Laptop GPU and WARP (`ANYXBOXX_GPU=warp`). - Rust reference interpreter verified byte-for-byte against Python across wave32 and wave64 (`test_v_sad_u16_parity`). - Failure case: `test_sad_u16_sums_unsigned_halfword_differences`, `test_sad_u16_hlsl_and_gpu_parity`, and `test_v_sad_u16_parity` fail with `Untranslated` on `main` and pass 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,986 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/604:upstream-pr/604'
git switch 'upstream-pr/604'

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