142439Sbostic/*- 2*61222Sbostic * Copyright (c) 1990, 1993 3*61222Sbostic * The Regents of the University of California. All rights reserved. 442439Sbostic * 542439Sbostic * %sccs.include.redist.c% 642439Sbostic */ 742439Sbostic 842439Sbostic#if defined(LIBC_SCCS) && !defined(lint) 9*61222Sbostic .asciz "@(#)memchr.s 8.1 (Berkeley) 06/04/93" 1042439Sbostic#endif /* LIBC_SCCS and not lint */ 1142439Sbostic 1242439Sbostic/* 1342439Sbostic * Find the first occurence of c in the memory at cp (length n). 1442439Sbostic * Return pointer to match or null pointer. 1542439Sbostic * 1642439Sbostic * This code optimises the usual case (0 < n < 65535). 1742439Sbostic * 1842439Sbostic * void * 1942439Sbostic * memchr(cp, c, n) 2042439Sbostic * char *cp, c; 2142439Sbostic * size_t n; 2242439Sbostic */ 2342439Sbostic 2442439Sbostic#include "DEFS.h" 2542439Sbostic 2642439SbosticENTRY(memchr, 0) 2742439Sbostic movq 4(ap),r1 # r1 = cp; r2 = c 2842439Sbostic movl 12(ap),r0 # r0 = n 2942439Sbostic movzwl $65535,r4 # handy constant 3042439Sbostic0: 3142439Sbostic cmpl r0,r4 # check for annoying locc limit 3242439Sbostic bgtru 3f 3342439Sbostic 3442439Sbostic /* n <= 65535 */ 3542439Sbostic locc r2,r0,(r1) # search n bytes for c 3642439Sbostic beql 2f # done if not found (r0 already 0) 3742439Sbostic1: /* found character c at (r1) */ 3842439Sbostic movl r1,r0 3942439Sbostic2: 4042439Sbostic ret 4142439Sbostic 4242439Sbostic3: /* n > 65535 */ 4342439Sbostic locc r2,r4,(r1) # search 65535 bytes for c 4442439Sbostic beql 1b # done if found 4542439Sbostic decw r0 # from 0 to 65535 4642439Sbostic subl2 r0,r4 # adjust n 4742439Sbostic brb 0b # and loop 48