2005-04-17 02:20:36 +04:00
/* Copyright 2002 Andi Kleen */
2006-10-04 11:38:54 +04:00
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 >
# include < a s m / c p u f e a t u r e . h >
2005-04-17 02:20:36 +04:00
/ *
* memcpy - C o p y a m e m o r y b l o c k .
*
* Input :
* rdi d e s t i n a t i o n
* rsi s o u r c e
* rdx c o u n t
*
* Output :
* 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
memcpy_c :
CFI_ S T A R T P R O C
movq % r d i ,% r a x
movl % e d x ,% e c x
shrl $ 3 ,% e c x
andl $ 7 ,% e d x
rep m o v s q
movl % e d x ,% e c x
rep m o v s b
ret
CFI_ E N D P R O C
ENDPROC( m e m c p y _ c )
ENTRY( _ _ m e m c p y )
ENTRY( m e m c p y )
CFI_ S T A R T P R O C
2006-02-03 23:51:02 +03:00
movq % r d i ,% r a x
movl % e d x ,% 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 s i ) ,% r11
movq 8 ( % r s i ) ,% r8
movq % r11 ,( % r d i )
movq % r8 ,1 * 8 ( % r d i )
movq 2 * 8 ( % r s i ) ,% r9
movq 3 * 8 ( % r s i ) ,% r10
movq % r9 ,2 * 8 ( % r d i )
movq % r10 ,3 * 8 ( % r d i )
movq 4 * 8 ( % r s i ) ,% r11
movq 5 * 8 ( % r s i ) ,% r8
movq % r11 ,4 * 8 ( % r d i )
movq % r8 ,5 * 8 ( % r d i )
movq 6 * 8 ( % r s i ) ,% r9
movq 7 * 8 ( % r s i ) ,% r10
movq % r9 ,6 * 8 ( % r d i )
movq % r10 ,7 * 8 ( % r d i )
leaq 6 4 ( % r s i ) ,% r s i
leaq 6 4 ( % r d i ) ,% r d i
jnz . L l o o p _ 6 4
.Lhandle_tail :
movl % e d x ,% e c x
andl $ 6 3 ,% e c x
shrl $ 3 ,% e c x
jz . L h a n d l e _ 7
.p2align 4
.Lloop_8 :
decl % e c x
movq ( % r s i ) ,% r8
movq % r8 ,( % r d i )
leaq 8 ( % r d i ) ,% r d i
leaq 8 ( % r s i ) ,% r s i
jnz . L l o o p _ 8
.Lhandle_7 :
movl % e d x ,% e c x
andl $ 7 ,% e c x
jz . L e n d e
.p2align 4
.Lloop_1 :
movb ( % r s i ) ,% r8 b
movb % r8 b ,( % r d i )
incq % r d i
incq % r s i
decl % e c x
jnz . L l o o p _ 1
.Lende :
ret
2006-09-26 12:52:32 +04:00
CFI_ E N D P R O C
ENDPROC( m e m c p y )
ENDPROC( _ _ m e m c p y )
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 c o p y 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 * /
2006-09-26 12:52:32 +04:00
.section .altinstr_replacement , " ax"
1 : .byte 0xeb /* jmp <disp8> */
.byte ( memcpy_ c - m e m c p y ) - ( 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 memcpy
.quad 1b
.byte X86_FEATURE_REP_GOOD
2007-08-12 12:12:52 +04:00
/ * Replace o n l y b e g i n n i n g , m e m c p y i s u s e d t o a p p l y a l t e r n a t i v e s , s o i t
* is s i l l y t o o v e r w r i t e i t s e l f w i t h n o p s - r e b o o t i s o n l y o u t c o m e . . . * /
.byte 2b - 1 b
2006-09-26 12:52:32 +04:00
.byte 2b - 1 b
2006-02-03 23:51:02 +03:00
.previous