Instruction Model
PowerPC e500 Core Family Reference Manual, Rev. 1
Freescale Semiconductor
3-45
Accesses that cross a translation boundary where the endianness changes cause a byte-ordering
data storage interrupt.
3.5
Using msync and mbar to Order Memory Accesses
This section gives examples of how dependencies and the msync and mbar instructions can be used to
control memory access ordering when memory is shared between programs.
3.5.1
Lock Acquisition and Import Barriers
An import barrier is an instruction or sequence of instructions that prevents memory accesses caused by
instructions following the barrier from being performed before memory accesses that acquire a lock have
been performed. An import barrier can be used to ensure that a shared data structure protected by a lock is
not accessed until the lock is acquired. An msync can always be used as an import barrier, but the
approaches shown in this section generally yield better performance because they order only the relevant
memory accesses.
3.5.1.1
Acquire Lock and Import Shared Memory
If lwarx and stwcx. instructions are used to obtain the lock, an import barrier can be constructed by placing
an isync instruction immediately following the loop containing the lwarx and stwcx.. The following
example uses the ‘Compare and Swap’ primitive to acquire the lock.
In this example it is assumed that the address of the lock is in GPR 3, the value indicating that the lock is
free is in GPR 4, the value to which the lock should be set is in GPR 5, the old value of the lock is returned
in GPR 6, and the address of the shared data structure is in GPR 9.
loop: lwarx
r6,0,r3
# load lock and reserve
cmp
cr0,0,r4,r6
# skip ahead if
bc
4,2,wait
# lock not free
stwcx.
r5,0,r3
# try to set lock
bc
4,2,loop
# loop if lost reservation
isync #
import
barrier
lwz
r7,data1(r9) # load shared data
.
.
wait: ...
# wait for lock to free
The second bc does not complete until CR0 has been set by the stwcx.. The stwcx. does not set CR0 until
it has completed (successfully or unsuccessfully). The lock is acquired when the stwcx. completes
successfully. Together, the second bc and the subsequent isync create an import barrier that prevents the
load from data1 from being performed until the branch has been resolved not to be taken.
3.5.1.2
Obtain Pointer and Import Shared Memory
If lwarx and stwcx. instructions are used to obtain a pointer into a shared data structure, an import barrier
is not needed if all the accesses to the shared data structure depend on the value obtained for the pointer.
Содержание PowerPC e500 Core
Страница 1: ...PowerPC e500 Core Family Reference Manual Supports e500v1 e500v2 E500CORERM Rev 1 4 2005...
Страница 36: ...PowerPC e500 Core Family Reference Manual Rev 1 xxxvi Freescale Semiconductor...
Страница 38: ...PowerPC e500 Core Family Reference Manual Rev 1 Part I 2 Freescale Semiconductor...
Страница 316: ...PowerPC e500 Core Family Reference Manual Rev 1 7 18 Freescale Semiconductor Performance Monitor...
Страница 332: ...PowerPC e500 Core Family Reference Manual Rev 1 Part II 2 Freescale Semiconductor...
Страница 362: ...PowerPC e500 Core Family Reference Manual Rev 1 10 26 Freescale Semiconductor Auxiliary Processing Units APUs...
Страница 440: ...PowerPC e500 Core Family Reference Manual Rev 1 A 8 Freescale Semiconductor Programming Examples...
Страница 444: ...PowerPC e500 Core Family Reference Manual Rev 1 B 4 Freescale Semiconductor Guidelines for 32 Bit Book E...
Страница 530: ...Opcode Listings PowerPC e500 Core Family Reference Manual Rev 1 D 50 Freescale Semiconductor...
Страница 534: ...PowerPC e500 Core Family Reference Manual Rev 1 E 4 Freescale Semiconductor Revision History...