From c067621f5d6d8289d191d8ceea10ba6c6e328ed8 Mon Sep 17 00:00:00 2001 From: tedu Date: Thu, 9 Jan 2014 05:39:41 +0000 Subject: [PATCH] tiny tweak to asm. prefer memcpy and memmove, with bcopy wrapper ok guenther --- sys/lib/libkern/arch/amd64/memmove.S | 13 ++++---- 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 /* - * 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 -- 2.20.1