cpu: lower RDTSC and RDTSCP in the shared lowering #739
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#739
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@legacy-code-archaeologist on GitHub · 2026-11-23 00:05 UTC · original
Claim and design question: lower
RDTSCandRDTSCPin the shared loweringdocs/coverage/x64_zen2.tsvlistsrdtscandrdtscpin the Integer group, and onmainatfd2486fneither has a passing fixture (tools/form_coverage.py --gaps x64_zen2).lower()intools/ffx_version_query.pyrejects both today. I found no open issue or PR that covers them. I'd like to take them as one small PR.Proposed behavior
RDTSCreads the host time-stamp counter (__rdtsc()) and writes the low 32 bits to EAX and the high 32 bits to EDX, zero-extending RAX and RDX. Flags are unchanged.RDTSCPdoes the same through__rdtscp(&aux)and also writesaux(IA32_TSC_AUX) to ECX, zero-extending RCX./O2cannot merge or drop them.Proposed fixture (source-built MASM, differential)
Because the value is non-deterministic, the check compares properties rather than bytes:
native_before <= translated <= native_after(bracketing reads in the harness)./O2.RDTSCP's ECX equals the nativeRDTSCPECX on the same thread.RDTSCPbit) returns 77 on hosts without it.Question before I start
The translation would pass the host TSC through unscaled. Guest code that converts ticks to time with its own fixed frequency would then run at the host's rate. Is passing the host value through the intended contract, with timing calibration left to the runtime layer? Or should the lowering call a runtime hook, so the shim can scale or virtualize the counter later? I'd keep the first PR to the pass-through, and document the frequency question in
docs/experiments.md.Test hosts: Intel Skylake (i7-6820HQ) on Windows 11 26100.
AI-assisted (Claude Code).
@R0Y00 on GitHub · 2026-11-23 00:26 UTC · original
The first PR can use the unscaled host TSC as an explicit profile. Document that it supplies host ticks and host TSC_AUX, with no guest frequency or virtual-CPU guarantee. Keep each read observable even when its result is unused, and preserve the distinct RDTSC/RDTSCP instruction ordering rather than adding fences to the generated code. Use serialized measurement boundaries in the harness and pin the test thread or detect migration before comparing TSC_AUX. Keep the feature skip specific to RDTSCP, so RDTSC checks still run on those hosts.
@R0Y00 on GitHub · 2026-11-23 06:25 UTC · original
Implemented in #789 (
2056156). The explicit host TSC profile preserves both read forms, including a read whose result is discarded at /O2. Native bracketing runs on a pinned thread and RDTSCP has its own capability check. The profile reports host ticks and TSC_AUX.