xref: /original-bsd/lib/libc/vax/string/strspn.s (revision bbb96de4)
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 */
7
8#if defined(LIBC_SCCS) && !defined(lint)
9	.asciz "@(#)strspn.s	5.1 (Berkeley) 05/15/90"
10#endif /* LIBC_SCCS and not lint */
11
12/*
13 * Span the string s2 (skip characters that are in s2).
14 * Return the number of characters in s1 that were skipped.
15 *
16 * size_t
17 * strspn(s1, s2)
18 *	const char *s1, *s2;
19 */
20#include "DEFS.h"
21
22ENTRY(strspn, 0)
23	subl2	$32,sp		/* make 256 bit table */
24	movc5	$0,(sp),$0,$32,(sp)
25	movq	4(ap),r1	/* r1 = s1, r2 = s2 */
26
27	/* turn on bit for each character in s2, including '\0' */
281:
29	movzbl	(r2)+,r0
30	bbss	r0,(sp),1b
31	bneq	1b
32
33	/* now clear bit for '\0' */
34	/* (this is easier than avoiding setting it in the first place) */
35	bicb2	$1,(sp)		/* stop at '\0' */
36	movl	r1,r0		/* r0 = s (current pos in s1) */
37
38	/* look for a character that is not in s2 */
392:
40	movzbl	(r0)+,r2	/* c = *s++ */
41	bbs	r2,(sp),2b	/* loop while c is in table */
42	decl	r0		/* s-- */
43	subl2	r1,r0		/* r0 = s - s1 = count */
44	ret
45