2007-10-15 16:41:44 -07:00
/ * atomic. S : T h e s e t h i n g s a r e t o o b i g t o d o i n l i n e .
2005-04-16 15:20:36 -07:00
*
2012-11-09 19:37:59 -08:00
* Copyright ( C ) 1 9 9 9 , 2 0 0 7 2 0 1 2 D a v i d S . M i l l e r ( d a v e m @davemloft.net)
2005-04-16 15:20:36 -07:00
* /
2012-05-11 20:33:22 -07:00
# include < l i n u x / l i n k a g e . h >
2005-04-16 15:20:36 -07:00
# include < a s m / a s i . h >
2007-10-15 16:41:44 -07:00
# include < a s m / b a c k o f f . h >
2005-04-16 15:20:36 -07:00
.text
/ * Two v e r s i o n s o f t h e a t o m i c r o u t i n e s , o n e t h a t
* does n o t r e t u r n a v a l u e a n d d o e s n o t p e r f o r m
* memory b a r r i e r s , a n d a s e c o n d w h i c h r e t u r n s
* a v a l u e a n d d o e s t h e b a r r i e r s .
* /
2014-03-26 18:29:28 +01:00
# define A T O M I C _ O P ( o p ) \
ENTRY( a t o m i c _ ## o p ) / * % o 0 = i n c r e m e n t , % o 1 = a t o m i c _ p t r * / \
BACKOFF_ S E T U P ( % o 2 ) ; \
1 : lduw [ % o 1 ] , % g 1 ; \
op % g 1 , % o 0 , % g 7 ; \
cas [ % o 1 ] , % g 1 , % g 7 ; \
cmp % g 1 , % g 7 ; \
bne,p n % i c c , B A C K O F F _ L A B E L ( 2 f , 1 b ) ; \
nop; \
retl; \
nop; \
2 : BACKOFF_ S P I N ( % o 2 , % o 3 , 1 b ) ; \
ENDPROC( a t o m i c _ ## o p ) ; \
2005-04-16 15:20:36 -07:00
2014-03-26 18:29:28 +01:00
# define A T O M I C _ O P _ R E T U R N ( o p ) \
ENTRY( a t o m i c _ ## o p # # _ r e t u r n ) / * % o 0 = i n c r e m e n t , % o 1 = a t o m i c _ p t r * / \
BACKOFF_ S E T U P ( % o 2 ) ; \
1 : lduw [ % o 1 ] , % g 1 ; \
op % g 1 , % o 0 , % g 7 ; \
cas [ % o 1 ] , % g 1 , % g 7 ; \
cmp % g 1 , % g 7 ; \
bne,p n % i c c , B A C K O F F _ L A B E L ( 2 f , 1 b ) ; \
2014-09-02 11:40:16 +02:00
op % g 1 , % o 0 , % g 1 ; \
2014-03-26 18:29:28 +01:00
retl; \
sra % g 1 , 0 , % o 0 ; \
2 : BACKOFF_ S P I N ( % o 2 , % o 3 , 1 b ) ; \
ENDPROC( a t o m i c _ ## o p # # _ r e t u r n ) ;
2005-04-16 15:20:36 -07:00
2014-03-26 18:29:28 +01:00
# define A T O M I C _ O P S ( o p ) A T O M I C _ O P ( o p ) A T O M I C _ O P _ R E T U R N ( o p )
2005-04-16 15:20:36 -07:00
2014-03-26 18:29:28 +01:00
ATOMIC_ O P S ( a d d )
ATOMIC_ O P S ( s u b )
2014-04-23 19:40:25 +02:00
ATOMIC_ O P ( a n d )
ATOMIC_ O P ( o r )
ATOMIC_ O P ( x o r )
2005-04-16 15:20:36 -07:00
2014-03-26 18:29:28 +01:00
# undef A T O M I C _ O P S
# undef A T O M I C _ O P _ R E T U R N
# undef A T O M I C _ O P
2005-04-16 15:20:36 -07:00
2014-03-26 18:29:28 +01:00
# define A T O M I C 6 4 _ O P ( o p ) \
ENTRY( a t o m i c64 _ ## o p ) / * % o 0 = i n c r e m e n t , % o 1 = a t o m i c _ p t r * / \
BACKOFF_ S E T U P ( % o 2 ) ; \
1 : ldx [ % o 1 ] , % g 1 ; \
op % g 1 , % o 0 , % g 7 ; \
casx [ % o 1 ] , % g 1 , % g 7 ; \
cmp % g 1 , % g 7 ; \
bne,p n % x c c , B A C K O F F _ L A B E L ( 2 f , 1 b ) ; \
nop; \
retl; \
nop; \
2 : BACKOFF_ S P I N ( % o 2 , % o 3 , 1 b ) ; \
ENDPROC( a t o m i c64 _ ## o p ) ; \
2005-04-16 15:20:36 -07:00
2014-03-26 18:29:28 +01:00
# define A T O M I C 6 4 _ O P _ R E T U R N ( o p ) \
ENTRY( a t o m i c64 _ ## o p # # _ r e t u r n ) / * % o 0 = i n c r e m e n t , % o 1 = a t o m i c _ p t r * / \
BACKOFF_ S E T U P ( % o 2 ) ; \
1 : ldx [ % o 1 ] , % g 1 ; \
op % g 1 , % o 0 , % g 7 ; \
casx [ % o 1 ] , % g 1 , % g 7 ; \
cmp % g 1 , % g 7 ; \
bne,p n % x c c , B A C K O F F _ L A B E L ( 2 f , 1 b ) ; \
nop; \
retl; \
2014-09-02 11:40:16 +02:00
op % g 1 , % o 0 , % o 0 ; \
2014-03-26 18:29:28 +01:00
2 : BACKOFF_ S P I N ( % o 2 , % o 3 , 1 b ) ; \
ENDPROC( a t o m i c64 _ ## o p # # _ r e t u r n ) ;
# define A T O M I C 6 4 _ O P S ( o p ) A T O M I C 6 4 _ O P ( o p ) A T O M I C 6 4 _ O P _ R E T U R N ( o p )
ATOMIC6 4 _ O P S ( a d d )
ATOMIC6 4 _ O P S ( s u b )
2014-04-23 19:40:25 +02:00
ATOMIC6 4 _ O P ( a n d )
ATOMIC6 4 _ O P ( o r )
ATOMIC6 4 _ O P ( x o r )
2014-03-26 18:29:28 +01:00
# undef A T O M I C 6 4 _ O P S
# undef A T O M I C 6 4 _ O P _ R E T U R N
# undef A T O M I C 6 4 _ O P
2012-11-09 19:37:59 -08:00
ENTRY( a t o m i c64 _ d e c _ i f _ p o s i t i v e ) / * % o 0 = a t o m i c _ p t r * /
BACKOFF_ S E T U P ( % o 2 )
1 : ldx [ % o 0 ] , % g 1
brlez,p n % g 1 , 3 f
sub % g 1 , 1 , % g 7
casx [ % o 0 ] , % g 1 , % g 7
cmp % g 1 , % g 7
bne,p n % x c c , B A C K O F F _ L A B E L ( 2 f , 1 b )
nop
3 : retl
sub % g 1 , 1 , % o 0
2 : BACKOFF_ S P I N ( % o 2 , % o 3 , 1 b )
ENDPROC( a t o m i c64 _ d e c _ i f _ p o s i t i v e )