xref: /csrg-svn/lib/libc/vax/string/index.s (revision 26677)
1/*
2 * Copyright (c) 1980 Regents of the University of California.
3 * All rights reserved.  The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
6
7#ifdef LIBC_SCCS
8	.asciz	"@(#)index.s	5.3 (Berkeley) 03/09/86"
9#endif LIBC_SCCS
10
11/*
12 * Find the first occurence of c in the string cp.
13 * Return pointer to match or null pointer.
14 *
15 * char *
16 * index(cp, c)
17 *	char *cp, c;
18 */
19#include "DEFS.h"
20
21ENTRY(index, 0)
22	movq	4(ap),r1	# r1 = cp; r2 = c
23	tstl	r2		# check for special case c == '\0'
24	bneq	2f
251:
26	locc	$0,$65535,(r1)	# just find end of string
27	beql	1b		# still looking
28	movl	r1,r0		# found it
29	ret
302:
31	moval	tbl,r3		# r3 = address of table
32	bbss	$0,(r3),5f	# insure not reentering
33	movab	(r3)[r2],r5	# table entry for c
34	incb	(r5)
35	movzwl	$65535,r4	# fast access
363:
37	scanc	r4,(r1),(r3),$1	# look for c or '\0'
38	beql	3b		# still looking
39	movl	r1,r0		# return pointer to char
40	tstb	(r0)		#    if have found '\0'
41	bneq	4f
42	clrl	r0		# else return 0
434:
44	clrb	(r5)		# clean up table
45	clrb	(r3)
46	ret
47
48	.data
49tbl:	.space	256
50	.text
51
52/*
53 * Reentrant, but slower version of index
54 */
555:
56	movl	r1,r3
576:
58	locc	$0,$65535,(r3)	# look for '\0'
59	bneq	7f
60	locc	r2,$65535,(r3)	# look for c
61	bneq	8f
62	movl	r1,r3		# reset pointer and ...
63	jbr	6b		# ... try again
647:
65	subl3	r3,r1,r4	# length of short block
66	incl	r4		# +1 for '\0'
67	locc	r2,r4,(r3)	# look for c
68	bneq	8f
69	ret
708:
71	movl	r1,r0		# return pointer to char
72	ret
73