feat: implement v_permlane16_b32 and v_permlanex16_b32 in Python, Rust, and HLSL #606

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

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


Change

Implements v_permlane16_b32 (VOP3 opcode 0x377) and v_permlanex16_b32 (VOP3 opcode 0x378) across the Python reference interpreter, the Rust reference interpreter (anyxboxx-rdna2-ref), and the HLSL/DXIL recompiler (both wave32 and wave64).

Per AMD's "RDNA 2" Instruction Set Architecture Reference Guide (30 Nov 2020, SHA-256 22aec03f..., section 12.12, VOP3 887–888, printed pp. 186–187):

  • Performs 16-lane row gather within each row (v_permlane16_b32) or across adjacent row pairs 0<->1 / 2<->3 (v_permlanex16_b32) using the 64-bit lane selector {S2.u, S1.u} (4 bits per lane in the row).
  • Snapshots src0 before writing vdst so in-place permutes (vdst == src0) read pre-instruction values.
  • Honours OP_SEL[0] (FI, fetch inactive) and OP_SEL[1] (BOUND_CTRL, write 0 on inactive source lane when FI == 0, else preserve vdst).
  • Refuses non-zero abs/neg/clamp/omod, reserved op_sel[3:2], non-VGPR src0, and non-scalar src1/src2 by name across Python, Rust, and HLSL.

Files changed:

  • PrototypeScarlett/emu/rdna2_exec_vop3.py: add permlane16_refusal, _permlane16, and register both ops in LANE_OPERATIONS.
  • crates/anyxboxx-rdna2-ref/src/vop3.rs, vop3_forms.rs, int16.rs: expose Fields::op_sel, implement permlane16 in lane(), and add Rust unit test permlane16_rotates_within_and_across_rows_with_fi_and_bound_ctrl.
  • PrototypeScarlett/emu/rdna2_hlsl.py, rdna2_hlsl_wave64.py, rdna2_hlsl_graphics.py: add permlane16_statements (wave32 ReadLane and wave64 ReadLane64), add both to coverage_names() and CROSS_LANE_OPS.
  • crates/anyxboxx-report/data/rdna2-coverage.txt: regenerated via python tests/test_rust_traduction_parity.py (VOP3: 425 -> 427 / 438; total 1,366 / 1,490).
  • tests/test_rdna2_exec_permlane16.py: ISA rotation examples (wave32/wave64), in-place permute, all four (FI, BOUND_CTRL) modes, all 8 refusal cases across Python/HLSL32/HLSL64, wave32 & wave64 GPU/WARP byte-for-byte parity, and Rust anyxboxx-rdna2-ref parity.

Verification

python -m pytest -n auto                                                   → 1997 passed in 54.17s
python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools      → All checks passed!
python -m pytest tests/test_rdna2_exec_permlane16.py -v                    → 14 passed (NVIDIA RTX 4060 Laptop GPU)
ANYXBOXX_GPU=warp python -m pytest tests/test_rdna2_exec_permlane16.py -k gpu → 2 passed (wave32 & wave64)
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/vop3.rs crates/anyxboxx-rdna2-ref/src/vop3_forms.rs crates/anyxboxx-rdna2-ref/src/int16.rs → clean (exit 0)

