Типовые опрерации для CISC машин: Exchange: Semaphore Operations
temp = source Start Bus Lock [ source = Memory[EA] Memory[EA] = temp ] Finish Bus Lock |
Exchange and Add:
Start Bus Lock [ temp = Memory[EA] Memory[EA] = temp + source ] Finish Bus Lock destination = temp |
Compare and Exchange
Start Bus Lock [ temp = Memory[EA] if (temp == comparand) { Memory[EA] = source } ] destination = temp |
Типовые операции для RISC машин:
lock_flag = 1 lock_address = EA destination = Memory[EA] |
Each bus cycle [ if (Bus.Address == EA) { lock_flag = 0; } ] |
if (lock_flag == 1) { Memory[EA] = source } destination = lock_flag lock_flag = 0 |
Alpha: LDL_L Reg, Mem ! 4-bytes LDQ_L Reg, Mem ! 8-bytes
STL_C Reg, Mem ! 4-bytes STQ_C Reg, Mem ! 8-bytes
|
# Atomic Fetch # r3 - address # r4 - data loop: lwarx r4,0,r3 # load stwcx. r4,0,r3 # store old value if still reserved bne- loop |
# Fetch and Store (Exchange) # r3 - address # r4 - new value # r3 - old value loop: lwarx r5,0,r3 # load stwcx. r4,0,r3 # store if still reserved bne- loop |
# Fetch and Add # r3 - address # r4 - value to add # r5 - old value loop: lwarx r5,0,r3 # read add r0,r4,r5 # modify stwcx. r0,0,r3 # write bne- loop |
# Fetch and And # r3 - address # r4 - value to and # r5 - old value loop: lwarx r5,0,r3 # read and r0,r4,r5 # modify stwcx. r0,0,r3 # write bne- loop |
# Test and Set # r3 - address # r4 - new value (!=0) # r5 - old value loop: lwarx r5,0,r3 cmpwi r5,0 bne- $+12 stwcx. r4,0,r3 bne- loop |
# Compare and Swap # r3 - address # r4 - comparant / old value # r5 - new value loop: lwarx r6,0,r3 cmpw r4,r6 bne- exit stwcx. r5,0,r3 bne- loop exit: mr r4,r6 |