summaryrefslogtreecommitdiff
path: root/lib/libc/arch/amd64/string/memchr.S
blob: 4fe2d4d996a0afd5dceef6edf746db26dce8406a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
 * Written by J.T. Conklin <jtc@netbsd.org>.
 * Public domain.
 * Adapted for NetBSD/x86_64 by Frank van der Linden <fvdl@wasabisystems.com>
 */

#include "SYS.h"

ENTRY(memchr)
	movb	%sil,%al		/* set character to search for */
	movq	%rdx,%rcx		/* set length of search */
	testq	%rcx,%rcx		/* test for len == 0 */
	jz	L1
	cld				/* set search forward */
	repne				/* search! */
	scasb
	jne	L1			/* scan failed, return null */
	leaq	-1(%rdi),%rax		/* adjust result of scan */
	ret
L1:	xorq	%rax,%rax
	ret
END_STRONG(memchr)