* Pull up files from lib/libc/arch/ns32/string.

* DEFS.h and setjmp.S are no longer in use.
This commit is contained in:
matthias 1996-11-07 07:36:05 +00:00
parent 10af6d961f
commit eb8718eafb
20 changed files with 808 additions and 153 deletions

View File

@ -1,49 +0,0 @@
/* $NetBSD: DEFS.h,v 1.2 1994/10/26 06:39:41 cgd Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* William Jolitz.
*
* 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. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. 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.
*
* @(#)DEFS.h 5.1 (Berkeley) 4/23/90
*/
#ifdef PROF
#define ENTRY(x) .globl _/**/x; _/**/x: \
.data; 1:; .long 0; .text; addr 1b,tos ; bsr mcount
#define ASENTRY(x) .globl x; x: \
.data; 1:; .long 0; .text; addr 1b,tos ; bsr mcount
#else
#define ENTRY(x) .globl _/**/x; _/**/x:
#define ASENTRY(x) .globl x; x:
#endif

View File

@ -1,6 +1,6 @@
# $NetBSD: Makefile.inc,v 1.9 1996/08/27 00:44:33 cgd Exp $
# $NetBSD: Makefile.inc,v 1.10 1996/11/07 07:36:07 matthias Exp $
SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \
bcmp.c ffs.c strcat.c strcmp.c strcpy.c strlen.c strncmp.c strncpy.c \
scanc.c skpc.c strncasecmp.c htonl.S htons.S ntohl.S ntohs.S \
__assert.c
bcmp.S bcopy.S bzero.S ffs.S strcat.S strcmp.S strcpy.S strlen.S \
strncmp.S strncpy.S htonl.S htons.S ntohl.S ntohs.S \
scanc.c skpc.c strncasecmp.c __assert.c

View File

@ -1,5 +1,3 @@
/* $NetBSD: SYS.h,v 1.2 1994/10/26 06:39:44 cgd Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
@ -36,31 +34,43 @@
* SUCH DAMAGE.
*
* @(#)SYS.h 5.5 (Berkeley) 5/7/91
*
* $Id: SYS.h,v 1.3 1996/11/07 07:36:09 matthias Exp $
*
* Modified for the ns532 by Phil Nelson, 12/1/92
*
*/
#include <machine/asm.h>
#include <sys/syscall.h>
#ifdef PROF
#define ENTRY(x) .globl _/**/x; \
.data; 1:; .long 0; .text; .align 1; _/**/x: \
addr $1b,tos; bsr mcount
#else
#define ENTRY(x) .globl _/**/x; .text; .align 1; _/**/x:
#endif PROF
#define SYSTRAP(x) \
movd CAT(SYS_,x),r0; \
SVC
#define SYSCALL(x) ENTRY(x); movd SYS_/**/x, r0; svc; bcs cerror
#define RSYSCALL(x) SYSCALL(x); ret 0
#define PSEUDO(x,y) ENTRY(x); movd SYS_/**/y, r0; svc; ret 0
#define CALL(x,y) bsr _/**/y; adjspd -4*x
#define SYSCALL_NOERROR(x) \
ENTRY(x); \
SYSTRAP(x);
#define ASMSTR .asciz
#define RSYSCALL_NOERROR(x) \
SYSCALL_NOERROR(x); \
ret 0
#define SYSCALL(x) \
SYSCALL_NOERROR(x); \
bcs cerror
#define RSYSCALL(x) \
SYSCALL(x); \
ret 0
#define PSEUDO(x,y) \
ENTRY(x); \
SYSTRAP(y); \
ret 0
#define CALL(x,y) \
bsr CAT(_,y); \
adjspd -4*x
.globl cerror
#define SVC svc
#define S_ARG0 4(sp)
#define S_ARG1 8(sp)
#define S_ARG2 12(sp)
#define S_ARG3 16(sp)

View File

@ -0,0 +1,28 @@
/*
* Written by Matthias Pfaller, 1996
* Public domain.
*/
#include <machine/asm.h>
#if defined(LIBC_SCCS)
RCSID("$NetBSD: bcmp.S,v 1.1 1996/11/07 07:36:10 matthias Exp $")
#endif
/*
* int
* bcmp (const void *b1, const void *b2, size_t len)
*/
ENTRY(bcmp)
enter [],0
movd B_ARG2,r0
movd B_ARG0,r1
movd B_ARG1,r2
lshd -2,r0
cmpsd
bne 0f
movqd 3,r0
andd B_ARG2,r0
cmpsb
0: exit []
ret 0

