xref: /csrg-svn/lib/libc/vax/string/index.s (revision 17334)
1*17334Smckusick/*	index.s	4.3	84/11/04	*/
217326Ssam
317326Ssam/*
417326Ssam * Find the first occurence of c in the string cp.
517326Ssam * Return pointer to match or null pointer.
617326Ssam *
717326Ssam * char *
817326Ssam * index(cp, c)
917326Ssam *	char *cp, c;
1017326Ssam */
1117329Ssam#include "DEFS.h"
1217326Ssam
1317329SsamENTRY(index, 0)
1417326Ssam	movq	4(ap),r1	# r1 = cp; r2 = c
1517326Ssam	tstl	r2		# check for special case c == '\0'
1617326Ssam	bneq	2f
1717326Ssam1:
1817326Ssam	locc	$0,$65535,(r1)	# just find end of string
1917326Ssam	beql	1b		# still looking
2017326Ssam	movl	r1,r0		# found it
2117326Ssam	ret
2217326Ssam2:
23*17334Smckusick	moval	tbl,r3		# r3 = address of table
24*17334Smckusick	bbss	$0,(r3),5f	# insure not reentering
25*17334Smckusick	movab	(r3)[r2],r5	# table entry for c
2617326Ssam	incb	(r5)
2717326Ssam	movzwl	$65535,r4	# fast access
2817326Ssam3:
29*17334Smckusick	scanc	r4,(r1),(r3),$1	# look for c or '\0'
3017326Ssam	beql	3b		# still looking
3117326Ssam	movl	r1,r0		# return pointer to char
3217326Ssam	tstb	(r0)		#    if have found '\0'
3317326Ssam	bneq	4f
3417326Ssam	clrl	r0		# else return 0
3517326Ssam4:
3617326Ssam	clrb	(r5)		# clean up table
37*17334Smckusick	clrb	(r3)
3817326Ssam	ret
3917326Ssam
4017326Ssam	.data
41*17334Smckusicktbl:	.space	256
4217326Ssam	.text
43*17334Smckusick
44*17334Smckusick/*
45*17334Smckusick * Reentrant, but slower version of index
46*17334Smckusick */
47*17334Smckusick5:
48*17334Smckusick	movl	r1,r3
49*17334Smckusick6:
50*17334Smckusick	locc	$0,$65535,(r3)	# look for '\0'
51*17334Smckusick	bneq	7f
52*17334Smckusick	locc	r2,$65535,(r3)	# look for c
53*17334Smckusick	bneq	8f
54*17334Smckusick	movl	r1,r3		# reset pointer and ...
55*17334Smckusick	jbr	6b		# ... try again
56*17334Smckusick7:
57*17334Smckusick	subl3	r3,r1,r4	# length of short block
58*17334Smckusick	incl	r4		# +1 for '\0'
59*17334Smckusick	locc	r2,r4,(r3)	# look for c
60*17334Smckusick	bneq	8f
61*17334Smckusick	ret
62*17334Smckusick8:
63*17334Smckusick	movl	r1,r0		# return pointer to char
64*17334Smckusick	ret
65