2013-03-21 20:28:47 +04:00
/ *
* Based o n a r c h / a r m / l i b / b i t o p s . h
*
* Copyright ( C ) 2 0 1 3 A R M L t d .
*
* This p r o g r a m i s f r e e s o f t w a r e ; you can redistribute it and/or modify
* it u n d e r t h e t e r m s o f t h e G N U G e n e r a l P u b l i c L i c e n s e v e r s i o n 2 a s
* published b y t h e F r e e S o f t w a r e F o u n d a t i o n .
*
* This p r o g r a m i s d i s t r i b u t e d i n t h e h o p e t h a t i t w i l l b e u s e f u l ,
* but W I T H O U T A N Y W A R R A N T Y ; without even the implied warranty of
* MERCHANTABILITY o r F I T N E S S F O R A P A R T I C U L A R P U R P O S E . S e e t h e
* GNU G e n e r a l P u b l i c L i c e n s e f o r m o r e d e t a i l s .
*
* You s h o u l d h a v e r e c e i v e d a c o p y o f t h e G N U G e n e r a l P u b l i c L i c e n s e
* along w i t h t h i s p r o g r a m . I f n o t , s e e < h t t p : / / w w w . g n u . o r g / l i c e n s e s / > .
* /
# include < l i n u x / l i n k a g e . h >
# include < a s m / a s s e m b l e r . h >
2015-02-12 07:17:37 +03:00
# include < a s m / l s e . h >
2013-03-21 20:28:47 +04:00
/ *
* x0 : bits 5 : 0 b i t o f f s e t
2013-05-07 21:02:58 +04:00
* bits 3 1 : 6 w o r d o f f s e t
2013-03-21 20:28:47 +04:00
* x1 : address
* /
2015-02-12 07:17:37 +03:00
.macro bitop, n a m e , l l s c , l s e
2013-03-21 20:28:47 +04:00
ENTRY( \ n a m e )
2013-05-07 21:02:58 +04:00
and w3 , w0 , #63 / / G e t b i t o f f s e t
eor w0 , w0 , w3 / / C l e a r l o w b i t s
2013-03-21 20:28:47 +04:00
mov x2 , #1
add x1 , x1 , x0 , l s r #3 / / G e t w o r d o f f s e t
lsl x3 , x2 , x3 / / C r e a t e m a s k
2015-02-12 07:17:37 +03:00
alt_ l s e " 1 : l d x r x2 , [ x1 ] " , " \ l s e x3 , [ x1 ] "
alt_ l s e " \ l l s c x2 , x2 , x3 " , " n o p "
alt_ l s e " s t x r w0 , x2 , [ x1 ] " , " n o p "
alt_ l s e " c b n z w0 , 1 b " , " n o p "
2013-03-21 20:28:47 +04:00
ret
ENDPROC( \ n a m e )
.endm
2015-02-12 07:17:37 +03:00
.macro testop, n a m e , l l s c , l s e
2013-03-21 20:28:47 +04:00
ENTRY( \ n a m e )
2013-05-07 21:02:58 +04:00
and w3 , w0 , #63 / / G e t b i t o f f s e t
eor w0 , w0 , w3 / / C l e a r l o w b i t s
2013-03-21 20:28:47 +04:00
mov x2 , #1
add x1 , x1 , x0 , l s r #3 / / G e t w o r d o f f s e t
lsl x4 , x2 , x3 / / C r e a t e m a s k
2015-02-12 07:17:37 +03:00
alt_ l s e " 1 : l d x r x2 , [ x1 ] " , " \ l s e x4 , x2 , [ x1 ] "
lsr x0 , x2 , x3
alt_ l s e " \ l l s c x2 , x2 , x4 " , " n o p "
alt_ l s e " s t l x r w5 , x2 , [ x1 ] " , " n o p "
alt_ l s e " c b n z w5 , 1 b " , " n o p "
alt_ l s e " d m b i s h " , " n o p "
2013-03-21 20:28:47 +04:00
and x0 , x0 , #1
2015-02-12 07:17:37 +03:00
ret
2013-03-21 20:28:47 +04:00
ENDPROC( \ n a m e )
.endm
/ *
* Atomic b i t o p e r a t i o n s .
* /
2015-02-12 07:17:37 +03:00
bitop c h a n g e _ b i t , e o r , s t e o r
bitop c l e a r _ b i t , b i c , s t c l r
bitop s e t _ b i t , o r r , s t s e t
2013-03-21 20:28:47 +04:00
2015-02-12 07:17:37 +03:00
testop t e s t _ a n d _ c h a n g e _ b i t , e o r , l d e o r a l
testop t e s t _ a n d _ c l e a r _ b i t , b i c , l d c l r a l
testop t e s t _ a n d _ s e t _ b i t , o r r , l d s e t a l