View File

@ -0,0 +1,2 @@
#define BCOPY
#include "memcpy.S"

View File

@ -0,0 +1,2 @@
#define BZERO
#include "memset.S"

View File

@ -0,0 +1,19 @@
/*
* Written by Matthias Pfaller, 1996
* Public domain.
*/
#include <machine/asm.h>
#if defined(LIBC_SCCS)
RCSID("$NetBSD: ffs.S,v 1.1 1996/11/07 07:36:13 matthias Exp $")
#endif
ENTRY(ffs)
enter [],0
movqd 0,r0
ffsd B_ARG0,r0
bfs 1f
addqd 1,r0
1: exit []
ret 0

View File

@ -1,5 +1,3 @@
/* $NetBSD: htonl.S,v 1.2 1994/10/26 06:39:45 cgd Exp $ */
/*
* Mach Operating System
* Copyright (c) 1992 Carnegie Mellon University
@ -31,6 +29,8 @@
* HISTORY
* 11-May-92 Johannes Helander (jvh) at Helsinki University of Technology
* Created.
*
* $Id: htonl.S,v 1.3 1996/11/07 07:36:15 matthias Exp $
*/
#include <machine/asm.h>

View File

@ -1,5 +1,3 @@
/* $NetBSD: htons.S,v 1.2 1994/10/26 06:39:46 cgd Exp $ */
/*
* Mach Operating System
* Copyright (c) 1992 Carnegie Mellon University
@ -31,6 +29,8 @@
* HISTORY
* 11-May-92 Johannes Helander (jvh) at Helsinki University of Technology
* Created.
*
* $Id: htons.S,v 1.3 1996/11/07 07:36:17 matthias Exp $
*/
#include <machine/asm.h>

View File

@ -0,0 +1,122 @@
/*
* Written by Matthias Pfaller, 1996
* Public domain.
*/
#include <machine/asm.h>
#if defined(LIBC_SCCS)
RCSID("$NetBSD: memcpy.S,v 1.1 1996/11/07 07:36:18 matthias Exp $")
#endif
#if !defined(BCOPY) && !defined(MEMMOVE)
/*
* void *
* memcpy (void *d, const void *s, size_t len)
* copy len bytes from the string s to d.
*/
ENTRY(memcpy)
#elif defined(BCOPY)
/*
* void
* bcopy (void *s, const void *d, size_t len)
* copy len bytes from the string s to d.
* s and d may overlap.
*/
# ifdef _KERNEL
ALTENTRY(ovbcopy,bcopy)
# endif
ENTRY(bcopy)
#else
/*
* void *
* memmove (void *d, const void *s, size_t len)
* copy len bytes from the string s to d.
* s and d may overlap.
*/
ENTRY(memmove)
#endif
enter [r3],0
movd B_ARG2,r0
#if defined(BCOPY)
movd B_ARG0,r1
movd B_ARG1,r2
#else
movd B_ARG1,r1
movd B_ARG0,r2
#endif
#if defined(MEMMOVE) || defined(BCOPY)
cmpd r2,r1
bls 0f
movd r1,r3
addd r0,r3
cmpd r2,r3
bls 2f
#endif
0: cmpqd 4,r0
bhi 1f
/*
* Align destination address.
*/
movd 3,r3
andd r2,r3
movd 0(r1),0(r2)
negd r3,r3
addqd 4,r3
addd r3,r1
addd r3,r2
subd r3,r0
movqd 3,r3
andd r0,r3
lshd -2,r0
movsd
movd r3,r0
1: movsb
#if !defined(BCOPY)
movd B_ARG0,r0
#endif
exit [r3]
ret 0
#if defined(MEMMOVE) || defined(BCOPY)
2: addd r0,r1
addd r0,r2
addqd -1,r1
addqd -1,r2
cmpqd 4,r0
bhi 0f
/*
* Align destination address.
*/
movd r0,r3
movqd 1,r0
addd r2,r0
andd 3,r0
subd r0,r3
movsb b
movd r3,r0
andd 3,r3
addqd -3,r1
addqd -3,r2
lshd -2,r0
movsd b
movd r3,r0
addqd 3,r1
addqd 3,r2
0: movsb b
#if !defined(BCOPY)
movd B_ARG0,r0
#endif
exit [r3]
ret 0
#endif

