xref: /original-bsd/lib/libc/vax/string/index.s (revision c3e32dec)
1/*
2 * Copyright (c) 1980, 1993
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 */
7
8#if defined(LIBC_SCCS) && !defined(lint)
9	.asciz "@(#)index.s	8.1 (Berkeley) 06/04/93"
10#endif /* LIBC_SCCS and not lint */
11
12/*
13 * Find the first occurence of c in the string cp.
14 * Return pointer to match or null pointer.
15 *
16 * char *
17 * index(cp, c)
18 *	char *cp, c;
19 */
20#include "DEFS.h"
21
22ENTRY(index, 0)
23	movq	4(ap),r1	# r1 = cp; r2 = c
24	tstl	r2		# check for special case c == '\0'
25	bneq	2f
261:
27	locc	$0,$65535,(r1)	# just find end of string
28	beql	1b		# still looking
29	movl	r1,r0		# found it
30	ret
312:
32	moval	tbl,r3		# r3 = address of table
33	bbss	$0,(r3),5f	# insure not reentering
34	movab	(r3)[r2],r5	# table entry for c
35	incb	(r5)
36	movzwl	$65535,r4	# fast access
373:
38	scanc	r4,(r1),(r3),$1	# look for c or '\0'
39	beql	3b		# still looking
40	movl	r1,r0		# return pointer to char
41	tstb	(r0)		#    if have found '\0'
42	bneq	4f
43	clrl	r0		# else return 0
444:
45	clrb	(r5)		# clean up table
46	clrb	(r3)
47	ret
48
49	.data
50tbl:	.space	256
51	.text
52
53/*
54 * Reentrant, but slower version of index
55 */
565:
57	movl	r1,r3
586:
59	locc	$0,$65535,(r3)	# look for '\0'
60	bneq	7f
61	locc	r2,$65535,(r3)	# look for c
62	bneq	8f
63	movl	r1,r3		# reset pointer and ...
64	jbr	6b		# ... try again
657:
66	subl3	r3,r1,r4	# length of short block
67	incl	r4		# +1 for '\0'
68	locc	r2,r4,(r3)	# look for c
69	bneq	8f
70	ret
718:
72	movl	r1,r0		# return pointer to char
73	ret
74