install approved copyright notice
[unix-history] / usr / src / lib / libc / vax / string / strchr.s
CommitLineData
a35f6d0c
KB
1/*
2 * Copyright (c) 1988 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are permitted
6 * provided that this notice is preserved and that due credit is given
7 * to the University of California at Berkeley. The name of the University
8 * may not be used to endorse or promote products derived from this
9 * software without specific written prior permission. This software
10 * is provided ``as is'' without express or implied warranty.
11 */
12
13#if defined(SYSLIBC_SCCS) && !defined(lint)
14_sccsid:.asciz "@(#)strchr.s 5.1 (Berkeley) %G%"
15#endif /* SYSLIBC_SCCS and not lint */
16
17#ifdef notdef
18_sccsid:.asciz "@(#)index.s 5.4 (Berkeley) 5/25/88"
19#endif
20
21/*
22 * Find the first occurence of c in the string cp.
23 * Return pointer to match or null pointer.
24 *
25 * char *
26 * index(cp, c)
27 * char *cp, c;
28 */
29#include "DEFS.h"
30
31ENTRY(strchr, 0)
32 movq 4(ap),r1 # r1 = cp; r2 = c
33 tstl r2 # check for special case c == '\0'
34 bneq 2f
351:
36 locc $0,$65535,(r1) # just find end of string
37 beql 1b # still looking
38 movl r1,r0 # found it
39 ret
402:
41 moval tbl,r3 # r3 = address of table
42 bbss $0,(r3),5f # insure not reentering
43 movab (r3)[r2],r5 # table entry for c
44 incb (r5)
45 movzwl $65535,r4 # fast access
463:
47 scanc r4,(r1),(r3),$1 # look for c or '\0'
48 beql 3b # still looking
49 movl r1,r0 # return pointer to char
50 tstb (r0) # if have found '\0'
51 bneq 4f
52 clrl r0 # else return 0
534:
54 clrb (r5) # clean up table
55 clrb (r3)
56 ret
57
58 .data
59tbl: .space 256
60 .text
61
62/*
63 * Reentrant, but slower version of index
64 */
655:
66 movl r1,r3
676:
68 locc $0,$65535,(r3) # look for '\0'
69 bneq 7f
70 locc r2,$65535,(r3) # look for c
71 bneq 8f
72 movl r1,r3 # reset pointer and ...
73 jbr 6b # ... try again
747:
75 subl3 r3,r1,r4 # length of short block
76 incl r4 # +1 for '\0'
77 locc r2,r4,(r3) # look for c
78 bneq 8f
79 ret
808:
81 movl r1,r0 # return pointer to char
82 ret