2.3.3-74
[glibc.git] / sysdeps / vax / memchr.s
blob5c54ba8e791aea2097d2527f3782842679d9c537
1 /*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
30 #if defined(LIBC_SCCS) && !defined(lint)
31 .asciz "@(#)memchr.s 5.1 (Berkeley) 5/29/90"
32 #endif /* LIBC_SCCS and not lint */
35 * Find the first occurrence of c in the memory at cp (length n).
36 * Return pointer to match or null pointer.
38 * This code optimises the usual case (0 < n < 65535).
40 * void *
41 * memchr(cp, c, n)
42 * char *cp, c;
43 * size_t n;
46 #include "DEFS.h"
48 ENTRY(__memchr, 0)
49 movq 4(ap),r1 # r1 = cp; r2 = c
50 movl 12(ap),r0 # r0 = n
51 movzwl $65535,r4 # handy constant
53 cmpl r0,r4 # check for annoying locc limit
54 bgtru 3f
56 /* n <= 65535 */
57 locc r2,r0,(r1) # search n bytes for c
58 beql 2f # done if not found (r0 already 0)
59 1: /* found character c at (r1) */
60 movl r1,r0
62 ret
64 3: /* n > 65535 */
65 locc r2,r4,(r1) # search 65535 bytes for c
66 beql 1b # done if found
67 decw r0 # from 0 to 65535
68 subl2 r0,r4 # adjust n
69 brb 0b # and loop
71 weak_alias (__memchr, memchr)
72 #if !__BOUNDED_POINTERS__
73 weak_alias (__memchr, __ubp_memchr)
74 #endif