cpu: lower MOVNTPS, MOVNTPD, MOVNTDQ and MOVNTI in the shared lowering #2887
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!2887
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2887"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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 UTCWhat this does
The shared CPU lowering (
tools/ffx_version_query.py) refused four non-temporal store instructions. This PR adds them:MOVNTPS/MOVNTPD/MOVNTDQMOVAPSMOVNTIEach 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 VEXVMOVNT*forms, theMOVNTDQAload, and XMM3 and above (the same register limitMOVAPShas 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:PAGE_NOACCESStarget raises the same write fault at the same address;MOVUPSthat must not fault.Registered in
tests/cmake/cpu_nt_store.cmake, documented indocs/experiments.md.Verification
Windows 11 (26200), MSVC 19.44.35230, on head
e1d478c4(based onb505c32b):ctest --preset dev --no-tests=error -j 8 -R '^cpu_' -E '_hardware$': 297/297 passedgit diff --check,tests/docs_links_check.py,tests/bidi_controls_check.py: passAI-assisted; commands listed were executed locally.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Sir6Mr49SZWax95VApRPvz
@thepatrickworld on GitHub · 2026-11-27 08:30 UTC · original
Python-only receipt on
e1d478c4: whatcpu_nt_storepins, and where the two new entries runNot 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
iced-x86==1.21.0andpefile==2024.8.26(the pins ofrequirements-dev.txt)e1d478c4bea003ab8ae51dc8ad4d8b2cefcd0f1a, baseb505c32b20fee62bafd51f86a87a26a6f48b5ecb, in two separate worktrees,git status --porcelain --untracked-files=noempty in bothCommands
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:base, rc 1:
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.pyand injected throughsys.path; the baseline mutant is the unmodified file and passes. Each run costs about a second and no build:& 15u→& 7u0f2b01 checks 16-byte alignment: MISMATCHmemcpy(&value, …, 16)→, 8)PASS)0f2b01 raises the fault before the store: MISMATCHand i.encoding == EncodingKind.LEGACYremovedPASS)i.op1_register in wide_xmmremovedKeyError: 80(XMM3), a crash, not aMISMATCH_mm_stream_si128→_mm_stream_si640f2b01 stores with _mm_stream_si128: MISMATCHsi32480fc301 stores with _mm_stream_si64: MISMATCHraise_aligned_m128_fault()call removed0f2b01 checks 16-byte alignment: MISMATCHshuffle_ops(line 602)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:
_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.LEGACYis 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 toMOVNTPS/MOVNTPD/MOVNTDQand all 348 reportEncodingKind.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
princlude regex (CMakePresets.json:45) matches neither name.windows.yml:486/489runscmake --build --preset prandctest --preset pron apull_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.python-linuxjob has noif:(windows.yml:181, so it runs on pull requests) and readstests/checks/python-linux/*.txt—tests/checks/README.md:9/14documents exactly this as the way to add a check that already exists inline.tests/cpu/nt_store_check.pyruns on Linux as-is (this receipt is that run), so a one-linepython-linux/nt_store.txtputs the text half of this PR in front of every pull request without touching a preset.princlude regex and theprbuild target list (CMakePresets.json:28-33), since--build --preset prwould 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:1885says "XMM3 and above stay refused" without reserve. In a body that also carries a VEX shuffle,wide_xmmgains XMM3 (ffx_version_query.py:543) andmovntps [rcx], xmm3is accepted, storingwide3— measured withc5f8c6c100+0f2b19. That is exactly what MOVAPS does, asnt_store_check.py:41says ("the register set MOVAPS has here"), so it is the doc sentence that over-promises, not the test.movntps [rip+0x10]andmovnti [rip+0x10]are refused withValueError("unsupported query operation …"); on this head the same bytes reachglobals_[i.ip_rel_memory_address](line 831) and raise an uncaughtKeyError(23).MOVAPS/MOVUPS/MOVDQAdo 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 theValueErrorthe translator drivers report as a refusal (cpu_switch_aot.py:1957,fuzz_cpu.py:2191). Non-blocking.Limits
_mm_stream_si64and the SEH fault records are unverified here. Every statement above about the fixture is a reading of the emitted code and of its 64-bytememcmp, not a run.SFENCE, so a plain aligned store would pass the aligned cases.lower(..., globals_={}), so the RIP-relative class above is structurally invisible to it.AI-assisted.
@R0Y00 on GitHub · 2026-11-27 08:42 UTC · original · approved these changes
Reviewed
e1d478c4integrated withmain0e704468(f1ec3871locally). 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_fixtureandcpu_hint_nop_fixtureand ranctest --preset <dev|release> --no-tests=error -V -R '^cpu_(nt_store|nt_store_fixture|hint_nop|hint_nop_fixture)$'. Debug and Release/O2each 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.