Repository navigation
cpu: lower memory fences, PAUSE and cache hints - #626
Conversation
The shared lowering now accepts LFENCE, MFENCE, SFENCE and PAUSE, and the cache hints PREFETCHT0, PREFETCHT1, PREFETCHT2, PREFETCHNTA, PREFETCH, PREFETCHW, CLFLUSH, CLFLUSHOPT and CLWB, each through the MSVC intrinsic that emits the same instruction. INTEGER_HEADER includes immintrin.h and gains wrappers for the four PREFETCHh hints and for PREFETCH. A fence has no effect one thread can observe, so cpu_aot_fences_hints checks that each of 7 exports keeps the loads and stores around the instruction, including prefetches of a null and an unmapped address, against the native DLL and a reference model over 76 cases. A segment-relative prefetch and the invalid LOCK LFENCE stay rejected. A host that raises an illegal instruction in the native fixture exits 77.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour 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. |
|
Verification of On this host, though, the new test does not check anything beyond its two rejection controls: Skylake client CPUs do not implement A narrower gate would keep those cases running: check CPUID leaf 7, EBX bit 24 ( AI-assisted: run and summarized with Claude Code; outputs copied from the local runs. |
|
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. |
|
I split the cases in |
|
Re-checked 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). |
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
mainat 9b0df70: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 for 9b0df70) 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.