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 >
2005-04-17 02:20:36 +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 .
*
* 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
* /
2006-09-26 12:52:32 +04:00
ALIGN
memset_c :
CFI_ S T A R T P R O C
movq % r d i ,% r9
movl % e d x ,% r8 d
andl $ 7 ,% r8 d
movl % e d x ,% e c x
shrl $ 3 ,% e c x
/* 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
mulq % r s i / * w i t h r a x , c l o b b e r s r d x * /
rep s t o s q
movl % r8 d ,% e c x
rep s t o s b
movq % r9 ,% r a x
ret
CFI_ E N D P R O C
ENDPROC( m e m s e t _ c )
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
movq % r d x ,% r11
/* 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
mul % r c x / * w i t h r a x , c l o b b e r s r d x * /
/* 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 :
movl % r11 d ,% e c x
shrl $ 6 ,% e c x
jz . L h a n d l e _ t a i l
.p2align 4
.Lloop_64 :
decl % e c x
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 :
movl % r11 d ,% e c x
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 :
movl % r11 d ,% e c x
andl $ 7 ,% e c x
jz . L e n d e
.p2align 4
.Lloop_1 :
decl % e c x
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 :
cmpq $ 7 ,% r11
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
subq % r8 ,% r11
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
/ * Some C P U s r u n f a s t e r u s i n g t h e s t r i n g i n s t r u c t i o n s .
It i s a l s o a l o t s i m p l e r . U s e t h i s w h e n p o s s i b l e * /
# include < a s m / c p u f e a t u r e . h >
2006-09-26 12:52:32 +04:00
.section .altinstr_replacement , " ax"
1 : .byte 0xeb /* jmp <disp8> */
.byte ( memset_ c - m e m s e t ) - ( 2 f - 1 b ) / * o f f s e t * /
2 :
.previous
2006-02-03 23:51:02 +03:00
.section .altinstructions , " a"
.align 8
2006-09-26 12:52:32 +04:00
.quad memset
.quad 1b
.byte X86_FEATURE_REP_GOOD
.byte .Lfinal - memset
.byte 2b - 1 b
2006-02-03 23:51:02 +03:00
.previous