xref: /original-bsd/lib/libc/vax/string/memchr.s (revision 37dcaed2)
1/*-
2 * Copyright (c) 1990, 1993
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 */
7
8#if defined(LIBC_SCCS) && !defined(lint)
9	.asciz "@(#)memchr.s	8.1 (Berkeley) 06/04/93"
10#endif /* LIBC_SCCS and not lint */
11
12/*
13 * Find the first occurence of c in the memory at cp (length n).
14 * Return pointer to match or null pointer.
15 *
16 * This code optimises the usual case (0 < n < 65535).
17 *
18 * void *
19 * memchr(cp, c, n)
20 *	char *cp, c;
21 *	size_t n;
22 */
23
24#include "DEFS.h"
25
26ENTRY(memchr, 0)
27	movq	4(ap),r1	# r1 = cp; r2 = c
28	movl	12(ap),r0	# r0 = n
29	movzwl	$65535,r4	# handy constant
300:
31	cmpl	r0,r4		# check for annoying locc limit
32	bgtru	3f
33
34	/* n <= 65535 */
35	locc	r2,r0,(r1)	# search n bytes for c
36	beql	2f		# done if not found (r0 already 0)
371:	/* found character c at (r1) */
38	movl	r1,r0
392:
40	ret
41
423:	/* n > 65535 */
43	locc	r2,r4,(r1)	# search 65535 bytes for c
44	beql	1b		# done if found
45	decw	r0		# from 0 to 65535
46	subl2	r0,r4		# adjust n
47	brb	0b		# and loop
48