You are on page 1of 17

| 

  
    
    

    


 
      

 
  !     
  "
# $ %%&      "
 ' %%&(
# $     
    
   
# )   |"
 |  
       %%&
**+ |+  * "
# ,  -./(

)-  
%%&
 **  01 23 -4     23-4  "
 )- 
  &&333" " & 3 1&  &0 &
asm
long // <- Zero on failure, one on success (r3).
AtomicStore(
long prev, // -> Previous value (r3).
long next, // -> New value (r4).
void *addr ) // -> Location to update (r5).
{
retry:
lwarx r6, 0, r5 // current = *addr;
cmpw r6, r3 // if( current != prev )
bne fail // goto fail;
stwcx. r4, 0, r5 // if( reservation == addr ) *addr = next;
bne- retry // else goto retry;
li r3, 1 // Return true.
blr // We're outta here.
fail:
stwcx. r6, 0, r5 // Clear reservation.
li r3, 0 // Return false.
blr // We're outta here.
}
±
  
 *       0 
   
    23
 4
 5    
  ! 
          
  "
   "  
#   

  3    


 
    
# 5 

   3    "


Ò
   6 
 
 
  v    

v   



 
v   
  v    

 6   7  01   


  1        "
#  
  0  
  
#    
 
0

   


  1    3
#     30

    
"

V
      
 )   3   1 
      
# '    
 +
   3  
3 1 
!  3  
 1"
       3 
  1  3 
 3 "

/
    6 0
 
 6 
  3 
 
"
   3      2
  
  4"
#   3  
83  9 3 

# |!  3  
8  9 3 
"

¦
 
      "    - 
# *  |  5    
# *  |   
   9"
# ,3 | 3      
-    
   & 
    "
#
*  5 2   34    + 
      |  3 :
         

#   8    30
 ;9
 "
 *        
  
   "

.
 
 $   1<=> ? 1<@>
#  ±0  + 1  
 
1<=>AA 0B 
0B 1<@>AA
   1<@>+  +  1<=>"
1<=> CC 1<@> ("
# D   
# , 3         ""  
  
         3 
# ,         "

ë
)-  *   E
 |    3      
       2 -"
   !4
    
# *1  - 2 4 
# )-  - 
#   3 
 *   !     
0        "
@=
 
  F
Ô  (   )
!G  ° H
 1<>H  (  )
I *!G H

 *!G  J 



H
&' $  
 *!G!2*!G  JJ 4F
*!G   

 &J    J&
!G  J ° + J ° H &J !  J&
 H

 + H

3 2@4 F
 

C G12 4H

 °  C ? 

0B H       !     
 °  C ? 

0B H  "   #$ 

  C  

0B1<@>H      
 2 ° +  ° 4H î        
 C  

0B1<=>H

2
  CC 4 F  $%
 C !G!2 ° 4H

2 G2 +  ° 44  1H 
I &J 
J&
I &J 3 J&
 

C  

H
  H
I &J *!G! J&
@@
)-   
 6   !  !
 @/0  0!"
 ,K  3    


 
 !   3
3  !
 | - 10



 "

 ,  
  C
   L 
  2

@
%  
 %     

 !      
  

# |      
# % #    #  
    
      3  
3  "
    
#    %%
# $ !      3  
# 3   3    

%      
   1 !   !
  
-
#  3     3
  3  
 *  3 1 
  "
#
   
1+    
 3 1
    "
        
  "


  
 51   
  
#  + |+ M 

%*
++ 

++  

%*   %*


  

@V
%   *
 
   -   
3   
-   
 V@  
@/
 

@/
 
 6  3  
  
  !
        3 

 "
# 6 
     
  3 - 
01 3
1

#    " + +  9


1 
    "
   ,5  
#   3      
   3     

"
# ' 1+      13    
  "
 |   
 
#
  
           0
  +  3     ,5"
# *      3   
   "