Oracle and test data

  • Primary source: AMD "RDNA 2" Instruction Set Architecture Reference Guide (section 12.12, VOP3 887–888, printed pp. 186–187).
  • HLSL translation verified byte-for-byte against the Python reference interpreter in both wave32 and wave64 on NVIDIA GeForce RTX 4060 Laptop GPU and WARP (ANYXBOXX_GPU=warp).
  • Rust reference interpreter verified byte-for-byte against Python in wave32 and wave64 (test_permlane16_rust_ref_parity).
  • Failure case: all 14 tests in tests/test_rdna2_exec_permlane16.py 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,997 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:5591234616 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/606). Originally posted by [mahmudintaginting2024](https://github.com/mahmudintaginting2024) on 2026-12-01T17:47:27Z. --- ## Change Implements `v_permlane16_b32` (VOP3 opcode `0x377`) and `v_permlanex16_b32` (VOP3 opcode `0x378`) across the Python reference interpreter, the Rust reference interpreter (`anyxboxx-rdna2-ref`), and the HLSL/DXIL recompiler (both wave32 and wave64). Per AMD's *"RDNA 2" Instruction Set Architecture* Reference Guide (30 Nov 2020, SHA-256 `22aec03f...`, section 12.12, VOP3 887–888, printed pp. 186–187): - Performs 16-lane row gather within each row (`v_permlane16_b32`) or across adjacent row pairs `0<->1` / `2<->3` (`v_permlanex16_b32`) using the 64-bit lane selector `{S2.u, S1.u}` (4 bits per lane in the row). - Snapshots `src0` before writing `vdst` so in-place permutes (`vdst == src0`) read pre-instruction values. - Honours `OP_SEL[0]` (`FI`, fetch inactive) and `OP_SEL[1]` (`BOUND_CTRL`, write 0 on inactive source lane when `FI == 0`, else preserve `vdst`). - Refuses non-zero `abs`/`neg`/`clamp`/`omod`, reserved `op_sel[3:2]`, non-VGPR `src0`, and non-scalar `src1`/`src2` by name across Python, Rust, and HLSL. Files changed: - `PrototypeScarlett/emu/rdna2_exec_vop3.py`: add `permlane16_refusal`, `_permlane16`, and register both ops in `LANE_OPERATIONS`. - `crates/anyxboxx-rdna2-ref/src/vop3.rs`, `vop3_forms.rs`, `int16.rs`: expose `Fields::op_sel`, implement `permlane16` in `lane()`, and add Rust unit test `permlane16_rotates_within_and_across_rows_with_fi_and_bound_ctrl`. - `PrototypeScarlett/emu/rdna2_hlsl.py`, `rdna2_hlsl_wave64.py`, `rdna2_hlsl_graphics.py`: add `permlane16_statements` (wave32 `ReadLane` and wave64 `ReadLane64`), add both to `coverage_names()` and `CROSS_LANE_OPS`. - `crates/anyxboxx-report/data/rdna2-coverage.txt`: regenerated via `python tests/test_rust_traduction_parity.py` (`VOP3`: 425 -> 427 / 438; total 1,366 / 1,490). - `tests/test_rdna2_exec_permlane16.py`: ISA rotation examples (wave32/wave64), in-place permute, all four `(FI, BOUND_CTRL)` modes, all 8 refusal cases across Python/HLSL32/HLSL64, wave32 & wave64 GPU/WARP byte-for-byte parity, and Rust `anyxboxx-rdna2-ref` parity. ## Verification ``` python -m pytest -n auto → 1997 passed in 54.17s python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools → All checks passed! python -m pytest tests/test_rdna2_exec_permlane16.py -v → 14 passed (NVIDIA RTX 4060 Laptop GPU) ANYXBOXX_GPU=warp python -m pytest tests/test_rdna2_exec_permlane16.py -k gpu → 2 passed (wave32 & wave64) 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/vop3.rs crates/anyxboxx-rdna2-ref/src/vop3_forms.rs crates/anyxboxx-rdna2-ref/src/int16.rs → clean (exit 0) ``` ## Oracle and test data - Primary source: AMD *"RDNA 2" Instruction Set Architecture* Reference Guide (section 12.12, VOP3 887–888, printed pp. 186–187). - HLSL translation verified byte-for-byte against the Python reference interpreter in both wave32 and wave64 on NVIDIA GeForce RTX 4060 Laptop GPU and WARP (`ANYXBOXX_GPU=warp`). - Rust reference interpreter verified byte-for-byte against Python in wave32 and wave64 (`test_permlane16_rust_ref_parity`). - Failure case: all 14 tests in `tests/test_rdna2_exec_permlane16.py` 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,997 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/606:upstream-pr/606'
git switch 'upstream-pr/606'

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