cpu: lower MOVNTPS, MOVNTPD, MOVNTDQ and MOVNTI in the shared lowering #2887

Manually merged
github merged 1 commit from github-bot/gh-2887 into gh-pr/2887/base 2026-11-27 08:49:20 +00:00 AGit
Owner

@⁠Miffedrandir on GitHub · 2026-11-26 16:36 UTC · original
Miffedrandir:cpu/nt-stores → main · +383 −0 · 5 files · 1 commits · merged 2026-11-27 08:48 UTC

What this does

The shared CPU lowering (tools/ffx_version_query.py) refused four non-temporal store instructions. This PR adds them:

Instruction Stores Alignment
MOVNTPS / MOVNTPD / MOVNTDQ 16 bytes from XMM0–XMM2 must be 16-byte aligned, faults like MOVAPS
MOVNTI a 32- or 64-bit register none

Each one becomes the matching streaming-store intrinsic (_mm_stream_si128, _mm_stream_si32, _mm_stream_si64), so it behaves like the original instruction. No flags change.

Still refused: MOVNTQ (MMX), MOVNTSS/MOVNTSD (SSE4a), the VEX VMOVNT* forms, the MOVNTDQA load, and XMM3 and above (the same register limit MOVAPS has here).

Tests

  • cpu_nt_store (tests/cpu/nt_store_check.py): 8 encodings must lower, 8 neighbouring encodings must stay refused.
  • cpu_nt_store_fixture (tests/cpu/nt_store_fixture.py): runs the real instruction bytes and the lowered C++ side by side and compares the written bytes and any fault:
    • aligned, displaced and odd-address stores match byte for byte;
    • misaligned XMM targets fault the same way, with nothing written;
    • a PAGE_NOACCESS target raises the same write fault at the same address;
    • three controls must fail: no alignment check, no store, and a plain MOVUPS that must not fault.

Registered in tests/cmake/cpu_nt_store.cmake, documented in docs/experiments.md.

Verification

Windows 11 (26200), MSVC 19.44.35230, on head e1d478c4 (based on b505c32b):

ctest --preset dev --no-tests=error -j 1 -R '^cpu_(nt_store|nt_store_fixture|hint_nop|hint_nop_fixture)$' -V
ctest --preset release --no-tests=error -j 1 -R '^cpu_(nt_store|nt_store_fixture|hint_nop|hint_nop_fixture)$' -V
  • dev: 4/4 passed
  • release: 4/4 passed
  • ctest --preset dev --no-tests=error -j 8 -R '^cpu_' -E '_hardware$': 297/297 passed
  • git diff --check, tests/docs_links_check.py, tests/bidi_controls_check.py: pass

AI-assisted; commands listed were executed locally.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Sir6Mr49SZWax95VApRPvz

**@⁠Miffedrandir** on GitHub · 2026-11-26 16:36 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2887) `Miffedrandir:cpu/nt-stores` → `main` · +383 −0 · 5 files · 1 commits · merged 2026-11-27 08:48 UTC ## What this does The shared CPU lowering (`tools/ffx_version_query.py`) refused four non-temporal store instructions. This PR adds them: | Instruction | Stores | Alignment | |---|---|---| | `MOVNTPS` / `MOVNTPD` / `MOVNTDQ` | 16 bytes from XMM0–XMM2 | must be 16-byte aligned, faults like `MOVAPS` | | `MOVNTI` | a 32- or 64-bit register | none | Each one becomes the matching streaming-store intrinsic (`_mm_stream_si128`, `_mm_stream_si32`, `_mm_stream_si64`), so it behaves like the original instruction. No flags change. **Still refused:** `MOVNTQ` (MMX), `MOVNTSS`/`MOVNTSD` (SSE4a), the VEX `VMOVNT*` forms, the `MOVNTDQA` load, and XMM3 and above (the same register limit `MOVAPS` has here). ## Tests - `cpu_nt_store` (`tests/cpu/nt_store_check.py`): 8 encodings must lower, 8 neighbouring encodings must stay refused. - `cpu_nt_store_fixture` (`tests/cpu/nt_store_fixture.py`): runs the real instruction bytes and the lowered C++ side by side and compares the written bytes and any fault: - aligned, displaced and odd-address stores match byte for byte; - misaligned XMM targets fault the same way, with nothing written; - a `PAGE_NOACCESS` target raises the same write fault at the same address; - three controls must fail: no alignment check, no store, and a plain `MOVUPS` that must not fault. Registered in `tests/cmake/cpu_nt_store.cmake`, documented in `docs/experiments.md`. ## Verification Windows 11 (26200), MSVC 19.44.35230, on head `e1d478c4` (based on `b505c32b`): ``` ctest --preset dev --no-tests=error -j 1 -R '^cpu_(nt_store|nt_store_fixture|hint_nop|hint_nop_fixture)$' -V ctest --preset release --no-tests=error -j 1 -R '^cpu_(nt_store|nt_store_fixture|hint_nop|hint_nop_fixture)$' -V ``` - dev: 4/4 passed - release: 4/4 passed - `ctest --preset dev --no-tests=error -j 8 -R '^cpu_' -E '_hardware$'`: 297/297 passed - `git diff --check`, `tests/docs_links_check.py`, `tests/bidi_controls_check.py`: pass AI-assisted; commands listed were executed locally. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Sir6Mr49SZWax95VApRPvz
MOVNTPS, MOVNTPD and MOVNTDQ from XMM0-XMM2 (the registers the shared
lowering models for MOVAPS) and MOVNTI from a 32- or 64-bit register
lower to their streaming-store intrinsics, so the non-temporal hint and
the weak ordering stay the guest's. The XMM forms keep the 16-byte
alignment fault of MOVAPS before anything is written; MOVNTI has no
alignment rule. MOVNTQ, MOVNTSS/MOVNTSD, the VEX forms and the MOVNTDQA
load stay refused.