View File

@ -0,0 +1,136 @@
/*
* Written by Matthias Pfaller, 1996
* Public domain.
*/
#include <machine/asm.h>
#if defined(LIBC_SCCS)
RCSID("$NetBSD: memset.S,v 1.1 1996/11/07 07:36:19 matthias Exp $")
#endif
#ifndef BZERO
/*
* void *
* memset (void *b, int c, size_t len)
* write len bytes of value c to the string b.
*/
#define SETMEMB(d) movb r4,d
#define SETMEMD(d) movd r4,d
ENTRY(memset)
enter [r3,r4],0
movd B_ARG0,r1 /* b */
movzbd B_ARG1,r0 /* c */
movd 0x01010101,r4
muld r0,r4
movd B_ARG2,r2 /* len */
#else
/*
* void
* bzero (void *b, size_t len)
* write len zero bytes to the string b.
*/
#define SETMEMB(d) movqb 0,d
#define SETMEMD(d) movqd 0,d
ENTRY(bzero)
enter [r3],0
movd B_ARG0,r1 /* b */
movd B_ARG1,r2 /* len */
#endif
cmpd 19,r2
bhs 6f /* Not worth the trouble. */
/*
* Is address aligned?
*/
movqd 3,r0
andd r1,r0 /* r0 = b & 3 */
cmpqd 0,r0
beq 0f
/*
* Align address (if necessary).
*/
SETMEMD(0(r1))
addr -4(r0)[r2:b],r2 /* len = len + (r0 - 4) */
negd r0,r0
addr 4(r0)[r1:b],r1 /* b = b + (-r0 + 4) */
0: /*
* Compute loop start address.
*/
movd r2,r0
addr 60(r2),r3
andd 60,r0 /* r0 = len & 60 */
lshd -6,r3 /* r3 = (len + 60) >> 6 */
andd 3,r2 /* len &= 3 */
cmpqd 0,r0
beq 1f
addr -64(r1)[r0:b],r1 /* b = b - 64 + r0 */
lshd -2,r0
addr 0(r0)[r0:w],r0
negd r0,r0 /* r0 = -3 * r0 / 4 */
jump 2f(pc)[r0:b] /* Now enter the loop */
/*
* Zero 64 bytes per loop iteration.
*/
.align 2
1: SETMEMD(0(r1))
SETMEMD(4(r1))
SETMEMD(8(r1))
SETMEMD(12(r1))
SETMEMD(16(r1))
SETMEMD(20(r1))
SETMEMD(24(r1))
SETMEMD(28(r1))
SETMEMD(32(r1))
SETMEMD(36(r1))
SETMEMD(40(r1))
SETMEMD(44(r1))
SETMEMD(48(r1))
SETMEMD(52(r1))
SETMEMD(56(r1))
SETMEMD(60(r1))
2: addd 64,r1
acbd -1,r3,1b
3: cmpqd 0,r2
beq 5f
/*
* Zero out blocks shorter then four bytes.
*/
4: SETMEMB(-1(r1)[r2:b])
acbd -1,r2,4b
#ifndef BZERO
5: movd B_ARG0,r0
exit [r3,r4]
ret 0
#else
5: exit [r3]
ret 0
#endif
/*
* For blocks smaller then 20 bytes
* this is faster.
*/
.align 2
6: cmpqd 3,r2
bhs 3b
movd r2,r0
andd 3,r2
lshd -2,r0
7: SETMEMD(0(r1))
addqd 4,r1
acbd -1,r0,7b
br 3b

View File

@ -1,5 +1,3 @@
/* $NetBSD: ntohl.S,v 1.2 1994/10/26 06:39:47 cgd Exp $ */
/*
* Mach Operating System
* Copyright (c) 1992 Carnegie Mellon University
@ -31,6 +29,8 @@
* HISTORY
* 11-May-92 Johannes Helander (jvh) at Helsinki University of Technology
* Created.
*
* $Id: ntohl.S,v 1.3 1996/11/07 07:36:21 matthias Exp $
*/
#include <machine/asm.h>

