14.06.2015 Views

Power ISA™ Version 2.03 - Power.org

Power ISA™ Version 2.03 - Power.org

Power ISA™ Version 2.03 - Power.org

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Version</strong> <strong>2.03</strong><br />

B.2.2 Lock Release and Export<br />

Barriers<br />

An “export barrier” is an instruction or sequence of<br />

instructions that prevents the store that releases a lock<br />

from being performed before stores caused by instructions<br />

preceding the barrier have been performed. An<br />

export barrier can be used to ensure that all stores to a<br />

shared data structure protected by a lock will be performed<br />

with respect to any other processor before the<br />

store that releases the lock is performed with respect to<br />

that processor.<br />

B.2.2.1 Export Shared Storage and<br />

Release Lock<br />

A sync instruction can be used as an export barrier<br />

independent of the storage control attributes (e.g.,<br />

presence or absence of the Caching Inhibited attribute)<br />

of the storage containing the shared data structure.<br />

Because the lock must be in storage that is neither<br />

Write Through Required nor Caching Inhibited, if the<br />

shared data structure is in storage that is Write<br />

Through Required or Caching Inhibited a sync instruction<br />

must be used as the export barrier.<br />

In this example it is assumed that the shared data<br />

structure is in storage that is Caching Inhibited, the<br />

address of the lock is in GPR 3, the value indicating<br />

that the lock is free is in GPR 4, and the address of the<br />

shared data structure is in GPR 9.<br />

stw<br />

sync<br />

stw<br />

r7,data1(r9)#store shared data (last)<br />

#export barrier<br />

r4,lock(r3)#release lock<br />

The sync ensures that the store that releases the lock<br />

will not be performed with respect to any other processor<br />

until all stores caused by instructions preceding the<br />

sync have been performed with respect to that processor.<br />

The lwsync ensures that the store that releases the<br />

lock will not be performed with respect to any other processor<br />

until all stores caused by instructions preceding<br />

the lwsync have been performed with respect to that<br />

processor.<br />

B.2.3<br />

Safe Fetch<br />

If a load must be performed before a subsequent store<br />

(e.g., the store that releases a lock protecting a shared<br />

data structure), a technique similar to the following can<br />

be used.<br />

In this example it is assumed that the address of the<br />

storage operand to be loaded is in GPR 3, the contents<br />

of the storage operand are returned in GPR 4, and the<br />

address of the storage operand to be stored is in GPR<br />

5.<br />

lwz r4,0(r3)#load shared data<br />

cmpw r4,r4 #set CR0 to “equal”<br />

bne- $-8 #branch never taken<br />

stw r7,0(r5)#store other shared data<br />

An alternative is to use a technique similar to that<br />

described in Section B.2.1.2, by causing the stw to<br />

depend on the value returned by the lwz and omitting<br />

the cmpw and bne-. The dependency could be created<br />

by ANDing the value returned by the lwz with zero and<br />

then adding the result to the value to be stored by the<br />

stw. If both storage operands are in storage that is neither<br />

Write Through Required nor Caching Inhibited,<br />

another alternative is to replace the cmpw and bnewith<br />

an lwsync instruction.<br />

B.2.2.2 Export Shared Storage and<br />

Release Lock using lwsync<br />

If the shared data structure is in storage that is neither<br />

Write Through Required nor Caching Inhibited, an<br />

lwsync instruction can be used as the export barrier.<br />

Using lwsync rather than sync will yield better performance<br />

in most systems.<br />

In this example it is assumed that the shared data<br />

structure is in storage that is neither Write Through<br />

Required nor Caching Inhibited, the address of the lock<br />

is in GPR 3, the value indicating that the lock is free is<br />

in GPR 4, and the address of the shared data structure<br />

is in GPR 9.<br />

stw<br />

lwsync<br />

stw<br />

r7,data1(r9)#store shared data (last)<br />

#export barrier<br />

r4,lock(r3)#release lock<br />

380<br />

<strong>Power</strong> ISA -- Book II

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!