1/* strspn (str, ss) -- Return the length of the maximum initial segment
2		       of S which contains only characters in ACCEPT.
3   For SPARC v9.
4   Copyright (C) 1999-2022 Free Software Foundation, Inc.
5   This file is part of the GNU C Library.
6
7   The GNU C Library is free software; you can redistribute it and/or
8   modify it under the terms of the GNU Lesser General Public
9   License as published by the Free Software Foundation; either
10   version 2.1 of the License, or (at your option) any later version.
11
12   The GNU C Library is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15   Lesser General Public License for more details.
16
17   You should have received a copy of the GNU Lesser General Public
18   License along with the GNU C Library; if not, see
19   <https://www.gnu.org/licenses/>.  */
20
21#include <sysdep.h>
22#include <asm/asi.h>
23#ifndef XCC
24#define XCC xcc
25#define STACK_SIZE	128
26#define STACK_OFFSET	128+0x7ff
27	.register	%g2, #scratch
28#else
29#define STACK_SIZE	64
30#define STACK_OFFSET	64
31#endif
32
33	.text
34	.align		32
35ENTRY(strspn)
36	sub		%sp, STACK_SIZE+32, %sp		/* IEU0		Group		*/
37	mov		1, %o4				/* IEU1				*/
38	stx		%g0, [%sp + STACK_OFFSET]	/* Store	Group		*/
39	mov		%o0, %g4			/* IEU0				*/
40
41	stx		%g0, [%sp + STACK_OFFSET + 8]	/* Store	Group		*/
42	add		%sp, STACK_OFFSET, %o5		/* IEU0				*/
43	stx		%g0, [%sp + STACK_OFFSET + 16]	/* Store	Group		*/
44	stx		%g0, [%sp + STACK_OFFSET + 24]	/* Store	Group		*/
45
461:	ldub		[%o1], %o2			/* Load		Group		*/
47	brz,pn		%o2, 2f				/* CTI+IEU1	Group		*/
48	 srl		%o2, 3, %o3			/* IEU0				*/
49	and		%o3, 0x18, %o3			/* IEU0		Group		*/
50
51	and		%o2, 0x3f, %o2			/* IEU1				*/
52	ldx		[%o5 + %o3], %g2		/* Load		Group		*/
53	sllx		%o4, %o2, %g1			/* IEU0				*/
54	add		%o1, 1, %o1			/* IEU1				*/
55
56	or		%g2, %g1, %g2			/* IEU0		Group		*/
57	ba,pt		%xcc, 1b			/* CTI				*/
58	 stx		%g2, [%o5 + %o3]		/* Store			*/
592:	andcc		%o0, 7, %g0			/* IEU1		Group		*/
60
61	be,a,pt		%xcc, 4f			/* CTI				*/
62	 ldx		[%o0], %o2			/* Load				*/
63	ldub		[%o0], %o2			/* Load		Group		*/
643:	srl		%o2, 3, %o3			/* IEU0		Group		*/
65
66	and		%o2, 0x3f, %o2			/* IEU1				*/
67	and		%o3, 0x18, %o3			/* IEU0		Group		*/
68	ldx		[%o5 + %o3], %g2		/* Load		Group		*/
69	sllx		%o4, %o2, %g1			/* IEU0				*/
70
71	add		%o0, 1, %o0			/* IEU1				*/
72	andcc		%g2, %g1, %g0			/* IEU1		Group		*/
73	be,pn		%xcc, 12f			/* CTI				*/
74	 andcc		%o0, 7, %g0			/* IEU1		Group		*/
75
76	bne,a,pt	%icc, 3b			/* CTI				*/
77	 ldub		[%o0], %o2			/* Load				*/
78	ldx		[%o0], %o2			/* Load		Group		*/
794:	srlx		%o2, 59, %o3			/* IEU0		Group		*/
80
81	srlx		%o2, 56, %g5			/* IEU0		Group		*/
825:	and		%o3, 0x18, %o3			/* IEU1				*/
83	andcc		%g5, 0x3f, %g5			/* IEU1		Group		*/
84	ldx		[%o5 + %o3], %g2		/* Load				*/
85
86	srlx		%o2, 51, %o3			/* IEU0				*/
87	sllx		%o4, %g5, %g1			/* IEU0		Group		*/
88	srlx		%o2, 48, %g5			/* IEU0		Group		*/
89	andcc		%g2, %g1, %g2			/* IEU1				*/
90
91	be,pn		%xcc, 13f			/* CTI				*/
92	 and		%o3, 0x18, %o3			/* IEU0		Group		*/
93	and		%g5, 0x3f, %g5			/* IEU1				*/
94	ldx		[%o5 + %o3], %g2		/* Load		Group		*/
95
96	srlx		%o2, 43, %o3			/* IEU0				*/
97	sllx		%o4, %g5, %g1			/* IEU0		Group		*/
98	srlx		%o2, 40, %g5			/* IEU0		Group		*/
99	andcc		%g2, %g1, %g2			/* IEU1				*/
100
101	be,pn		%xcc, 14f			/* CTI				*/
102	 and		%o3, 0x18, %o3			/* IEU0		Group		*/
103	and		%g5, 0x3f, %g5			/* IEU1				*/
104	ldx		[%o5 + %o3], %g2		/* Load		Group		*/
105
106	srlx		%o2, 35, %o3			/* IEU0				*/
107	sllx		%o4, %g5, %g1			/* IEU0		Group		*/
108	srlx		%o2, 32, %g5			/* IEU0		Group		*/
109	andcc		%g2, %g1, %g2			/* IEU1				*/
110
111	be,pn		%xcc, 15f			/* CTI				*/
112	 and		%o3, 0x18, %o3			/* IEU0		Group		*/
113	and		%g5, 0x3f, %g5			/* IEU1				*/
114	ldx		[%o5 + %o3], %g2		/* Load		Group		*/
115
116	srlx		%o2, 27, %o3			/* IEU0				*/
117	sllx		%o4, %g5, %g1			/* IEU0		Group		*/
118	srlx		%o2, 24, %g5			/* IEU0		Group		*/
119	andcc		%g2, %g1, %g2			/* IEU1				*/
120
121	be,pn		%xcc, 16f			/* CTI				*/
122	 and		%o3, 0x18, %o3			/* IEU0		Group		*/
123	and		%g5, 0x3f, %g5			/* IEU1				*/
124	ldx		[%o5 + %o3], %g2		/* Load		Group		*/
125
126	srlx		%o2, 19, %o3			/* IEU0				*/
127	sllx		%o4, %g5, %g1			/* IEU0		Group		*/
128	srlx		%o2, 16, %g5			/* IEU0		Group		*/
129	andcc		%g2, %g1, %g2			/* IEU1				*/
130
131	be,pn		%xcc, 17f			/* CTI				*/
132	 and		%o3, 0x18, %o3			/* IEU0		Group		*/
133	and		%g5, 0x3f, %g5			/* IEU1				*/
134	ldx		[%o5 + %o3], %g2		/* Load		Group		*/
135
136	srlx		%o2, 11, %o3			/* IEU0				*/
137	sllx		%o4, %g5, %g1			/* IEU0		Group		*/
138	add		%o0, 8, %o0			/* IEU1				*/
139	srlx		%o2, 8, %g5			/* IEU0		Group		*/
140
141	andcc		%g2, %g1, %g2			/* IEU1				*/
142	be,pn		%xcc, 18f			/* CTI				*/
143	 and		%o3, 0x18, %o3			/* IEU0		Group		*/
144	and		%g5, 0x3f, %g5			/* IEU1				*/
145
146	ldx		[%o5 + %o3], %g2		/* Load		Group		*/
147	sllx		%o4, %g5, %g1			/* IEU0				*/
148	mov		%o2, %g5			/* IEU1				*/
149	srlx		%o2, 3, %o3			/* IEU0		Group		*/
150
151	ldxa		[%o0] ASI_PNF, %o2		/* Load				*/
152	andcc		%g2, %g1, %g2			/* IEU1		Group		*/
153	be,pn		%xcc, 19f			/* CTI				*/
154	 and		%o3, 0x18, %o3			/* IEU0		Group		*/
155
156	and		%g5, 0x3f, %g5			/* IEU1				*/
157	ldx		[%o5 + %o3], %g2		/* Load		Group		*/
158	sllx		%o4, %g5, %g1			/* IEU0				*/
159	srlx		%o2, 59, %o3			/* IEU0		Group		*/
160
161	andcc		%g2, %g1, %g2			/* IEU1		Group		*/
162	bne,pt		%xcc, 5b			/* CTI				*/
163	 srlx		%o2, 56, %g5			/* IEU0		Group		*/
164	sub		%o0, 1, %o0			/* IEU1				*/
165
166	add		%sp, STACK_SIZE+32, %sp		/* IEU0		Group		*/
167	retl						/* CTI+IEU1	Group		*/
168	 sub		%o0, %g4, %o0			/* IEU0				*/
169
170	.align		16
17119:	sub		%o0, 2, %o0			/* IEU1				*/
172	add		%sp, STACK_SIZE+32, %sp		/* IEU0		Group		*/
173	retl						/* CTI+IEU1	Group		*/
174	 sub		%o0, %g4, %o0			/* IEU0				*/
175
17618:	sub		%o0, 3, %o0			/* IEU1				*/
177	add		%sp, STACK_SIZE+32, %sp		/* IEU0		Group		*/
178	retl						/* CTI+IEU1	Group		*/
179	 sub		%o0, %g4, %o0			/* IEU0				*/
180
18117:	add		%o0, 4, %o0			/* IEU1				*/
182	add		%sp, STACK_SIZE+32, %sp		/* IEU0		Group		*/
183	retl						/* CTI+IEU1	Group		*/
184	 sub		%o0, %g4, %o0			/* IEU0				*/
185
18616:	add		%o0, 3, %o0			/* IEU1				*/
187	add		%sp, STACK_SIZE+32, %sp		/* IEU0		Group		*/
188	retl						/* CTI+IEU1	Group		*/
189	 sub		%o0, %g4, %o0			/* IEU0				*/
190
19115:	add		%o0, 2, %o0			/* IEU1				*/
192	add		%sp, STACK_SIZE+32, %sp		/* IEU0		Group		*/
193	retl						/* CTI+IEU1	Group		*/
194	 sub		%o0, %g4, %o0			/* IEU0				*/
195
19614:	add		%o0, 1, %o0			/* IEU1				*/
197	add		%sp, STACK_SIZE+32, %sp		/* IEU0		Group		*/
198	retl						/* CTI+IEU1	Group		*/
199	 sub		%o0, %g4, %o0			/* IEU0				*/
200
20113:	add		%sp, STACK_SIZE+32, %sp		/* IEU1				*/
202	retl						/* CTI+IEU1	Group		*/
203	 sub		%o0, %g4, %o0			/* IEU0				*/
204
205	.align		16
20612:	sub		%o0, 1, %o0			/* IEU0		Group		*/
207	add		%sp, STACK_SIZE+32, %sp		/* IEU1				*/
208	retl						/* CTI+IEU1	Group		*/
209	 sub		%o0, %g4, %o0			/* IEU0				*/
210END(strspn)
211libc_hidden_builtin_def (strspn)
212