cpu: lower memory fences, PAUSE and cache hints #620
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/626"
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?
Imported from R0Y00/Xbox2Windows. Originally posted by danielradosa on 2026-11-22T16:20:58Z.
Change
The shared lowering in
tools/ffx_version_query.pynow accepts the memory-ordering fenceslfence,mfenceandsfence,pause, and the cache hintsprefetcht0,prefetcht1,prefetcht2,prefetchnta,prefetch,prefetchw,clflush,clflushoptandclwb. Each one lowers to the MSVC intrinsic that emits the same instruction.INTEGER_HEADERnow includesimmintrin.h, for_mm_clflushoptand_mm_clwb, and gains small wrappers for the four_mm_prefetchhints and for the 3DNow!prefetch.They add 13 x64 forms to the coverage chart. Open PR #609 also covers
lfenceandmfence, in its separate SSE2 leaf translator (tools/cpu_sse2_aot.py, as a compiler barrier). Here they go through the shared lowering thatcpu_exe_aot.pyand theffx_*andbink_*translators reuse, and emit the instructions themselves. No open PR covers the other 11 forms; if #609 merges first, this PR adds 11 forms to the chart.Verification
A fence has no effect a single thread can observe.
cpu_aot_fences_hints(tests/cpu/fences_hints.asm, 7 exports) therefore loads and stores around each instruction, so a lowering that dropped or moved those accesses would change the result. It compares return values and the buffer against the native DLL and a reference model over 76 cases. The cases include prefetches of a null and an unmapped address, which never fault. Two negative controls stay rejected: a segment-relativeprefetcht0 fs:[rcx]and the invalidlock lfence. A host that raises an illegal instruction in the native fixture (forclflushopt,clwb,prefetchorprefetchw) exits 77 instead of claiming the forms.Windows 11 build 26300.9974, Ryzen 5 7600, MSVC 19.51.36256, Python 3.14.4, on
mainat9b0df70:devrelease(/O2)cpu_tests,devcpu_native_archive_readerandcpu_native_archive_blast, which need the Zig-builtarchive_reader.exe(ziglangis not installed on this machine)tools/form_coverage.pyon a JUnit run ofmainplus this PR and the two companion PRs below lists all 13 forms as covered. x64 coverage goes from 551 (the published chart for9b0df70) to 573 of 948 with all three.Evidence and follow-up
The intrinsics also act as compiler barriers, so
/O2does not move the surrounding accesses. The test only shows this for one thread; it says nothing about ordering as another processor observes it.Companion PRs from the same session, independent of this one and of each other: x87
ftst/fxam/ficom/ficomp/fnop/fnclex(#627), andcmpxchg8b/cmpxchg16b(#628).AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-22T16:21:07Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
d4a31cfℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-22T18:25:21Z.
Verification of
d4a31cfon an Intel Core i7-6820HQ (Skylake client,Intel64 Family 6 Model 94), Windows 11 26100.9168, MSVC/ML64 19.52.37029,devpreset. It merges cleanly withmain, and all 115cpu_tests pass.On this host, though, the new test does not check anything beyond its two rejection controls:
Skylake client CPUs do not implement
CLWB, soclwb_storeraises #UD natively. The check then returns 77 for the whole test. As a result, theMFENCE/LFENCE/SFENCE,PAUSEand prefetch cases are never compared on any host withoutCLWB, which includes Intel client CPUs before Ice Lake.A narrower gate would keep those cases running: check CPUID leaf 7, EBX bit 24 (
CLWB) up front, skip onlyclwb_store, and run the remaining exports. Reporting the skipped export by name would also keep the capability skip visible.AI-assisted: run and summarized with Claude Code; outputs copied from the local runs.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T21:58:08Z.
The Skylake report above shows why the green job alone cannot confirm this fixture: missing CLWB makes the whole test exit 77 before it reaches PAUSE or completes the repetitions. Please keep the required fences/PAUSE cases running to completion and split optional CLWB/CLFLUSHOPT and vendor prefetch forms into separate capability-gated cases with named skip results. Continue treating an unexpected translated-side illegal instruction as a failure. That will make the Windows CI result interpretable across older and newer hosts.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T23:02:13Z.
I split the cases in
089afa5.cpu_aot_fences_hintsalways runs the 34 baseline fence, PAUSE and standard prefetch cases and the two rejection controls. AMD prefetch, CLFLUSH, CLFLUSHOPT and CLWB each have a separate CTest. Local native/AOT checks passed all 76 cases at/Odand/O2. A synthetic illegal-instruction control confirmed that only an unavailable optional native case exits 77; the same error in a baseline or lifted case still fails. The two Windows CI jobs are running on the updated branch.Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-22T23:22:44Z.
Re-checked
089afa5on the same Skylake client CPU (i7-6820HQ, no CLWB), which previously skipped the whole fixture. Windows 11 26100.9168, MSVC/ML64 19.52.37029,devpreset. It merges cleanly withmain, and all 132cpu_tests pass.The split works as intended on this host. The required fence, PAUSE and standard prefetch cases now run to completion, the optional CLFLUSH, CLFLUSHOPT and AMD-prefetch cases each run on their own, and only CLWB is a named capability skip.
AI-assisted (Claude Code).