View File

@ -1,5 +1,3 @@
/* $NetBSD: ntohs.S,v 1.2 1994/10/26 06:39:48 cgd Exp $ */
/*
* Mach Operating System
* Copyright (c) 1992 Carnegie Mellon University
@ -31,6 +29,8 @@
* HISTORY
* 11-May-92 Johannes Helander (jvh) at Helsinki University of Technology
* Created.
*
* $Id: ntohs.S,v 1.3 1996/11/07 07:36:22 matthias Exp $
*/
#include <machine/asm.h>

View File

@ -1,70 +0,0 @@
/* $NetBSD: setjmp.S,v 1.3 1995/11/30 01:00:12 jtc Exp $ */
/*
* Copyright (c) 1992 Helsinki University of Technology
* All Rights Reserved.
*
* Permission to use, copy, modify and distribute this software and its
* documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
*
* HELSINKI UNIVERSITY OF TECHNOLOGY ALLOWS FREE USE OF THIS SOFTWARE IN
* ITS "AS IS" CONDITION. HELSINKI UNIVERSITY OF TECHNOLOGY DISCLAIMS ANY
* LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE
* USE OF THIS SOFTWARE.
*/
/*
* HISTORY
* 29-Apr-92 Johannes Helander (jvh) at Helsinki University of Technology
* Created.
*/
#include <machine/asm.h>
#include <machine/jmpbuf.h>
ENTRY(setjmp)
movqd 0, tos
bsr EX(sigblock)
adjspb -4
movd 4(sp), r2 /* jmp_buf */
movd 0(sp), JMP_BUF_PC(r2) /* pc of caller */
movd r0, JMP_BUF_SIGMASK(r2) /* save mask */
sprd sp, JMP_BUF_SP(r2)
sprd fp, JMP_BUF_FP(r2)
sprd sb, JMP_BUF_SB(r2)
movd r3, JMP_BUF_R3(r2) /* save registers r3-r7 */
movd r4, JMP_BUF_R4(r2)
movd r5, JMP_BUF_R5(r2)
movd r6, JMP_BUF_R6(r2)
movd r7, JMP_BUF_R7(r2)
movqd 0, r0
ret 0
ENTRY(longjmp)
movd 4(sp),r2 /* jmp_buf */
movd JMP_BUF_SIGMASK(r2), tos /* restore mask */
bsr EX(sigsetmask)
adjspb -4
movd 4(sp), r2 /* jmp_buf */
movd 8(sp), r0 /* value */
lprd sp, JMP_BUF_SP(r2)
lprd fp, JMP_BUF_FP(r2)
lprd sb, JMP_BUF_SB(r2)
movd JMP_BUF_R3(r2), r3 /* load registers r3-r7 */
movd JMP_BUF_R4(r2), r4
movd JMP_BUF_R5(r2), r5
movd JMP_BUF_R6(r2), r6
movd JMP_BUF_R7(r2), r7
movd JMP_BUF_PC(r2), 0(sp) /* patch return pc */
cmpqd 0, r0
bne nonzero
movqd 1, r0
nonzero:
ret 0

View File

@ -0,0 +1,29 @@
/*
* Written by Matthias Pfaller, 1996
* Public domain.
*/
#include <machine/asm.h>
#if defined(LIBC_SCCS)
RCSID("$NetBSD: strcat.S,v 1.1 1996/11/07 07:36:24 matthias Exp $")
#endif
/*
* char *
* strcat (char *d, const char *s)
* append string s to d.
*/
ENTRY(strcat)
enter [],0
movd B_ARG0,tos
bsr _strlen
addd B_ARG0,r0
movd B_ARG1,0(sp)
movd r0,tos
bsr _strcpy
adjspd -8
movd B_ARG0,r0
exit []
ret 0

View File

