From 2e5fdca416ef1f99ee8e09d8dc6b5c05adc4ec9d Mon Sep 17 00:00:00 2001 From: legacy-code-archaeologist <359844974+legacy-code-archaeologist@users.noreply.github.com> Date: Tue, 24 Nov 2026 23:30:43 +0100 Subject: [PATCH] tests: pin the SDWA v_movrel* selections without a GPU Follow-up to ChazY11's review of #1934: the device-free pixel_aot_check.py run only checked that SDWA_MOVREL_BODY translates, so dropping the source selection still passed it (the draw caught it). SDWA_MOVREL_PINS now lists the exact expression each source and destination selection of the body produces, with temporaries as \d+, and how often it must appear (once per static move, once per reachable destination of a dynamic one). Each of five one-line mutations of tools/pixel_aot.py, applied alone, now makes `python -B tests/pixel_aot_check.py` exit 1: the source selection dropped (the reported survivor), sext ignored, the single-destination selection dropped, the dynamic-destination selection dropped, and dynamic UNUSED_PRESERVE treated as UNUSED_PAD. tools/pixel_aot.py is unchanged. Refs #1917, #1934 Co-Authored-By: Claude Opus 5.5 --- docs/experiments.md | 2 +- tests/pixel_aot_check.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/docs/experiments.md b/docs/experiments.md index 1823ce2de..7554784e9 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -6708,7 +6708,7 @@ The plain VOP1 (`_e32`) and VOP3 (`_e64`) encodings of the same four moves (`v_m `v_swaprel_b32` (VOP1 only, `7e18d118` decodes as `v_swaprel_b32 v12, v24` for gfx1013 and gfx1030) exchanges VGPR[vdst + `m0[25:16]`] and VGPR[vsrc + `m0[9:0]`], the same split as `v_movrelsd_2_b32` (#1795). That reading follows the RDNA 2 naming and LLVM's definition; it has not been measured on RDNA hardware. The lowering uses the movrel `m0` rules (static, or dynamic with a proven bit mask; the same refusals). It reads both reachable sides before writing, and then gives each reachable register the source value when the destination offset selects it, the old destination value when the source offset selects it, and its old value otherwise, so a swap of a register with itself changes nothing. `SWAPREL_BODY` runs a dynamic swap between two banks (`m0` = word 3 & `0x30003`, which differs between the two `DPP_MOVREL_SETS`), then, in a second pair of banks, an overlapping swap inside one bank (`m0` = `0x30001`), a swap of a register with itself (`0x20002`) and a static swap between the banks (`0x20001`). The four bank sums (816, 117, 338, 125 and 218, 128, 338, 125) come from an independent list-swap reference. On WARP (driver 10.0.26100.8972) and an NVIDIA Quadro M1000M (driver 32.0.15.7371) on Windows 11 build 26100, with the debug layer unavailable, all 4096 pixels matched with zero error for both sets. Three controls must mismatch, and did on both adapters: a one-way `v_movrelsd_2_b32_e32` in place of the dynamic swap, swapped static `m0` halves, and the dynamic `m0` replaced by 0. The translation controls check five refusals. They also pin the generated selects without a GPU: for a static swap of v25 and v26, and for a dynamic swap with `m0` masked to `0x30001`, the swap lines must match an expected text with the temporaries renamed in order of appearance. So swapped `m0` halves, a source side that reads the wrong old value, source offsets taken from the wrong half, or a missing destination select each fail `python -B tests/pixel_aot_check.py`, not only the draw. Reproduce with `ctest --preset dev --no-tests=error -R "^pixel_aot_swaprel_" -V`. -The SDWA encodings of the four moves (`v_movreld_b32_sdwa`, `v_movrels_b32_sdwa`, `v_movrelsd_b32_sdwa`, `v_movrelsd_2_b32_sdwa`; LLVM 15 decodes `7e1886f9 00001518` as `v_movrels_b32_sdwa v12, v24 dst_sel:WORD_1 dst_unused:UNUSED_PRESERVE src0_sel:BYTE_0` for gfx1013 and gfx1030 alike) lower through the same movrel block (#1917). The source selection, with an optional `sext(...)`, applies to the indexed source word, and the destination selection to each indexed destination, as `v_mov_b32_sdwa` applies them (`sdwa_source`, `sdwa_dest`); that order follows the RDNA 2 naming and the other movrel forms and has not been measured on RDNA hardware. `UNUSED_PAD` zeroes the unselected bits and `UNUSED_PRESERVE` keeps them from that destination's own tracked old value, so under a dynamic `m0` every reachable destination merges its own word. Under a dynamic `m0` every reachable destination must hold a tracked numeric word, also for `UNUSED_PAD`, as for the other movrel forms. `UNUSED_SEXT`, `UNUSED_PRESERVE` into an untracked destination, `clamp`, 16-bit (low-half) values as source or kept destination, SGPR sources and the movrel refusals are refused. `SDWA_MOVREL_BODY` runs each move with a dynamic and a static `m0` over integer banks, mixing BYTE, WORD and DWORD selections, `sext`, `UNUSED_PAD` and `UNUSED_PRESERVE`, and exports four words through the bit-exact R32G32B32A32_UINT target. They must equal an independent SDWA model on both `DPP_MOVREL_SETS`; the expected words are (`0x008856aa 0x3600ffbb 0xffffffdd 0x332143bb` and `0x00cc56aa 0x3600ffb9 0x0048ffdd 0x887743bb`), which they did on WARP (driver 10.0.26100.8972) and an NVIDIA Quadro M1000M (driver 32.0.15.7371) on Windows 11 build 26100. Five controls must mismatch, and did on both adapters: a dropped source selection, `UNUSED_PRESERVE` turned into `UNUSED_PAD`, an ignored dynamic `m0`, the wrong source byte and a missing `sext`. The translation controls check nine refusals, the entry mask and a dynamic `UNUSED_PRESERVE` move inside one bank, where each reachable register merges its own old word, and the body is in the LLVM 15 round trip. Reproduce with `ctest --preset dev --no-tests=error -R "^pixel_aot_sdwa_movrel_" -V`. +The SDWA encodings of the four moves (`v_movreld_b32_sdwa`, `v_movrels_b32_sdwa`, `v_movrelsd_b32_sdwa`, `v_movrelsd_2_b32_sdwa`; LLVM 15 decodes `7e1886f9 00001518` as `v_movrels_b32_sdwa v12, v24 dst_sel:WORD_1 dst_unused:UNUSED_PRESERVE src0_sel:BYTE_0` for gfx1013 and gfx1030 alike) lower through the same movrel block (#1917). The source selection, with an optional `sext(...)`, applies to the indexed source word, and the destination selection to each indexed destination, as `v_mov_b32_sdwa` applies them (`sdwa_source`, `sdwa_dest`); that order follows the RDNA 2 naming and the other movrel forms and has not been measured on RDNA hardware. `UNUSED_PAD` zeroes the unselected bits and `UNUSED_PRESERVE` keeps them from that destination's own tracked old value, so under a dynamic `m0` every reachable destination merges its own word. Under a dynamic `m0` every reachable destination must hold a tracked numeric word, also for `UNUSED_PAD`, as for the other movrel forms. `UNUSED_SEXT`, `UNUSED_PRESERVE` into an untracked destination, `clamp`, 16-bit (low-half) values as source or kept destination, SGPR sources and the movrel refusals are refused. `SDWA_MOVREL_BODY` runs each move with a dynamic and a static `m0` over integer banks, mixing BYTE, WORD and DWORD selections, `sext`, `UNUSED_PAD` and `UNUSED_PRESERVE`, and exports four words through the bit-exact R32G32B32A32_UINT target. They must equal an independent SDWA model on both `DPP_MOVREL_SETS`; the expected words are (`0x008856aa 0x3600ffbb 0xffffffdd 0x332143bb` and `0x00cc56aa 0x3600ffb9 0x0048ffdd 0x887743bb`), which they did on WARP (driver 10.0.26100.8972) and an NVIDIA Quadro M1000M (driver 32.0.15.7371) on Windows 11 build 26100. Five controls must mismatch, and did on both adapters: a dropped source selection, `UNUSED_PRESERVE` turned into `UNUSED_PAD`, an ignored dynamic `m0`, the wrong source byte and a missing `sext`. The translation controls check nine refusals, the entry mask and a dynamic `UNUSED_PRESERVE` move inside one bank, where each reachable register merges its own old word, and the body is in the LLVM 15 round trip. The device-free run also pins every selection in the body: `SDWA_MOVREL_PINS` lists the exact expression each source and destination selection produces (temporaries as `\d+`) and how often it must appear, so a dropped source or destination selection, an ignored `sext` or `UNUSED_PRESERVE` treated as `UNUSED_PAD` fails `python -B tests/pixel_aot_check.py`, not only the draw. Reproduce with `ctest --preset dev --no-tests=error -R "^pixel_aot_sdwa_movrel_" -V`. The scalar relative moves `s_movrels_b32`, `s_movrels_b64`, `s_movreld_b32`, `s_movreld_b64` and `s_movrelsd_2_b32` (SOP1; LLVM 15 decodes `be942e28` as `s_movrels_b32 s20, s40` and the others alike for gfx1013 and gfx1030) lower with the same `m0` split as the vector forms (#1882): `s_movrels` reads SGPR[src + m0], `s_movreld` writes SGPR[dst + m0], and `s_movrelsd_2_b32` reads with `m0[9:0]` and writes with `m0[25:16]`; `_b64` moves a pair, with `m0` counted in dwords. That reading follows the RDNA 2 naming and the vector forms; it has not been measured on RDNA hardware. With a static `m0` the move is an `s_mov` from or to the indexed SGPR, so its tracked value (constant, expression, descriptor or pointer word) and bit mask carry over: moving the texture descriptor pointer with `s_movrels_b64 s[72:73], s[16:17]` and `m0` = 4 translates exactly like two `s_mov_b32`. A dynamic `m0` with a proven bit mask becomes a bounded select, and only over plain numeric SGPRs, so no resource depends on a runtime index; for `s_movreld` each reachable destination keeps its old value unless selected. An unbounded or non-numeric `m0`, an index past s105, a write into an outstanding scalar load, a symbolic source or destination under a dynamic `m0` and a `_b64` pair base that could be odd (a static odd offset, or a dynamic mask that allows bit 0) are refused. Every source is read before any destination is written: self-moves, overlapping pairs and a dynamic `s_movreld` whose source lies in its own destination bank are pinned by the exported constants or the generated selects. `SMOVREL_BODY` moves cbuffer-indexed words with each form, static and dynamic, and exports weighted sums (60, 67, 805, 193 and 80, 63, 244, 165 on the two `DPP_MOVREL_SETS`) from an independent reference. On WARP (driver 10.0.26100.8972) and an NVIDIA Quadro M1000M (driver 32.0.15.7371) on Windows 11 build 26100, with the debug layer unavailable, all 4096 pixels matched with zero error for both sets. Four controls must mismatch, and did on both adapters: the dynamic `m0` replaced by 0 for `s_movrels_b32`, `s_movreld_b32` and `s_movreld_b64`, and swapped static halves for `s_movrelsd_2_b32`. The translation controls check the descriptor move, the overlaps and ten refusals. Reproduce with `ctest --preset dev --no-tests=error -R "^pixel_aot_smovrel_" -V`. diff --git a/tests/pixel_aot_check.py b/tests/pixel_aot_check.py index 11c677d06..960fad1cc 100644 --- a/tests/pixel_aot_check.py +++ b/tests/pixel_aot_check.py @@ -16917,6 +16917,7 @@ def _check_controls_inline(directory): # SDWA v_movrel* (#1917): the selections apply to the indexed words; the refusals of v_mov_b32_sdwa hold. sdwa_hlsl = translate_int(uncompressed_export(SDWA_MOVREL_BODY)) assert "dpp_soff" in sdwa_hlsl and "dpp_doff" in sdwa_hlsl and "QuadRead" not in sdwa_hlsl + check_sdwa_movrel_pins(sdwa_hlsl) sdwa_bank = ["v_mov_b32_e32 v24, 0x44332211", "v_mov_b32_e32 v25, 0x88776655"] for bad_seq, message in ( (sdwa_bank + ["s_mov_b32 m0, 1", @@ -21882,6 +21883,38 @@ def case(name, words, expected): return 0 +# Device-free pins of the SDWA selections in SDWA_MOVREL_BODY (#1917): each pattern is the exact expression one source +# or destination selection produces, with temporaries as \d+, and the count is how often it must appear (once per +# static move, once per reachable destination of a dynamic one). Dropping, swapping or changing a selection fails. +SDWA_MOVREL_PINS = ( + # R: dynamic v_movrels, src0_sel:BYTE_3 into dst_sel:WORD_1 with UNUSED_PRESERVE. + (r"asfloat\(\(\(asuint\(alu\d+\) & 0xffffu\) \| \(\(\(\(asuint\(dpp_src\d+\) >> 24u\) & 0xffu\) & 0xffffu\) << 16u\)\)\)", 1), + # R: static v_movrels, sext(BYTE_1) into BYTE_0 with UNUSED_PRESERVE. + (r"asfloat\(\(\(asuint\(alu\d+\) & 0xffffff00u\) \| \(\(asuint\(asint\(asuint\(alu\d+\) << 16u\) >> 24u\) & 0xffu\) << 0u\)\)\)", 1), + # G: dynamic v_movreld, sext(BYTE_2) of the source, then WORD_0 with UNUSED_PRESERVE in each of four destinations. + (r"uint dpp_val\d+ = asuint\(asint\(asuint\(alu\d+\) << 8u\) >> 24u\);", 1), + (r"asfloat\(\(\(asuint\(alu\d+\) & 0xffff0000u\) \| \(\(dpp_val\d+ & 0xffffu\) << 0u\)\)\)", 4), + # G: static v_movreld, WORD_1 into BYTE_3 with UNUSED_PAD. + (r"asfloat\(\(\(\(\(asuint\(alu\d+\) >> 16u\) & 0xffffu\) & 0xffu\) << 24u\)\)", 1), + # B and A: dynamic moves read WORD_0 of the indexed source. + (r"uint dpp_val\d+ = \(\(asuint\(dpp_src\d+\) >> 0u\) & 0xffffu\);", 2), + # B: dynamic v_movrelsd, BYTE_2 with UNUSED_PRESERVE in each of four destinations. + (r"asfloat\(\(\(asuint\(alu\d+\) & 0xff00ffffu\) \| \(\(dpp_val\d+ & 0xffu\) << 16u\)\)\)", 4), + # B: static v_movrelsd, sext(BYTE_0) into DWORD with UNUSED_PAD. + (r"asfloat\(asuint\(asint\(asuint\(alu\d+\) << 24u\) >> 24u\)\)", 1), + # A: dynamic v_movrelsd_2, WORD_1 with UNUSED_PRESERVE in each of four destinations. + (r"asfloat\(\(\(asuint\(alu\d+\) & 0xffffu\) \| \(\(dpp_val\d+ & 0xffffu\) << 16u\)\)\)", 4), + # A: static v_movrelsd_2, BYTE_3 into BYTE_0 with UNUSED_PAD. + (r"asfloat\(\(\(\(\(asuint\(alu\d+\) >> 24u\) & 0xffu\) & 0xffu\) << 0u\)\)", 1), +) + + +def check_sdwa_movrel_pins(hlsl): + for pattern, count in SDWA_MOVREL_PINS: + found = len(re.findall(pattern, hlsl)) + assert found == count, f"SDWA movrel selection {pattern!r}: {found} occurrences, expected {count}" + + def check_swaprel_draw(directory, compiler, renderer, backend): program = with_constants(SWAPREL_BODY) source = directory / "swaprel.hlsl"