diff options
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/amd64/string/Makefile.inc | 2 | ||||
-rw-r--r-- | lib/libc/amd64/string/stpcpy.S (renamed from lib/libc/amd64/string/strcpy.S) | 40 | ||||
-rw-r--r-- | lib/libc/amd64/string/strcpy.c | 38 |
3 files changed, 60 insertions, 20 deletions
diff --git a/lib/libc/amd64/string/Makefile.inc b/lib/libc/amd64/string/Makefile.inc index f5d69d6..46571ab 100644 --- a/lib/libc/amd64/string/Makefile.inc +++ b/lib/libc/amd64/string/Makefile.inc @@ -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 diff --git a/lib/libc/amd64/string/strcpy.S b/lib/libc/amd64/string/stpcpy.S index 5feb925..c8772f8 100644 --- a/lib/libc/amd64/string/strcpy.S +++ b/lib/libc/amd64/string/stpcpy.S @@ -1,17 +1,14 @@ /* - * Written by J.T. Conklin <jtc@acorntoolworks.com> + * Adapted by Guillaume Morin <guillaume@hudson-trading.com> from strcpy.S + * written by J.T. Conklin <jtc@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 diff --git a/lib/libc/amd64/string/strcpy.c b/lib/libc/amd64/string/strcpy.c new file mode 100644 index 0000000..11a24eb --- /dev/null +++ b/lib/libc/amd64/string/strcpy.c @@ -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); +} |