2005-04-17 02:20:36 +04:00
/* Copyright 2002 Andi Kleen, SuSE Labs */
2006-09-26 12:52:32 +04:00
# include < l i n u x / l i n k a g e . h >
# include < a s m / d w a r f2 . h >
2011-05-18 02:29:18 +04:00
# include < a s m / c p u f e a t u r e . h >
# include < a s m / a l t e r n a t i v e - a s m . h >
2006-09-26 12:52:32 +04:00
2005-04-17 02:20:36 +04:00
/ *
2011-05-18 02:29:18 +04:00
* ISO C m e m s e t - s e t a m e m o r y b l o c k t o a b y t e v a l u e . T h i s f u n c t i o n u s e s f a s t
* string t o g e t b e t t e r p e r f o r m a n c e t h a n t h e o r i g i n a l f u n c t i o n . T h e c o d e i s
* simpler a n d s h o r t e r t h a n t h e o r i g n a l f u n c t i o n a s w e l l .
2005-04-17 02:20:36 +04:00
*
* rdi d e s t i n a t i o n
* rsi v a l u e ( c h a r )
* rdx c o u n t ( b y t e s )
*
* rax o r i g i n a l d e s t i n a t i o n
* /
2009-12-18 19:16:03 +03:00
.section .altinstr_replacement , " ax" , @progbits
.Lmemset_c :
2006-09-26 12:52:32 +04:00
movq % r d i ,% r9
2012-01-05 20:10:42 +04:00
movq % r d x ,% r c x
andl $ 7 ,% e d x
shrq $ 3 ,% r c x
2006-09-26 12:52:32 +04:00
/* expand byte value */
movzbl % s i l ,% e s i
movabs $ 0 x01 0 1 0 1 0 1 0 1 0 1 0 1 0 1 ,% r a x
2012-01-05 20:10:42 +04:00
imulq % r s i ,% r a x
2006-09-26 12:52:32 +04:00
rep s t o s q
2012-01-05 20:10:42 +04:00
movl % e d x ,% e c x
2006-09-26 12:52:32 +04:00
rep s t o s b
movq % r9 ,% r a x
ret
2009-12-18 19:16:03 +03:00
.Lmemset_e :
.previous
2006-09-26 12:52:32 +04:00
2011-05-18 02:29:18 +04:00
/ *
* ISO C m e m s e t - s e t a m e m o r y b l o c k t o a b y t e v a l u e . T h i s f u n c t i o n u s e s
* enhanced r e p s t o s b t o o v e r r i d e t h e f a s t s t r i n g f u n c t i o n .
* The c o d e i s s i m p l e r a n d s h o r t e r t h a n t h e f a s t s t r i n g f u n c t i o n a s w e l l .
*
* rdi d e s t i n a t i o n
* rsi v a l u e ( c h a r )
* rdx c o u n t ( b y t e s )
*
* rax o r i g i n a l d e s t i n a t i o n
* /
.section .altinstr_replacement , " ax" , @progbits
.Lmemset_c_e :
movq % r d i ,% r9
movb % s i l ,% a l
2012-01-05 20:10:42 +04:00
movq % r d x ,% r c x
2011-05-18 02:29:18 +04:00
rep s t o s b
movq % r9 ,% r a x
ret
.Lmemset_e_e :
.previous
2006-09-26 12:52:32 +04:00
ENTRY( m e m s e t )
ENTRY( _ _ m e m s e t )
CFI_ S T A R T P R O C
2006-02-03 23:51:02 +03:00
movq % r d i ,% r10
/* expand byte value */
movzbl % s i l ,% e c x
movabs $ 0 x01 0 1 0 1 0 1 0 1 0 1 0 1 0 1 ,% r a x
2012-01-05 20:10:42 +04:00
imulq % r c x ,% r a x
2006-02-03 23:51:02 +03:00
/* align dst */
movl % e d i ,% r9 d
andl $ 7 ,% r9 d
jnz . L b a d _ a l i g n m e n t
2006-09-26 12:52:32 +04:00
CFI_ R E M E M B E R _ S T A T E
2006-02-03 23:51:02 +03:00
.Lafter_bad_alignment :
2012-01-05 20:10:42 +04:00
movq % r d x ,% r c x
shrq $ 6 ,% r c x
2006-02-03 23:51:02 +03:00
jz . L h a n d l e _ t a i l
.p2align 4
.Lloop_64 :
2012-01-05 20:10:42 +04:00
decq % r c x
2006-02-03 23:51:02 +03:00
movq % r a x ,( % r d i )
movq % r a x ,8 ( % r d i )
movq % r a x ,1 6 ( % r d i )
movq % r a x ,2 4 ( % r d i )
movq % r a x ,3 2 ( % r d i )
movq % r a x ,4 0 ( % r d i )
movq % r a x ,4 8 ( % r d i )
movq % r a x ,5 6 ( % r d i )
leaq 6 4 ( % r d i ) ,% r d i
jnz . L l o o p _ 6 4
/ * Handle t a i l i n l o o p s . T h e l o o p s s h o u l d b e f a s t e r t h a n h a r d
to p r e d i c t j u m p t a b l e s . * /
.p2align 4
.Lhandle_tail :
2012-01-05 20:10:42 +04:00
movl % e d x ,% e c x
2006-02-03 23:51:02 +03:00
andl $ 6 3 & ( ~ 7 ) ,% e c x
jz . L h a n d l e _ 7
shrl $ 3 ,% e c x
.p2align 4
.Lloop_8 :
decl % e c x
movq % r a x ,( % r d i )
leaq 8 ( % r d i ) ,% r d i
jnz . L l o o p _ 8
.Lhandle_7 :
2012-01-05 20:10:42 +04:00
andl $ 7 ,% e d x
2006-02-03 23:51:02 +03:00
jz . L e n d e
.p2align 4
.Lloop_1 :
2012-01-05 20:10:42 +04:00
decl % e d x
2006-02-03 23:51:02 +03:00
movb % a l ,( % r d i )
leaq 1 ( % r d i ) ,% r d i
jnz . L l o o p _ 1
.Lende :
movq % r10 ,% r a x
ret
2006-09-26 12:52:32 +04:00
CFI_ R E S T O R E _ S T A T E
2006-02-03 23:51:02 +03:00
.Lbad_alignment :
2012-01-05 20:10:42 +04:00
cmpq $ 7 ,% r d x
2006-02-03 23:51:02 +03:00
jbe . L h a n d l e _ 7
movq % r a x ,( % r d i ) / * u n a l i g n e d s t o r e * /
movq $ 8 ,% r8
subq % r9 ,% r8
addq % r8 ,% r d i
2012-01-05 20:10:42 +04:00
subq % r8 ,% r d x
2006-02-03 23:51:02 +03:00
jmp . L a f t e r _ b a d _ a l i g n m e n t
2006-09-26 12:52:32 +04:00
.Lfinal :
CFI_ E N D P R O C
ENDPROC( m e m s e t )
ENDPROC( _ _ m e m s e t )
2006-02-03 23:51:02 +03:00
2011-05-18 02:29:18 +04:00
/ * Some C P U s s u p p o r t e n h a n c e d R E P M O V S B / S T O S B f e a t u r e .
* It i s r e c o m m e n d e d t o u s e t h i s w h e n p o s s i b l e .
*
* If e n h a n c e d R E P M O V S B / S T O S B f e a t u r e i s n o t a v a i l a b l e , u s e f a s t s t r i n g
* instructions.
*
* Otherwise, u s e o r i g i n a l m e m s e t f u n c t i o n .
*
* In . a l t i n s t r u c t i o n s s e c t i o n , E R M S f e a t u r e i s p l a c e d a f t e r R E G _ G O O D
* feature t o i m p l e m e n t t h e r i g h t p a t c h o r d e r .
* /
2006-02-03 23:51:02 +03:00
.section .altinstructions , " a"
2011-05-18 02:29:18 +04:00
altinstruction_ e n t r y m e m s e t ,. L m e m s e t _ c ,X 8 6 _ F E A T U R E _ R E P _ G O O D ,\
.Lfinal - memset,. L m e m s e t _ e - . L m e m s e t _ c
altinstruction_ e n t r y m e m s e t ,. L m e m s e t _ c _ e ,X 8 6 _ F E A T U R E _ E R M S , \
.Lfinal - memset,. L m e m s e t _ e _ e - . L m e m s e t _ c _ e
2006-02-03 23:51:02 +03:00
.previous