cpu_nt_store pins the accepted encodings and the refused neighbours.
cpu_nt_store_fixture compares native bytes with the lowered C++ for
aligned, displaced and odd-address stores, misaligned XMM targets and a
PAGE_NOACCESS target, with three controls that must break a rule.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Sir6Mr49SZWax95VApRPvz
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 01:27:57 +00:00
Author
Owner

@⁠thepatrickworld on GitHub · 2026-11-27 08:30 UTC · original

Python-only receipt on e1d478c4: what cpu_nt_store pins, and where the two new entries run

Not a code change; measurements only. The C++ fixture (and its native arm) did not run here — this host is Linux with no MSVC and no Windows SEH, see Limits.

Environment

  • Linux 7.0.0-38-generic, Python 3.11.16, iced-x86==1.21.0 and pefile==2024.8.26 (the pins of requirements-dev.txt)
  • head e1d478c4bea003ab8ae51dc8ad4d8b2cefcd0f1a, base b505c32b20fee62bafd51f86a87a26a6f48b5ecb, in two separate worktrees, git status --porcelain --untracked-files=no empty in both
  • no file of either tree was modified: the mutants below live in copies whose sha256 is printed by the harness

Commands

cd wt2887      && python3 -B tests/cpu/nt_store_check.py     # head
cd wt2887_base && python3 -B tests/cpu/nt_store_check.py     # same file copied into the base tree

The check resolves tools/ from its own path, so the cwd does not matter — the head prints the same result from /tmp.

Observed

head, rc 0, 37 assertion lines, no MISMATCH:

PASS: 8 non-temporal stores lowered, 8 neighbours still refused

base, rc 1:

accepted 0f2b5110 (movntps [rcx+16], xmm2): MISMATCH (unsupported query operation at 0x0: movntps [rcx+10h],xmm2)
...
FAIL: 8 case(s)

The eight failures are exactly the eight accepted encodings. The eight refusal assertions already hold on the base (movntps [rcx], xmm3, MOVNTQ, MOVNTSS/MOVNTSD, the three VEX forms, MOVNTDQA), so they do not separate the two trees; the accepted half does.

What the check does not pin

Nine textual mutants of the added block, applied to copies of tools/ffx_version_query.py and injected through sys.path; the baseline mutant is the unmodified file and passes. Each run costs about a second and no build:

mutant verdict first failure
alignment mask & 15u → & 7u killed 0f2b01 checks 16-byte alignment: MISMATCH
memcpy(&value, …, 16) → , 8) survives — (PASS)
fault emitted after the store killed 0f2b01 raises the fault before the store: MISMATCH
and i.encoding == EncodingKind.LEGACY removed survives — (PASS)
i.op1_register in wide_xmm removed killed KeyError: 80 (XMM3), a crash, not a MISMATCH
_mm_stream_si128 → _mm_stream_si64 killed 0f2b01 stores with _mm_stream_si128: MISMATCH
MOVNTI 64-bit emitted as si32 killed 480fc301 stores with _mm_stream_si64: MISMATCH
the raise_aligned_m128_fault() call removed killed 0f2b01 checks 16-byte alignment: MISMATCH
the three opcodes removed from shuffle_ops (line 602) killed accepted 0f2b01 …: MISMATCH (unsupported query operation …)

