* ws@tools.de (Wolfgang Solfrank, TooLs GmbH) +49-228-985800
*/
-ENTRY(memcpy)
- movq %rdi,%r11 /* save dest */
- movq %rdx,%rcx
- jmp 2f /* jump to forward copy code path */
-
ENTRY(bcopy)
xchgq %rdi,%rsi
/* fall into memmove */
subq %rsi,%rax
cmpq %rcx,%rax /* overlapping? */
jb 1f
-2: cld /* nope, copy forwards. */
+ jmp 2f /* nope */
+
+ENTRY(memcpy)
+ movq %rdi,%r11 /* save dest */
+ movq %rdx,%rcx
+2:
+ cld /* copy forwards. */
shrq $3,%rcx /* copy by words */
rep
movsq
-/* $OpenBSD: memmove.S,v 1.5 2013/06/15 19:45:26 miod Exp $ */
+/* $OpenBSD: memmove.S,v 1.6 2014/01/09 05:39:41 tedu Exp $ */
/*-
* Copyright (c) 1993, 1994, 1995 Charles M. Hannum. All rights reserved.
#include <machine/asm.h>
/*
- * Emulate memmove() by swapping the first two arguments, and jumping
- * into bcopy(), which handles overlapping regions.
+ * Emulate bcopy() by swapping the first two arguments, and jumping
+ * into memmove(), which handles overlapping regions.
*/
-ENTRY(memmove)
+ENTRY(bcopy)
pushl %esi
pushl %edi
- movl 12(%esp),%edi
- movl 16(%esp),%esi
+ movl 12(%esp),%esi
+ movl 16(%esp),%edi
jmp docopy
/*
- * Emulate memcpy() by loading the first two arguments in reverse order
- * and jumping into bcopy()'s forward copy code.
+ * memmove(caddr_t dst, caddr_t src, size_t len);
+ * Copy len bytes, coping with overlapping space.
*/
-ENTRY(memcpy)
+ENTRY(memmove)
pushl %esi
pushl %edi
movl 12(%esp),%edi
movl 16(%esp),%esi
- movl 20(%esp),%ecx
- jmp docopyf
-
-/*
- * bcopy(caddr_t from, caddr_t to, size_t len);
- * Copy len bytes, copying with overlapping space.
- */
-ENTRY(bcopy)
- pushl %esi
- pushl %edi
- movl 12(%esp),%esi
- movl 16(%esp),%edi
docopy:
movl 20(%esp),%ecx
movl %edi,%eax
subl %esi,%eax
cmpl %ecx,%eax # overlapping?
jb 1f
+ jmp docopyf # nope
+/*
+ * memcpy() doesn't worry about overlap and always copies forward
+ */
+ENTRY(memcpy)
+ pushl %esi
+ pushl %edi
+ movl 12(%esp),%edi
+ movl 16(%esp),%esi
+ movl 20(%esp),%ecx
docopyf:
movl %edi,%eax # setup return value for memcpy/memmove
- cld # nope, copy forward
+ cld # copy forward
shrl $2,%ecx # copy by 32-bit words
rep
movsl
ret
_ALIGN_TEXT
-1: movl %edi,%eax # setup return value for memcpy/memmove
+1: movl %edi,%eax # setup return value for memmove
addl %ecx,%edi # copy backward
addl %ecx,%esi
std