fix: share SDWA/DPP operand types between interpreter and HLSL #215

Manually merged
github merged 2 commits from gh-pr/215/head into gh-pr/215/base 2026-11-26 05:37:50 +00:00
Owner

@⁠KainanP on GitHub · 2026-11-25 16:02 UTC · original
KainanP:fix/shared-operand-float-flags → main · +161 −33 · 12 files · 2 commits · merged 2026-11-25 18:10 UTC

Change

Since #133, the interpreter (rdna2_exec_ext.py) and the HLSL recompiler (rdna2_hlsl_ext.py) each had their own _operand_float_flags, and only the interpreter's was updated. This PR keeps one definition, operand_float_flags, in rdna2_exec_ext.py; rdna2_hlsl_ext.py imports it (the same way rdna2_hlsl.py already imports float_result / float_inputs from the interpreter for VOP3).

The function reads the operand types from the mnemonic. When it names two types, the destination type comes first, as in LLVM's VOP profiles (v_cvt_flr_i32_f32, v_cvt_off_f32_i4, v_frexp_exp_i32_f32, v_cvt_f32_ubyte0). Otherwise one type covers both. It returns (src_is_f32, dst_is_f32). SDWA applies neg/abs to f32 sources and sext to the others, and omod/clamp to f32 results. DPP16 applies neg/abs to f32 sources.

Instruction Types Before: interpreter Before: HLSL Now (both) What the HLSL got wrong
v_cvt_flr_i32_f32, v_cvt_rpi_i32_f32 f32 → i32 (True, False) (False, False) (True, False) SDWA/DPP16 neg/abs ignored
v_cvt_off_f32_i4 i4 → f32 (False, True) (True, False) (False, True) SDWA omod ignored, clamp refused
v_frexp_exp_i32_f32 f32 → i32 (True, False) (True, True) (True, False) SDWA omod/clamp applied as a float to the integer exponent

The issue's table lists v_cvt_off_f32_i4 as (False, False) on the HLSL side. The HLSL code actually returned (True, False), because it read parts[3] = "f32" as the source type. That difference doesn't show in the result: neg/abs only touch bit 31, sext only touches bits above the selected byte, and the conversion reads bits 3:0. The destination flag is what showed.

The new function gives the interpreter's old answer for every VOP1/VOP2/VOPC mnemonic in rdna2_ops.py (319 names, checked by script). It differs from the old HLSL copy only on the four instructions above and on v_cvt_pkrtz_f16_f32, which neither back end implements yet.

One behaviour change on both sides: SDWA omod on an integer result is now refused by name, the same way SDWA clamp already was ("SDWA clamp/omod not supported on an integer result"). Before, the interpreter ignored it and the HLSL applied it to v_frexp_exp_i32_f32. LLVM only encodes SDWA omod when the destination is a float (HasSDWAOMod), and what hardware does with it on an integer result has not been measured. Under rule 3 the instruction is refused instead of guessing.

Linked issue: Fixes #205

Verification

The runtime was built from this branch with VS 2022 Build Tools CMake (cmake -S runtime -B runtime/build -A x64, cmake --build runtime/build --config Release). Laptop with three adapters:

python -m pytest                                  (RTX 4060 Laptop, default)  → 1187 passed, 17 skipped
ANYXBOXX_GPU=warp  python -m pytest               (WARP)                      → 1187 passed, 17 skipped
ANYXBOXX_GPU=Intel python -m pytest               (Intel UHD a78b, no FP64)   → 1185 passed, 19 skipped
python -m pytest tests/test_rdna2_sdwa_dpp_types.py  → 23 passed on each of the three adapters
python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools → All checks passed!

Why tests were skipped: 15 need the Rust crates or the TomBox DLLs, which this PR doesn't touch and which weren't built here. 2 need spirv-as/spirv-val. On Intel, 2 more are FP64 tests.

