diff options
author | 2014-01-09 05:39:41 +0000 | |
---|---|---|
committer | 2014-01-09 05:39:41 +0000 | |
commit | c067621f5d6d8289d191d8ceea10ba6c6e328ed8 (patch) | |
tree | cbe7de41453782d8623f3289726e475122bb9fbb /sys/lib/libkern/arch | |
parent | Switch to string copy rather than memcpy so we stop past '\0' and (diff) | |
download | wireguard-openbsd-c067621f5d6d8289d191d8ceea10ba6c6e328ed8.tar.xz wireguard-openbsd-c067621f5d6d8289d191d8ceea10ba6c6e328ed8.zip |
tiny tweak to asm. prefer memcpy and memmove, with bcopy wrapper
ok guenther
Diffstat (limited to 'sys/lib/libkern/arch')
-rw-r--r-- | sys/lib/libkern/arch/amd64/memmove.S | 13 | ||||
-rw-r--r-- | sys/lib/libkern/arch/i386/memmove.S | 44 |
2 files changed, 28 insertions, 29 deletions
diff --git a/sys/lib/libkern/arch/amd64/memmove.S b/sys/lib/libkern/arch/amd64/memmove.S index cf81c4c3880..1516c743660 100644 --- a/sys/lib/libkern/arch/amd64/memmove.S +++ b/sys/lib/libkern/arch/amd64/memmove.S @@ -40,11 +40,6 @@ * 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 */ @@ -56,7 +51,13 @@ ENTRY(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 diff --git a/sys/lib/libkern/arch/i386/memmove.S b/sys/lib/libkern/arch/i386/memmove.S index 59cadfc01b2..a88b08a5114 100644 --- a/sys/lib/libkern/arch/i386/memmove.S +++ b/sys/lib/libkern/arch/i386/memmove.S @@ -1,4 +1,4 @@ -/* $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. @@ -37,46 +37,44 @@ #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 @@ -89,7 +87,7 @@ docopyf: 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 |