Instruction
XSETBV
Writes EDX:EAX to the extended control register that ECX selects, such as XCR0, which enables AVX and other XSAVE state; ring 0 only.
- Extensions
- Forms
- 1 (1 Legacy)
- Data
- Intel XED v2026.08.23
XSETBV writes EDX:EAX into the extended control register that ECX selects; bits 63:32 of RCX, RAX and RDX are ignored. The only register it writes is XCR0, the set of state components that the operating system manages with the XSAVE instructions and lets programs use. The operating system sets it after CR4.OSXSAVE, and programs read the result with XGETBV. XCR1, which XGETBV can read, is read-only here: XSETBV with ECX = 1 raises #GP(0), as does any other ECX but 0.
The rules for XCR0
A bit may be set only if CPUID leaf 0DH, sub-leaf 0, reports it in EAX (or EDX for the upper half); anything else is a reserved bit and raises #GP(0). The components must also come in usable sets, or XSETBV raises #GP(0):
- bit 0, x87, must always be set;
- bit 2, AVX, needs bit 1, SSE;
- bits 3 and 4, MPX, go together;
- bits 5 to 7, AVX-512, go together and need bits 1 and 2;
- bits 17 and 18, AMX tile configuration and data, go together.
Setting a bit is what lets programs run the instructions of that state: with XCR0 bit 2 clear, AVX instructions raise #UD even where CPUID reports AVX, and the same holds for AVX-512 and AMX, whereas SSE instructions run whatever bit 1 says. Clearing a bit keeps the state in the registers but, in Intel’s manual, may slow SSE and AVX instructions if that state is not in its initial configuration. AMD’s manual adds bit 62, through which an operating system makes its LWP extension available.
Privilege and virtualization
XSETBV runs at CPL 0 or in real mode, and raises #GP(0) elsewhere; it
raises #UD while CR4.OSXSAVE is clear, on a processor without XSAVE, and
with a LOCK prefix. In a guest under Intel’s VMX it always causes a VM
exit, reason 55, so that the hypervisor decides which components the
guest may enable; AMD’s SVM has an intercept bit for it. The probe does
not run it, being a CPL 3 program; the XGETBV page
shows the XCR0 that the probe’s Linux guest set on Zen 5. GCC 14 and
Clang 23 offer _xsetbv(0, v) with -mxsave or a -march that has XSAVE,
compiling it to a split of v into EDX:EAX, ECX cleared and XSETBV. AMD’s
Zen 5 guide lists XSETBV as microcoded.
Forms
| Instruction | Encoding | Requires |
|---|---|---|
XSETBV
XSETBV | NP 0F 01 D1 | XSAVE + OSXSAVE |
Latency and throughput
| Model | XSETBV |
|---|---|
| Sandy Bridge | 100 / 0.33p015 |
| Haswell, Broadwell, Skylake, Skylake-SP, Ice Lake | 5 / 1.25p0156 |
| Alder Lake, Sapphire Rapids | 5 / 10.8p0 p1 p5 p6 p11 |
| Lunar Lake | 5 / 8.67V0 V1 V2 V3 p0 p1 p2 p3 p4 p5 |
| Piledriver | 100 / 0.5EX0 EX1 |
| Zen, Zen 2 | 100 / 0.25 |
| Zen 3, Zen 4 | 100 / 25ALU0 ALU1 ALU2 ALU3 |
| Jaguar | 100 / 0.5ALU0 ALU1 |
Operation
What the forms do, in pseudocode that our tests run against results recorded on real processors. How to read.
if CPL > 0 or ecx != 0: # XCR0 is the only one it writes
fault(GP, 0)
v = edx << 32 | eax
r = cpuid_leaf(0xD, 0) # the user components there are
if v & ~(r[3] << 32 | r[0]):
fault(GP, 0)
if not v & 1 or v & 6 == 4: # x87 always; AVX only with SSE
fault(GP, 0)
if v & 0x18 not in (0, 0x18): # MPX's two together
fault(GP, 0)
if v & 0xE0 and v & 0xE6 != 0xE6: # AVX-512's three together, with
fault(GP, 0) # AVX and SSE
if v >> 17 & 1 != v >> 18 & 1: # AMX's two together
fault(GP, 0)
xcr0 = vNot run on a processor: XSETBV runs at CPL 0 only.
Operands
| Operand | Kind | Action |
|---|---|---|
XSETBV | ||
ECX | implicit | read |
EDX | implicit | read |
EAX | implicit | read |
XCR0 | implicit | write |
Flags
None: XED records no flag that the forms test or change.
Attributes
What else XED records about the forms. How to read.
- All forms
- privileged: CPL 0 only; 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 |
|---|---|---|
XSAVE | XSAVE + OSXSAVE XED and Intel’s SDM differ: XED also asks for the OSXSAVE bit, Sources: Intel XED v2026.08.23, datafiles/cpuid.xed.txt; Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 2 (325383-093, September 2026), XSAVE, XRSTOR, XGETBV and XSETBV: the opcode tables and the exception lists, from pages 6-58, 6-49, 6-36 and 6-70; Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 1 (253665-093, September 2026), section 13.3, Enabling the XSAVE Feature Set and XSAVE-Enabled Features, page 13-6. | Sandy Bridge, Ivy Bridge, Haswell, Broadwell, Skylake, Comet Lake, Cannon Lake, Ice Lake (client), Tiger Lake, Alder Lake, Arrow Lake, Panther Lake, Nova Lake, Skylake-SP, Cascade Lake, Cooper Lake, Ice Lake (server), Sapphire Rapids, Emerald Rapids, Granite Rapids, Diamond Rapids, Goldmont, Goldmont Plus, Tremont, Snow Ridge, Lakefield, Sierra Forest, Clearwater Forest, Knights Landing, Knights Mill, Bulldozer, Piledriver, Zen, Zen+, Zen 2, Zen 3, Zen 4, Zen 5, Zen 6 |
More XSAVE 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 2D, page 6-70 (XSETBV)
- Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 1 (253665-093, September 2026)
- Linux kernel documentation: Using XSTATE features in user space applications
- Intel Advanced Performance Extensions (Intel APX) Architecture Specification, revision 9.0 (355828-009, August 2026)
- 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.46, 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.