powerpc: Regenerate ULPs
[glibc.git] / sysdeps / s390 / multiarch / strpbrk-vx.S
blob6a0bbd9d1954a0cf3fae835197fccf502cb067aa
1 /* Vector optimized 32/64 bit S/390 version of strpbrk.
2    Copyright (C) 2015-2016 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
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.
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.
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/>.  */
19 #if defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)
21 # include "sysdep.h"
22 # include "asm-syntax.h"
24         .text
26 /* char *strpbrk (const char *s, const char * accept)
27    The  strpbrk()  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.
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.
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
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
62 ENTRY(__strpbrk_vx)
63         .machine "z13"
64         .machinemode "zarch_nohighgprs"
66         /*
67           Check if accept-string fits in one vreg:
68           ----------------------------------------
69         */
70         vlbb    %v17,0(%r3),6   /* Load accept.  */
71         lghi    %r1,0           /* Zero out current len.  */
72         vlgvb   %r0,%v17,0      /* Get first element.  */
73         clije   %r0,0,.Lfast_end_null /* Return null if accept is empty.  */
74         lcbb    %r0,0(%r3),6
75         jo      .Lcheck_onbb    /* Special case if accept lays
76                                    on block-boundary.  */
77 .Lcheck_notonbb:
78         vistrbs %v17,%v17       /* Fill with zeros after first zero.  */
79         je      .Lfast          /* Zero found -> accept fits in one vreg.  */
80         j       .Lslow          /* No zero -> accept exceeds one vreg  */
83 .Lcheck_onbb:
84         /* Accept lays on block-boundary.  */
85         vfenezb %v18,%v17,%v17  /* Search zero in loaded accept bytes.  */
86         vlgvb   %r4,%v18,7      /* Get index of zero or 16 if not found.  */
87         clrjl   %r4,%r0,.Lcheck_notonbb /* Zero index < loaded bytes count ->
88                                             Accept fits in one vreg;
89                                             Fill with zeros and proceed
90                                             with FAST.  */
91         vl      %v17,0(%r3)     /* Load accept, which exceeds loaded bytes.  */
92         j       .Lcheck_notonbb /* Check if accept fits in one vreg.  */
95         /*
96           Search s for accept in one vreg
97           -------------------------------
98         */
99 .Lfast:
100         /* Complete accept-string in v17 and remaining bytes are zero.  */
102         vlbb    %v16,0(%r2),6   /* Load s until next 4k-byte boundary.  */
103         lcbb    %r0,0(%r2),6    /* Get bytes to 4k-byte boundary or 16.  */
105         vfaezbs %v18,%v16,%v17,0 /* Find first element in v16 unequal to any
106                                     in v17 or first zero element.  */
108         vlgvb   %r4,%v18,7      /* Load byte index of found element.  */
109         /* If found index is within loaded bytes, return with found
110            element index (=equal count).  */
111         clrjl   %r4,%r0,.Lfast_loop_found2
113         /* Align s to 16 byte.  */
114         risbgn  %r4,%r2,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15.  */
115         lghi    %r1,16          /* current_len = 16.  */
116         slr     %r1,%r4         /* Compute bytes to 16bytes boundary.  */
118         /* Process s in 16byte aligned loop.  */
119 .Lfast_loop:
120         vl      %v16,0(%r1,%r2) /* Load search-string.  */
121         vfaezbs %v18,%v16,%v17,0 /* Find first element in v16 equal to any
122                                     in v17 or first zero element.  */
123         jno     .Lfast_loop_found
125         vl      %v16,16(%r1,%r2)
126         vfaezbs %v18,%v16,%v17,0
127         jno     .Lfast_loop_found16
129         vl      %v16,32(%r1,%r2)
130         vfaezbs %v18,%v16,%v17,0
131         jno     .Lfast_loop_found32
133         vl      %v16,48(%r1,%r2)
134         vfaezbs %v18,%v16,%v17,0
135         jno     .Lfast_loop_found48
137         aghi    %r1,64
138         j       .Lfast_loop     /* Loop if no element was unequal to accept
139                                    and not zero.  */
141         /* Found equal or zero element.  */
142 .Lfast_loop_found48:
143         aghi    %r1,16
144 .Lfast_loop_found32:
145         aghi    %r1,16
146 .Lfast_loop_found16:
147         aghi    %r1,16
148 .Lfast_loop_found:
149         vlgvb   %r4,%v18,7      /* Load byte index of found element.  */
150 .Lfast_loop_found2:
151         vlgvb   %r0,%v16,0(%r4) /* Get found element.  */
152         clije   %r0,0,.Lfast_end_null /* Return null if no accept-char found */
153         algfr   %r1,%r4         /* Add found index of char to current len.  */
154         la      %r2,0(%r1,%r2)  /* And return pointer to first equal char.  */
155         br      %r14
157 .Lfast_end_null:
158         lghi    %r2,0           /* Return null if no character is equal.  */
159         br      %r14
164         /*
165           Search s for accept in multiple vregs
166           -------------------------------------
167         */
168 .Lslow:
169         /* Save registers.  */
170         vlvgg   %v30,%r6,0
171         vlvgp   %v31,%r8,%r9
173         /* accept in v17 without zero.  */
174         vlr     %v19,%v17       /* Save first acc-part for a fast reload.  */
175         vzero   %v20            /* Zero for preparing acc-vector.  */
176         vone    %v24            /* One for checking result of former string.  */
178         /* Align s to 16 byte.  */
179         risbg   %r4,%r2,60,128+63,0 /* Test if s is aligned and
180                                        %r4 = bits 60-63 'and' 15.  */
181         je      .Lslow_loop_str /* If s is aligned, loop aligned.  */
182         lghi    %r0,15
183         slr     %r0,%r4         /* Compute highest index to load (15-x).  */
184         vll     %v16,%r0,0(%r2) /* Load up to 16 byte boundary (vll needs
185                                    highest index, remaining bytes are 0).  */
186         ahi     %r0,1           /* Work with loaded byte count.  */
187         vzero   %v21            /* Zero out global mask.  */
188         lghi    %r5,0           /* Set current len of accept-string to zero.  */
189         vfenezb %v18,%v16,%v16  /* Find zero in current string-part.  */
190         lghi    %r8,0           /* There is no zero in first accept-part.  */
191         vlgvb   %r6,%v18,7      /* Load byte index of zero or 16 if no zero.  */
192         clije   %r6,0,.Lslow_end_null /* If first element is zero
193                                           (end of string) -> return null */
194         clr     %r0,%r6         /* cc==1 if loaded byte count < zero-index.  */
195         locrl   %r6,%r0         /* Load on cc==1; zero-index = lbc.  */
196         j       .Lslow_loop_acc
199         /* Process s in 16byte aligned loop.  */
200 .Lslow_next_str:
201         /* Check results of former processed str-part.  */
202         vfeeb   %v18,%v21,%v24  /* Find first equal match in global mask
203                                    (ones in element).  */
204         vlgvb   %r4,%v18,7      /* Get index of first one (=equal)
205                                    or 16 if no match.  */
206         /* Equal-index < min(zero-index, loaded byte count)
207            -> return pointer to equal element.  */
208         clrjl   %r4,%r6,.Lslow_index_found
209         /* Zero-index < loaded byte count
210            -> former str-part was last str-part
211            -> return null */
212         clrjl   %r6,%r0,.Lslow_end_null
213         /* All elements are zero (=no match) -> proceed with next str-part.  */
215         vlr     %v17,%v19       /* Load first part of accept (no zero).  */
216         algfr   %r1,%r0         /* Add loaded byte count to current len.  */
218 .Lslow_loop_str:
219         vl      %v16,0(%r1,%r2) /* Load search-string */
220         lghi    %r0,16          /* Loaded byte count is 16.  */
221         vzero   %v21            /* Zero out global mask.  */
222         lghi    %r5,0           /* Set current len of accept to zero.  */
223         vfenezb %v18,%v16,%v16  /* Find zero in current string-part.  */
224         lghi    %r8,0           /* There is no zero in first accept-part.  */
225         vlgvb   %r6,%v18,7      /* Load byte index of zero or 16 if no zero.  */
226         clije   %r6,0,.Lslow_end_null /* If first element is zero
227                                           (end of string) -> return null.  */
229 .Lslow_loop_acc:
230         vfaeb   %v22,%v16,%v17,4 /* Create matching-mask (1 in mask ->
231                                     Character matches any accepted character in
232                                     this accept-string-part) IN=0, RT=1.  */
233         vlgvb   %r4,%v22,0      /* Get result of first element.  */
234         /* First element is equal to any accepted characters
235            (all other parts of accept cannot lead to a match before this one)
236            -> current len is pointing to first element
237            -> return found  */
238         clijh   %r4,0,.Lslow_end_found
239         vo      %v21,%v21,%v22  /* Global-mask = global-|matching-mask.  */
240         /* Proceed with next acc until end of acc is reached.  */
243 .Lslow_next_acc:
244         clijh   %r8,0,.Lslow_next_str /* There was a zero in the last acc-part
245                                           -> add index to current_len and
246                                              end.  */
247         vlbb    %v17,16(%r5,%r3),6 /* Load next accept part.  */
248         aghi    %r5,16          /* Increment current len of accept-string.  */
249         lcbb    %r9,0(%r5,%r3),6 /* Get loaded byte count of accept-string.  */
250         jo      .Lslow_next_acc_onbb /* Jump away ifaccept-string is
251                                          on block-boundary.  */
252 .Lslow_next_acc_notonbb:
253         vistrbs %v17,%v17       /* Fill with zeros after first zero.  */
254         jo      .Lslow_loop_acc /* No zero found -> no preparation needed.  */
256 .Lslow_next_acc_prepare_zero:
257         /* Zero in accept-part: fill zeros with first-accept-character.  */
258         vlgvb   %r8,%v17,0      /* Load first element of acc-part.  */
259         clije   %r8,0,.Lslow_next_str /* Proceed with next string-part,
260                                           if first char in this part of accept
261                                           is a zero.  */
262         /* r8>0 -> zero found in this acc-part.  */
263         vrepb   %v18,%v17,0     /* Replicate first char accross all chars.  */
264         vceqb   %v22,%v20,%v17  /* Create a mask (v22) of null chars
265                                    by comparing with 0 (v20).  */
266         vsel    %v17,%v18,%v17,%v22 /* Replace null chars with first char.  */
267         j       .Lslow_loop_acc /* Accept part is prepared -> process.  */
269 .Lslow_next_acc_onbb:
270         vfenezb %v18,%v17,%v17  /* Find zero in loaded bytes of accept part.  */
271         vlgvb   %r8,%v18,7      /* Load byte index of zero.  */
272         clrjl   %r8,%r9,.Lslow_next_acc_notonbb /* Found a zero in loaded bytes
273                                                     -> Prepare vreg.  */
274         vl      %v17,0(%r5,%r3) /* Load over boundary ...  */
275         lghi    %r8,0           /* r8=0 -> no zero in this part of acc,
276                                    check for zero is in jump-target.  */
277         j       .Lslow_next_acc_notonbb /* ... and search for zero in
278                                             fully loaded vreg again.  */
280 .Lslow_end_null:
281         lghi    %r1,0           /* Return null if no character is equal.  */
282         j       .Lslow_end
284 .Lslow_loop_found:
285         vlgvb   %r4,%v18,7      /* Load byte index of found element.  */
286         vlgvb   %r0,%v16,0(%r4) /* Get found element.  */
287         clije   %r0,0,.Lslow_end_null /* Return null if no acc-char found.  */
289 .Lslow_index_found:
290         algfr   %r1,%r4         /* Add found index of char to current len.  */
291 .Lslow_end_found:
292         la      %r1,0(%r1,%r2)  /* And return pointer to first equal char.  */
294 .Lslow_end:
295         /* Restore registers.  */
296         vlgvg   %r6,%v30,0
297         vlgvg   %r8,%v31,0
298         vlgvg   %r9,%v31,1
299         lgr     %r2,%r1
300         br      %r14
301 END(__strpbrk_vx)
302 #endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */