Instruction
POPF
Pops the flags from the stack, changing only those the privilege level allows; POPFQ, the 64-bit form, pops RFLAGS.
- Extensions
- Mnemonics
- POPF, POPFD, POPFQ
- Forms
- 3 (3 Legacy)
- Data
- Intel XED v2026.08.23
POPF loads the flags register from the top of the stack, the reverse of
PUSHF. In 64-bit mode it is POPFQ and takes 8 bytes;
with a 66 prefix it takes 2 and loads only bits 15:0, FLAGS, leaving
the upper bits as they were. POPFD, the 4-byte form, cannot be encoded
there. C code reaches it through __builtin_ia32_writeeflags_u64(),
which GCC 14 and Clang 23 compile to a PUSH of the argument and a POPF.
What it may not change
POPF does not load every bit it pops, and which bits it skips depends on the privilege level:
- IF changes only where CPL is at most IOPL, as for CLI and STI.
- IOPL changes only at CPL 0.
- VM, VIF and VIP never change, and RF is always cleared.
- The reserved bits keep their values: bit 1 stays 1.
The six status flags, TF, DF, NT, and in the 8-byte form AC and ID, are loaded at any privilege. Unlike CLI and STI, POPF never raises #GP for the bits it may not change in protected or 64-bit mode: it leaves them alone in silence, so code that pops an image with IF clear cannot assume that interrupts are now off.
Zen 5 showed this at CPL 3 with IOPL 0. Popping 0 with either form left IF set; popping FFFFFFFFFFFFFEFFH with POPFQ loaded the status flags, DF, NT, AC and ID but left IOPL at 0 and RF, VM, VIF and VIP clear. None of the twenty recorded cases faulted.
TF and AC
Setting TF with POPF is how a program single-steps itself: the first debug trap comes after the instruction that follows the POPF, not after the POPF itself (Intel’s Volume 3). Setting AC, bit 18, enables alignment checking of user-mode accesses where the operating system has set CR0.AM; the PUSHF page shows the sequence.
Cost
AMD’s Zen 5 guide lists POPF, like PUSHF, as microcoded. To restore only SF, ZF, AF, PF and CF, SAHF from AH is a single macro-op.
Forms
| Instruction | Encoding | Requires |
|---|---|---|
POPF
POPF | 66 9D | Base instruction set |
POPFD not in 64-bit mode
POPFD | 9D | Base instruction set |
POPFQ 64-bit mode only
POPFQ | 9DREX.W 9D | LM |
Latency and throughput
| Model | POPFQ |
|---|---|
| Sandy Bridge, Haswell, Skylake, Skylake-SP, Ice Lake | 5 / 0.5p23 |
| Broadwell | 22 / 4.25p012356 |
| Alder Lake, Sapphire Rapids | 5 / 1p0 p1 p2 p3 p6 p10 |
| Lunar Lake | 5 / 0.67p0 p1 p2 p3 p4 p5 p20 p21 p22 |
| Bonnell | 26 / 13p01 |
| Silvermont | 3 / 1MEC |
| Piledriver | 5 / 1AGLU01 Load |
| Zen | 4 / 0.5AGU0 AGU1 |
| Zen 2 | 4 / 0.33AGU0 AGU1 AGU2 |
| Zen 3, Zen 4 | 5 / 0.33AGU0 AGU1 AGU2 LSU Load |
| Jaguar | 3 / 1LAGU |
Operation
What the forms do, in pseudocode that our tests run against results recorded on real processors. How to read.
v = load(rsp, OSIZE) # POPF: 16 bits, bits 15:0 of RFLAGS
rsp = rsp + OSIZE // 8
pl = iopl
cf = v & 1
pf = v >> 2 & 1
af = v >> 4 & 1
zf = v >> 6 & 1
sf = v >> 7 & 1
tf = v >> 8 & 1 # a trap after the next instruction
df = v >> 10 & 1
of = v >> 11 & 1
nt = v >> 14 & 1
if CPL == 0:
iopl = v >> 12 & 3
if CPL <= pl:
if_ = v >> 9 & 1 # else IF stays, and nothing faults
if OSIZE != 16:
ac = v >> 18 & 1
id = v >> 21 & 1
rf = 0
# VM, VIF, VIP and the reserved bits stay as they wereRun on AMD Zen 5 (EPYC 9645): 20 cases. The forms that 64-bit mode lacks were not run: the probe runs in 64-bit mode.
Operands
Flags
| OF | SF | ZF | AF | PF | CF | DF | IF | TF | AC | IOPL | NT | RF | VM | VIF | VIP | ID |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| All forms | ||||||||||||||||
| P | P | P | P | P | P | P | P | P | P | TP | P | 0 | T | M | T | P |
Attributes
What else XED records about the forms. How to read.
- All forms
- may abort a TSX transaction
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 |
|---|---|---|
I86 | No CPUID bit: part of the base instruction set. | Every x86-64 processor in XED’s model and Zen 3 to Zen 6 |
I386 | No CPUID bit: part of the base instruction set. | Every x86-64 processor in XED’s model and Zen 3 to Zen 6 |
LONGMODE | LM | Every x86-64 processor in XED’s model and Zen 3 to Zen 6 |
More General-purpose 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. - LLVM 23.1.2's x86 scheduling models (commit
85ac56026243): the latency, reciprocal throughput and ports of each form, as llvm-mca reports them. - Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 2 (325383-093, September 2026): Volume 2B, page 4-407 (POPF/
POPFD/ POPFQ) - Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 1 (253665-093, September 2026)
- Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 3 (325384-093, September 2026)
- AMD64 Architecture Programmer's Manual, Volume 3: General-Purpose and System Instructions (24594, rev. 3.39, October 2026)
- Software Optimization Guide for the AMD Zen5 Microarchitecture (58455, rev. 1.00, August 2024), Wayback Machine copy of AMD's ZIP
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 timings come from LLVM's scheduling models, part of the LLVM Project, licensed under the Apache License 2.0 with LLVM Exceptions. The text is our own.