x86_64 - cmpxchg。 Return 值

x86_64 - cmpxchg. Return value

我正在阅读英特尔手册,卷。 2A.

Compares the value in the AL, AX, EAX, or RAX register with the first operand (destination operand). If the two values are equal, the second operand (source operand) is loaded into the destination operand. Otherwise, the destination operand is loaded into the AL, AX, EAX or RAX register. RAX register is available only in 64-bit mode.

在失败的情况下将目标加载到累加器中的目的是什么?

这很方便,您不必自己执行此操作。通常在循环中使用 cmpxchg,在循环中根据当前值计算新值。如果失败,您可能需要当前值重新计算并重试。