xref: /csrg-svn/lib/libc/vax/string/index.s (revision 34480)
1/*
2 * Copyright (c) 1980 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	"@(#)index.s	5.4 (Berkeley) 05/25/88"
15#endif /* SYSLIBC_SCCS and not lint */
16
17/*
18 * Find the first occurence of c in the string cp.
19 * Return pointer to match or null pointer.
20 *
21 * char *
22 * index(cp, c)
23 *	char *cp, c;
24 */
25#include "DEFS.h"
26
27ENTRY(index, 0)
28	movq	4(ap),r1	# r1 = cp; r2 = c
29	tstl	r2		# check for special case c == '\0'
30	bneq	2f
311:
32	locc	$0,$65535,(r1)	# just find end of string
33	beql	1b		# still looking
34	movl	r1,r0		# found it
35	ret
362:
37	moval	tbl,r3		# r3 = address of table
38	bbss	$0,(r3),5f	# insure not reentering
39	movab	(r3)[r2],r5	# table entry for c
40	incb	(r5)
41	movzwl	$65535,r4	# fast access
423:
43	scanc	r4,(r1),(r3),$1	# look for c or '\0'
44	beql	3b		# still looking
45	movl	r1,r0		# return pointer to char
46	tstb	(r0)		#    if have found '\0'
47	bneq	4f
48	clrl	r0		# else return 0
494:
50	clrb	(r5)		# clean up table
51	clrb	(r3)
52	ret
53
54	.data
55tbl:	.space	256
56	.text
57
58/*
59 * Reentrant, but slower version of index
60 */
615:
62	movl	r1,r3
636:
64	locc	$0,$65535,(r3)	# look for '\0'
65	bneq	7f
66	locc	r2,$65535,(r3)	# look for c
67	bneq	8f
68	movl	r1,r3		# reset pointer and ...
69	jbr	6b		# ... try again
707:
71	subl3	r3,r1,r4	# length of short block
72	incl	r4		# +1 for '\0'
73	locc	r2,r4,(r3)	# look for c
74	bneq	8f
75	ret
768:
77	movl	r1,r0		# return pointer to char
78	ret
79