Same GPU tests with rdna2_exec_ext.py and rdna2_hlsl_ext.py reverted to main (the new test file kept), on each of RTX, WARP and Intel: 3 failed, 1 passed.

  • [flr_rpi_neg_abs]: the output memory differs, because the HLSL drops neg/abs.
  • [cvt_off_omod_sext]: the output memory differs, because the HLSL drops omod.
  • [cvt_off_clamp]: Untranslatable: SDWA clamp ... v_cvt_off_f32_i4.
  • [frexp_exp_neg_abs] passes on main, as expected: both sides already applied neg/abs to its f32 source, and its divergence was on the destination. That divergence is covered by the refusal test below.

Oracle and test data

New file tests/test_rdna2_sdwa_dpp_types.py (23 tests). It builds its programs from the existing encoders (vop1, sdwa_word, dpp16_word, run_wave, compare, store_lane), so it adds no external data.

  • test_sdwa_and_dpp16_type_modifiers_match_interpreter_on_gpu[...] (4 groups) is the byte-for-byte interpreter/HLSL comparison (rule 4) on GPU or WARP. The groups cover: SDWA neg, abs and neg+abs, and DPP16 quad_perm:[1,0,3,2] neg/abs, on flr/rpi with 16 f32 inputs per lane (±halves, −0.0, 1e10 saturation, 1e-3); SDWA neg+abs and DPP16 neg on v_frexp_exp_i32_f32; SDWA omod ×2 and ×0.5 with BYTE_1 + sext, and clamp, on v_cvt_off_f32_i4. 4 → 3 fail on main (see above).
  • test_sdwa_output_modifiers_on_an_integer_result_are_refused_by_name (4 cases): clamp or omod on the i32 results of v_frexp_exp_i32_f32, v_cvt_flr_i32_f32 and v_cvt_rpi_i32_f32 must be refused by name in both back ends. 3 of 4 fail on main; the rpi + clamp case was already refused by both.
  • Interpreter values worked out by hand from the ISA descriptions: floor(-2.5) = -3, floor(-|2.5| + 0.5) = -2, 7/16 × 2 = 0.875, clamp(-1/16) = 0, -1/16 × 0.5 = -0.03125. These already passed on main, because the interpreter was right.
  • test_operand_types_follow_the_mnemonic (12 names) and test_interpreter_and_hlsl_share_one_definition fail on main, because the shared function doesn't exist there.

The suite crosses 1,200 tests, so the 9 READMEs go from 1100+ to 1200+.

Out of scope

Both back ends treat these the same way, so there is no parity bug, but they may be wrong compared with hardware or LLVM:

  • v_cmp_class_f32 / v_cmpx_class_f32 in SDWA: src1 is the i32 class mask. LLVM gives it sext (Int32SDWAInputMods), but both back ends treat it as f32 (neg/abs, no sext). The interpreter has no SDWA table entry for class compares (VECTOR_COMPARE), so only the HLSL would translate it today.
  • f16 sources in DPP16 (v_cvt_f32_f16, v_*_f16): neg/abs should act on bit 15, but both back ends treat these sources as integers and ignore neg/abs. Most of these instructions aren't implemented in either back end yet.

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 all 9 languages (test_readme_sync.py checks it).
  • 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 (names, slots, argument shapes, flag values, HRESULTs, IIDs, counts), with how they were obtained; no address or RVA.
  • Code taken from another project: compatible licence and credit in THIRD_PARTY.md. (None taken.)

AI use: written with Claude Code (Claude Opus 5.5). I reviewed and ran it on the three adapters above.

🤖 Generated with Claude Code

