Memory, caches and atomics
CMPXCHG16B
CMPXCHG16B compares and exchanges 16 bytes of memory atomically, for lock-free structures that update a pointer and a counter together.
- CPUID
- CMPXCHG16B
CPUID.01H:ECX[13] - Instructions
- 1 mnemonic
- Processors
- Every x86-64 processor in XED’s model
- Linux flag
cx16
CMPXCHG16B compares RDX:RAX with 16 bytes of memory and, if they are equal, stores RCX:RBX there; otherwise it loads the memory into RDX:RAX. With a LOCK prefix it does all this atomically. The operand must be aligned to 16 bytes.
Lock-free data structures use it to update two words at once, such as a pointer and a counter that changes with every update, which defeats the ABA problem of a plain compare-and-exchange. It is the 64-bit counterpart of CMPXCHG8B. Some early x86-64 processors, such as AMD’s K8, lack it, so it has its own CPUID bit, CPUID.01H:ECX[13]; it is part of x86-64-v2.
Instructions
| Mnemonic | Summary | Forms |
|---|---|---|
| CMPXCHG16B | Compares RDX:RAX with 16 aligned bytes of memory: if equal, stores RCX:RBX there and sets ZF, else loads them into RDX:RAX; atomic with LOCK. | 2 |
CPUID and processors
XED splits CMPXCHG16B into 1 ISA set. Software can use a form when the processor reports every CPUID bit of one alternative of the form's ISA set.
| ISA set | CPUID | Processors in XED |
|---|---|---|
CMPXCHG16B | CMPXCHG16B | Every x86-64 processor in XED’s model |
Sources
- Intel XED v2026.08.23 (commit
0bcb6237345c): forms, encodings, ISA sets, CPUID bits and chip model. - Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 2 (325383-092, June 2026)
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.