cpu: lower RDTSC and RDTSCP in the shared lowering #783
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/789"
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 legacy-code-archaeologist on 2026-11-23T03:28:25Z.
Change
Lowers RDTSC and RDTSCP in
tools/ffx_version_query.pyas the explicit host TSC profile from #739. The reads supply host ticks and, for RDTSCP, the host IA32_TSC_AUX. There is no guarantee of a guest TSC frequency or of a virtual-CPU number.__rdtsc()and__rdtscp(). It adds no fence to the generated code.volatilelocal, so a read stays in the code even when the guest overwrites its result. Withoutvolatile, MSVC/O2removes such an RDTSC. Theplaincontrol below shows this.Tests
cpu_aot_rdtsc(rdtsc.asm) runs on every host. It covers one RDTSC, two RDTSC in a row, and one RDTSC whose result is overwritten.cpu_aot_rdtscp(rdtscp.asm) covers one RDTSCP and one RDTSCP whose result is overwritten. It exits 77 on a host without RDTSCP (CPUID 80000001h EDX bit 27). It also exits 77, after its other checks, when TSC_AUX is 0 on every processor of the affinity mask. RDTSCP has its own source file, so its coverage follows only this test.rdtsc_harness.asmis never translated. It supplies CPUID and the bracket reads, each serialized by LFENCE before and after. It has no coverage header and is listed as a native harness intools/form_coverage.py.Both checks pin the thread to one logical processor and confirm through
GetCurrentProcessorNumberthat it runs there before reading. Over 2,000 rounds they require:add r8, r8).Controls: each mutated C++ control must break a property:
constant(zero counter),swap,noext,stale(each read keeps its first value),flags.swap,noext,noaux,pflags./O2builds: the translation is also built withcl /O2. A walk that follows every branch from each export must find every RDTSC and RDTSCP of the source, and the/O2build must keep the properties. Theplaincontrol removesvolatileand is built only at/O2. There the walk must report the overwritten RDTSC missing.Verification
At
749131fon Windows 11 Pro (build 26100), Intel Core i7-6820HQ (RDTSCP present, TSC_AUX 0x7 on the pinned processor 7), MSVC from VS 2026 BuildTools, Python 3.12:ctest --preset dev --no-tests=error -R '^cpu_aot_rdtscp?$' -V: both pass. Every control reports its broken property, for examplecontrol noaux: rdtscp_op ECX 0x0, TSC_AUX of the pinned processor 0x7. Theplain/O2build reportsrdtsc_unused: ().ctest --preset dev --no-tests=error -R '^cpu_' -j 4: 137 of 137 pass. The capability skips arecpu_aot_fences_hints_clwb,cpu_aot_crypto_shaandcpu_shim_chain_hardware, as onmainfor this host.has_rdtscpforced to 0, RDTSCP exports raising):cpu_aot_rdtscpasses,cpu_aot_rdtscpexits 77.tools/form_coverage.pymeasure()withcpu_aot_rdtscpskipped placesrdtscpinblocked_by_skip, andrdtscstays covered.tests/docs_links_check.py,tests/bidi_controls_check.pyandtests/form_coverage_check.pypass.Limits
noextcan only fail once the counter exceeds 2^32, that is, a few seconds after reset.Refs #739
AI-assisted: written with Claude Code, three precommit review rounds by fresh agents; checked and submitted by the account owner.
🤖 Generated with Claude Code