2013-03-21 16:16:43 +00:00
/ *
* Copyright ( C ) 2 0 1 3 A R M L t d .
2014-04-28 06:11:31 +01:00
* Copyright ( C ) 2 0 1 3 L i n a r o .
*
* This c o d e i s b a s e d o n g l i b c c o r t e x s t r i n g s w o r k o r i g i n a l l y a u t h o r e d b y L i n a r o
* and r e - l i c e n s e d u n d e r G P L v2 f o r t h e L i n u x k e r n e l . T h e o r i g i n a l c o d e c a n
* be f o u n d @
*
* http : / / bazaar. l a u n c h p a d . n e t / ~ l i n a r o - t o o l c h a i n - d e v / c o r t e x - s t r i n g s / t r u n k /
* files/ h e a d : / s r c / a a r c h64 /
2013-03-21 16:16:43 +00:00
*
* 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 >
2014-04-28 06:11:31 +01:00
# include < a s m / c a c h e . h >
2013-03-21 16:16:43 +00:00
/ *
* Fill i n t h e b u f f e r w i t h c h a r a c t e r c ( a l i g n m e n t h a n d l e d b y t h e h a r d w a r e )
*
* Parameters :
* x0 - b u f
* x1 - c
* x2 - n
* Returns :
* x0 - b u f
* /
2014-04-28 06:11:31 +01:00
dstin . r e q x0
val . r e q w1
count . r e q x2
tmp1 . r e q x3
tmp1 w . r e q w3
tmp2 . r e q x4
tmp2 w . r e q w4
zva_ l e n _ x . r e q x5
zva_ l e n . r e q w5
zva_ b i t s _ x . r e q x6
A_ l . r e q x7
A_ l w . r e q w7
dst . r e q x8
tmp3 w . r e q w9
tmp3 . r e q x9
2015-10-12 18:52:58 +03:00
.weak memset
ENTRY( _ _ m e m s e t )
2013-03-21 16:16:43 +00:00
ENTRY( m e m s e t )
2014-04-28 06:11:31 +01:00
mov d s t , d s t i n / * P r e s e r v e r e t u r n v a l u e . * /
and A _ l w , v a l , #255
orr A _ l w , A _ l w , A _ l w , l s l #8
orr A _ l w , A _ l w , A _ l w , l s l #16
orr A _ l , A _ l , A _ l , l s l #32
cmp c o u n t , #15
b. h i . L o v e r16 _ p r o c
/*All store maybe are non-aligned..*/
tbz c o u n t , #3 , 1 f
str A _ l , [ d s t ] , #8
1 :
tbz c o u n t , #2 , 2 f
str A _ l w , [ d s t ] , #4
2 :
tbz c o u n t , #1 , 3 f
strh A _ l w , [ d s t ] , #2
3 :
tbz c o u n t , #0 , 4 f
strb A _ l w , [ d s t ]
4 :
ret
.Lover16_proc :
/*Whether the start address is aligned with 16.*/
neg t m p2 , d s t
ands t m p2 , t m p2 , #15
b. e q . L a l i g n e d
/ *
* The c o u n t i s n o t l e s s t h a n 1 6 , w e c a n u s e s t p t o s t o r e t h e s t a r t 1 6 b y t e s ,
* then a d j u s t t h e d s t a l i g n e d w i t h 1 6 . T h i s p r o c e s s w i l l m a k e t h e c u r r e n t
* memory a d d r e s s a t a l i g n m e n t b o u n d a r y .
* /
stp A _ l , A _ l , [ d s t ] / * n o n - a l i g n e d s t o r e . . * /
/*make the dst aligned..*/
sub c o u n t , c o u n t , t m p2
add d s t , d s t , t m p2
.Laligned :
cbz A _ l , . L z e r o _ m e m
.Ltail_maybe_long :
cmp c o u n t , #64
b. g e . L n o t _ s h o r t
.Ltail63 :
ands t m p1 , c o u n t , #0x30
b. e q 3 f
cmp t m p1 w , #0x20
b. e q 1 f
b. l t 2 f
stp A _ l , A _ l , [ d s t ] , #16
1 :
stp A _ l , A _ l , [ d s t ] , #16
2 :
stp A _ l , A _ l , [ d s t ] , #16
/ *
* The l a s t s t o r e l e n g t h i s l e s s t h a n 1 6 ,u s e s t p t o w r i t e l a s t 1 6 b y t e s .
* It w i l l l e a d s o m e b y t e s w r i t t e n t w i c e a n d t h e a c c e s s i s n o n - a l i g n e d .
* /
3 :
ands c o u n t , c o u n t , #15
cbz c o u n t , 4 f
add d s t , d s t , c o u n t
stp A _ l , A _ l , [ d s t , #- 16 ] / * R e p e a t s o m e / a l l o f l a s t s t o r e . * /
4 :
ret
/ *
* Critical l o o p . S t a r t a t a n e w c a c h e l i n e b o u n d a r y . A s s u m i n g
* 6 4 bytes p e r l i n e , t h i s e n s u r e s t h e e n t i r e l o o p i s i n o n e l i n e .
* /
.p2align L1_CACHE_SHIFT
.Lnot_short :
sub d s t , d s t , #16 / * P r e - b i a s . * /
sub c o u n t , c o u n t , #64
1 :
stp A _ l , A _ l , [ d s t , #16 ]
stp A _ l , A _ l , [ d s t , #32 ]
stp A _ l , A _ l , [ d s t , #48 ]
stp A _ l , A _ l , [ d s t , #64 ] !
subs c o u n t , c o u n t , #64
b. g e 1 b
tst c o u n t , #0x3f
add d s t , d s t , #16
b. n e . L t a i l 6 3
.Lexitfunc :
ret
/ *
* For z e r o i n g m e m o r y , c h e c k t o s e e i f w e c a n u s e t h e Z V A f e a t u r e t o
* zero e n t i r e ' c a c h e ' l i n e s .
* /
.Lzero_mem :
cmp c o u n t , #63
b. l e . L t a i l 6 3
/ *
* For z e r o i n g s m a l l a m o u n t s o f m e m o r y , i t ' s n o t w o r t h s e t t i n g u p
* the l i n e - c l e a r c o d e .
* /
cmp c o u n t , #128
b. l t . L n o t _ s h o r t / * c o u n t i s a t l e a s t 1 2 8 b y t e s * /
mrs t m p1 , d c z i d _ e l 0
tbnz t m p1 , #4 , . L n o t _ s h o r t
mov t m p3 w , #4
and z v a _ l e n , t m p1 w , #15 / * S a f e t y : o t h e r b i t s r e s e r v e d . * /
lsl z v a _ l e n , t m p3 w , z v a _ l e n
ands t m p3 w , z v a _ l e n , #63
/ *
* ensure t h e z v a _ l e n i s n o t l e s s t h a n 6 4 .
* It i s n o t m e a n i n g f u l t o u s e Z V A i f t h e b l o c k s i z e i s l e s s t h a n 6 4 .
* /
b. n e . L n o t _ s h o r t
.Lzero_by_line :
/ *
* Compute h o w f a r w e n e e d t o g o t o b e c o m e s u i t a b l y a l i g n e d . W e ' r e
* already a t q u a d - w o r d a l i g n m e n t .
* /
cmp c o u n t , z v a _ l e n _ x
b. l t . L n o t _ s h o r t / * N o t e n o u g h t o r e a c h a l i g n m e n t . * /
sub z v a _ b i t s _ x , z v a _ l e n _ x , #1
neg t m p2 , d s t
ands t m p2 , t m p2 , z v a _ b i t s _ x
b. e q 2 f / * A l r e a d y a l i g n e d . * /
/* Not aligned, check that there's enough to copy after alignment.*/
sub t m p1 , c o u n t , t m p2
/ *
* grantee t h e r e m a i n l e n g t h t o b e Z V A i s b i g g e r t h a n 6 4 ,
* avoid t o m a k e t h e 2 f ' s p r o c e s s o v e r m e m r a n g e . * /
cmp t m p1 , #64
ccmp t m p1 , z v a _ l e n _ x , #8 , g e / * N Z C V =0b1000 * /
b. l t . L n o t _ s h o r t
/ *
* We k n o w t h a t t h e r e ' s a t l e a s t 6 4 b y t e s t o z e r o a n d t h a t i t ' s s a f e
* to o v e r r u n b y 6 4 b y t e s .
* /
mov c o u n t , t m p1
1 :
stp A _ l , A _ l , [ d s t ]
stp A _ l , A _ l , [ d s t , #16 ]
stp A _ l , A _ l , [ d s t , #32 ]
subs t m p2 , t m p2 , #64
stp A _ l , A _ l , [ d s t , #48 ]
add d s t , d s t , #64
b. g e 1 b
/* We've overrun a bit, so adjust dst downwards.*/
add d s t , d s t , t m p2
2 :
sub c o u n t , c o u n t , z v a _ l e n _ x
3 :
dc z v a , d s t
add d s t , d s t , z v a _ l e n _ x
subs c o u n t , c o u n t , z v a _ l e n _ x
b. g e 3 b
ands c o u n t , c o u n t , z v a _ b i t s _ x
b. n e . L t a i l _ m a y b e _ l o n g
ret
2015-10-08 20:02:03 +01:00
ENDPIPROC( m e m s e t )
2015-10-12 18:52:58 +03:00
ENDPROC( _ _ m e m s e t )