summaryrefslogtreecommitdiffstats
path: root/sys/lib/libkern/arch/i386/memchr.S
diff options
context:
space:
mode:
Diffstat (limited to 'sys/lib/libkern/arch/i386/memchr.S')
-rw-r--r--sys/lib/libkern/arch/i386/memchr.S27
1 files changed, 27 insertions, 0 deletions
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