@ -0,0 +1,129 @@
/*
* Written by Randy Hyde, 1993
* Public domain.
*/
#include <machine/asm.h>
#if defined(LIBC_SCCS)
RCSID("$NetBSD: strcmp.S,v 1.1 1996/11/07 07:36:25 matthias Exp $")
#endif
/*
* int
* strcmp (const char *s1, const char *s2)
* compare strings s1 and s2.
*/
ENTRY(strcmp)
enter [r3,r4,r5],0
movd B_ARG1,r1
movd B_ARG0,r2
/*
* First begin by seeing if we can doubleword align the
* pointers. The following code only aligns the pointer in R1.
* If the L.O. two bits of R2 do not match, it's going to run
* slower but there is nothing we can do about that. Better to
* have at least one of them double word aligned rather than
* neither.
*/
movqd 3,r3
andd r1,r3
0: casew 1f(pc)[r3:w]
1: .word 5f-0b
.word 2f-0b
.word 3f-0b
.word 4f-0b
.align 2,0xa2
2: cmpb 0(r1),0(r2) ; bne 8f ; cmpqb 0,0(r1) ; beq 9f
cmpb 1(r1),1(r2) ; bne 8f ; cmpqb 0,1(r1) ; beq 9f
cmpb 2(r1),2(r2) ; bne 8f ; cmpqb 0,2(r1) ; beq 9f
addqd 3,r1
addqd 3,r2
br 5f
.align 2,0xa2
3: cmpb 0(r1),0(r2) ; bne 8f ; cmpqb 0,0(r1) ; beq 9f
cmpb 1(r1),1(r2) ; bne 8f ; cmpqb 0,1(r1) ; beq 9f
addqd 2,r1
addqd 2,r2
br 5f
.align 2,0xa2
4: cmpb 0(r1),0(r2) ; bne 8f ; cmpqb 0,0(r1) ; beq 9f
addqd 1,r1
addqd 1,r2
/*
* Okay, when we get down here R1 points at a double word
* algined source block of bytes, R2 points at another block of
* bytes (typically, though not always double word aligned).
* This guy processes four bytes at a time and checks for the
* zero terminating byte amongst the bytes in the double word.
* This algorithm is de to Dave Rand.
*
* Sneaky test for zero amongst four bytes:
*
* xxyyzztt
* -01010101
* ---------
* aabbccdd
* bic xxyyzztt
* ---------
* eeffgghh ee=0x80 if xx=0, ff=0x80 if yy=0, etc.
*
* This whole result will be zero if there
* was no zero byte, it will be non-zero if
* there is a zero byte present.
*/
5: movd 0x01010101,r3 /* Magic number to use */
movd 0x80808080,r4 /* Another magic number. */
movd 0(r1),r5 /* Get 1st double word. */
movd r5,r0 /* Save for storage later. */
subd r3,r0 /* Gets borrow if byte = 0. */
bicd r5,r0 /* Clear original bits. */
andd r4,r0 /* See if borrow occurred. */
cmpqd 0,r0
bne 1f /* If this DWORD contained a 0. */
.align 2,0xa2
0: movd 4(r1),r0 /* Get next 4 bytes to process */
cmpd r5,0(r2) /* Compare prev four bytes. */
bne 1f
addqd 4,r1
addqd 4,r2
movd r0,r5 /* Save for storage if no zeros. */
subd r3,r0
bicd r5,r0
andd r4,r0
cmpqd 0,r0
beq 0b
/*
* At this point either the strings are not equal or
* they contain a zero byte. Check them.
*/
1: cmpb 0(r1),0(r2) ; bne 8f ; cmpqb 0,0(r1) ; beq 9f
cmpb 1(r1),1(r2) ; bne 8f ; cmpqb 0,1(r1) ; beq 9f
cmpb 2(r1),2(r2) ; bne 8f ; cmpqb 0,2(r1) ; beq 9f
cmpb 3(r1),3(r2) ; bne 8f
9: movqd 0,r0
exit [r3,r4,r5]
ret 0
8: blo 0f /* Operands were reversed on cmp. */
movqd -1,r0 /* It's >, so return one. */
exit [r3,r4,r5]
ret 0
0: movqd 1,r0 /* It's <, so return -1. */
exit [r3,r4,r5]
ret 0

View File

