tiny tweak to asm. prefer memcpy and memmove, with bcopy wrapper
authortedu <tedu@openbsd.org>
Thu, 9 Jan 2014 05:39:41 +0000 (05:39 +0000)
committertedu <tedu@openbsd.org>
Thu, 9 Jan 2014 05:39:41 +0000 (05:39 +0000)
ok guenther

sys/lib/libkern/arch/amd64/memmove.S
sys/lib/libkern/arch/i386/memmove.S

index cf81c4c..1516c74 100644 (file)
         *  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
index 59cadfc..a88b08a 100644 (file)
@@ -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.
 #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