summaryrefslogtreecommitdiff
path: root/sys/lib/libkern/arch/i386
diff options
context:
space:
mode:
authorchuck <chuck@cvs.openbsd.org>1997-11-04 19:08:20 +0000
committerchuck <chuck@cvs.openbsd.org>1997-11-04 19:08:20 +0000
commit543ad208f86c4407686b5ae68e8136a299c887d4 (patch)
tree5ecf9d115175fea3fabbc922e906ca70018372de /sys/lib/libkern/arch/i386
parent6b57d10d1974c94e115608d07f1c152a2447e274 (diff)
add memchr to libkern
Diffstat (limited to 'sys/lib/libkern/arch/i386')
-rw-r--r--sys/lib/libkern/arch/i386/Makefile.inc3
-rw-r--r--sys/lib/libkern/arch/i386/memchr.S27
2 files changed, 29 insertions, 1 deletions
diff --git a/sys/lib/libkern/arch/i386/Makefile.inc b/sys/lib/libkern/arch/i386/Makefile.inc
index 857134d5146..e048a85a5de 100644
--- a/sys/lib/libkern/arch/i386/Makefile.inc
+++ b/sys/lib/libkern/arch/i386/Makefile.inc
@@ -1,7 +1,8 @@
-# $OpenBSD: Makefile.inc,v 1.4 1996/04/21 22:27:52 deraadt Exp $
+# $OpenBSD: Makefile.inc,v 1.5 1997/11/04 19:08:05 chuck 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 \
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/memchr.S b/sys/lib/libkern/arch/i386/memchr.S
new file mode 100644
index 00000000000..43f7a91e0a1
--- /dev/null
+++ b/sys/lib/libkern/arch/i386/memchr.S
@@ -0,0 +1,27 @@
+/* $OpenBSD: memchr.S,v 1.1 1997/11/04 19:08:06 chuck Exp $ */
+
+/*
+ * Written by J.T. Conklin <jtc@netbsd.org>.
+ * Public domain.
+ */
+
+#include <machine/asm.h>
+
+ENTRY(memchr)
+ 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 2,0x90
+L1: xorl %eax,%eax
+ popl %edi
+ ret