@ -0,0 +1,120 @@
/*
* Written by Randy Hyde, 1993
* Public domain.
*/
#include <machine/asm.h>
#if defined(LIBC_SCCS)
RCSID("$NetBSD: strcpy.S,v 1.1 1996/11/07 07:36:26 matthias Exp $")
#endif
/*
* char *
* strcpy (char *d, const char *s)
* copy string s to d.
*/
ENTRY(strcpy)
enter [r3,r4,r5],0
movd B_ARG1,r1
movd B_ARG0,r2
/*
* First begin by seeing if we can doubleword align the
* pointers. The following code only aligns the pointer in R2.
* If the L.O. two bits of R1 do not match, it's going to run
* slower but there is nothing we can do about that. Better to
* have at least one of them double word aligned rather than
* neither.
*/
movqd 3,r3
andd r2,r3
0: casew 1f(pc)[r3:w]
1: .word 5f-0b
.word 2f-0b
.word 3f-0b
.word 4f-0b
.align 2,0xa2
2: movb 0(r1),0(r2) ; cmpqb 0,0(r1) ; beq 9f
movb 1(r1),1(r2) ; cmpqb 0,1(r1) ; beq 9f
movb 2(r1),2(r2) ; cmpqb 0,2(r1) ; beq 9f
addqd 3,r1
addqd 3,r2
br 5f
.align 2,0xa2
3: movb 0(r1),0(r2) ; cmpqb 0,0(r1) ; beq 9f
movb 1(r1),1(r2) ; cmpqb 0,1(r1) ; beq 9f
addqd 2,r1
addqd 2,r2
br 5f
.align 2,0xa2
4: movb 0(r1),0(r2) ; cmpqb 0,0(r1) ; beq 9f
addqd 1,r1
addqd 1,r2
/*
* Okay, when we get down here R2 points at a double word
* aligned destination block of bytes, R1 points at another
* block of bytes (typically, though not always double word
* aligned).
* This guy processes four bytes at a time and checks for the
* zero terminating byte amongst the bytes in the double word.
* This algorithm is de to Dave Rand.
*
* Sneaky test for zero amongst four bytes:
*
* xxyyzztt
* -01010101
* ---------
* aabbccdd
* bic xxyyzztt
* ---------
* eeffgghh ee=0x80 if xx=0, ff=0x80 if yy=0, etc.
*
* This whole result will be zero if there
* was no zero byte, it will be non-zero if
* there is a zero byte present.
*/
5: movd 0x01010101,r3 /* Magic number to use */
movd 0x80808080,r4 /* Another magic number. */
movd 0(r1),r5 /* Get 1st double word. */
movd r5,r0 /* Save for storage later. */
subd r3,r0 /* Gets borrow if byte = 0. */
bicd r5,r0 /* Clear original bits. */
andd r4,r0 /* See if borrow occurred. */
cmpqd 0,r0
bne 1f /* See if this DWORD contained a 0. */
.align 2,0xa2
0: movd 4(r1),r0 /* Get next 4 bytes to process */
movd r5,0(r2) /* Save away prev four bytes. */
addd 4,r1 /* addd is faster then addqd here */
addd 4,r2
movd r0,r5 /* Save for storage if no zeros. */
subd r3,r0
bicd r5,r0
andd r4,r0
cmpqd 0,r0
beq 0b
/*
* At this point, R1 points at a double word which
* contains a zero byte. Copy the characters up to
* (and including) the zero byte and quit.
*/
1: movb 0(r1),0(r2) ; cmpqb 0,0(r1) ; beq 9f
movb 1(r1),1(r2) ; cmpqb 0,1(r1) ; beq 9f
movb 2(r1),2(r2) ; cmpqb 0,2(r1) ; beq 9f
movb 3(r1),3(r2) /* This one must be a zero byte */
9: movd B_ARG0,r0
exit [r3,r4,r5]
ret 0

View File

