• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*	$OpenBSD: memchr.S,v 1.3 2005/08/07 11:30:38 espie Exp $ */
2/*
3 * Written by J.T. Conklin <jtc@netbsd.org>.
4 * Public domain.
5 */
6
7#include <machine/asm.h>
8
9ENTRY(memchr)
10	pushl	%edi
11	movl	8(%esp),%edi		/* string address */
12	movl	12(%esp),%eax		/* set character to search for */
13	movl	16(%esp),%ecx		/* set length of search */
14	testl	%ecx,%ecx		/* test for len == 0 */
15	jz	L1
16	cld				/* set search forward */
17	repne				/* search! */
18	scasb
19	jne	L1			/* scan failed, return null */
20	leal	-1(%edi),%eax		/* adjust result of scan */
21	popl	%edi
22	ret
23	.align 2,0x90
24L1:	xorl	%eax,%eax
25	popl	%edi
26	ret
27END(memchr)
28