Skip to content
Qingtian edited this page Aug 23, 2019 · 4 revisions

X86

LOAD

MOV (from memory)			; any memory order

STORE

MOV (into memory)			; memory_order_relaxed, memory_order_release 
MOV (into memory), MFENCE		; other memory orders

Compare and Exchange

LOCK CMPXCHG				; any memory order

SUB

  1. If not use the return value
; system/atomic/sub ptr value
; system/atomic/sub/old ptr value

LOCK SUB ptr, value			; any memory order
  1. If use the return value
; ret: system/atomic/sub/old ptr 123

  mov eax, -123
  lock xadd ptr, eax

  the old value is in eax.
; ret: system/atomic/sub ptr value

  mov eax, -123
  lock xadd ptr, eax
  sub eax, 123

  the new value is in eax.

ADD

  1. If not use the return value
LOCK ADD ptr, value			; any memory order
  1. If use the return value

Refer to the Sub instruction.

XOR

  1. If not use the return value
; system/atomic/xor ptr value
; system/atomic/xor/old ptr value
LOCK XOR ptr, value			; any memory order
  1. If use the return value
; ret: system/atomic/xor/old ptr 321

  mov eax, ptr
.L3:
  mov edx, eax
  xor edx, 321
  lock cmpxchg DWORD PTR a, edx
  jne .L3

  the old value is in edx.
; ret: system/atomic/xor ptr 321

mov eax, DWORD PTR a
.L4:
mov ecx, eax
mov edx, eax
xor ecx, 321
lock cmpxchg DWORD PTR a, ecx
jne .L4

the new value is in edx.

AND

Refer to the XOR instruction.

OR

Refer to the XOR instruction.

Clone this wiki locally