]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/s390/multiarch/wcsspn-vx.S
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / s390 / multiarch / wcsspn-vx.S
1 /* Vector optimized 32/64 bit S/390 version of wcsspn.
2 Copyright (C) 2015-2017 Free Software Foundation, Inc.
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 /* size_t wcsspn (const wchar_t *s, const wchar_t * accept)
27 The wcsspn() function calculates the length of the initial segment
28 of s which consists entirely of characters in accept.
29
30 This method checks the length of accept string. If it fits entirely
31 in one vector register, a fast algorithm is used, which does not need
32 to check multiple parts of accept-string. Otherwise a slower full
33 check of accept-string is used.
34
35 register overview:
36 r3: pointer to start of accept-string
37 r2: pointer to start of search-string
38 r4: loaded byte count of vl search-string
39 r0: found byte index
40 r1: current return len of s
41 v16: search-string
42 v17: accept-string
43 v18: temp-vreg
44
45 ONLY FOR SLOW:
46 v19: first accept-string
47 v20: zero for preparing acc-vector
48 v21: global mask; 1 indicates a match between
49 search-string-vreg and any accept-character
50 v22: current mask; 1 indicates a match between
51 search-string-vreg and any accept-character in current acc-vreg
52 v30, v31: for re-/storing registers r6, r8, r9
53 r5: current len of accept-string
54 r6: zero-index in search-string or 16 if no zero
55 or min(zero-index, loaded byte count)
56 r8: >0, if former accept-string-part contains a zero,
57 otherwise =0;
58 r9: loaded byte count of vlbb accept-string
59 */
60 ENTRY(__wcsspn_vx)
61 .machine "z13"
62 .machinemode "zarch_nohighgprs"
63
64 tmll %r2,3 /* Test if s is 4-byte aligned? */
65 jne .Lfallback /* And use common-code variant if not. */
66
67 /*
68 Check if accept-string fits in one vreg:
69 ----------------------------------------
70 */
71 vlbb %v17,0(%r3),6 /* Load accept. */
72 lcbb %r4,0(%r3),6
73 jo .Lcheck_onbb /* Special case if accept lays
74 on block-boundary. */
75 .Lcheck_notonbb:
76 vistrfs %v17,%v17 /* Fill with zeros after first zero. */
77 je .Lfast /* Zero found -> accept fits in one vreg. */
78 j .Lslow /* No zero -> accept exceeds one vreg. */
79
80 .Lcheck_onbb:
81 /* Accept lays on block-boundary. */
82 nill %r4,65532 /* Recognize only fully loaded characters. */
83 je .Lcheck_onbb2 /* Reload vr if no full wchar_t. */
84 vfenezf %v18,%v17,%v17 /* Search zero in loaded accept bytes. */
85 vlgvb %r0,%v18,7 /* Get index of zero or 16 if not found. */
86 clrjl %r0,%r4,.Lcheck_notonbb /* Zero index < loaded bytes count ->
87 Accept fits in one vreg;
88 Fill with zeros and proceed
89 with FAST. */
90 .Lcheck_onbb2:
91 vl %v17,0(%r3) /* Load accept, which exceeds loaded bytes. */
92 j .Lcheck_notonbb /* Check if accept fits in one vreg. */
93
94
95 /*
96 Search s for accept in one vreg
97 -------------------------------
98 */
99 .Lfast:
100 /* Complete accept-string in v17 and remaining bytes are zero. */
101
102 vlbb %v16,0(%r2),6 /* Load s until next 4k-byte boundary. */
103 lcbb %r1,0(%r2),6 /* Get bytes to 4k-byte boundary or 16. */
104
105 vfaezfs %v16,%v16,%v17,8 /* Find first element in v16
106 unequal to any in v17
107 or first zero element. */
108
109 vlgvb %r0,%v16,7 /* Load byte index of found element. */
110 /* If found index is within loaded bytes (%r0 < %r1),
111 return with found element index (=equal count). */
112 clr %r0,%r1
113 srlg %r0,%r0,2 /* Convert byte-count to character-count. */
114 locgrl %r2,%r0
115 blr %r14
116
117 /* Align s to 16 byte. */
118 risbgn %r4,%r2,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15. */
119 lghi %r1,16 /* current_len = 16. */
120 slr %r1,%r4 /* Compute bytes to 16bytes boundary. */
121
122 .Lfast_loop:
123 vl %v16,0(%r1,%r2) /* Load search-string. */
124 vfaezfs %v16,%v16,%v17,8 /* Find first element in v16
125 unequal to any in v17
126 or first zero element. */
127 jno .Lfast_loop_found
128 vl %v16,16(%r1,%r2)
129 vfaezfs %v16,%v16,%v17,8
130 jno .Lfast_loop_found16
131 vl %v16,32(%r1,%r2)
132 vfaezfs %v16,%v16,%v17,8
133 jno .Lfast_loop_found32
134 vl %v16,48(%r1,%r2)
135 vfaezfs %v16,%v16,%v17,8
136 jno .Lfast_loop_found48
137
138 aghi %r1,64
139 j .Lfast_loop /* Loop if no element was unequal to accept
140 and not zero. */
141
142 /* Found unequal or zero element. */
143 .Lfast_loop_found48:
144 aghi %r1,16
145 .Lfast_loop_found32:
146 aghi %r1,16
147 .Lfast_loop_found16:
148 aghi %r1,16
149 .Lfast_loop_found:
150 vlgvb %r0,%v16,7 /* Load byte index of found element. */
151 algrk %r2,%r1,%r0 /* And add it to current len. */
152 srlg %r2,%r2,2 /* Convert byte-count to character-count. */
153 br %r14
154
155
156 /*
157 Search s for accept in multiple vregs
158 -------------------------------------
159 */
160 .Lslow:
161 /* Save registers. */
162 vlvgg %v30,%r6,0
163 vlvgp %v31,%r8,%r9
164 lghi %r1,0 /* Zero out current len. */
165
166 /* accept in v17 without zero. */
167 vlr %v19,%v17 /* Save first acc-part for a fast reload. */
168 vzero %v20 /* Zero for preparing acc-vector. */
169
170 /* Align s to 16 byte. */
171 risbg %r0,%r2,60,128+63,0 /* Test if s is aligned and
172 %r0 = bits 60-63 'and' 15. */
173 je .Lslow_loop_str /* If s is aligned, loop aligned */
174 lghi %r4,15
175 slr %r4,%r0 /* Compute highest index to load (15-x). */
176 vll %v16,%r4,0(%r2) /* Load up to 16byte boundary (vll needs
177 highest index, remaining bytes are 0). */
178 aghi %r4,1 /* Work with loaded byte count. */
179 vzero %v21 /* Zero out global mask. */
180 lghi %r5,0 /* Set current len of accept-string to zero. */
181 vfenezf %v18,%v16,%v16 /* Find zero in current string-part. */
182 lghi %r8,0 /* There is no zero in first accept-part. */
183 vlgvb %r6,%v18,7 /* Load byte index of zero or 16
184 if there is no zero. */
185 clr %r4,%r6 /* cc==1 if loaded byte count < zero-index. */
186 locrl %r6,%r4 /* Load on cc==1. */
187 j .Lslow_loop_acc
188
189 /* Process s in 16byte aligned loop. */
190 .Lslow_next_str:
191 vlr %v17,%v19 /* Load first part of accept (no zero). */
192 algfr %r1,%r4 /* Add loaded byte count to current len. */
193 .Lslow_loop_str:
194 vl %v16,0(%r1,%r2) /* Load search-string. */
195 lghi %r4,16 /* Loaded byte count is 16. */
196 vzero %v21 /* Zero out global mask. */
197 lghi %r5,0 /* Set current len of accept-string to zero. */
198 vfenezf %v18,%v16,%v16 /* Find zero in current string-part. */
199 lghi %r8,0 /* There is no zero in first accept-part. */
200 vlgvb %r6,%v18,7 /* Load byte index of zero or 16 if no zero. */
201
202 .Lslow_loop_acc:
203 vfaef %v22,%v16,%v17,4 /* Create matching-mask (1 in mask ->
204 character matches any accepted character in
205 this accept-string-part) IN=0, RT=1. */
206 vo %v21,%v21,%v22 /* global-mask = global- | matching-mask. */
207 vfenezf %v18,%v21,%v21 /* Find first zero in global-mask. */
208 vlgvb %r0,%v18,7 /* Get first found zero-index
209 (= first mismatch). */
210 clrjl %r0,%r6,.Lslow_next_acc /* Mismatch-index < min(lbc,zero-index)
211 -> Process this string-part
212 with next acc-part. */
213 clrjhe %r0,%r4,.Lslow_next_str /* Found-index >= loaded byte count
214 -> All loaded bytes are matching
215 any accept-character
216 and are not zero. */
217 /* All bytes are matching any characters in accept-string
218 and search-string is fully processed (found-index == zero-index). */
219 .Lslow_add_lbc_end:
220 algrk %r2,%r1,%r0 /* Add matching characters to current len. */
221 srlg %r2,%r2,2 /* Convert byte-count to character-count. */
222 /* Restore registers. */
223 vlgvg %r6,%v30,0
224 vlgvg %r8,%v31,0
225 vlgvg %r9,%v31,1
226 br %r14
227
228 .Lslow_next_acc:
229 clijh %r8,0,.Lslow_add_lbc_end /* There was a zero in last acc-part
230 -> Add found index to current len
231 and end. */
232 vlbb %v17,16(%r5,%r3),6 /* Load next accept part. */
233 aghi %r5,16 /* Increment current len of accept-string. */
234 lcbb %r9,0(%r5,%r3),6 /* Get loaded byte count of accept-string. */
235 jo .Lslow_next_acc_onbb /* Jump away if accept-string is
236 on block-boundary. */
237 .Lslow_next_acc_notonbb:
238 vistrfs %v17,%v17 /* Fill with zeros after first zero. */
239 jo .Lslow_loop_acc /* No zero found -> no preparation needed. */
240
241 .Lslow_next_acc_prepare_zero:
242 /* Zero in accept-part: fill zeros with first-accept-character. */
243 vlgvf %r8,%v17,0 /* Load first element of acc-part. */
244 clije %r8,0,.Lslow_add_lbc_end /* End if zero is first character
245 in this part of accept-string. */
246 /* r8>0 -> zero found in this acc-part. */
247 vrepf %v18,%v17,0 /* Replicate first char accross all chars. */
248 vceqf %v22,%v20,%v17 /* Create a mask (v22) of null chars
249 by comparing with 0 (v20). */
250 vsel %v17,%v18,%v17,%v22 /* Replace null chars with first char. */
251 j .Lslow_loop_acc /* Accept part is prepared -> process. */
252
253 .Lslow_next_acc_onbb:
254 nill %r9,65532 /* Recognize only fully loaded characters. */
255 je .Lslow_next_acc_onbb2 /* Reload vr, if we loaded no full
256 wchar_t. */
257 vfenezf %v18,%v17,%v17 /* Find zero in loaded bytes of accept part. */
258 vlgvb %r8,%v18,7 /* Load byte index of zero. */
259 clrjl %r8,%r9,.Lslow_next_acc_notonbb /* Found a zero in loaded bytes
260 -> Prepare vreg. */
261 .Lslow_next_acc_onbb2:
262 vl %v17,0(%r5,%r3) /* Load over boundary ... */
263 lghi %r8,0 /* r8=0 -> no zero in this part of acc,
264 check for zero is in jump-target. */
265 j .Lslow_next_acc_notonbb /* ... and search for zero in
266 fully loaded vreg again. */
267 .Lfallback:
268 jg __wcsspn_c
269 END(__wcsspn_vx)
270 #endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */