diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2000-06-16 19:56:57 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2000-06-16 19:56:57 +0000 |
commit | cdc559bb524525107694db17b1e269e743085f56 (patch) | |
tree | d99c41f760a211344a0f82ba47a278e36c838806 | |
parent | df68efa4282fc04c1355936aca4fc234c5a96d6e (diff) |
Pull memcmp() into libkern. Also, use asm version of memset() on m68k.
-rw-r--r-- | sys/lib/libkern/arch/alpha/Makefile.inc | 4 | ||||
-rw-r--r-- | sys/lib/libkern/arch/arm32/Makefile.inc | 4 | ||||
-rw-r--r-- | sys/lib/libkern/arch/hppa/Makefile.inc | 5 | ||||
-rw-r--r-- | sys/lib/libkern/arch/i386/Makefile.inc | 4 | ||||
-rw-r--r-- | sys/lib/libkern/arch/i386/memcmp.S | 44 | ||||
-rw-r--r-- | sys/lib/libkern/arch/m68k/Makefile.inc | 4 | ||||
-rw-r--r-- | sys/lib/libkern/arch/m68k/memcmp.S | 101 | ||||
-rw-r--r-- | sys/lib/libkern/arch/m68k/memset.S | 112 | ||||
-rw-r--r-- | sys/lib/libkern/arch/m88k/Makefile.inc | 4 | ||||
-rw-r--r-- | sys/lib/libkern/arch/mips/Makefile.inc | 4 | ||||
-rw-r--r-- | sys/lib/libkern/arch/ns32k/Makefile.inc | 4 | ||||
-rw-r--r-- | sys/lib/libkern/arch/powerpc/Makefile.inc | 4 | ||||
-rw-r--r-- | sys/lib/libkern/arch/sparc/Makefile.inc | 4 | ||||
-rw-r--r-- | sys/lib/libkern/arch/vax/Makefile.inc | 4 |
14 files changed, 280 insertions, 22 deletions
diff --git a/sys/lib/libkern/arch/alpha/Makefile.inc b/sys/lib/libkern/arch/alpha/Makefile.inc index 22ee7218ea2..2be9a23527a 100644 --- a/sys/lib/libkern/arch/alpha/Makefile.inc +++ b/sys/lib/libkern/arch/alpha/Makefile.inc @@ -1,8 +1,8 @@ -# $OpenBSD: Makefile.inc,v 1.8 1997/11/04 19:08:01 chuck Exp $ +# $OpenBSD: Makefile.inc,v 1.9 2000/06/16 19:56:53 millert Exp $ # $NetBSD: Makefile.inc,v 1.9 1996/08/27 00:44:24 cgd Exp $ SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \ - memchr.c \ + memchr.c memcmp.c \ bcmp.c bzero.S ffs.S strcat.c strcmp.c strcpy.c strlen.c strncmp.c \ strncpy.c scanc.c skpc.c htonl.S htons.S ntohl.S ntohs.S \ random.c strncasecmp.c diff --git a/sys/lib/libkern/arch/arm32/Makefile.inc b/sys/lib/libkern/arch/arm32/Makefile.inc index a70d9e658fa..f07fb93aadf 100644 --- a/sys/lib/libkern/arch/arm32/Makefile.inc +++ b/sys/lib/libkern/arch/arm32/Makefile.inc @@ -1,7 +1,7 @@ -# $OpenBSD: Makefile.inc,v 1.3 1997/11/07 15:56:57 niklas Exp $ +# $OpenBSD: Makefile.inc,v 1.4 2000/06/16 19:56:54 millert Exp $ SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \ - memchr.c \ + memchr.c memcmp.c \ bcmp.c bzero.c ffs.c strcat.c strcmp.c strcpy.c strlen.c strncmp.c \ strncpy.c scanc.c skpc.c locc.c htonl.c htons.c ntohl.c ntohs.c \ div.S random.c strncasecmp.c diff --git a/sys/lib/libkern/arch/hppa/Makefile.inc b/sys/lib/libkern/arch/hppa/Makefile.inc index 337a2fd52a7..10a8edd6f43 100644 --- a/sys/lib/libkern/arch/hppa/Makefile.inc +++ b/sys/lib/libkern/arch/hppa/Makefile.inc @@ -1,8 +1,9 @@ -# $OpenBSD: Makefile.inc,v 1.8 2000/04/25 15:28:23 mickey Exp $ +# $OpenBSD: Makefile.inc,v 1.9 2000/06/16 19:56:54 millert Exp $ SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \ random.c ashrdi3.c divdi3.c strncpy.c strncmp.c strcmp.c memchr.c \ - memset.c strlen.c strcpy.c strcat.c skpc.c strncasecmp.c scanc.c + memcmp.c memset.c strlen.c strcpy.c strcat.c skpc.c strncasecmp.c \ + scanc.c SRCS+= milli.S bcmp.S ffs.S OBJS+= bzero.o diff --git a/sys/lib/libkern/arch/i386/Makefile.inc b/sys/lib/libkern/arch/i386/Makefile.inc index e048a85a5de..54e09fde511 100644 --- a/sys/lib/libkern/arch/i386/Makefile.inc +++ b/sys/lib/libkern/arch/i386/Makefile.inc @@ -1,8 +1,8 @@ -# $OpenBSD: Makefile.inc,v 1.5 1997/11/04 19:08:05 chuck Exp $ +# $OpenBSD: Makefile.inc,v 1.6 2000/06/16 19:56:54 millert Exp $ # $NetBSD: Makefile.inc,v 1.10 1996/04/13 01:17:41 cgd Exp $ SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \ - memchr.S \ + memchr.S memcmp.S \ bcmp.S ffs.S memset.S strcat.S strcmp.S strcpy.S strlen.S strncmp.c \ strncpy.c scanc.S skpc.S locc.S htonl.S htons.S ntohl.S ntohs.S \ strncasecmp.c diff --git a/sys/lib/libkern/arch/i386/memcmp.S b/sys/lib/libkern/arch/i386/memcmp.S new file mode 100644 index 00000000000..4ad4fd46469 --- /dev/null +++ b/sys/lib/libkern/arch/i386/memcmp.S @@ -0,0 +1,44 @@ +/* $OpenBSD: memcmp.S,v 1.1 2000/06/16 19:56:54 millert Exp $ */ + +/* + * Written by J.T. Conklin <jtc@netbsd.org>. + * Public domain. + */ + +#include <machine/asm.h> + +ENTRY(memcmp) + pushl %edi + pushl %esi + movl 12(%esp),%edi + movl 16(%esp),%esi + cld /* set compare direction forward */ + + movl 20(%esp),%ecx /* compare by words */ + shrl $2,%ecx + repe + cmpsl + jne L5 /* do we match so far? */ + + movl 20(%esp),%ecx /* compare remainder by bytes */ + andl $3,%ecx + repe + cmpsb + jne L6 /* do we match? */ + + xorl %eax,%eax /* we match, return zero */ + popl %esi + popl %edi + ret + +L5: movl $4,%ecx /* We know that one of the next */ + subl %ecx,%edi /* four pairs of bytes do not */ + subl %ecx,%esi /* match. */ + repe + cmpsb +L6: movzbl -1(%edi),%eax /* Perform unsigned comparison */ + movzbl -1(%esi),%edx + subl %edx,%eax + popl %esi + popl %edi + ret diff --git a/sys/lib/libkern/arch/m68k/Makefile.inc b/sys/lib/libkern/arch/m68k/Makefile.inc index ae04c77f283..3f55124d332 100644 --- a/sys/lib/libkern/arch/m68k/Makefile.inc +++ b/sys/lib/libkern/arch/m68k/Makefile.inc @@ -1,8 +1,8 @@ -# $OpenBSD: Makefile.inc,v 1.5 1998/06/19 09:14:42 espie Exp $ +# $OpenBSD: Makefile.inc,v 1.6 2000/06/16 19:56:54 millert Exp $ # $NetBSD: Makefile.inc,v 1.7 1996/04/18 01:53:04 cgd Exp $ SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \ - memchr.c memset.c \ + memchr.c memcmp.S memset.S \ bcmp.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.S skpc.S locc.S \ strncasecmp.c diff --git a/sys/lib/libkern/arch/m68k/memcmp.S b/sys/lib/libkern/arch/m68k/memcmp.S new file mode 100644 index 00000000000..b0ebb297072 --- /dev/null +++ b/sys/lib/libkern/arch/m68k/memcmp.S @@ -0,0 +1,101 @@ +/* $OpenBSD: memcmp.S,v 1.1 2000/06/16 19:56:55 millert Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * the Systems Programming Group of the University of Utah Computer + * Science Department. + * + * 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. + */ + +#include "DEFS.h" + +#if defined(LIBC_SCCS) + .text + .asciz "$OpenBSD: memcmp.S,v 1.1 2000/06/16 19:56:55 millert Exp $" +#endif /* LIBC_SCCS */ + +/* memcmp(s1, s2, n) */ + +/* + * This is probably not the best we can do, but it is still 2-10 times + * faster than the C version in the portable gen directory. + * + * Things that might help: + * - longword align when possible (only on the 68020) + * - use nested DBcc instructions or use one and limit size to 64K + */ +ENTRY(memcmp) + movl sp@(4),a0 | string 1 + movl sp@(8),a1 | string 2 + movl sp@(12),d0 | length + beq bcdone | if zero, nothing to do + movl a0,d1 + btst #0,d1 | string 1 address odd? + beq bceven | no, skip alignment + cmpmb a0@+,a1@+ | yes, compare a byte + bne bcnoteq | not equal, return non-zero + subql #1,d0 | adjust count + beq bcdone | count 0, reutrn zero +bceven: + movl a1,d1 + btst #0,d1 | string 2 address odd? + bne bcbloop | yes, no hope for alignment, compare bytes + movl d0,d1 | no, both even + lsrl #2,d1 | convert count to longword count + beq bcbloop | count 0, skip longword loop +bclloop: + cmpml a0@+,a1@+ | compare a longword + bne bcnoteql | not equal, return non-zero + subql #1,d1 | adjust count + bne bclloop | still more, keep comparing + andl #3,d0 | what remains + beq bcdone | nothing, all done +bcbloop: + cmpmb a0@+,a1@+ | compare a byte + bne bcnoteq | not equal, return non-zero + subql #1,d0 | adjust count + bne bcbloop | still more, keep going + rts +bcnoteql: + subql #4,a0 + subql #4,a1 + movl #4,d0 + jra bcbloop +bcnoteq: + clrl d0 + clrl d1 + movb a0@-,d0 + movb a1@-,d1 + subl d1,d0 +bcdone: + rts diff --git a/sys/lib/libkern/arch/m68k/memset.S b/sys/lib/libkern/arch/m68k/memset.S new file mode 100644 index 00000000000..45e258dff7a --- /dev/null +++ b/sys/lib/libkern/arch/m68k/memset.S @@ -0,0 +1,112 @@ +/* $OpenBSD: memset.S,v 1.1 2000/06/16 19:56:55 millert Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * the Systems Programming Group of the University of Utah Computer + * Science Department. + * + * 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. + */ + +#include "DEFS.h" + +#if defined(LIBC_SCCS) + .text + .asciz "$OpenBSD: memset.S,v 1.1 2000/06/16 19:56:55 millert Exp $" +#endif /* LIBC_SCCS */ + +/* + * This is probably not the best we can do, but it is still much + * faster than the C version in the portable gen directory. + * + * Things that might help: + * - unroll the longword loop (might not be good for a 68020) + * - longword, as opposed to word, align when possible (only on the 68020) + * - use nested DBcc instructions or use one and limit size to 64K + */ +ENTRY(memset) + movl d2,sp@- + movl sp@(8),a0 | destination + movl sp@(16),d0 | count + beq bzdone | nothing to do + movb sp@(15),d2 | character + movl a0,d1 + btst #0,d1 | address odd? + beq bzeven | no, skip alignment + movb d2,a0@+ | set one byte + subql #1,d0 | adjust count + beq bzdone | if zero, all done +bzeven: + cmpl #15,d0 + ble bzbloop | too small to be worthwhile + clrl d1 | replicate byte to fill longword + movb d2,d1 + movl d1,d2 + lsll #8,d1 + orl d1,d2 + lsll #8,d1 + orl d1,d2 + lsll #8,d1 + orl d1,d2 + movl d0,d1 | convert to longword count + lsrl #2,d1 +#ifdef DEBUG + moveml #0xffff,sp@- + movl d2,sp@- + movl d1,sp@- + movl d0,sp@- + movl a0,sp@- + movl #foo,sp@- + jsr _printf + addl #20,sp + moveml sp@+,#0xffff +#endif +bzlloop: + movl d2,a0@+ | set one longword + subql #1,d1 | adjust count + bne bzlloop | still more, keep going + andl #3,d0 | what remains + beq bzdone | nothing, all done +bzbloop: + movb d2,a0@+ | set one byte + subql #1,d0 | adjust count + bne bzbloop | still more, keep going +bzdone: + movl sp@(8),d0 | return destination + movl sp@+,d2 + rts + +#ifdef DEBUG + .globl _printf +foo: + .asciz "a0=%08x d0=%08x d1=%08x d2=%08x\n" +#endif diff --git a/sys/lib/libkern/arch/m88k/Makefile.inc b/sys/lib/libkern/arch/m88k/Makefile.inc index f8fe4047ad1..d60183ac96a 100644 --- a/sys/lib/libkern/arch/m88k/Makefile.inc +++ b/sys/lib/libkern/arch/m88k/Makefile.inc @@ -1,7 +1,7 @@ -# $OpenBSD: Makefile.inc,v 1.2 1999/03/03 06:13:11 smurph Exp $ +# $OpenBSD: Makefile.inc,v 1.3 2000/06/16 19:56:55 millert Exp $ # $NetBSD: Makefile.inc,v 1.2 1996/04/13 01:17:58 cgd Exp $ SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \ - memchr.c bcmp.c random.c \ + memchr.c memcmp.c bcmp.c random.c \ strcat.c strcmp.c strcpy.c strlen.c strncmp.c \ strncpy.c scanc.c skpc.c strncasecmp.c ffs.c diff --git a/sys/lib/libkern/arch/mips/Makefile.inc b/sys/lib/libkern/arch/mips/Makefile.inc index d1c939cbba3..908b0199907 100644 --- a/sys/lib/libkern/arch/mips/Makefile.inc +++ b/sys/lib/libkern/arch/mips/Makefile.inc @@ -1,10 +1,10 @@ -# $OpenBSD: Makefile.inc,v 1.6 1998/03/18 20:47:10 mickey Exp $ +# $OpenBSD: Makefile.inc,v 1.7 2000/06/16 19:56:55 millert Exp $ # $NetBSD: Makefile.inc,v 1.4 1996/04/13 01:17:46 cgd Exp $ # # There are likely more that we will notice when we go native SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \ - memchr.c strcmp.c \ + memchr.c memcmp.c strcmp.c \ bcmp.S bcopy.S bzero.S strcat.c strcmp.c strcpy.c ffs.S htonl.S \ htons.S strcmp.S strlen.S strncmp.c random.c scanc.c skpc.c strncpy.c \ strncasecmp.c diff --git a/sys/lib/libkern/arch/ns32k/Makefile.inc b/sys/lib/libkern/arch/ns32k/Makefile.inc index d55cdd2c4de..04849294d70 100644 --- a/sys/lib/libkern/arch/ns32k/Makefile.inc +++ b/sys/lib/libkern/arch/ns32k/Makefile.inc @@ -1,8 +1,8 @@ -# $OpenBSD: Makefile.inc,v 1.4 1997/11/04 19:08:11 chuck Exp $ +# $OpenBSD: Makefile.inc,v 1.5 2000/06/16 19:56:55 millert Exp $ # $NetBSD: Makefile.inc,v 1.7 1996/04/13 01:17:50 cgd Exp $ SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \ - memchr.S \ + memchr.S memcmp.c \ bcmp.c ffs.c strcat.c strcmp.c strcpy.c strlen.c strncmp.c strncpy.c \ scanc.c skpc.c locc.c strncasecmp.c \ htonl.S htons.S ntohl.S ntohs.S diff --git a/sys/lib/libkern/arch/powerpc/Makefile.inc b/sys/lib/libkern/arch/powerpc/Makefile.inc index 70c59ba12df..f41665d1850 100644 --- a/sys/lib/libkern/arch/powerpc/Makefile.inc +++ b/sys/lib/libkern/arch/powerpc/Makefile.inc @@ -1,11 +1,11 @@ -# $OpenBSD: Makefile.inc,v 1.5 1999/11/09 04:18:30 rahnds Exp $ +# $OpenBSD: Makefile.inc,v 1.6 2000/06/16 19:56:55 millert Exp $ # $NetBSD: Makefile.inc,v 1.6 1994/10/26 06:39:03 cgd Exp $ CFLAGS += -D_KERNEL SRCS+= __main.c __eabi.c \ imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \ - memset.c memchr.c \ + memchr.c memcmp.c memset.c \ bcmp.c bzero.c ffs.c strcat.c strcmp.c strcpy.c strlen.c strncmp.c \ strncpy.c scanc.c skpc.c locc.c htonl.c htons.c ntohl.c ntohs.c \ memcpy.c random.c strncasecmp.c diff --git a/sys/lib/libkern/arch/sparc/Makefile.inc b/sys/lib/libkern/arch/sparc/Makefile.inc index d66b88ec73f..6aabd416334 100644 --- a/sys/lib/libkern/arch/sparc/Makefile.inc +++ b/sys/lib/libkern/arch/sparc/Makefile.inc @@ -1,8 +1,8 @@ -# $OpenBSD: Makefile.inc,v 1.7 2000/02/22 19:27:18 deraadt Exp $ +# $OpenBSD: Makefile.inc,v 1.8 2000/06/16 19:56:55 millert Exp $ # $NetBSD: Makefile.inc,v 1.12 1996/04/23 23:05:22 christos Exp $ SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \ - memchr.c memset.c \ + memchr.c memcmp.c memset.c \ bcmp.c bzero.S strcat.c strcmp.c strcpy.c strlen.S strncmp.c \ strncpy.c htonl.S htons.S ntohl.S ntohs.S scanc.c skpc.c \ strncasecmp.c diff --git a/sys/lib/libkern/arch/vax/Makefile.inc b/sys/lib/libkern/arch/vax/Makefile.inc index 57949c7e78a..1aa7fdb673c 100644 --- a/sys/lib/libkern/arch/vax/Makefile.inc +++ b/sys/lib/libkern/arch/vax/Makefile.inc @@ -1,7 +1,7 @@ -# $OpenBSD: Makefile.inc,v 1.4 1997/11/04 19:08:19 chuck Exp $ +# $OpenBSD: Makefile.inc,v 1.5 2000/06/16 19:56:56 millert Exp $ # $NetBSD: Makefile.inc,v 1.2 1996/04/13 01:17:58 cgd Exp $ SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \ - memchr.c \ + memchr.c memcmp.c \ strcat.c strcmp.c strcpy.c strlen.c strncmp.c \ strncpy.c scanc.c skpc.c strncasecmp.c |