Author: gnn
Date: Thu Jul 21 16:32:13 2011
New Revision: 224246
URL: http://svn.freebsd.org/changeset/base/224246

Log:
  Make both stpcpy and strcpy be assembly language implementations
  on amd64.
  
  Submitted by: Guillaume Morin (guillaume at morinfr.org)
  Reviewed by:  kib, jhb
  Approved by:  re (bz)
  MFC after:    1 month

Added:
  head/lib/libc/amd64/string/stpcpy.S
     - copied, changed from r223967, head/lib/libc/amd64/string/strcpy.S
  head/lib/libc/amd64/string/strcpy.c   (contents, props changed)
Deleted:
  head/lib/libc/amd64/string/strcpy.S
Modified:
  head/lib/libc/amd64/string/Makefile.inc

Modified: head/lib/libc/amd64/string/Makefile.inc
==============================================================================
--- head/lib/libc/amd64/string/Makefile.inc     Thu Jul 21 14:25:12 2011        
(r224245)
+++ head/lib/libc/amd64/string/Makefile.inc     Thu Jul 21 16:32:13 2011        
(r224246)
@@ -1,4 +1,4 @@
 # $FreeBSD$
 
 MDSRCS+= bcmp.S bcopy.S bzero.S memcmp.S memcpy.S memmove.S memset.S \
-       strcat.S strcmp.S strcpy.S
+       strcat.S strcmp.S stpcpy.S strcpy.c

Copied and modified: head/lib/libc/amd64/string/stpcpy.S (from r223967, 
head/lib/libc/amd64/string/strcpy.S)
==============================================================================
--- head/lib/libc/amd64/string/strcpy.S Tue Jul 12 20:38:42 2011        
(r223967, copy source)
+++ head/lib/libc/amd64/string/stpcpy.S Thu Jul 21 16:32:13 2011        
(r224246)
@@ -1,17 +1,14 @@
 /*
- * Written by J.T. Conklin <j...@acorntoolworks.com>
+ * Adapted by Guillaume Morin <guilla...@hudson-trading.com> from strcpy.S
+ * written by J.T. Conklin <j...@acorntoolworks.com>
  * Public domain.
  */
 
 #include <machine/asm.h>
 __FBSDID("$FreeBSD$");
 
-#if 0
-       RCSID("$NetBSD: strcpy.S,v 1.3 2004/07/19 20:04:41 drochner Exp $")
-#endif
-
 /*
- * This strcpy implementation copies a byte at a time until the
+ * This stpcpy implementation copies a byte at a time until the
  * source pointer is aligned to a word boundary, it then copies by
  * words until it finds a word containing a zero byte, and finally
  * copies by bytes until the end of the string is reached.
@@ -23,10 +20,11 @@ __FBSDID("$FreeBSD$");
  * requirements.
  */
 
-ENTRY(strcpy)
-       movq    %rdi,%rax
-       movabsq $0x0101010101010101,%r8
-       movabsq $0x8080808080808080,%r9
+       .globl  stpcpy,__stpcpy
+ENTRY(stpcpy)
+__stpcpy:
+       movabsq $0x0101010101010101,%r8
+       movabsq $0x8080808080808080,%r9
 
        /*
         * Align source to a word boundary.
@@ -41,6 +39,8 @@ ENTRY(strcpy)
        incq    %rdi
        testb   %dl,%dl
        jne     .Lalign
+       movq    %rdi,%rax
+       dec     %rax
        ret
 
        .p2align 4
@@ -61,54 +61,56 @@ ENTRY(strcpy)
         */
 
        movb    %dl,(%rdi)
-       incq    %rdi
        testb   %dl,%dl         /* 1st byte == 0? */
        je      .Ldone
+       incq    %rdi
 
        shrq    $8,%rdx
        movb    %dl,(%rdi)
-       incq    %rdi
        testb   %dl,%dl         /* 2nd byte == 0? */
        je      .Ldone
+       incq    %rdi
 
        shrq    $8,%rdx
        movb    %dl,(%rdi)
-       incq    %rdi
        testb   %dl,%dl         /* 3rd byte == 0? */
        je      .Ldone
+       incq    %rdi
 
        shrq    $8,%rdx
        movb    %dl,(%rdi)
-       incq    %rdi
        testb   %dl,%dl         /* 4th byte == 0? */
        je      .Ldone
+       incq    %rdi
 
        shrq    $8,%rdx
        movb    %dl,(%rdi)
-       incq    %rdi
        testb   %dl,%dl         /* 5th byte == 0? */
        je      .Ldone
+       incq    %rdi
 
        shrq    $8,%rdx
        movb    %dl,(%rdi)
-       incq    %rdi
        testb   %dl,%dl         /* 6th byte == 0? */
        je      .Ldone
+       incq    %rdi
 
        shrq    $8,%rdx
        movb    %dl,(%rdi)
-       incq    %rdi
        testb   %dl,%dl         /* 7th byte == 0? */
        je      .Ldone
+       incq    %rdi
 
        shrq    $8,%rdx
        movb    %dl,(%rdi)
        incq    %rdi
        testb   %dl,%dl         /* 8th byte == 0? */
        jne     .Lword_aligned
+       decq    %rdi
 
 .Ldone:
+       movq    %rdi,%rax
        ret
-END(strcpy)
-
+END(stpcpy)
+       
        .section .note.GNU-stack,"",%progbits

Added: head/lib/libc/amd64/string/strcpy.c
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/lib/libc/amd64/string/strcpy.c Thu Jul 21 16:32:13 2011        
(r224246)
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2011 George V. Neville-Neil. All rights reserved.
+ *
+ * The compilation of software known as FreeBSD is distributed under the
+ * following terms:
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+char *__stpcpy(char * __restrict, const char * __restrict);
+
+char *
+strcpy(char * __restrict to, const char * __restrict from)
+{
+       __stpcpy(to, from);
+       return(to);
+}
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to