cmpccxadd
Compare and Add if Condition is Met
Atomically adds if condition is met.
Pseudocode Operation
temp ← [dest]; ZF ← (temp == src1); if (condition_met) { [dest] ← [dest] + src2; CF ← carry_from_add; OF ← overflow_from_add; SF ← sign_of_result; } src1 ← temp;
Example
Encoding
Operands
-
dest
Mem -
src1
Reg -
src2
Reg
Related
More in CMPccXADD
Reference
Instruction Forms
| Opcode | Instruction | Op/En | 64/32-bit Mode | CPUID | Description |
|---|---|---|---|---|---|
| VEX.128.66.0F38.W0 E0+cc /r | CMPccXADD m32, r32, r32 | A | V/N.E. | CMPCCXADD | Compare value in r32 with value in m32; if condition cc is met, add the third operand to m32. The second operand always receives the original memory value. Opcodes E0-EF select the condition (O, NO, B, NB, Z, NZ, BE, NBE, S, NS, P, NP, L, NL, LE, NLE). |
| VEX.128.66.0F38.W1 E0+cc /r | CMPccXADD m64, r64, r64 | A | V/N.E. | CMPCCXADD | 64-bit form of the compare-and-add. Opcodes E0-EF select the condition. |
Description
This instruction compares the value from memory with the value of the second operand. If the specified condition is met, then the processor will add the third operand to the memory operand and write it into memory, else the memory is unchanged by this instruction. This instruction must have MODRM.MOD equal to 0, 1, or 2. The value 3 for MODRM.MOD is reserved and will cause an invalid opcode exception (#UD). The second operand is always updated with the original value of the memory operand. The EFLAGS conditions are updated from the results of the comparison.The instruction uses an implicit lock. This instruction does not permit the use of an explicit lock prefix.
Operation
CMPCCXADD srcdest1, srcdest2, src3 tmp1 := load lock srcdest1 tmp2 := tmp1 + src3 EFLAGS.CS,OF,SF,ZF,AF,PF := CMP tmp1, srcdest2 IF <condition>: srcdest1 := store unlock tmp2 ELSE srcdest1 := store unlock tmp1 srcdest2 :=tmp1 1. ModRM.MOD != 011B
Intel C/C++ Compiler Intrinsic Equivalent
CMPCCXADD int _cmpccxadd_epi32 (void* __A, int __B, int __C, const int __D); CMPCCXADD __int64 _cmpccxadd_epi64 (void* __A, __int64 __B, __int64 __C, const int __D);