Instruction
RDTSC
Reads the time-stamp counter into EDX:EAX, unordered with nearby instructions; user code may run it unless CR4.TSD is set.
- Extensions
- Forms
- 1 (1 Legacy)
- Data
- Intel XED v2026.08.23
RDTSC reads a clock without a system call or a device access. The
result arrives split, the high half in EDX and the low half in EAX;
GCC 14 and Clang 23 at -O2 compile the __rdtsc() intrinsic to RDTSC
followed by shl rdx, 32 and or rax, rdx.
What the counter counts:
- On processors with an invariant TSC (CPUID 80000007H, EDX bit 8, the same bit on Intel and AMD), it ticks at a constant rate in every power and sleep state, so the operating system may use it as its clock.
- That rate is not the core’s current clock. Intel’s optimization manual notes that on Skylake it runs at the guaranteed (P1) frequency whatever the turbo state, and Intel’s manual recommends the performance counters (see RDPMC) for counting core cycles.
- Each logical processor has its own counter, which privileged software can write, so two of them need not agree. RDTSCP also returns a value that the operating system keeps per processor (Linux stores the CPU and node number), so a program can tell whether it moved between two readings.
RDTSC waits for nothing: it may read the counter before earlier
instructions finish, and later ones may start before it reads. To time
a piece of code on Intel’s processors, surround each RDTSC with
LFENCEs: the one before makes the read wait for the
code ahead of it, the one after keeps the code behind it from starting
early. RDTSCP waits for earlier instructions by itself, so
RDTSCP; LFENCE serves at the end. LFENCE does this on
AMD’s processors only where it is dispatch serializing, as on Zen 5.
To wait for earlier stores as well, Intel’s manual puts an
MFENCE before the LFENCE; AMD’s counts MFENCE as
serializing on its own.
The operating system can forbid RDTSC outside ring 0 by setting CR4.TSD, which makes it raise #GP there. Under virtualization the guest reads the host’s counter scaled and offset by values the hypervisor sets (TSC offsetting and scaling in Intel’s VMX, the TSC offset and ratio in AMD’s SVM), unless the hypervisor makes RDTSC exit to it.
In the optimization guide
What the optimization guide says about RDTSC, a line per claim. Each links to the claim in the guide, with its sources and where they differ.
Measuring
- Core cycles, reference cycles and the TSC: The invariant TSC ticks at a constant rate near the base frequency, so under turbo it measures time rather than core cycles. sources differ
- Reading the time-stamp counter: RDTSC runs out of order with its neighbours unless LFENCE (or MFENCE and LFENCE) before it and LFENCE after it hold it in place.
- Reading the time-stamp counter: The TSC suits long intervals, not a handful of instructions, whose readings vary from run to run.
- Reading the time-stamp counter: CR4.TSD confines RDTSC and RDTSCP to ring 0, and they then raise #GP in user code.
- Setting up the test: A guest’s TSC may be scaled and offset by the hypervisor, and its counters may be fewer.
Forms
| Instruction | Encoding | Requires |
|---|---|---|
RDTSC
RDTSC | 0F 31 | Base instruction set |
Operation
What the forms do, in pseudocode that our tests run against results recorded on real processors. How to read.
if CPL > 0 and cr4 >> 2 & 1: # CR4.TSD: only CPL 0 may read the
fault(GP, 0) # counter
t = tsc() # the count at this moment: time's,
# not an input of the instruction
edx = t >> 32 # the high half; bits 63:32 of RDX
eax = low(t, 32) # and RAX cleared
# 66 and REX.W change nothing. Not serializing: the counter may be
# read before earlier instructions are done, or after later ones
# have started (Intel's manual: an LFENCE before or after orders it)Run on AMD Zen 5 (EPYC 9645): 3 cases.
Operands
| Operand | Kind | Action |
|---|---|---|
RDTSC | ||
EAX | implicit | write |
EDX | implicit | write |
TSC | implicit | read |
Flags
None: XED records no flag that the forms test or change.
CPUID and processors
Each form belongs to an XED ISA set. A form can be used when the processor reports every CPUID bit of one of its ISA set's alternatives.
| ISA set | CPUID | Processors |
|---|---|---|
PENTIUMREAL | No CPUID bit: part of the base instruction set. | Every x86-64 processor in XED’s model and Zen 3 to Zen 6 |
More System instructions
Sources
- Intel XED v2026.08.23 (commit
0bcb6237345c): forms, encodings, operands, flags, exception classes, attributes, ISA sets, CPUID bits and chip model. - The CPU data of x86-64.net: Zen 3 to Zen 6, from GCC’s
-marchfeature sets and AMD’s Processor Programming References, which the page of each processor cites. - Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 2 (325383-093, September 2026): Volume 2B, page 4-559 (RDTSC)
- Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 3 (325384-093, September 2026)
- AMD64 Architecture Programmer's Manual, Volume 2: System Programming (24593, rev. 3.42, March 2024), Wayback Machine copy of AMD's PDF
- AMD64 Architecture Programmer's Manual, Volume 3: General-Purpose and System Instructions (24594, rev. 3.36, March 2024), Wayback Machine copy of AMD's PDF
- Intel 64 and IA-32 Architectures Optimization Reference Manual, Volume 1 (248966-051, October 2026)
- Linux arch/x86/include/asm/segment.h: the CPU and node number in IA32_TSC_AUX
The tables are derived from Intel XED, Copyright Intel Corporation, licensed under the Apache License 2.0; x86-64.net converted and reformatted them. The text is our own.