**@⁠KainanP** on GitHub · 2026-11-25 16:02 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/215) `KainanP:fix/shared-operand-float-flags` → `main` · +161 −33 · 12 files · 2 commits · merged 2026-11-25 18:10 UTC ## Change Since #133, the interpreter (`rdna2_exec_ext.py`) and the HLSL recompiler (`rdna2_hlsl_ext.py`) each had their own `_operand_float_flags`, and only the interpreter's was updated. This PR keeps one definition, `operand_float_flags`, in `rdna2_exec_ext.py`; `rdna2_hlsl_ext.py` imports it (the same way `rdna2_hlsl.py` already imports `float_result` / `float_inputs` from the interpreter for VOP3). The function reads the operand types from the mnemonic. When it names two types, the destination type comes first, as in LLVM's VOP profiles (`v_cvt_flr_i32_f32`, `v_cvt_off_f32_i4`, `v_frexp_exp_i32_f32`, `v_cvt_f32_ubyte0`). Otherwise one type covers both. It returns `(src_is_f32, dst_is_f32)`. SDWA applies neg/abs to f32 sources and sext to the others, and omod/clamp to f32 results. DPP16 applies neg/abs to f32 sources. | Instruction | Types | Before: interpreter | Before: HLSL | Now (both) | What the HLSL got wrong | | --- | --- | --- | --- | --- | --- | | `v_cvt_flr_i32_f32`, `v_cvt_rpi_i32_f32` | f32 → i32 | (True, False) | (False, False) | (True, False) | SDWA/DPP16 neg/abs ignored | | `v_cvt_off_f32_i4` | i4 → f32 | (False, True) | (True, False) | (False, True) | SDWA omod ignored, clamp refused | | `v_frexp_exp_i32_f32` | f32 → i32 | (True, False) | (True, True) | (True, False) | SDWA omod/clamp applied as a float to the integer exponent | The issue's table lists `v_cvt_off_f32_i4` as (False, False) on the HLSL side. The HLSL code actually returned (True, False), because it read `parts[3] = "f32"` as the source type. That difference doesn't show in the result: neg/abs only touch bit 31, sext only touches bits above the selected byte, and the conversion reads bits 3:0. The destination flag is what showed. The new function gives the interpreter's old answer for every VOP1/VOP2/VOPC mnemonic in `rdna2_ops.py` (319 names, checked by script). It differs from the old HLSL copy only on the four instructions above and on `v_cvt_pkrtz_f16_f32`, which neither back end implements yet. One behaviour change on both sides: SDWA **omod** on an integer result is now refused by name, the same way SDWA clamp already was ("SDWA clamp/omod not supported on an integer result"). Before, the interpreter ignored it and the HLSL applied it to `v_frexp_exp_i32_f32`. LLVM only encodes SDWA omod when the destination is a float (`HasSDWAOMod`), and what hardware does with it on an integer result has not been measured. Under rule 3 the instruction is refused instead of guessing. Linked issue: Fixes #205 ## Verification The runtime was built from this branch with VS 2022 Build Tools CMake (`cmake -S runtime -B runtime/build -A x64`, `cmake --build runtime/build --config Release`). Laptop with three adapters: ``` python -m pytest (RTX 4060 Laptop, default) → 1187 passed, 17 skipped ANYXBOXX_GPU=warp python -m pytest (WARP) → 1187 passed, 17 skipped ANYXBOXX_GPU=Intel python -m pytest (Intel UHD a78b, no FP64) → 1185 passed, 19 skipped python -m pytest tests/test_rdna2_sdwa_dpp_types.py → 23 passed on each of the three adapters python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools → All checks passed! ``` Why tests were skipped: 15 need the Rust crates or the TomBox DLLs, which this PR doesn't touch and which weren't built here. 2 need `spirv-as`/`spirv-val`. On Intel, 2 more are FP64 tests. Same GPU tests with `rdna2_exec_ext.py` and `rdna2_hlsl_ext.py` reverted to `main` (the new test file kept), on each of RTX, WARP and Intel: `3 failed, 1 passed`. - `[flr_rpi_neg_abs]`: the output memory differs, because the HLSL drops neg/abs. - `[cvt_off_omod_sext]`: the output memory differs, because the HLSL drops omod. - `[cvt_off_clamp]`: `Untranslatable: SDWA clamp ... v_cvt_off_f32_i4`. - `[frexp_exp_neg_abs]` passes on `main`, as expected: both sides already applied neg/abs to its f32 source, and its divergence was on the destination. That divergence is covered by the refusal test below. ## Oracle and test data New file `tests/test_rdna2_sdwa_dpp_types.py` (23 tests). It builds its programs from the existing encoders (`vop1`, `sdwa_word`, `dpp16_word`, `run_wave`, `compare`, `store_lane`), so it adds no external data. - `test_sdwa_and_dpp16_type_modifiers_match_interpreter_on_gpu[...]` (4 groups) is the byte-for-byte interpreter/HLSL comparison (rule 4) on GPU or WARP. The groups cover: SDWA neg, abs and neg+abs, and DPP16 `quad_perm:[1,0,3,2]` neg/abs, on flr/rpi with 16 f32 inputs per lane (±halves, −0.0, 1e10 saturation, 1e-3); SDWA neg+abs and DPP16 neg on `v_frexp_exp_i32_f32`; SDWA omod ×2 and ×0.5 with `BYTE_1` + sext, and clamp, on `v_cvt_off_f32_i4`. 4 → 3 fail on `main` (see above). - `test_sdwa_output_modifiers_on_an_integer_result_are_refused_by_name` (4 cases): clamp or omod on the i32 results of `v_frexp_exp_i32_f32`, `v_cvt_flr_i32_f32` and `v_cvt_rpi_i32_f32` must be refused by name in both back ends. 3 of 4 fail on `main`; the rpi + clamp case was already refused by both. - Interpreter values worked out by hand from the ISA descriptions: `floor(-2.5) = -3`, `floor(-|2.5| + 0.5) = -2`, `7/16 × 2 = 0.875`, `clamp(-1/16) = 0`, `-1/16 × 0.5 = -0.03125`. These already passed on `main`, because the interpreter was right. - `test_operand_types_follow_the_mnemonic` (12 names) and `test_interpreter_and_hlsl_share_one_definition` fail on `main`, because the shared function doesn't exist there. The suite crosses 1,200 tests, so the 9 READMEs go from `1100+` to `1200+`. ### Out of scope Both back ends treat these the same way, so there is no parity bug, but they may be wrong compared with hardware or LLVM: - `v_cmp_class_f32` / `v_cmpx_class_f32` in SDWA: src1 is the i32 class mask. LLVM gives it sext (`Int32SDWAInputMods`), but both back ends treat it as f32 (neg/abs, no sext). The interpreter has no SDWA table entry for class compares (`VECTOR_COMPARE`), so only the HLSL would translate it today. - f16 sources in DPP16 (`v_cvt_f32_f16`, `v_*_f16`): neg/abs should act on bit 15, but both back ends treat these sources as integers and ignore neg/abs. Most of these instructions aren't implemented in either back end yet. ## 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 all 9 languages (`test_readme_sync.py` checks it). - [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 (names, slots, argument shapes, flag values, HRESULTs, IIDs, counts), with how they were obtained; no address or RVA. - [x] Code taken from another project: compatible licence and credit in `THIRD_PARTY.md`. (None taken.) AI use: written with Claude Code (Claude Opus 5.5). I reviewed and ran it on the three adapters above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Since #133 the interpreter and the HLSL recompiler each had their own
_operand_float_flags, and only the interpreter's was updated. The HLSL
copy read v_cvt_flr_i32_f32 and v_cvt_rpi_i32_f32 as integer -> integer
(SDWA/DPP16 neg/abs dropped), v_cvt_off_f32_i4 as f32 -> integer (SDWA
omod dropped, clamp refused) and v_frexp_exp_i32_f32 as f32 -> f32 (SDWA
omod/clamp applied to the integer exponent).

operand_float_flags now lives once in rdna2_exec_ext and rdna2_hlsl_ext
imports it. It reads the types from the mnemonic (destination type
before source type when both are named, as in LLVM's VOP profiles) and
gives the interpreter's previous answer for all 319 VOP1/VOP2/VOPC
mnemonics. SDWA omod on an integer result is now refused by name on both
sides, like clamp, instead of being ignored by one and applied by the
other.

Fixes #205

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:37:48 +00:00
github manually merged commit 02e5bd8d18 into gh-pr/215/base 2026-11-26 05:37:50 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.