]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/s390/multiarch/wcspbrk-vx.S
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / s390 / multiarch / wcspbrk-vx.S
CommitLineData
f0ba6598 1/* Vector optimized 32/64 bit S/390 version of wcspbrk.
bfff8b1b 2 Copyright (C) 2015-2017 Free Software Foundation, Inc.
f0ba6598
SL
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#if defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)
20
21# include "sysdep.h"
22# include "asm-syntax.h"
23
24 .text
25
26/* wchar_t *wcspbrk (const wchar_t *s, const wchar_t * accept)
27 The wcspbrk() function locates the first occurrence in the string s
28 of any of the characters in the string accept and returns a pointer
29 to that character or NULL if not found.
30
31 This method checks the length of accept string. If it fits entirely
32 in one vector register, a fast algorithm is used, which does not need
33 to check multiple parts of accept-string. Otherwise a slower full
34 check of accept-string is used.
35
36 register overview:
37 r3: pointer to start of accept-string
38 r2: pointer to start of search-string
39 r0: loaded byte count of vlbb search-string (32bit unsigned)
40 r4: found byte index (32bit unsigned)
41 r1: current return len (64bit unsigned)
42 v16: search-string
43 v17: accept-string
44 v18: temp-vreg
45
46 ONLY FOR SLOW:
47 v19: first accept-string
48 v20: zero for preparing acc-vector
49 v21: global mask; 1 indicates a match between
50 search-string-vreg and any accept-character
51 v22: current mask; 1 indicates a match between
52 search-string-vreg and any accept-character in current acc-vreg
53 v24: one for result-checking of former string-part
54 v30, v31: for re-/storing registers r6, r8, r9
55 r5: current len of accept-string
56 r6: zero-index in search-string or 16 if no zero
57 or min(zero-index, loaded byte count)
58 r8: >0, if former accept-string-part contains a zero,
59 otherwise =0;
60 r9: loaded byte count of vlbb accept-string
61*/
62ENTRY(__wcspbrk_vx)
63 .machine "z13"
64 .machinemode "zarch_nohighgprs"
65
66 tmll %r2,3 /* Test if s is 4-byte aligned? */
67 jne .Lfallback /* And use common-code variant if not. */
68
69 /*
70 Check if accept-string fits in one vreg:
71 ----------------------------------------
72 */
73 vlbb %v17,0(%r3),6 /* Load accept. */
74 lcbb %r0,0(%r3),6
75 jo .Lcheck_onbb /* Special case if accept lays
76 on block-boundary. */
77
78.Lcheck_notonbb:
79 lghi %r1,0 /* Zero out current len. */
80 vlgvf %r0,%v17,0 /* Get first element. */
81 clije %r0,0,.Lfast_end_null /* Return null if accept is empty. */
82
83 vistrfs %v17,%v17 /* Fill with zeros after first zero. */
84 je .Lfast /* Zero found -> accept fits in one vreg. */
85 j .Lslow /* No zero -> accept exceeds one vreg */
86
87
88.Lcheck_onbb:
89 /* Accept lays on block-boundary. */
90 nill %r0,65532 /* Recognize only fully loaded characters. */
91 je .Lcheck_onbb2 /* Reload vr, if we loaded no full wchar_t. */
92 vfenezf %v18,%v17,%v17 /* Search zero in loaded accept bytes. */
93 vlgvb %r4,%v18,7 /* Get index of zero or 16 if not found. */
94 clrjl %r4,%r0,.Lcheck_notonbb /* Zero index < loaded bytes count ->
95 accept fits in one vreg;
96 Fill with zeros and proceed
97 with FAST. */
98.Lcheck_onbb2:
99 vl %v17,0(%r3) /* Load accept, which exceeds loaded bytes. */
100 j .Lcheck_notonbb /* Check if accept fits in one vreg. */
101
102
103 /*
104 Search s for accept in one vreg
105 -------------------------------
106 */
107.Lfast:
108 /* Complete accept-string in v17 and remaining bytes are zero. */
109
110 vlbb %v16,0(%r2),6 /* Load s until next 4k-byte boundary. */
111 lcbb %r0,0(%r2),6 /* Get bytes to 4k-byte boundary or 16. */
112
113 vfaezfs %v18,%v16,%v17,0 /* Find first element in v16 unequal to any
114 in v17 or first zero element. */
115 vlgvb %r4,%v18,7 /* Load byte index of found element. */
116 /* If found index is within loaded bytes, return with found
117 element index (=equal count). */
118 clrjl %r4,%r0,.Lfast_loop_found2
119
120 /* Align s to 16 byte. */
121 risbgn %r4,%r2,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15. */
122 lghi %r1,16 /* current_len = 16. */
123 slr %r1,%r4 /* Compute bytes to 16bytes boundary. */
124
125.Lfast_loop:
126 vl %v16,0(%r1,%r2) /* Load search-string. */
127 vfaezfs %v18,%v16,%v17,0 /* Find first element in v16 equal to any
128 in v17 or first zero element. */
129 jno .Lfast_loop_found
130
131 vl %v16,16(%r1,%r2)
132 vfaezfs %v18,%v16,%v17,0
133 jno .Lfast_loop_found16
134
135 vl %v16,32(%r1,%r2)
136 vfaezfs %v18,%v16,%v17,0
137 jno .Lfast_loop_found32
138
139 vl %v16,48(%r1,%r2)
140 vfaezfs %v18,%v16,%v17,0
141 jno .Lfast_loop_found48
142
143 aghi %r1,64
144 j .Lfast_loop /* Loop if no element was unequal to accept
145 and not zero. */
146
147 /* Found equal or zero element. */
148.Lfast_loop_found48:
149 aghi %r1,16
150.Lfast_loop_found32:
151 aghi %r1,16
152.Lfast_loop_found16:
153 aghi %r1,16
154.Lfast_loop_found:
155 vlgvb %r4,%v18,7 /* Load byte index of found element. */
156.Lfast_loop_found2:
157 srlg %r5,%r4,2 /* Convert byte-index to character-index. */
158 vlgvf %r0,%v16,0(%r5) /* Get found element. */
159 clije %r0,0,.Lfast_end_null /* Return null if no accept-char found */
160 algfr %r1,%r4 /* Add found index of char to current len. */
161 la %r2,0(%r1,%r2) /* And return pointer to first equal char. */
162 br %r14
163
164.Lfast_end_null:
165 lghi %r2,0 /* Return null if no character is equal. */
166 br %r14
167
168
169
170
171 /*
172 Search s for accept in multiple vregs
173 -------------------------------------
174 */
175.Lslow:
176 /* Save registers. */
177 vlvgg %v30,%r6,0
178 vlvgp %v31,%r8,%r9
179
180 /* Accept in v17 without zero */
181 vlr %v19,%v17 /* Save first acc-part for a fast reload. */
182 vzero %v20 /* Zero for preparing acc-vector. */
183 vone %v24 /* One for checking result of former string. */
184
185 /* Align s to 16 byte. */
186 risbg %r4,%r2,60,128+63,0 /* Test if s is aligned and
187 %r4 = bits 60-63 'and' 15. */
188 je .Lslow_loop_str /* If s is aligned, loop aligned. */
189 lghi %r0,15
190 slr %r0,%r4 /* Compute highest index to load (15-x). */
191 vll %v16,%r0,0(%r2) /* Load up to 16byte boundary;
192 needs highest index, left bytes are 0. */
193 ahi %r0,1 /* Work with loaded byte count. */
194 vzero %v21 /* Zero out global mask. */
195 lghi %r5,0 /* Set current len of accept-string to zero. */
196 vfenezf %v18,%v16,%v16 /* Find zero in current string-part. */
197 lghi %r8,0 /* There is no zero in first accept-part. */
198 vlgvb %r6,%v18,7 /* Load byte index of zero or 16 if no zero. */
199 clije %r6,0,.Lslow_end_null /* If first element is zero
200 (end of string) -> return null */
201 clr %r0,%r6 /* cc==1 if loaded byte count < zero-index. */
202 locrl %r6,%r0 /* Load on cc==1; zero-index = lbc. */
203 j .Lslow_loop_acc
204
205
206 /* Process s in 16byte aligned loop. */
207.Lslow_next_str:
208 /* Check results of former processed str-part. */
209 vfeef %v18,%v21,%v24 /* Find first equal match in global mask
210 (ones in element). */
211 vlgvb %r4,%v18,7 /* Get index of first one (=equal)
212 or 16 if no match. */
213 /* Equal-index < min(zero-index, loaded byte count)
214 -> return pointer to equal element. */
215 clrjl %r4,%r6,.Lslow_index_found
216 /* Zero-index < loaded byte count
217 -> former str-part was last str-part
218 -> return null */
219 clrjl %r6,%r0,.Lslow_end_null
220 /* All elements are zero (=no match) -> proceed with next str-part. */
221
222 vlr %v17,%v19 /* Load first part of accept (no zero). */
223 algfr %r1,%r0 /* Add loaded byte count to current len. */
224
225.Lslow_loop_str:
226 vl %v16,0(%r1,%r2) /* Load search-string */
227 lghi %r0,16 /* Loaded byte count is 16. */
228 vzero %v21 /* Zero out global mask. */
229 lghi %r5,0 /* Set current len of accept to zero. */
230 vfenezf %v18,%v16,%v16 /* Find zero in current string-part. */
231 lghi %r8,0 /* There is no zero in first accept-part. */
232 vlgvb %r6,%v18,7 /* Load byte index of zero or 16 if no zero. */
233 clije %r6,0,.Lslow_end_null /* If first element is zero
234 (end of string) -> return null. */
235
236.Lslow_loop_acc:
237 vfaef %v22,%v16,%v17,4 /* Create matching-mask (1 in mask ->
238 Character matches any accepted character in
239 this accept-string-part) IN=0, RT=1. */
240 vlgvf %r4,%v22,0 /* Get result of first element. */
241 /* First element is equal to any accepted characters
242 (all other parts of accept cannot lead to a match before this one)
243 -> current len is pointing to first element
244 -> return found */
245 clijh %r4,0,.Lslow_end_found
246 vo %v21,%v21,%v22 /* Global-mask = global-|matching-mask. */
247 /* Proceed with next acc until end of acc is reached. */
248
249
250.Lslow_next_acc:
251 clijh %r8,0,.Lslow_next_str /* There was a zero in the last acc-part
252 -> add index to current len and
253 end. */
254 vlbb %v17,16(%r5,%r3),6 /* Load next accept part. */
255 aghi %r5,16 /* Increment current len of accept-string. */
256 lcbb %r9,0(%r5,%r3),6 /* Get loaded byte count of accept-string. */
257 jo .Lslow_next_acc_onbb /* Jump away ifaccept-string is
258 on block-boundary. */
259.Lslow_next_acc_notonbb:
260 vistrfs %v17,%v17 /* Fill with zeros after first zero. */
261 jo .Lslow_loop_acc /* No zero found -> no preparation needed. */
262
263.Lslow_next_acc_prepare_zero:
264 /* Zero in accept-part: fill zeros with first-accept-character. */
265 vlgvf %r8,%v17,0 /* Load first element of acc-part. */
266 clije %r8,0,.Lslow_next_str /* Proceed with next string-part,
267 If first char in this part of accept
268 is a zero. */
269 /* r8>0 -> zero found in this acc-part. */
270 vrepf %v18,%v17,0 /* Replicate first char accross all chars. */
271 vceqf %v22,%v20,%v17 /* Create a mask (v22) of null chars
272 by comparing with 0 (v20). */
273 vsel %v17,%v18,%v17,%v22 /* Replace null chars with first char. */
274 j .Lslow_loop_acc /* Accept part is prepared -> process. */
275
276.Lslow_next_acc_onbb:
277 nill %r9,65532 /* Recognize only fully loaded characters. */
278 je .Lslow_next_acc_onbb2 /* Reload vr, if no full wchar_t. */
279 vfenezf %v18,%v17,%v17 /* Find zero in loaded bytes of accept part. */
280 vlgvb %r8,%v18,7 /* Load byte index of zero. */
281 clrjl %r8,%r9,.Lslow_next_acc_notonbb /* Found a zero in loaded bytes
282 -> Prepare vreg. */
283.Lslow_next_acc_onbb2:
284 vl %v17,0(%r5,%r3) /* Load over boundary ... */
285 lghi %r8,0 /* r8=0 -> no zero in this part of acc,
286 check for zero is in jump-target. */
287 j .Lslow_next_acc_notonbb /* ... and search for zero in
288 fully loaded vreg again. */
289
290.Lslow_end_null:
291 lghi %r1,0 /* Return null if no character is equal. */
292 j .Lslow_end
293
294.Lslow_loop_found:
295 vlgvb %r4,%v18,7 /* Load byte index of found element. */
296 srlg %r5,%r4,2 /* Convert byte-index to character-index. */
297 vlgvf %r0,%v16,0(%r5) /* Get found element. */
298 clije %r0,0,.Lslow_end_null /* Return null if no acc-char found. */
299
300.Lslow_index_found:
301 algfr %r1,%r4 /* Add found index of char to current len. */
302.Lslow_end_found:
303 la %r1,0(%r1,%r2) /* And return pointer to first equal char. */
304
305.Lslow_end:
306 /* Restore registers. */
307 vlgvg %r6,%v30,0
308 vlgvg %r8,%v31,0
309 vlgvg %r9,%v31,1
310 lgr %r2,%r1
311 br %r14
312.Lfallback:
313 jg __wcspbrk_c
314END(__wcspbrk_vx)
315#endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */