Instruction
CMPccXADD
Atomically compares memory with a register, adds a second register to memory if the condition holds, and returns the old value in the first.
- Extensions
- Mnemonics
- CMPOXADD, CMPNOXADD, CMPBXADD, CMPCXADD, CMPNAEXADD, CMPNBXADD, CMPNCXADD, CMPAEXADD, CMPZXADD, CMPEXADD, CMPNZXADD, CMPNEXADD, CMPBEXADD, CMPNAXADD, CMPNBEXADD, CMPAXADD, CMPSXADD, CMPNSXADD, CMPPXADD, CMPPEXADD, CMPNPXADD, CMPPOXADD, CMPLXADD, CMPNGEXADD, CMPNLXADD, CMPGEXADD, CMPLEXADD, CMPNGXADD, CMPNLEXADD, CMPGXADD
- Forms
- 4 (2 VEX, 2 EVEX)
- Data
- Intel XED v2026.08.23
CMPccXADD m, r1, r2 performs these steps as one locked operation:
- Read the memory value and compare it with r1, setting the flags as CMP would (memory minus r1).
- If the condition cc holds for those flags, write the memory value plus r2 back to memory; otherwise leave memory unchanged.
- Put the original memory value in r1.
Without it, a conditional atomic update such as “increment the counter unless it has reached the limit” needs a loop around LOCK CMPXCHG that retries whenever another thread changed the value in between. CMPccXADD always completes in one step and returns the old value and the flags of the comparison, so the caller knows whether the addition happened. The lock is implicit, a LOCK prefix is not allowed, and the memory operand cannot be a register.
XED marks the memory operand as needing natural alignment, four bytes for m32 and eight for m64, as the attributes below show. Intel’s manual of September 2026 (325383-093) has no such rule. Of the exceptions of CMPccXADD (Exceptions Type 14, Table 2-31), only #AC(0) concerns alignment: an unaligned operand raises it when alignment checking is enabled at CPL 3. #GP(0) comes only from a non-canonical address. As with any locked access, an operand that spans two cache lines needs a bus lock, which system software can turn into #AC(0) with split-lock disable (Volume 3A, Section 11.1.2.3).
Forms
| Instruction | Encoding | Requires |
|---|---|---|
CMPccXADD m32, r32, r32 64-bit mode only
CMPccXADD_MEMu32_GPR32u32_GPR32u32 | VEX.LZ.66.0F38.W0 E0+cc /r | CMPCCXADD |
CMPccXADD m64, r64, r64 64-bit mode only
CMPccXADD_MEMu64_GPR64u64_GPR64u64 | VEX.LZ.66.0F38.W1 E0+cc /r | CMPCCXADD |
CMPccXADD m32, r32, r32
CMPccXADD_MEMu32_GPR32u32_GPR32u32_APX | EVEX.LLZ.66.0F38.W0 E0+cc /r | APX_F + CMPCCXADD |
CMPccXADD m64, r64, r64
CMPccXADD_MEMu64_GPR64u64_GPR64u64_APX | EVEX.LLZ.66.0F38.W1 E0+cc /r | APX_F + CMPCCXADD |
Operation
What the forms do, in pseudocode that our tests run against results recorded on real processors. How to read.
old = dest.read() # one locked read-modify-write
f = sub_flags(old, src1) # as CMP dest, src1
if cond(CC, f): # the condition on these new flags
dest.write(old + src2)
else:
dest.write(old) # memory is written back all the same
src1.write(old) # whatever the condition
flags = fNot run on a processor: none of these processors has CMPccXADD.
Operands
| Operand | Kind | Action |
|---|---|---|
CMPccXADD m32, r32, r32 64-bit mode only CMPccXADD m64, r64, r64 64-bit mode only | ||
m32/64 | explicit | read, write |
r32/64 | explicit | read, write |
r32/64 | explicit | read |
RFLAGS | implicit | write |
Flags
| OF | SF | ZF | AF | PF | CF |
|---|---|---|---|---|---|
| All forms | |||||
| M | M | M | M | M | M |
Exceptions
The exception class is XED's name for the set of exception conditions that a form follows. How to read.
- VEX forms
avx-type-14- EVEX forms
APX-EVEX-CMPCCXADD
Attributes
What else XED records about the forms. How to read.
- All forms
- always atomic
CMPccXADD m32, r32, r3264-bit mode only- 4-byte aligned memory operand
CMPccXADD m64, r64, r6464-bit mode only- 8-byte aligned memory operand
Intrinsics
The C intrinsics of Clang 23.1.2 that compile to CMPccXADD, each with the form it compiles to and the Clang options it needs. The forms come from compiling every intrinsic and decoding the result with Intel XED; all intrinsics A–Z explains the method.
| Intrinsic | Compiles to |
|---|---|
_cmpccxadd_epi32
int _cmpccxadd_epi32(void *__A, int __B, int __C, const int __D) |
|
_cmpccxadd_epi64
long long _cmpccxadd_epi64(long long *__A, long long __B, long long __C, const int __D) |
|
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 |
|---|---|---|
CMPCCXADD | CMPCCXADD | Arrow Lake, Panther Lake, Nova Lake, Diamond Rapids, Sierra Forest, Clearwater Forest |
APX_F_CMPCCXADD | APX_F + CMPCCXADD | Nova Lake, Diamond Rapids |
More APX instructions
Sources
- Intel XED v2026.08.23 (commit
0bcb6237345c): forms, encodings, operands, flags, exception classes, attributes, ISA sets, CPUID bits and chip model. - Clang's x86 intrinsic headers, LLVM 23.1.2 (commit
85ac56026243): the intrinsics, their signatures and doc comments, and the Clang of that release, which compiled each of them. - Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 2 (325383-093, September 2026): Volume 2A, page 3-163 (CMPccXADD)
- 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)
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 intrinsics and their signatures come from Clang, part of the LLVM Project, licensed under the Apache License 2.0 with LLVM Exceptions. The text is our own.