feat: close 32-bit RDNA 2 ALU HLSL parity and add v_mul_legacy_f32, v_perm_b32 (#21) #119

Manually merged
github merged 3 commits from gh-pr/119/head into gh-pr/119/base 2026-11-26 05:32:29 +00:00
Owner

@⁠Lewandox on GitHub · 2026-11-24 00:18 UTC · original
Lewandox:feat/rdna2-alu-hlsl-parity → main · +397 −18 · 14 files · 3 commits · merged 2026-11-24 10:14 UTC

Closes the remaining 32-bit Scalar, Vector, VOP3, and VOP3b carry parity gap between
dna2_exec and
dna2_hlsl, and adds _mul_legacy_f32 and _perm_b32 to both the reference interpreter and HLSL recompiler (part of #21; intentionally avoids all f16/16-bit instructions claimed in #115).

Summary

  • Reference interpreter (
    dna2_exec_ops.py,
    dna2_exec_vop3.py)
    :
    • _mul_legacy_f32 (VOP2 & VOP3): .0 * anything == +0.0 (including NaN/Inf).
    • _perm_b32 (VOP3): full AMD RDNA 2 ISA byte permute (byte selectors ..7, zero 8, sign-extend 9..12, xFF for >=13).
  • HLSL recompiler (
    dna2_hlsl_ops.py,
    dna2_hlsl.py,
    dna2_hlsl_graphics.py)
    :
    • Added pure 32-bit SM 6.0 HLSL helpers (MulHiU32, MulHiI32, BfeI32, AlignBit, SadU32, MulLegacyF32, FmaLegacyF32, PermB32) injected into compute, vertex, and pixel shaders (no uint64_t extension needed).
    • Added all remaining 32-bit SCALAR ops (s_addc_u32, s_subb_u32, s_cmov_b32, s_cmovk_i32, s_addk_i32, s_mulk_i32, s_min_i32, s_max_i32, s_abs_i32, s_sext_i32_i8, s_sext_i32_i16, s_brev_b32, s_bcnt1_i32_b32, s_ff1_i32_b32, s_flbit_i32_b32, s_bfm_b32, s_orn2_b32, s_nand_b32, s_nor_b32, s_xnor_b32, s_bitcmp0_b32, s_bitcmp1_b32, s_xor_saveexec_b32, plus waitcnt/nop forms).
    • Added all remaining 32-bit VECTOR / VOP3 ops ( _mul_legacy_f32, _fma_legacy_f32, _perm_b32, _mul_hi_u32, _mul_hi_i32, _mul_hi_u32_u24, _mul_i32_i24, _mad_i32_i24, _bfe_i32, _bfm_b32, _alignbit_b32, _alignbyte_b32, _sad_u32, _xad_u32, _add_lshl_u32, _bfrev_b32, _ffbl_b32, _ffbh_u32, _cvt_f32_ubyte0..3, _sin_f32, _cos_f32, _rndne_f32, _ldexp_f32, _xnor_b32, _min3/max3/med3 f32/i32/u32, _mbcnt_hi_u32_b32).
    • Added remaining VOP3b carry ops ( _subrev_co_u32, _sub_co_ci_u32, _subrev_co_ci_u32) to CARRY.
  • Tests & Docs:
    • Added ests/test_rdna2_alu_parity.py (including a meta-test asserting 100% 32-bit ALU coverage parity between
      dna2_exec and
      dna2_hlsl, plus an @⁠gpu parity test for Windows CI).
    • Synced test count across all 8 READMEs (555 -> 561).

Verification

  • pytest tests/test_rdna2_alu_parity.py tests/test_rdna2_exec.py tests/test_rdna2_hlsl.py tests/test_rdna2_graphics.py tests/test_readme_sync.py -v -> 29 passed, 8 skipped (@⁠gpu tests skip locally without dxc/nyxboxx_gpu_run.exe).
  • ruff check --select W605,F,E9 PrototypeScarlett tests tools -> All checks passed!

(AI-assisted implementation; zero game, console, or SDK data used.)

**@⁠Lewandox** on GitHub · 2026-11-24 00:18 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/119) `Lewandox:feat/rdna2-alu-hlsl-parity` → `main` · +397 −18 · 14 files · 3 commits · merged 2026-11-24 10:14 UTC Closes the remaining 32-bit Scalar, Vector, VOP3, and VOP3b carry parity gap between dna2_exec and dna2_hlsl, and adds _mul_legacy_f32 and _perm_b32 to both the reference interpreter and HLSL recompiler (part of #21; intentionally avoids all f16/16-bit instructions claimed in #115). ### Summary - **Reference interpreter ( dna2_exec_ops.py, dna2_exec_vop3.py)**: - _mul_legacy_f32 (VOP2 & VOP3): .0 * anything == +0.0 (including NaN/Inf). - _perm_b32 (VOP3): full AMD RDNA 2 ISA byte permute (byte selectors ..7, zero 8, sign-extend 9..12, xFF for >=13). - **HLSL recompiler ( dna2_hlsl_ops.py, dna2_hlsl.py, dna2_hlsl_graphics.py)**: - Added pure 32-bit SM 6.0 HLSL helpers (MulHiU32, MulHiI32, BfeI32, AlignBit, SadU32, MulLegacyF32, FmaLegacyF32, PermB32) injected into compute, vertex, and pixel shaders (no uint64_t extension needed). - Added all remaining 32-bit SCALAR ops (s_addc_u32, s_subb_u32, s_cmov_b32, s_cmovk_i32, s_addk_i32, s_mulk_i32, s_min_i32, s_max_i32, s_abs_i32, s_sext_i32_i8, s_sext_i32_i16, s_brev_b32, s_bcnt1_i32_b32, s_ff1_i32_b32, s_flbit_i32_b32, s_bfm_b32, s_orn2_b32, s_nand_b32, s_nor_b32, s_xnor_b32, s_bitcmp0_b32, s_bitcmp1_b32, s_xor_saveexec_b32, plus waitcnt/nop forms). - Added all remaining 32-bit VECTOR / VOP3 ops ( _mul_legacy_f32, _fma_legacy_f32, _perm_b32, _mul_hi_u32, _mul_hi_i32, _mul_hi_u32_u24, _mul_i32_i24, _mad_i32_i24, _bfe_i32, _bfm_b32, _alignbit_b32, _alignbyte_b32, _sad_u32, _xad_u32, _add_lshl_u32, _bfrev_b32, _ffbl_b32, _ffbh_u32, _cvt_f32_ubyte0..3, _sin_f32, _cos_f32, _rndne_f32, _ldexp_f32, _xnor_b32, _min3/max3/med3 f32/i32/u32, _mbcnt_hi_u32_b32). - Added remaining VOP3b carry ops ( _subrev_co_u32, _sub_co_ci_u32, _subrev_co_ci_u32) to CARRY. - **Tests & Docs**: - Added ests/test_rdna2_alu_parity.py (including a meta-test asserting 100% 32-bit ALU coverage parity between dna2_exec and dna2_hlsl, plus an @⁠gpu parity test for Windows CI). - Synced test count across all 8 READMEs (555 -> 561). ### Verification - `pytest tests/test_rdna2_alu_parity.py tests/test_rdna2_exec.py tests/test_rdna2_hlsl.py tests/test_rdna2_graphics.py tests/test_readme_sync.py -v` -> **29 passed, 8 skipped** (@⁠gpu tests skip locally without dxc/nyxboxx_gpu_run.exe). - `ruff check --select W605,F,E9 PrototypeScarlett tests tools` -> **All checks passed!** *(AI-assisted implementation; zero game, console, or SDK data used.)*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:32:28 +00:00
github manually merged commit d3a5361e74 into gh-pr/119/base 2026-11-26 05:32:29 +00:00
Author
Owner

@⁠Lewandox on GitHub · 2026-11-24 08:57 UTC · original

Addressed all review points:

  1. Fixed \ op2('v_mul_legacy_f32', ...)\ in \ est_extended_alu_matches_interpreter_on_gpu\ (moved \
**@⁠Lewandox** on GitHub · 2026-11-24 08:57 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/119#issuecomment-7126768696) Addressed all review points: 1. Fixed \ op2('v_mul_legacy_f32', ...)\ in \ est_extended_alu_matches_interpreter_on_gpu\ (moved \
Author
Owner

@⁠LooperSalty on GitHub · 2026-11-24 08:31 UTC · original · requested changes

Thanks. One test fails and one table looks wrong:

  1. tests/test_rdna2_alu_parity.py::test_extended_alu_matches_interpreter_on_gpu fails with Untranslated: v_nop (VOP1, opcode 0x0). In vop2("v_mul_legacy_f32", 9, const(0), LITERAL), 0x7FC0_0000 the literal is in vsrc1, a VGPR field, so the next dword is decoded as an instruction. In VOP2 the literal can only be src0: vop2(..., 9, LITERAL, 0), 0x7FC0_0000 (or put the literal through VOP3 rules).
  2. v_perm_b32 selectors (_perm_b32 in rdna2_exec_vop3.py and PermB32 in rdna2_hlsl_ops.py): please check against the RDNA 2 ISA guide. As I read it, selectors 8-11 replicate sign bits (bit 15/31 of src1, then of src0), 12 gives 0x00, and 13+ give 0xFF. The PR has 8 → 0x00 and 9-12 → signs. The common zero-extension selector 0x0C0C0C00 would produce sign bytes here. The interpreter and the HLSL share the table, so the GPU comparison cannot catch it: the expected values should come from the ISA document or LLVM tests.
  3. Rule 4: most new opcodes (v_sin_f32, v_cos_f32, v_rndne_f32, v_ffbl_b32, v_cvt_f32_ubyte*…) are only checked by HLSL string search. Please run them through the GPU comparison too.

Conflicts: same COMMON.format(...) lines as #117 in rdna2_hlsl_graphics.py. CI is blocked by the deleted Leonida submodule until #120 is merged.

🤖 Generated with Claude Code

**@⁠LooperSalty** on GitHub · 2026-11-24 08:31 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/119#pullrequestreview-6035948588) · **requested changes** Thanks. One test fails and one table looks wrong: 1. `tests/test_rdna2_alu_parity.py::test_extended_alu_matches_interpreter_on_gpu` fails with `Untranslated: v_nop (VOP1, opcode 0x0)`. In `vop2("v_mul_legacy_f32", 9, const(0), LITERAL), 0x7FC0_0000` the literal is in `vsrc1`, a VGPR field, so the next dword is decoded as an instruction. In VOP2 the literal can only be src0: `vop2(..., 9, LITERAL, 0), 0x7FC0_0000` (or put the literal through VOP3 rules). 2. `v_perm_b32` selectors (`_perm_b32` in `rdna2_exec_vop3.py` and `PermB32` in `rdna2_hlsl_ops.py`): please check against the RDNA 2 ISA guide. As I read it, selectors 8-11 replicate sign bits (bit 15/31 of src1, then of src0), **12 gives 0x00**, and 13+ give 0xFF. The PR has 8 → 0x00 and 9-12 → signs. The common zero-extension selector `0x0C0C0C00` would produce sign bytes here. The interpreter and the HLSL share the table, so the GPU comparison cannot catch it: the expected values should come from the ISA document or LLVM tests. 3. Rule 4: most new opcodes (`v_sin_f32`, `v_cos_f32`, `v_rndne_f32`, `v_ffbl_b32`, `v_cvt_f32_ubyte*`…) are only checked by HLSL string search. Please run them through the GPU comparison too. Conflicts: same `COMMON.format(...)` lines as #117 in `rdna2_hlsl_graphics.py`. CI is blocked by the deleted Leonida submodule until #120 is merged. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Owner

@⁠LooperSalty on GitHub · 2026-11-24 10:06 UTC · original · reviewed

Checked: the v_mul_legacy_f32 VOP2 test is fixed and test_extended_alu_matches_interpreter_on_gpu passes on the GPU here. The v_perm_b32 table now matches the RDNA 2 ISA (selectors 8/9: sign of S1 bits 15/31, 10/11: sign of S0 bits 15/31, 12: 0x00, 13+: 0xFF), second-checked against the ISA document. Looks good to me.

🤖 Generated with Claude Code

**@⁠LooperSalty** on GitHub · 2026-11-24 10:06 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/119#pullrequestreview-6037238735) · **reviewed** Checked: the `v_mul_legacy_f32` VOP2 test is fixed and `test_extended_alu_matches_interpreter_on_gpu` passes on the GPU here. The `v_perm_b32` table now matches the RDNA 2 ISA (selectors 8/9: sign of S1 bits 15/31, 10/11: sign of S0 bits 15/31, 12: 0x00, 13+: 0xFF), second-checked against the ISA document. Looks good to me. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This discussion has been locked. Commenting is limited to contributors.
No description provided.