So seven of eight non-equivalent mutants die in a second, without a build — useful as a fast first gate. Two remarks on the survivors:

  • The copied width is not pinned by the check. It counts _mm_stream_si128( and matches the literal alignment line, never , 16). Only the C++ fixture sees the width, and it sees it through the 64-byte buffer comparison rather than an assertion: with , 8) the streaming store still writes 16 bytes, of which 8 are indeterminate stack (__m128i value; is uninitialised). __m128i value{}; would make that catch deterministic, and a , 16) assertion in the check would fail it before the fixture is even built.
  • and i.encoding == EncodingKind.LEGACY is equivalent for these three opcodes, verified rather than assumed: over 1 624 prefixed patterns (406 prefix heads, REX and 66 in both orders), 348 decode to MOVNTPS/MOVNTPD/MOVNTDQ and all 348 report EncodingKind.LEGACY (int 0), so the guard cannot change an outcome. Seven of eight, then, not seven of nine.

Also worth knowing when reading the score: four of the seven kills come from matching emitted text (the literal alignment line, find() ordering, the intrinsic name), so this is the sensitivity of those assertions, not behavioural coverage. A semantically identical rewrite — (target & 15u) != 0 — would fail the check.

Where the two entries run

  • The pr include regex (CMakePresets.json:45) matches neither name. windows.yml:486/489 runs cmake --build --preset pr and ctest --preset pr on a pull_request, and --preset dev -E '_hardware$' otherwise. Neither entry carries _hardware, so both run on the push sweep after merge and neither runs before it.
  • The python-linux job has no if: (windows.yml:181, so it runs on pull requests) and reads tests/checks/python-linux/*.txt — tests/checks/README.md:9/14 documents exactly this as the way to add a check that already exists inline. tests/cpu/nt_store_check.py runs on Linux as-is (this receipt is that run), so a one-line python-linux/nt_store.txt puts the text half of this PR in front of every pull request without touching a preset.
  • For the fixture the same move needs two edits — the pr include regex and the pr build target list (CMakePresets.json:28-33), since --build --preset pr would not build the executable — and whether an extra exe belongs in the Windows PR smoke is your call, not mine.

Two notes from the same run

  • docs/experiments.md:1885 says "XMM3 and above stay refused" without reserve. In a body that also carries a VEX shuffle, wide_xmm gains XMM3 (ffx_version_query.py:543) and movntps [rcx], xmm3 is accepted, storing wide3 — measured with c5f8c6c100 + 0f2b19. That is exactly what MOVAPS does, as nt_store_check.py:41 says ("the register set MOVAPS has here"), so it is the doc sentence that over-promises, not the test.
  • RIP-relative operands: on the base, movntps [rip+0x10] and movnti [rip+0x10] are refused with ValueError("unsupported query operation …"); on this head the same bytes reach globals_[i.ip_rel_memory_address] (line 831) and raise an uncaught KeyError(23). MOVAPS/MOVUPS/MOVDQA do the same on both trees, so the class is older than this PR and one guard upstream would fix all of it — but four more opcodes now reach a path that raises something other than the ValueError the translator drivers report as a refusal (cpu_switch_aot.py:1957, fuzz_cpu.py:2191). Non-blocking.

Limits

  • One host, Linux, no Windows: the fixture, its native arm, the availability of _mm_stream_si64 and the SEH fault records are unverified here. Every statement above about the fixture is a reading of the emitted code and of its 64-byte memcmp, not a run.
  • The matrix is textual substitution, so it says nothing about a rewrite of the lowering.
  • Nothing here exercises the non-temporal hint or the ordering property: every fixture case ends with SFENCE, so a plain aligned store would pass the aligned cases.
  • The check calls lower(..., globals_={}), so the RIP-relative class above is structurally invisible to it.

AI-assisted.

**@⁠thepatrickworld** on GitHub · 2026-11-27 08:30 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2887#issuecomment-7213620679) **Python-only receipt on `e1d478c4`: what `cpu_nt_store` pins, and where the two new entries run** Not a code change; measurements only. The C++ fixture (and its native arm) did not run here — this host is Linux with no MSVC and no Windows SEH, see Limits. ### Environment - Linux 7.0.0-38-generic, Python 3.11.16, `iced-x86==1.21.0` and `pefile==2024.8.26` (the pins of `requirements-dev.txt`) - head `e1d478c4bea003ab8ae51dc8ad4d8b2cefcd0f1a`, base `b505c32b20fee62bafd51f86a87a26a6f48b5ecb`, in two separate worktrees, `git status --porcelain --untracked-files=no` empty in both - no file of either tree was modified: the mutants below live in copies whose sha256 is printed by the harness ### Commands ``` cd wt2887 && python3 -B tests/cpu/nt_store_check.py # head cd wt2887_base && python3 -B tests/cpu/nt_store_check.py # same file copied into the base tree ``` The check resolves `tools/` from its own path, so the cwd does not matter — the head prints the same result from `/tmp`. ### Observed head, rc 0, 37 assertion lines, no `MISMATCH`: ``` PASS: 8 non-temporal stores lowered, 8 neighbours still refused ``` base, rc 1: ``` accepted 0f2b5110 (movntps [rcx+16], xmm2): MISMATCH (unsupported query operation at 0x0: movntps [rcx+10h],xmm2) ... FAIL: 8 case(s) ``` The eight failures are exactly the eight accepted encodings. The eight refusal assertions already hold on the base (`movntps [rcx], xmm3`, MOVNTQ, MOVNTSS/MOVNTSD, the three VEX forms, MOVNTDQA), so they do not separate the two trees; the accepted half does. ### What the check does not pin Nine textual mutants of the added block, applied to copies of `tools/ffx_version_query.py` and injected through `sys.path`; the baseline mutant is the unmodified file and passes. Each run costs about a second and no build: | mutant | verdict | first failure | |---|---|---| | alignment mask `& 15u` → `& 7u` | killed | `0f2b01 checks 16-byte alignment: MISMATCH` | | `memcpy(&value, …, 16)` → `, 8)` | **survives** | — (`PASS`) | | fault emitted after the store | killed | `0f2b01 raises the fault before the store: MISMATCH` | | `and i.encoding == EncodingKind.LEGACY` removed | **survives** | — (`PASS`) | | `i.op1_register in wide_xmm` removed | killed | `KeyError: 80` (XMM3), a crash, not a `MISMATCH` | | `_mm_stream_si128` → `_mm_stream_si64` | killed | `0f2b01 stores with _mm_stream_si128: MISMATCH` | | MOVNTI 64-bit emitted as `si32` | killed | `480fc301 stores with _mm_stream_si64: MISMATCH` | | the `raise_aligned_m128_fault()` call removed | killed | `0f2b01 checks 16-byte alignment: MISMATCH` | | the three opcodes removed from `shuffle_ops` (line 602) | killed | `accepted 0f2b01 …: MISMATCH (unsupported query operation …)` | So seven of eight non-equivalent mutants die in a second, without a build — useful as a fast first gate. Two remarks on the survivors: - **The copied width is not pinned by the check.** It counts `_mm_stream_si128(` and matches the literal alignment line, never `, 16)`. Only the C++ fixture sees the width, and it sees it through the 64-byte buffer comparison rather than an assertion: with `, 8)` the streaming store still writes 16 bytes, of which 8 are indeterminate stack (`__m128i value;` is uninitialised). `__m128i value{};` would make that catch deterministic, and a `, 16)` assertion in the check would fail it before the fixture is even built. - **`and i.encoding == EncodingKind.LEGACY` is equivalent for these three opcodes**, verified rather than assumed: over 1 624 prefixed patterns (406 prefix heads, REX and 66 in both orders), 348 decode to `MOVNTPS`/`MOVNTPD`/`MOVNTDQ` and all 348 report `EncodingKind.LEGACY` (int 0), so the guard cannot change an outcome. Seven of eight, then, not seven of nine. Also worth knowing when reading the score: four of the seven kills come from matching emitted text (the literal alignment line, `find()` ordering, the intrinsic name), so this is the sensitivity of those assertions, not behavioural coverage. A semantically identical rewrite — `(target & 15u) != 0` — would fail the check. ### Where the two entries run - The `pr` include regex (`CMakePresets.json:45`) matches neither name. `windows.yml:486/489` runs `cmake --build --preset pr` and `ctest --preset pr` on a `pull_request`, and `--preset dev -E '_hardware$'` otherwise. Neither entry carries `_hardware`, so both run on the push sweep after merge and neither runs before it. - The `python-linux` job has no `if:` (`windows.yml:181`, so it runs on pull requests) and reads `tests/checks/python-linux/*.txt` — `tests/checks/README.md:9/14` documents exactly this as the way to add a check that already exists inline. `tests/cpu/nt_store_check.py` runs on Linux as-is (this receipt is that run), so a one-line `python-linux/nt_store.txt` puts the text half of this PR in front of every pull request without touching a preset. - For the fixture the same move needs two edits — the `pr` include regex and the `pr` build target list (`CMakePresets.json:28-33`), since `--build --preset pr` would not build the executable — and whether an extra exe belongs in the Windows PR smoke is your call, not mine. ### Two notes from the same run - `docs/experiments.md:1885` says "XMM3 and above stay refused" without reserve. In a body that also carries a VEX shuffle, `wide_xmm` gains XMM3 (`ffx_version_query.py:543`) and `movntps [rcx], xmm3` is accepted, storing `wide3` — measured with `c5f8c6c100` + `0f2b19`. That is exactly what MOVAPS does, as `nt_store_check.py:41` says ("the register set MOVAPS has here"), so it is the doc sentence that over-promises, not the test. - RIP-relative operands: on the base, `movntps [rip+0x10]` and `movnti [rip+0x10]` are refused with `ValueError("unsupported query operation …")`; on this head the same bytes reach `globals_[i.ip_rel_memory_address]` (line 831) and raise an uncaught `KeyError(23)`. `MOVAPS`/`MOVUPS`/`MOVDQA` do the same on both trees, so the class is older than this PR and one guard upstream would fix all of it — but four more opcodes now reach a path that raises something other than the `ValueError` the translator drivers report as a refusal (`cpu_switch_aot.py:1957`, `fuzz_cpu.py:2191`). Non-blocking. ### Limits - One host, Linux, no Windows: the fixture, its native arm, the availability of `_mm_stream_si64` and the SEH fault records are unverified here. Every statement above about the fixture is a reading of the emitted code and of its 64-byte `memcmp`, not a run. - The matrix is textual substitution, so it says nothing about a rewrite of the lowering. - Nothing here exercises the non-temporal hint or the ordering property: every fixture case ends with `SFENCE`, so a plain aligned store would pass the aligned cases. - The check calls `lower(..., globals_={})`, so the RIP-relative class above is structurally invisible to it. _AI-assisted._
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-27 08:42 UTC · original · approved these changes

Reviewed e1d478c4 integrated with main 0e704468 (f1ec3871 locally). The shared lowering emits streaming-store intrinsics, preserves the XMM alignment fault and uses the existing fence lowering for guest fences.

I rebuilt cpu_nt_store_fixture and cpu_hint_nop_fixture and ran ctest --preset <dev|release> --no-tests=error -V -R '^cpu_(nt_store|nt_store_fixture|hint_nop|hint_nop_fixture)$'. Debug and Release /O2 each passed 4/4 with no skips on Windows 11 x64 with MSVC 19.51. The 14 source-built native-versus-lowered store cases matched for bytes and faults, including odd MOVNTI targets, SIMD alignment faults and PAGE_NOACCESS write faults. The three negative controls distinguished losing alignment, removing the store and substituting an unaligned move. Hosted Windows, Linux Python and gfx1013 checks passed.

**@⁠R0Y00** on GitHub · 2026-11-27 08:42 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2887#pullrequestreview-6085522825) · **approved these changes** Reviewed `e1d478c4` integrated with `main` `0e704468` (`f1ec3871` locally). The shared lowering emits streaming-store intrinsics, preserves the XMM alignment fault and uses the existing fence lowering for guest fences. I rebuilt `cpu_nt_store_fixture` and `cpu_hint_nop_fixture` and ran `ctest --preset <dev|release> --no-tests=error -V -R '^cpu_(nt_store|nt_store_fixture|hint_nop|hint_nop_fixture)$'`. Debug and Release `/O2` each passed 4/4 with no skips on Windows 11 x64 with MSVC 19.51. The 14 source-built native-versus-lowered store cases matched for bytes and faults, including odd MOVNTI targets, SIMD alignment faults and PAGE_NOACCESS write faults. The three negative controls distinguished losing alignment, removing the store and substituting an unaligned move. Hosted Windows, Linux Python and gfx1013 checks passed.
github-bot changed target branch from main to gh-pr/2887/base 2026-11-27 08:49:19 +00:00
github manually merged commit e1d478c4be into gh-pr/2887/base 2026-11-27 08:49:20 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.