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
This commit is contained in:
parent
f51c84eaf6
commit
c03b5ad6a9
@ -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
|
||||
|
@ -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
|
38
lib/libc/amd64/string/strcpy.c
Normal file
38
lib/libc/amd64/string/strcpy.c
Normal file
@ -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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user