cmpxchg16b
Compare and exchange 16 bytes
Compares rdx:rax with a 16-byte memory operand; if they match, stores rcx:rbx there, otherwise loads the operand into rdx:rax.
x86-64 and latertakes lock
CFPFAFZFSFDFOF –––●–––
- ● set from the result
- – not changed
Forms
cmpxchg16b
Operands
mem128- A 128-bit value in memory, for example
oword [rbx].
ZF is set when they matched; otherwise it is cleared and the memory value is loaded into rdx:rax. The operand must be aligned to 16 bytes: a misaligned address raises a general-protection fault, which a Linux program receives as a segmentation fault. With lock the whole exchange is atomic, which is what it is for, such as updating a pointer together with a counter.