xref: /original-bsd/lib/libc/vax/string/strchr.s (revision 6f738a42)
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 the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley.  The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16 */
17
18#if defined(LIBC_SCCS) && !defined(lint)
19	.asciz "@(#)strchr.s	5.2 (Berkeley) 06/27/88"
20#endif /* LIBC_SCCS and not lint */
21
22#ifdef notdef
23_sccsid:.asciz	"@(#)index.s	5.4 (Berkeley) 5/25/88"
24#endif
25
26/*
27 * Find the first occurence of c in the string cp.
28 * Return pointer to match or null pointer.
29 *
30 * char *
31 * index(cp, c)
32 *	char *cp, c;
33 */
34#include "DEFS.h"
35
36ENTRY(strchr, 0)
37	movq	4(ap),r1	# r1 = cp; r2 = c
38	tstl	r2		# check for special case c == '\0'
39	bneq	2f
401:
41	locc	$0,$65535,(r1)	# just find end of string
42	beql	1b		# still looking
43	movl	r1,r0		# found it
44	ret
452:
46	moval	tbl,r3		# r3 = address of table
47	bbss	$0,(r3),5f	# insure not reentering
48	movab	(r3)[r2],r5	# table entry for c
49	incb	(r5)
50	movzwl	$65535,r4	# fast access
513:
52	scanc	r4,(r1),(r3),$1	# look for c or '\0'
53	beql	3b		# still looking
54	movl	r1,r0		# return pointer to char
55	tstb	(r0)		#    if have found '\0'
56	bneq	4f
57	clrl	r0		# else return 0
584:
59	clrb	(r5)		# clean up table
60	clrb	(r3)
61	ret
62
63	.data
64tbl:	.space	256
65	.text
66
67/*
68 * Reentrant, but slower version of index
69 */
705:
71	movl	r1,r3
726:
73	locc	$0,$65535,(r3)	# look for '\0'
74	bneq	7f
75	locc	r2,$65535,(r3)	# look for c
76	bneq	8f
77	movl	r1,r3		# reset pointer and ...
78	jbr	6b		# ... try again
797:
80	subl3	r3,r1,r4	# length of short block
81	incl	r4		# +1 for '\0'
82	locc	r2,r4,(r3)	# look for c
83	bneq	8f
84	ret
858:
86	movl	r1,r0		# return pointer to char
87	ret
88