Revert everything to 2005-02-03 until the code is properly tested. Building
kde3 breaks with the head code.
This commit is contained in:
parent
ae20c95c70
commit
122f93c73b
|
@ -1,4 +1,101 @@
|
|||
/* $NetBSD: bcopy.S,v 1.13 2005/02/03 22:35:11 dsl Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 1990 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from locore.s.
|
||||
*
|
||||
* 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.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||
*/
|
||||
|
||||
#define BCOPY
|
||||
#include "memcpy.S"
|
||||
#include <machine/asm.h>
|
||||
|
||||
#if defined(LIBC_SCCS)
|
||||
RCSID("$NetBSD: bcopy.S,v 1.14 2005/02/07 05:22:51 christos Exp $")
|
||||
#endif
|
||||
|
||||
/*
|
||||
* (ov)bcopy (src,dst,cnt)
|
||||
* ws@tools.de (Wolfgang Solfrank, TooLs GmbH) +49-228-985800
|
||||
*/
|
||||
|
||||
#ifdef MEMCOPY
|
||||
ENTRY(memcpy)
|
||||
#else
|
||||
#ifdef MEMMOVE
|
||||
ENTRY(memmove)
|
||||
#else
|
||||
ENTRY(bcopy)
|
||||
#endif
|
||||
#endif
|
||||
pushl %esi
|
||||
pushl %edi
|
||||
#if defined(MEMCOPY) || defined(MEMMOVE)
|
||||
movl 12(%esp),%edi
|
||||
movl 16(%esp),%esi
|
||||
movl %edi,%eax /* return value */
|
||||
#else
|
||||
movl 12(%esp),%esi
|
||||
movl 16(%esp),%edi
|
||||
#endif
|
||||
movl 20(%esp),%ecx
|
||||
#if defined(MEMCOPY)
|
||||
movl %ecx,%edx
|
||||
#else
|
||||
movl %edi,%edx
|
||||
subl %esi,%edx
|
||||
cmpl %ecx,%edx /* overlapping? */
|
||||
movl %ecx,%edx
|
||||
jb 1f
|
||||
#endif
|
||||
cld /* nope, copy forwards. */
|
||||
shrl $2,%ecx /* copy by words */
|
||||
rep
|
||||
movsl
|
||||
movl %edx,%ecx
|
||||
andl $3,%ecx /* any bytes left? */
|
||||
rep
|
||||
movsb
|
||||
popl %edi
|
||||
popl %esi
|
||||
ret
|
||||
1:
|
||||
addl %ecx,%edi /* copy backwards. */
|
||||
addl %ecx,%esi
|
||||
std
|
||||
andl $3,%ecx /* any fractional bytes? */
|
||||
decl %edi
|
||||
decl %esi
|
||||
rep
|
||||
movsb
|
||||
movl %edx,%ecx /* copy remainder by words */
|
||||
shrl $2,%ecx
|
||||
subl $3,%esi
|
||||
subl $3,%edi
|
||||
rep
|
||||
movsl
|
||||
popl %edi
|
||||
popl %esi
|
||||
cld
|
||||
ret
|
||||
|
|
|
@ -1,4 +1,46 @@
|
|||
/* $NetBSD: bzero.S,v 1.10 2005/02/03 22:05:01 dsl Exp $ */
|
||||
/*
|
||||
* Written by J.T. Conklin <jtc@NetBSD.org>.
|
||||
* Public domain.
|
||||
*/
|
||||
|
||||
#define BZERO
|
||||
#include "memset.S"
|
||||
#include <machine/asm.h>
|
||||
|
||||
#if defined(LIBC_SCCS)
|
||||
RCSID("$NetBSD: bzero.S,v 1.11 2005/02/07 05:22:51 christos Exp $")
|
||||
#endif
|
||||
|
||||
ENTRY(bzero)
|
||||
pushl %edi
|
||||
movl 8(%esp),%edi
|
||||
movl 12(%esp),%edx
|
||||
|
||||
cld /* set fill direction forward */
|
||||
xorl %eax,%eax /* set fill data to 0 */
|
||||
|
||||
/*
|
||||
* if the string is too short, it's really not worth the overhead
|
||||
* of aligning to word boundries, etc. So we jump to a plain
|
||||
* unaligned set.
|
||||
*/
|
||||
cmpl $16,%edx
|
||||
jb L1
|
||||
|
||||
movl %edi,%ecx /* compute misalignment */
|
||||
negl %ecx
|
||||
andl $3,%ecx
|
||||
subl %ecx,%edx
|
||||
rep /* zero until word aligned */
|
||||
stosb
|
||||
|
||||
movl %edx,%ecx /* zero by words */
|
||||
shrl $2,%ecx
|
||||
andl $3,%edx
|
||||
rep
|
||||
stosl
|
||||
|
||||
L1: movl %edx,%ecx /* zero remainder by bytes */
|
||||
rep
|
||||
stosb
|
||||
|
||||
popl %edi
|
||||
ret
|
||||
|
|
|
@ -1,4 +1,29 @@
|
|||
/* $NetBSD: index.S,v 1.12 2005/02/04 18:12:52 drochner Exp $ */
|
||||
/*
|
||||
* Written by J.T. Conklin <jtc@NetBSD.org>.
|
||||
* Public domain.
|
||||
*/
|
||||
|
||||
#define INDEX
|
||||
#include "strchr.S"
|
||||
#include <machine/asm.h>
|
||||
|
||||
#if defined(LIBC_SCCS)
|
||||
RCSID("$NetBSD: index.S,v 1.13 2005/02/07 05:22:51 christos Exp $")
|
||||
#endif
|
||||
|
||||
#ifdef STRCHR
|
||||
ENTRY(strchr)
|
||||
#else
|
||||
ENTRY(index)
|
||||
#endif
|
||||
movl 4(%esp),%eax
|
||||
movb 8(%esp),%cl
|
||||
_ALIGN_TEXT,0x90
|
||||
L1:
|
||||
movb (%eax),%dl
|
||||
cmpb %dl,%cl /* found char??? */
|
||||
je L2
|
||||
incl %eax
|
||||
testb %dl,%dl /* null terminator??? */
|
||||
jnz L1
|
||||
xorl %eax,%eax
|
||||
L2:
|
||||
ret
|
||||
|
|
|
@ -1,109 +1,29 @@
|
|||
/*
|
||||
* Written by J.T. Conklin <jtc@acorntoolworks.com>
|
||||
* Written by J.T. Conklin <jtc@NetBSD.org>.
|
||||
* Public domain.
|
||||
*/
|
||||
|
||||
#include <machine/asm.h>
|
||||
|
||||
#if defined(LIBC_SCCS)
|
||||
RCSID("$NetBSD: memchr.S,v 1.12 2005/02/06 18:36:32 christos Exp $")
|
||||
RCSID("$NetBSD: memchr.S,v 1.13 2005/02/07 05:22:51 christos Exp $")
|
||||
#endif
|
||||
|
||||
ENTRY(memchr)
|
||||
pushl %esi
|
||||
movl 8(%esp),%eax
|
||||
movzbl 12(%esp),%ecx
|
||||
movl 16(%esp),%esi
|
||||
|
||||
/*
|
||||
* Align to word boundry
|
||||
* Consider unrolling loop?
|
||||
*/
|
||||
testl %esi,%esi /* nbytes == 0? */
|
||||
je .Lzero
|
||||
.Lalign:
|
||||
testb $3,%al
|
||||
je .Lword_aligned
|
||||
cmpb (%eax),%cl
|
||||
je .Ldone
|
||||
incl %eax
|
||||
decl %esi
|
||||
jnz .Lalign
|
||||
jmp .Lzero
|
||||
|
||||
.Lword_aligned:
|
||||
/* copy char to all bytes in word */
|
||||
movb %cl,%ch
|
||||
movl %ecx,%edx
|
||||
sall $16,%ecx
|
||||
orl %edx,%ecx
|
||||
|
||||
_ALIGN_TEXT
|
||||
.Lloop:
|
||||
cmpl $3,%esi /* nbytes > 4 */
|
||||
jbe .Lbyte
|
||||
movl (%eax),%edx
|
||||
addl $4,%eax
|
||||
xorl %ecx,%edx
|
||||
subl $4,%esi
|
||||
subl $0x01010101,%edx
|
||||
testl $0x80808080,%edx
|
||||
je .Lloop
|
||||
|
||||
/*
|
||||
* In rare cases, the above loop may exit prematurely. We must
|
||||
* return to the loop if none of the bytes in the word are
|
||||
* equal to ch.
|
||||
*/
|
||||
|
||||
/*
|
||||
* High load-use latency on the Athlon leads to significant
|
||||
* stalls, so we preload the next char as soon as possible
|
||||
* instead of using cmp mem8, reg8.
|
||||
*
|
||||
* Alignment here avoids a stall on the Athlon, even though
|
||||
* it's not a branch target.
|
||||
*/
|
||||
_ALIGN_TEXT
|
||||
cmpb -4(%eax),%cl /* 1st byte == ch? */
|
||||
movb -3(%eax),%dl
|
||||
jne 1f
|
||||
subl $4,%eax
|
||||
jmp .Ldone
|
||||
|
||||
_ALIGN_TEXT
|
||||
1: cmpb %dl,%cl /* 2nd byte == ch? */
|
||||
movb -2(%eax),%dl
|
||||
jne 1f
|
||||
subl $3,%eax
|
||||
jmp .Ldone
|
||||
|
||||
_ALIGN_TEXT
|
||||
1: cmpb %dl,%cl /* 3rd byte == ch? */
|
||||
movb -1(%eax),%dl
|
||||
jne 1f
|
||||
subl $2,%eax
|
||||
jmp .Ldone
|
||||
|
||||
_ALIGN_TEXT
|
||||
1: cmpb %dl,%cl /* 4th byte == ch? */
|
||||
jne .Lloop
|
||||
decl %eax
|
||||
jmp .Ldone
|
||||
|
||||
.Lbyte:
|
||||
testl %esi,%esi
|
||||
je .Lzero
|
||||
.Lbyte_loop:
|
||||
cmpb (%eax),%cl
|
||||
je .Ldone
|
||||
incl %eax
|
||||
decl %esi
|
||||
jnz .Lbyte_loop
|
||||
|
||||
.Lzero:
|
||||
xorl %eax,%eax
|
||||
|
||||
.Ldone:
|
||||
popl %esi
|
||||
pushl %edi
|
||||
movl 8(%esp),%edi /* string address */
|
||||
movl 12(%esp),%eax /* set character to search for */
|
||||
movl 16(%esp),%ecx /* set length of search */
|
||||
testl %ecx,%ecx /* test for len == 0 */
|
||||
jz L1
|
||||
cld /* set search forward */
|
||||
repne /* search! */
|
||||
scasb
|
||||
jne L1 /* scan failed, return null */
|
||||
leal -1(%edi),%eax /* adjust result of scan */
|
||||
popl %edi
|
||||
ret
|
||||
_ALIGN_TEXT,0x90
|
||||
L1: xorl %eax,%eax
|
||||
popl %edi
|
||||
ret
|
||||
|
|
|
@ -1,133 +1,4 @@
|
|||
/* $NetBSD: memcpy.S,v 1.3 2005/02/03 22:31:44 dsl Exp $ */
|
||||
/* $NetBSD: memcpy.S,v 1.4 2005/02/07 05:22:51 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from locore.s.
|
||||
* Optimised by David Laight 2003
|
||||
*
|
||||
* 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.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <machine/asm.h>
|
||||
|
||||
#if defined(LIBC_SCCS)
|
||||
RCSID("$NetBSD: memcpy.S,v 1.3 2005/02/03 22:31:44 dsl Exp $")
|
||||
#endif
|
||||
|
||||
/*
|
||||
* (ov)bcopy (src,dst,cnt)
|
||||
* ws@tools.de (Wolfgang Solfrank, TooLs GmbH) +49-228-985800
|
||||
*/
|
||||
|
||||
#ifdef BCOPY
|
||||
ENTRY(bcopy)
|
||||
#else
|
||||
#ifdef MEMMOVE
|
||||
ENTRY(memmove)
|
||||
#else
|
||||
#define MEMCPY
|
||||
#define NO_OVERLAP
|
||||
ENTRY(memcpy)
|
||||
#endif
|
||||
#endif
|
||||
push %esi
|
||||
mov %edi,%edx
|
||||
#if defined(MEMCPY) || defined(MEMMOVE)
|
||||
movl 8(%esp),%edi
|
||||
movl 12(%esp),%esi
|
||||
#else
|
||||
movl 8(%esp),%esi
|
||||
movl 12(%esp),%edi
|
||||
#endif
|
||||
movl 16(%esp),%ecx
|
||||
#if defined(NO_OVERLAP)
|
||||
movl %ecx,%eax
|
||||
#else
|
||||
movl %edi,%eax
|
||||
subl %esi,%eax
|
||||
cmpl %ecx,%eax /* overlapping? */
|
||||
movl %ecx,%eax
|
||||
jb backwards
|
||||
#endif
|
||||
cld /* nope, copy forwards. */
|
||||
shrl $2,%ecx /* copy by words */
|
||||
rep
|
||||
movsl
|
||||
and $3,%eax /* any bytes left? */
|
||||
jnz trailing
|
||||
done:
|
||||
#if defined(MEMCPY) || defined(MEMMOVE)
|
||||
movl 8(%esp),%eax
|
||||
#endif
|
||||
mov %edx,%edi
|
||||
pop %esi
|
||||
ret
|
||||
|
||||
trailing:
|
||||
cmp $2,%eax
|
||||
jb 1f
|
||||
movw (%esi),%ax
|
||||
movw %ax,(%edi)
|
||||
je done
|
||||
movb 2(%esi),%al
|
||||
movb %al,2(%edi)
|
||||
jmp done
|
||||
1: movb (%esi),%al
|
||||
movb %al,(%edi)
|
||||
jmp done
|
||||
|
||||
#if !defined(NO_OVERLAP)
|
||||
backwards:
|
||||
addl %ecx,%edi /* copy backwards. */
|
||||
addl %ecx,%esi
|
||||
and $3,%eax /* any fractional bytes? */
|
||||
jnz back_align
|
||||
back_aligned:
|
||||
shrl $2,%ecx
|
||||
subl $4,%esi
|
||||
subl $4,%edi
|
||||
std
|
||||
rep
|
||||
movsl
|
||||
cld
|
||||
jmp done
|
||||
|
||||
back_align:
|
||||
sub %eax,%esi
|
||||
sub %eax,%edi
|
||||
cmp $2,%eax
|
||||
jb 1f
|
||||
je 2f
|
||||
movb 2(%esi),%al
|
||||
movb %al,2(%edi)
|
||||
2: movw (%esi),%ax
|
||||
movw %ax,(%edi)
|
||||
jmp back_aligned
|
||||
1: movb (%esi),%al
|
||||
movb %al,(%edi)
|
||||
jmp back_aligned
|
||||
#endif
|
||||
#define MEMCOPY
|
||||
#include "bcopy.S"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: memmove.S,v 1.5 2005/02/03 22:31:44 dsl Exp $ */
|
||||
/* $NetBSD: memmove.S,v 1.6 2005/02/07 05:22:51 christos Exp $ */
|
||||
|
||||
#define MEMMOVE
|
||||
#include "memcpy.S"
|
||||
#include "bcopy.S"
|
||||
|
|
|
@ -1,59 +1,21 @@
|
|||
/* $NetBSD: memset.S,v 1.10 2005/02/03 22:05:01 dsl Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2003 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by David Laight.
|
||||
*
|
||||
* 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.
|
||||
* 3. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
|
||||
/*
|
||||
* Written by J.T. Conklin <jtc@NetBSD.org>.
|
||||
* Public domain.
|
||||
*/
|
||||
|
||||
#include <machine/asm.h>
|
||||
|
||||
#if defined(LIBC_SCCS)
|
||||
RCSID("$NetBSD: memset.S,v 1.10 2005/02/03 22:05:01 dsl Exp $")
|
||||
RCSID("$NetBSD: memset.S,v 1.11 2005/02/07 05:22:51 christos Exp $")
|
||||
#endif
|
||||
|
||||
#ifdef BZERO
|
||||
ENTRY(bzero)
|
||||
#else
|
||||
ENTRY(memset)
|
||||
#endif
|
||||
#ifdef BZERO
|
||||
movl 8(%esp),%ecx
|
||||
xor %eax,%eax
|
||||
#else
|
||||
movl 12(%esp),%ecx
|
||||
movzbl 8(%esp),%eax /* unsigned char, zero extend */
|
||||
#endif
|
||||
cmpl $0x0f,%ecx /* avoid mispredicted branch... */
|
||||
|
||||
pushl %edi
|
||||
movl 8(%esp),%edi
|
||||
pushl %ebx
|
||||
movl 12(%esp),%edi
|
||||
movzbl 16(%esp),%eax /* unsigned char, zero extend */
|
||||
movl 20(%esp),%ecx
|
||||
pushl %edi /* push address of buffer */
|
||||
|
||||
cld /* set fill direction forward */
|
||||
|
||||
|
@ -61,51 +23,36 @@ ENTRY(memset)
|
|||
* if the string is too short, it's really not worth the overhead
|
||||
* of aligning to word boundries, etc. So we jump to a plain
|
||||
* unaligned set.
|
||||
*
|
||||
* NB aligning the transfer is actually pointless on my athlon 700,
|
||||
* It does make a difference to a PII though.
|
||||
*
|
||||
* The PII, PIII and PIV all seem to have a massive performance
|
||||
* drop when the initial target address is an odd multiple of 4.
|
||||
*/
|
||||
jbe by_bytes
|
||||
cmpl $0x0f,%ecx
|
||||
jle L1
|
||||
|
||||
#ifndef BZERO
|
||||
movb %al,%ah /* copy char to all bytes in word */
|
||||
movl %eax,%edx
|
||||
sall $16,%eax
|
||||
orl %edx,%eax
|
||||
#endif
|
||||
|
||||
movl %edi,%edx /* detect misalignment */
|
||||
neg %edx
|
||||
andl $7,%edx
|
||||
jnz align
|
||||
aligned:
|
||||
movl %eax,-4(%edi,%ecx) /* zap last 4 bytes */
|
||||
shrl $2,%ecx /* zero by words */
|
||||
rep
|
||||
stosl
|
||||
done:
|
||||
#ifndef BZERO
|
||||
movl 8(%esp),%eax /* return address of buffer */
|
||||
#endif
|
||||
pop %edi
|
||||
ret
|
||||
movl %edi,%edx /* compute misalignment */
|
||||
negl %edx
|
||||
andl $3,%edx
|
||||
movl %ecx,%ebx
|
||||
subl %edx,%ebx
|
||||
|
||||
align:
|
||||
movl %eax,(%edi) /* zap first 8 bytes */
|
||||
movl %eax,4(%edi)
|
||||
subl %edx,%ecx /* remove from main count */
|
||||
add %edx,%edi
|
||||
jmp aligned
|
||||
|
||||
by_bytes:
|
||||
movl %edx,%ecx /* set until word aligned */
|
||||
rep
|
||||
stosb
|
||||
|
||||
#ifndef BZERO
|
||||
movl 8(%esp),%eax /* return address of buffer */
|
||||
#endif
|
||||
movl %ebx,%ecx
|
||||
shrl $2,%ecx /* set by words */
|
||||
rep
|
||||
stosl
|
||||
|
||||
movl %ebx,%ecx /* set remainder by bytes */
|
||||
andl $3,%ecx
|
||||
L1: rep
|
||||
stosb
|
||||
|
||||
popl %eax /* pop address of buffer */
|
||||
popl %ebx
|
||||
popl %edi
|
||||
ret
|
||||
|
|
|
@ -1,4 +1,32 @@
|
|||
/* $NetBSD: rindex.S,v 1.12 2005/02/04 18:12:52 drochner Exp $ */
|
||||
/*
|
||||
* Written by J.T. Conklin <jtc@NetBSD.org>.
|
||||
* Public domain.
|
||||
*/
|
||||
|
||||
#define RINDEX
|
||||
#include "strrchr.S"
|
||||
#include <machine/asm.h>
|
||||
|
||||
#if defined(LIBC_SCCS)
|
||||
RCSID("$NetBSD: rindex.S,v 1.13 2005/02/07 05:22:51 christos Exp $")
|
||||
#endif
|
||||
|
||||
#ifdef STRRCHR
|
||||
ENTRY(strrchr)
|
||||
#else
|
||||
ENTRY(rindex)
|
||||
#endif
|
||||
pushl %ebx
|
||||
movl 8(%esp),%edx
|
||||
movb 12(%esp),%cl
|
||||
xorl %eax,%eax /* init pointer to null */
|
||||
_ALIGN_TEXT,0x90
|
||||
L1:
|
||||
movb (%edx),%bl
|
||||
cmpb %bl,%cl
|
||||
jne L2
|
||||
movl %edx,%eax
|
||||
L2:
|
||||
incl %edx
|
||||
testb %bl,%bl /* null terminator??? */
|
||||
jnz L1
|
||||
popl %ebx
|
||||
ret
|
||||
|
|
|
@ -1,127 +1,69 @@
|
|||
/*
|
||||
* Written by J.T. Conklin <jtc@acorntoolworks.com>
|
||||
* Written by J.T. Conklin <jtc@NetBSD.org>.
|
||||
* Public domain.
|
||||
*/
|
||||
|
||||
#include <machine/asm.h>
|
||||
|
||||
#if defined(LIBC_SCCS)
|
||||
RCSID("$NetBSD: strcat.S,v 1.11 2005/02/04 18:12:52 drochner Exp $")
|
||||
RCSID("$NetBSD: strcat.S,v 1.12 2005/02/07 05:22:51 christos Exp $")
|
||||
#endif
|
||||
|
||||
/*
|
||||
* NOTE: I've unrolled the loop eight times: large enough to make a
|
||||
* significant difference, and small enough not to totally trash the
|
||||
* cache.
|
||||
*/
|
||||
|
||||
ENTRY(strcat)
|
||||
pushl %ebx
|
||||
movl 8(%esp),%ecx
|
||||
movl 12(%esp),%eax
|
||||
pushl %edi /* save edi */
|
||||
movl 8(%esp),%edi /* dst address */
|
||||
movl 12(%esp),%edx /* src address */
|
||||
pushl %edi /* push destination address */
|
||||
|
||||
/*
|
||||
* Align destination to word boundary.
|
||||
* Consider unrolling loop?
|
||||
*/
|
||||
.Lscan:
|
||||
.Lscan_align:
|
||||
testb $3,%cl
|
||||
je .Lscan_aligned
|
||||
cmpb $0,(%ecx)
|
||||
je .Lcopy
|
||||
incl %ecx
|
||||
jmp .Lscan_align
|
||||
cld /* set search forward */
|
||||
xorl %eax,%eax /* set search for null terminator */
|
||||
movl $-1,%ecx /* set search for lots of characters */
|
||||
repne /* search! */
|
||||
scasb
|
||||
|
||||
_ALIGN_TEXT
|
||||
.Lscan_aligned:
|
||||
.Lscan_loop:
|
||||
movl (%ecx),%ebx
|
||||
addl $4,%ecx
|
||||
leal -0x01010101(%ebx),%edx
|
||||
testl $0x80808080,%edx
|
||||
je .Lscan_loop
|
||||
leal -1(%edi),%ecx /* correct dst address */
|
||||
|
||||
/*
|
||||
* In rare cases, the above loop may exit prematurely. We must
|
||||
* return to the loop if none of the bytes in the word equal 0.
|
||||
*/
|
||||
|
||||
/*
|
||||
* The optimal code for determining whether each byte is zero
|
||||
* differs by processor. This space-optimized code should be
|
||||
* acceptable on all, especially since we don't expect it to
|
||||
* be run frequently,
|
||||
*/
|
||||
|
||||
testb %bl,%bl /* 1st byte == 0? */
|
||||
jne 1f
|
||||
subl $4,%ecx
|
||||
jmp .Lcopy
|
||||
|
||||
1: testb %bh,%bh /* 2nd byte == 0? */
|
||||
jne 1f
|
||||
subl $3,%ecx
|
||||
jmp .Lcopy
|
||||
|
||||
1: shrl $16,%ebx
|
||||
testb %bl,%bl /* 3rd byte == 0? */
|
||||
jne 1f
|
||||
subl $2,%ecx
|
||||
jmp .Lcopy
|
||||
|
||||
1: testb %bh,%bh /* 4th byte == 0? */
|
||||
jne .Lscan_loop
|
||||
subl $1,%ecx
|
||||
|
||||
/*
|
||||
* Align source to a word boundary.
|
||||
* Consider unrolling loop?
|
||||
*/
|
||||
.Lcopy:
|
||||
.Lcopy_align:
|
||||
testl $3,%eax
|
||||
je .Lcopy_aligned
|
||||
movb (%eax),%bl
|
||||
incl %eax
|
||||
movb %bl,(%ecx)
|
||||
incl %ecx
|
||||
testb %bl,%bl
|
||||
jne .Lcopy_align
|
||||
jmp .Ldone
|
||||
|
||||
_ALIGN_TEXT
|
||||
.Lcopy_loop:
|
||||
movl %ebx,(%ecx)
|
||||
addl $4,%ecx
|
||||
.Lcopy_aligned:
|
||||
movl (%eax),%ebx
|
||||
addl $4,%eax
|
||||
leal -0x01010101(%ebx),%edx
|
||||
testl $0x80808080,%edx
|
||||
je .Lcopy_loop
|
||||
|
||||
/*
|
||||
* In rare cases, the above loop may exit prematurely. We must
|
||||
* return to the loop if none of the bytes in the word equal 0.
|
||||
*/
|
||||
|
||||
movb %bl,(%ecx)
|
||||
incl %ecx
|
||||
testb %bl,%bl
|
||||
je .Ldone
|
||||
|
||||
movb %bh,(%ecx)
|
||||
incl %ecx
|
||||
testb %bh,%bh
|
||||
je .Ldone
|
||||
|
||||
shrl $16,%ebx
|
||||
movb %bl,(%ecx)
|
||||
incl %ecx
|
||||
testb %bl,%bl
|
||||
je .Ldone
|
||||
|
||||
movb %bh,(%ecx)
|
||||
incl %ecx
|
||||
testb %bh,%bh
|
||||
jne .Lcopy_aligned
|
||||
|
||||
.Ldone:
|
||||
movl 8(%esp),%eax
|
||||
popl %ebx
|
||||
_ALIGN_TEXT,0x90
|
||||
L1: movb (%edx),%al /* unroll loop, but not too much */
|
||||
movb %al,(%ecx)
|
||||
testb %al,%al
|
||||
jz L2
|
||||
movb 1(%edx),%al
|
||||
movb %al,1(%ecx)
|
||||
testb %al,%al
|
||||
jz L2
|
||||
movb 2(%edx),%al
|
||||
movb %al,2(%ecx)
|
||||
testb %al,%al
|
||||
jz L2
|
||||
movb 3(%edx),%al
|
||||
movb %al,3(%ecx)
|
||||
testb %al,%al
|
||||
jz L2
|
||||
movb 4(%edx),%al
|
||||
movb %al,4(%ecx)
|
||||
testb %al,%al
|
||||
jz L2
|
||||
movb 5(%edx),%al
|
||||
movb %al,5(%ecx)
|
||||
testb %al,%al
|
||||
jz L2
|
||||
movb 6(%edx),%al
|
||||
movb %al,6(%ecx)
|
||||
testb %al,%al
|
||||
jz L2
|
||||
movb 7(%edx),%al
|
||||
movb %al,7(%ecx)
|
||||
addl $8,%edx
|
||||
addl $8,%ecx
|
||||
testb %al,%al
|
||||
jnz L1
|
||||
L2: popl %eax /* pop destination address */
|
||||
popl %edi /* restore edi */
|
||||
ret
|
||||
|
|
|
@ -1,105 +1,4 @@
|
|||
/*
|
||||
* Written by J.T. Conklin <jtc@acorntoolworks.com>
|
||||
* Public domain.
|
||||
*/
|
||||
/* $NetBSD: strchr.S,v 1.7 2005/02/07 05:22:52 christos Exp $ */
|
||||
|
||||
#include <machine/asm.h>
|
||||
|
||||
#if defined(LIBC_SCCS)
|
||||
RCSID("$NetBSD: strchr.S,v 1.6 2005/02/06 18:36:32 christos Exp $")
|
||||
#endif
|
||||
|
||||
#ifdef INDEX
|
||||
ENTRY(index)
|
||||
#else
|
||||
ENTRY(strchr)
|
||||
#endif
|
||||
pushl %esi
|
||||
pushl %ebx
|
||||
movl 12(%esp),%eax
|
||||
movzbl 16(%esp),%ecx
|
||||
|
||||
/*
|
||||
* Align to word boundary.
|
||||
* Consider unrolling loop?
|
||||
*/
|
||||
.Lalign:
|
||||
testb $3,%al
|
||||
je .Lword_aligned
|
||||
movb (%eax),%bl
|
||||
cmpb %cl,%bl
|
||||
je .Ldone
|
||||
testb %bl,%bl
|
||||
je .Lzero
|
||||
incl %eax
|
||||
jmp .Lalign
|
||||
|
||||
.Lword_aligned:
|
||||
/* copy char to all bytes in word */
|
||||
movb %cl,%ch
|
||||
movl %ecx,%edx
|
||||
sall $16,%ecx
|
||||
orl %edx,%ecx
|
||||
|
||||
/* Check whether any byte in the word is equal to ch or 0. */
|
||||
_ALIGN_TEXT
|
||||
.Lloop:
|
||||
movl (%eax),%ebx
|
||||
addl $4,%eax
|
||||
movl %ebx,%esi
|
||||
leal -0x01010101(%ebx),%edx
|
||||
xorl %ecx,%esi
|
||||
subl $0x01010101,%esi
|
||||
orl %esi,%edx
|
||||
testl $0x80808080,%edx
|
||||
je .Lloop
|
||||
|
||||
/*
|
||||
* In rare cases, the above loop may exit prematurely. We must
|
||||
* return to the loop if none of the bytes in the word match
|
||||
* ch or are equal to 0.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Alignment here avoids a stall on the Athlon, even though
|
||||
* it's not a branch target.
|
||||
*/
|
||||
|
||||
_ALIGN_TEXT
|
||||
cmpb %cl,%bl /* 1st byte == ch? */
|
||||
jne 1f
|
||||
subl $4,%eax
|
||||
jmp .Ldone
|
||||
1: testb %bl,%bl /* 1st byte == 0? */
|
||||
je .Lzero
|
||||
|
||||
cmpb %cl,%bh /* 2nd byte == ch? */
|
||||
jne 1f
|
||||
subl $3,%eax
|
||||
jmp .Ldone
|
||||
1: testb %bh,%bh /* 2nd byte == 0? */
|
||||
je .Lzero
|
||||
|
||||
shrl $16,%ebx
|
||||
cmpb %cl,%bl /* 3rd byte == ch? */
|
||||
jne 1f
|
||||
subl $2,%eax
|
||||
jmp .Ldone
|
||||
1: testb %bl,%bl /* 3rd byte == 0? */
|
||||
je .Lzero
|
||||
|
||||
cmpb %cl,%bh /* 4th byte == ch? */
|
||||
jne 1f
|
||||
decl %eax
|
||||
jmp .Ldone
|
||||
1: testb %bh,%bh /* 4th byte == 0? */
|
||||
jne .Lloop
|
||||
|
||||
.Lzero:
|
||||
/* If a ch wasn't found, return 0. */
|
||||
xorl %eax,%eax
|
||||
|
||||
.Ldone:
|
||||
popl %ebx
|
||||
popl %esi
|
||||
ret
|
||||
#define STRCHR
|
||||
#include "index.S"
|
||||
|
|
|
@ -1,77 +1,84 @@
|
|||
/*
|
||||
* Written by J.T. Conklin <jtc@acorntoolworks.com>
|
||||
* Written by J.T. Conklin <jtc@NetBSD.org>.
|
||||
* Public domain.
|
||||
*/
|
||||
|
||||
#include <machine/asm.h>
|
||||
|
||||
#if defined(LIBC_SCCS)
|
||||
RCSID("$NetBSD: strcmp.S,v 1.14 2005/02/04 18:12:52 drochner Exp $")
|
||||
RCSID("$NetBSD: strcmp.S,v 1.15 2005/02/07 05:22:52 christos Exp $")
|
||||
#endif
|
||||
|
||||
/*
|
||||
* NOTE: I've unrolled the loop eight times: large enough to make a
|
||||
* significant difference, and small enough not to totally trash the
|
||||
* cache.
|
||||
*/
|
||||
|
||||
ENTRY(strcmp)
|
||||
pushl %esi
|
||||
pushl %ebx
|
||||
movl 12(%esp),%ebx
|
||||
movl 16(%esp),%esi
|
||||
movl 0x04(%esp),%eax
|
||||
movl 0x08(%esp),%edx
|
||||
jmp L2 /* Jump into the loop! */
|
||||
|
||||
/*
|
||||
* Align s1 to word boundary.
|
||||
* Consider unrolling loop?
|
||||
*/
|
||||
.Ls1align:
|
||||
testb $3,%bl
|
||||
je .Ls1aligned
|
||||
movb (%ebx),%al
|
||||
incl %ebx
|
||||
movb (%esi),%dl
|
||||
incl %esi
|
||||
testb %al,%al
|
||||
je .Ldone
|
||||
cmpb %al,%dl
|
||||
je .Ls1align
|
||||
jmp .Ldone
|
||||
|
||||
/*
|
||||
* Check whether s2 is aligned to a word boundry. If it is, we
|
||||
* can compare by words. Otherwise we have to compare by bytes.
|
||||
*/
|
||||
.Ls1aligned:
|
||||
testl $3,%esi
|
||||
jne .Lbyte_loop
|
||||
|
||||
subl $4,%ebx
|
||||
subl $4,%esi
|
||||
|
||||
_ALIGN_TEXT
|
||||
.Lword_loop:
|
||||
movl 4(%ebx),%eax
|
||||
addl $4,%ebx
|
||||
movl 4(%esi),%edx
|
||||
addl $4,%esi
|
||||
cmpl %eax,%edx
|
||||
jne .Lbyte_loop
|
||||
subl $0x01010101,%edx
|
||||
notl %eax
|
||||
andl %eax,%edx
|
||||
testl $0x80808080,%edx
|
||||
je .Lword_loop
|
||||
|
||||
_ALIGN_TEXT
|
||||
.Lbyte_loop:
|
||||
movb (%ebx),%al
|
||||
incl %ebx
|
||||
movb (%esi),%dl
|
||||
incl %esi
|
||||
testb %al,%al
|
||||
je .Ldone
|
||||
cmpb %al,%dl
|
||||
je .Lbyte_loop
|
||||
|
||||
.Ldone:
|
||||
movzbl %al,%eax
|
||||
movzbl %dl,%edx
|
||||
_ALIGN_TEXT,0x90
|
||||
L1: incl %eax
|
||||
incl %edx
|
||||
L2: movb (%eax),%cl
|
||||
testb %cl,%cl /* null terminator??? */
|
||||
jz L3
|
||||
cmpb %cl,(%edx) /* chars match??? */
|
||||
jne L3
|
||||
incl %eax
|
||||
incl %edx
|
||||
movb (%eax),%cl
|
||||
testb %cl,%cl
|
||||
jz L3
|
||||
cmpb %cl,(%edx)
|
||||
jne L3
|
||||
incl %eax
|
||||
incl %edx
|
||||
movb (%eax),%cl
|
||||
testb %cl,%cl
|
||||
jz L3
|
||||
cmpb %cl,(%edx)
|
||||
jne L3
|
||||
incl %eax
|
||||
incl %edx
|
||||
movb (%eax),%cl
|
||||
testb %cl,%cl
|
||||
jz L3
|
||||
cmpb %cl,(%edx)
|
||||
jne L3
|
||||
incl %eax
|
||||
incl %edx
|
||||
movb (%eax),%cl
|
||||
testb %cl,%cl
|
||||
jz L3
|
||||
cmpb %cl,(%edx)
|
||||
jne L3
|
||||
incl %eax
|
||||
incl %edx
|
||||
movb (%eax),%cl
|
||||
testb %cl,%cl
|
||||
jz L3
|
||||
cmpb %cl,(%edx)
|
||||
jne L3
|
||||
incl %eax
|
||||
incl %edx
|
||||
movb (%eax),%cl
|
||||
testb %cl,%cl
|
||||
jz L3
|
||||
cmpb %cl,(%edx)
|
||||
jne L3
|
||||
incl %eax
|
||||
incl %edx
|
||||
movb (%eax),%cl
|
||||
testb %cl,%cl
|
||||
jz L3
|
||||
cmpb %cl,(%edx)
|
||||
je L1
|
||||
_ALIGN_TEXT,0x90
|
||||
L3: movzbl (%eax),%eax /* unsigned comparison */
|
||||
movzbl (%edx),%edx
|
||||
subl %edx,%eax
|
||||
popl %ebx
|
||||
popl %esi
|
||||
ret
|
||||
|
|
|
@ -1,141 +1,23 @@
|
|||
/*
|
||||
* Written by J.T. Conklin <jtc@acorntoolworks.com>
|
||||
* Written by J.T. Conklin <jtc@NetBSD.org>.
|
||||
* Public domain.
|
||||
*/
|
||||
|
||||
#include <machine/asm.h>
|
||||
|
||||
#if defined(LIBC_SCCS)
|
||||
RCSID("$NetBSD: strlen.S,v 1.8 2005/02/04 18:12:52 drochner Exp $")
|
||||
RCSID("$NetBSD: strlen.S,v 1.9 2005/02/07 05:22:52 christos Exp $")
|
||||
#endif
|
||||
|
||||
ENTRY(strlen)
|
||||
movl 4(%esp),%eax
|
||||
|
||||
.Lalign:
|
||||
/* Consider unrolling loop? */
|
||||
testb $3,%al
|
||||
je .Lword_aligned
|
||||
cmpb $0,(%eax)
|
||||
je .Ldone
|
||||
incl %eax
|
||||
jmp .Lalign
|
||||
|
||||
/*
|
||||
* There are many well known branch-free sequences which are used
|
||||
* for determining whether a zero-byte is contained within a word.
|
||||
* These sequences are generally much more efficent than loading
|
||||
* and comparing each byte individually.
|
||||
*
|
||||
* The expression [1,2]:
|
||||
*
|
||||
* (1) ~(((x & 0x7f7f7f7f) + 0x7f7f7f7f) | (x | 0x7f7f7f7f))
|
||||
*
|
||||
* evaluates to a non-zero value if any of the bytes in the
|
||||
* original word is zero.
|
||||
*
|
||||
* It also has the useful property that bytes in the result word
|
||||
* that coorespond to non-zero bytes in the original word have
|
||||
* the value 0x00, while bytes cooresponding to zero bytes have
|
||||
* the value 0x80. This allows calculation of the first (and
|
||||
* last) occurance of a zero byte within the word (useful for C's
|
||||
* str* primitives) by counting the number of leading (or
|
||||
* trailing) zeros and dividing the result by 8. On machines
|
||||
* without (or with slow) clz() / ctz() instructions, testing
|
||||
* each byte in the result word for zero is necessary.
|
||||
*
|
||||
* This typically takes 4 instructions (5 on machines without
|
||||
* "not-or") not including those needed to load the constant.
|
||||
*
|
||||
*
|
||||
* The expression:
|
||||
*
|
||||
* (2) ((x - 0x01010101) & ~x & 0x80808080)
|
||||
*
|
||||
* evaluates to a non-zero value if any of the bytes in the
|
||||
* original word is zero.
|
||||
*
|
||||
* On little endian machines, the first byte in the result word
|
||||
* that cooresponds to a zero byte in the original byte is 0x80,
|
||||
* so clz() can be used as above. On big endian machines, and
|
||||
* little endian machines without (or with a slow) clz() insn,
|
||||
* testing each byte in the original for zero is necessary
|
||||
*
|
||||
* This typically takes 3 instructions (4 on machines without
|
||||
* "and with complement") not including those needed to load
|
||||
* constants.
|
||||
*
|
||||
*
|
||||
* The expression:
|
||||
*
|
||||
* (3) ((x - 0x01010101) & 0x80808080)
|
||||
*
|
||||
* always evaluates to a non-zero value if any of the bytes in
|
||||
* the original word is zero. However, in rare cases, it also
|
||||
* evaluates to a non-zero value when none of the bytes in the
|
||||
* original word is zero.
|
||||
*
|
||||
* To account for possible false positives, each byte of the
|
||||
* original word must be checked when the expression evaluates to
|
||||
* a non-zero value. However, because it is simpler than those
|
||||
* presented above, code that uses it will be faster as long as
|
||||
* the rate of false positives is low.
|
||||
*
|
||||
* This is likely, because the the false positive can only occur
|
||||
* if the most siginificant bit of a byte within the word is set.
|
||||
* The expression will never fail for typical 7-bit ASCII strings.
|
||||
*
|
||||
* This typically takes 2 instructions not including those needed
|
||||
* to load constants.
|
||||
*
|
||||
*
|
||||
* [1] Henry S. Warren Jr., "Hacker's Delight", Addison-Westley 2003
|
||||
*
|
||||
* [2] International Business Machines, "The PowerPC Compiler Writer's
|
||||
* Guide", Warthman Associates, 1996
|
||||
*/
|
||||
|
||||
_ALIGN_TEXT
|
||||
.Lword_aligned:
|
||||
.Lloop:
|
||||
movl (%eax),%ecx
|
||||
addl $4,%eax
|
||||
leal -0x01010101(%ecx),%edx
|
||||
testl $0x80808080,%edx
|
||||
je .Lloop
|
||||
|
||||
/*
|
||||
* In rare cases, the above loop may exit prematurely. We must
|
||||
* return to the loop if none of the bytes in the word equal 0.
|
||||
*/
|
||||
|
||||
/*
|
||||
* The optimal code for determining whether each byte is zero
|
||||
* differs by processor. This space-optimized code should be
|
||||
* acceptable on all, especially since we don't expect it to
|
||||
* be run frequently,
|
||||
*/
|
||||
|
||||
testb %cl,%cl /* 1st byte == 0? */
|
||||
jne 1f
|
||||
subl $4,%eax
|
||||
jmp .Ldone
|
||||
|
||||
1: testb %ch,%ch /* 2nd byte == 0? */
|
||||
jne 1f
|
||||
subl $3,%eax
|
||||
jmp .Ldone
|
||||
|
||||
1: shrl $16,%ecx
|
||||
testb %cl,%cl /* 3rd byte == 0? */
|
||||
jne 1f
|
||||
subl $2,%eax
|
||||
jmp .Ldone
|
||||
|
||||
1: testb %ch,%ch /* 4th byte == 0? */
|
||||
jne .Lloop
|
||||
decl %eax
|
||||
|
||||
.Ldone:
|
||||
subl 4(%esp),%eax
|
||||
pushl %edi
|
||||
movl 8(%esp),%edi /* string address */
|
||||
cld /* set search forward */
|
||||
xorl %eax,%eax /* set search for null terminator */
|
||||
movl $-1,%ecx /* set search for lots of characters */
|
||||
repne /* search! */
|
||||
scasb
|
||||
notl %ecx /* get length by taking complement */
|
||||
leal -1(%ecx),%eax /* and subtracting one */
|
||||
popl %edi
|
||||
ret
|
||||
|
|
|
@ -1,98 +1,4 @@
|
|||
/*
|
||||
* Written by J.T. Conklin <jtc@acorntoolworks.com>
|
||||
* Public domain.
|
||||
*/
|
||||
/* $NetBSD: strrchr.S,v 1.8 2005/02/07 05:22:52 christos Exp $ */
|
||||
|
||||
#include <machine/asm.h>
|
||||
|
||||
#if defined(LIBC_SCCS)
|
||||
RCSID("$NetBSD: strrchr.S,v 1.7 2005/02/06 18:36:32 christos Exp $")
|
||||
#endif
|
||||
|
||||
#ifdef RINDEX
|
||||
ENTRY(rindex)
|
||||
#else
|
||||
ENTRY(strrchr)
|
||||
#endif
|
||||
pushl %esi
|
||||
pushl %edi
|
||||
pushl %ebx
|
||||
movl 16(%esp),%edx
|
||||
movzbl 20(%esp),%ecx
|
||||
|
||||
/* zero return value */
|
||||
xorl %eax,%eax
|
||||
|
||||
/*
|
||||
* Align to word boundary.
|
||||
* Consider unrolling loop?
|
||||
*/
|
||||
.Lalign:
|
||||
testb $3,%dl
|
||||
je .Lword_aligned
|
||||
movb (%edx),%bl
|
||||
cmpb %cl,%bl
|
||||
jne 1f
|
||||
movl %edx,%eax
|
||||
1: testb %bl,%bl
|
||||
je .Ldone
|
||||
incl %edx
|
||||
jmp .Lalign
|
||||
|
||||
.Lword_aligned:
|
||||
/* copy char to all bytes in word */
|
||||
movb %cl,%ch
|
||||
movl %ecx,%edi
|
||||
sall $16,%ecx
|
||||
orl %edi,%ecx
|
||||
|
||||
/* Check whether any byte in the word is equal to ch or 0. */
|
||||
_ALIGN_TEXT
|
||||
.Lloop:
|
||||
movl (%edx),%ebx
|
||||
addl $4,%edx
|
||||
movl %ebx,%esi
|
||||
leal -0x01010101(%ebx),%edi
|
||||
xorl %ecx,%esi
|
||||
subl $0x01010101,%esi
|
||||
orl %esi,%edi
|
||||
testl $0x80808080,%edi
|
||||
je .Lloop
|
||||
|
||||
/*
|
||||
* In rare cases, the above loop may exit prematurely. We must
|
||||
* return to the loop if none of the bytes in the word match
|
||||
* ch or are equal to 0.
|
||||
*/
|
||||
|
||||
_ALIGN_TEXT
|
||||
cmpb %cl,%bl /* 1st byte == ch? */
|
||||
jne 1f
|
||||
leal -4(%edx),%eax
|
||||
1: testb %bl,%bl /* 1st byte == 0? */
|
||||
je .Ldone
|
||||
|
||||
cmpb %cl,%bh /* 2nd byte == ch? */
|
||||
jne 1f
|
||||
leal -3(%edx),%eax
|
||||
1: testb %bh,%bh /* 2nd byte == 0? */
|
||||
je .Ldone
|
||||
|
||||
shrl $16,%ebx
|
||||
cmpb %cl,%bl /* 3rd byte == ch? */
|
||||
jne 1f
|
||||
leal -2(%edx),%eax
|
||||
1: testb %bl,%bl /* 3rd byte == 0? */
|
||||
je .Ldone
|
||||
|
||||
cmpb %cl,%bh /* 4th byte == ch? */
|
||||
jne 1f
|
||||
leal -1(%edx),%eax
|
||||
1: testb %bh,%bh /* 4th byte == 0? */
|
||||
jne .Lloop
|
||||
|
||||
.Ldone:
|
||||
popl %ebx
|
||||
popl %edi
|
||||
popl %esi
|
||||
ret
|
||||
#define STRRCHR
|
||||
#include "rindex.S"
|
||||
|
|
Loading…
Reference in New Issue