Programming Examples
PowerPC e500 Core Family Reference Manual, Rev. 1
Freescale Semiconductor
A-3
A.1.1.2
Fetch and Store
The fetch and store primitive atomically loads and replaces a word in storage. In this example it is
assumed that the address of the word to be loaded and replaced is in GPR3, the new value is in
GPR4, and the old value is returned in GPR5.
loop:
lwarx r5,0,r3
#load
and
reserve
stwcx.
r4,0,r3
#store new value if still reserved
bc
4,2,loop
#loop if lost reservation
A.1.1.3
Fetch and Add
The fetch and add primitive atomically increments a word in storage. In this example it is assumed
that the address of the word to be incremented is in GPR3, the increment is in GPR4, and the old
value is returned in GPR5.
loop:
lwarx r5,0,r3
#load
and
reserve
add r0,r4,r5
#increment
word
stwcx.
r0,0,r3
#store new value if still reserved
bc
4,2,loop
#loop if lost reservation
A.1.1.4
Fetch and AND
The Fetch and AND primitive atomically ANDs a value into a word in storage.
In this example it is assumed that the address of the word to be ANDed is in GPR3, the value to
AND into it is in GPR4, and the old value is returned in GPR5.
loop: lwarx r5,0,r3
#load
and
reserve
and r0,r4,r5
#AND
word
stwcx.
r0,0,r3
#store new value if still reserved
bc
4,2,loop
#loop if lost reservation
This sequence can be changed to perform another Boolean operation atomically on a word in
memory by changing the and to the desired Boolean instruction (or, xor, etc.).
Summary of Contents for PowerPC e500 Core
Page 1: ...PowerPC e500 Core Family Reference Manual Supports e500v1 e500v2 E500CORERM Rev 1 4 2005...
Page 36: ...PowerPC e500 Core Family Reference Manual Rev 1 xxxvi Freescale Semiconductor...
Page 38: ...PowerPC e500 Core Family Reference Manual Rev 1 Part I 2 Freescale Semiconductor...
Page 332: ...PowerPC e500 Core Family Reference Manual Rev 1 Part II 2 Freescale Semiconductor...
Page 530: ...Opcode Listings PowerPC e500 Core Family Reference Manual Rev 1 D 50 Freescale Semiconductor...
Page 534: ...PowerPC e500 Core Family Reference Manual Rev 1 E 4 Freescale Semiconductor Revision History...