xref: /csrg-svn/lib/libc/vax/string/index.s (revision 61222)
121426Sdist/*
2*61222Sbostic * Copyright (c) 1980, 1993
3*61222Sbostic *	The Regents of the University of California.  All rights reserved.
434480Sbostic *
542639Sbostic * %sccs.include.redist.c%
621426Sdist */
717326Ssam
834819Sbostic#if defined(LIBC_SCCS) && !defined(lint)
9*61222Sbostic	.asciz "@(#)index.s	8.1 (Berkeley) 06/04/93"
1034819Sbostic#endif /* LIBC_SCCS and not lint */
1121426Sdist
1217326Ssam/*
1317326Ssam * Find the first occurence of c in the string cp.
1417326Ssam * Return pointer to match or null pointer.
1517326Ssam *
1617326Ssam * char *
1717326Ssam * index(cp, c)
1817326Ssam *	char *cp, c;
1917326Ssam */
2017329Ssam#include "DEFS.h"
2117326Ssam
2217329SsamENTRY(index, 0)
2317326Ssam	movq	4(ap),r1	# r1 = cp; r2 = c
2417326Ssam	tstl	r2		# check for special case c == '\0'
2517326Ssam	bneq	2f
2617326Ssam1:
2717326Ssam	locc	$0,$65535,(r1)	# just find end of string
2817326Ssam	beql	1b		# still looking
2917326Ssam	movl	r1,r0		# found it
3017326Ssam	ret
3117326Ssam2:
3217334Smckusick	moval	tbl,r3		# r3 = address of table
3317334Smckusick	bbss	$0,(r3),5f	# insure not reentering
3417334Smckusick	movab	(r3)[r2],r5	# table entry for c
3517326Ssam	incb	(r5)
3617326Ssam	movzwl	$65535,r4	# fast access
3717326Ssam3:
3817334Smckusick	scanc	r4,(r1),(r3),$1	# look for c or '\0'
3917326Ssam	beql	3b		# still looking
4017326Ssam	movl	r1,r0		# return pointer to char
4117326Ssam	tstb	(r0)		#    if have found '\0'
4217326Ssam	bneq	4f
4317326Ssam	clrl	r0		# else return 0
4417326Ssam4:
4517326Ssam	clrb	(r5)		# clean up table
4617334Smckusick	clrb	(r3)
4717326Ssam	ret
4817326Ssam
4917326Ssam	.data
5017334Smckusicktbl:	.space	256
5117326Ssam	.text
5217334Smckusick
5317334Smckusick/*
5417334Smckusick * Reentrant, but slower version of index
5517334Smckusick */
5617334Smckusick5:
5717334Smckusick	movl	r1,r3
5817334Smckusick6:
5917334Smckusick	locc	$0,$65535,(r3)	# look for '\0'
6017334Smckusick	bneq	7f
6117334Smckusick	locc	r2,$65535,(r3)	# look for c
6217334Smckusick	bneq	8f
6317334Smckusick	movl	r1,r3		# reset pointer and ...
6417334Smckusick	jbr	6b		# ... try again
6517334Smckusick7:
6617334Smckusick	subl3	r3,r1,r4	# length of short block
6717334Smckusick	incl	r4		# +1 for '\0'
6817334Smckusick	locc	r2,r4,(r3)	# look for c
6917334Smckusick	bneq	8f
7017334Smckusick	ret
7117334Smckusick8:
7217334Smckusick	movl	r1,r0		# return pointer to char
7317334Smckusick	ret
74