@ -0,0 +1,112 @@
/*
* Written by Randy Hyde, 1993
* Public domain.
*/
#include <machine/asm.h>
#if defined(LIBC_SCCS)
RCSID("$NetBSD: strlen.S,v 1.1 1996/11/07 07:36:28 matthias Exp $")
#endif
/*
* size_t
* strlen (char *s)
* compute the length of the string s.
*/
ENTRY(strlen)
enter [r3,r4],0
movd B_ARG0,r0
/*
* First begin by seeing if we can doubleword align the
* pointer. The following code aligns the pointer in r0.
*/
movqd 3,r3
andd r0,r3
0: casew 1f(pc)[r3:w]
1: .word 5f-0b
.word 2f-0b
.word 3f-0b
.word 4f-0b
.align 2,0xa2
2: cmpqb 0,0(r0) ; beq 7f
cmpqb 0,1(r0) ; beq 8f
cmpqb 0,2(r0) ; beq 9f
addqd 3,r0
br 5f
.align 2,0xa2
3: cmpqb 0,0(r0) ; beq 7f
cmpqb 0,1(r0) ; beq 8f
addqd 2,r0
br 5f
.align 2,0xa2
4: cmpqb 0,0(r0) ; beq 7f
addqd 1,r0
/*
* Okay, when we get down here r0 points at a double word
* algined source block of bytes.
* This guy processes four bytes at a time and checks for the
* zero terminating byte amongst the bytes in the double word.
* This algorithm is de to Dave Rand.
*
* Sneaky test for zero amongst four bytes:
*
* xxyyzztt
* -01010101
* ---------
* aabbccdd
* bic xxyyzztt
* ---------
* eeffgghh ee=0x80 if xx=0, ff=0x80 if yy=0, etc.
*
* This whole result will be zero if there
* was no zero byte, it will be non-zero if
* there is a zero byte present.
*/
5: movd 0x01010101,r2 /* Magic number to use */
movd 0x80808080,r3 /* Another magic number. */
addqd -4,r0
.align 2,0xa2
0: movd 4(r0),r1 /* Get next double word. */
addqd 4,r0 /* Advance pointer. */
movd r1,r4 /* Save for storage later. */
subd r2,r1 /* Gets borrow if byte = 0. */
bicd r4,r1 /* Clear original bits. */
andd r3,r1 /* See if borrow occurred. */
cmpqd 0,r1
beq 0b /* See if this DWORD contained a 0. */
/*
* At this point, r0 points at a double word which
* contains a zero byte. Count the bytes up to the
* zero.
*/
1: cmpqb 0,0(r0) ; beq 7f
cmpqb 0,1(r0) ; beq 8f
cmpqb 0,2(r0) ; beq 9f
addqd 3,r0 /* Must be in fourth byte. */
7: subd B_ARG0,r0
exit [r3,r4]
ret 0
8: addqd 1,r0
subd B_ARG0,r0
exit [r3,r4]
ret 0
9: addqd 2,r0
subd B_ARG0,r0
exit [r3,r4]
ret 0

View File

@ -0,0 +1,33 @@
/*
* Written by Matthias Pfaller, 1996
* Public domain.
*/
#include <machine/asm.h>
#if defined(LIBC_SCCS)
RCSID("$NetBSD: strncmp.S,v 1.1 1996/11/07 07:36:29 matthias Exp $")
#endif
/*
* int
* strncmp(const char *s1, const char *s2, size_t len)
*/
ENTRY(strncmp)
enter [r4],0
movd B_ARG2,r0
cmpqd 0,r0
beq 1f
movd B_ARG0,r1
movd B_ARG1,r2
movqd 0,r4
cmpsb u
bfc 0f
cmpb 0(r1),0(r2)
0: movqd 0,r0
beq 1f
movqd -1,r0
blo 1f
movqd 1,r0
1: exit [r4]
ret 0

View File

@ -0,0 +1,32 @@
/*
* Written by Matthias Pfaller, 1996
* Public domain.
*/
#include <machine/asm.h>
#if defined(LIBC_SCCS)
RCSID("$NetBSD: strncpy.S,v 1.1 1996/11/07 07:36:30 matthias Exp $")
#endif
/*
* char *
* strncpy (char *d, const char *s, size_t len)
* copy at most len characters from the string s to d.
*/
ENTRY(strncpy)
enter [r4],0
movd B_ARG2,r0
movd B_ARG1,r1
movd B_ARG0,r2
movqd 0,r4
movsb u
bfc 0f
movd r0,tos
movd r2,tos
bsr _bzero
adjspd -8
0: movd B_ARG0,r0
exit [r4]
ret 0