-
Notifications
You must be signed in to change notification settings - Fork 0
Atomic Operations
Qingtian edited this page Aug 23, 2019
·
4 revisions
MOV (from memory) ; any memory order
MOV (into memory) ; memory_order_relaxed, memory_order_release
MOV (into memory), MFENCE ; other memory orders
LOCK CMPXCHG ; any memory order
- If not use the return value
; system/atomic/sub ptr value
; system/atomic/sub/old ptr value
LOCK SUB ptr, value ; any memory order
- 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.
- If not use the return value
LOCK ADD ptr, value ; any memory order
- If use the return value
Refer to the Sub instruction.
- If not use the return value
; system/atomic/xor ptr value
; system/atomic/xor/old ptr value
LOCK XOR ptr, value ; any memory order
- 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.
Refer to the XOR instruction.
Refer to the XOR instruction.