powerpc: Regenerate ULPs
[glibc.git] / sysdeps / s390 / multiarch / strspn-vx.S
blob65d295937ac75f63e70b6690433c541a13f6d2c9
1 /* Vector optimized 32/64 bit S/390 version of strspn.
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 /* size_t strspn (const char *s, const char * accept)
27    The strspn() function calculates the length of the initial segment
28    of s which consists entirely of characters in accept.
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.
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
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
60 ENTRY(__strspn_vx)
61         .machine "z13"
62         .machinemode "zarch_nohighgprs"
64         /*
65           Check if accept-string fits in one vreg:
66           ----------------------------------------
67         */
68         vlbb    %v17,0(%r3),6   /* Load accept.  */
69         lcbb    %r4,0(%r3),6
70         jo      .Lcheck_onbb    /* Special case if accept lays
71                                    on block-boundary.  */
72 .Lcheck_notonbb:
73         vistrbs %v17,%v17       /* Fill with zeros after first zero.  */
74         je      .Lfast          /* Zero found -> accept fits in one vreg.  */
75         j       .Lslow          /* No zero -> accept exceeds one vreg.  */
77 .Lcheck_onbb:
78         /* Accept lays on block-boundary.  */
79         vfenezb %v18,%v17,%v17  /* Search zero in loaded accept bytes.  */
80         vlgvb   %r0,%v18,7      /* Get index of zero or 16 if not found.  */
81         clrjl   %r0,%r4,.Lcheck_notonbb /* Zero index < loaded bytes count ->
82                                            Accept fits in one vreg;
83                                            Fill with zeros and proceed
84                                            with FAST.  */
85         vl      %v17,0(%r3)     /* Load accept, which exceeds loaded bytes.  */
86         j       .Lcheck_notonbb /* Check if accept fits in one vreg.  */
89         /*
90           Search s for accept in one vreg
91           -------------------------------
92         */
93 .Lfast:
94         /* Complete accept-string is in v17 and remaining bytes are zero.  */
96         vlbb    %v16,0(%r2),6   /* Load s until next 4k-byte boundary.  */
97         lcbb    %r1,0(%r2),6    /* Get bytes to 4k-byte boundary or 16.  */
99         vfaezbs %v16,%v16,%v17,8 /* Find first element in v16
100                                     unequal to any in v17
101                                     or first zero element.  */
102         vlgvb   %r0,%v16,7      /* Load byte index of found element.  */
103         /* If found index is within loaded bytes (%r0 < %r1),
104            return with found element index (=equal count).  */
105         clr     %r0,%r1
106         locgrl  %r2,%r0
107         blr     %r14
109         /* Align s to 16 byte.  */
110         risbgn  %r4,%r2,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15.  */
111         lghi    %r1,16          /* current_len = 16.  */
112         slr     %r1,%r4         /* Compute bytes to 16bytes boundary.  */
114 .Lfast_loop:
115         vl      %v16,0(%r1,%r2) /* Load search-string.  */
116         vfaezbs %v16,%v16,%v17,8 /* Find first element in v16
117                                     unequal to any in v17
118                                     or first zero element.  */
119         jno     .Lfast_loop_found
120         vl      %v16,16(%r1,%r2)
121         vfaezbs %v16,%v16,%v17,8
122         jno     .Lfast_loop_found16
123         vl      %v16,32(%r1,%r2)
124         vfaezbs %v16,%v16,%v17,8
125         jno     .Lfast_loop_found32
126         vl      %v16,48(%r1,%r2)
127         vfaezbs %v16,%v16,%v17,8
128         jno     .Lfast_loop_found48
130         aghi    %r1,64
131         j       .Lfast_loop     /* Loop if no element was unequal to accept
132                                    and not zero.  */
134         /* Found unequal or zero element.  */
135 .Lfast_loop_found48:
136         aghi    %r1,16
137 .Lfast_loop_found32:
138         aghi    %r1,16
139 .Lfast_loop_found16:
140         aghi    %r1,16
141 .Lfast_loop_found:
142         vlgvb   %r0,%v16,7      /* Load byte index of found element.  */
143         algrk   %r2,%r1,%r0     /* And add it to current len.  */
144         br      %r14
147         /*
148           Search s for accept in multiple vregs
149           -------------------------------------
150         */
151 .Lslow:
152         /* Save registers.  */
153         vlvgg   %v30,%r6,0
154         vlvgp   %v31,%r8,%r9
155         lghi    %r1,0           /* current_len = 0.  */
157         /* Accept in v17 without zero.  */
158         vlr     %v19,%v17       /* Save first acc-part for a fast reload.  */
159         vzero   %v20            /* Zero for preparing acc-vector.  */
161         /* Align s to 16 byte.  */
162         risbg   %r0,%r2,60,128+63,0 /* Test if s is aligned and
163                                      %r0 = bits 60-63 'and' 15  */
164         je      .Lslow_loop_str /* If s is aligned, loop aligned */
165         lghi    %r4,15
166         slr     %r4,%r0         /* Compute highest index to load (15-x).  */
167         vll     %v16,%r4,0(%r2) /* Load up to 16byte boundary (vll needs
168                                    highest index, left bytes are 0).  */
169         ahi     %r4,1           /* Work with loaded byte count.  */
170         vzero   %v21            /* Zero out global mask.  */
171         lghi    %r5,0           /* Set current len of accept-string to zero.  */
172         vfenezb %v18,%v16,%v16  /* Find zero in current string-part.  */
173         lghi    %r8,0           /* There is no zero in first accept-part.  */
174         vlgvb   %r6,%v18,7      /* Load byte index of zero or 16
175                                    if there is no zero.  */
176         clr     %r4,%r6         /* cc==1 if loaded byte count < zero-index.  */
177         locrl   %r6,%r4         /* Load on cc==1.  */
178         j       .Lslow_loop_acc
180         /* Process s in 16byte aligned loop.  */
181 .Lslow_next_str:
182         vlr     %v17,%v19       /* Load first part of accept (no zero).  */
183         algfr   %r1,%r4         /* Add loaded byte count to current len.  */
184 .Lslow_loop_str:
185         vl      %v16,0(%r1,%r2) /* Load search-string.  */
186         lghi    %r4,16          /* Loaded byte count is 16.  */
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.  */
193 .Lslow_loop_acc:
194         vfaeb   %v22,%v16,%v17,4 /* Create matching-mask (1 in mask ->
195                                     character matches any accepted character in
196                                     this accept-string-part) IN=0, RT=1.  */
197         vo      %v21,%v21,%v22  /* global-mask = global- | matching-mask.  */
198         vfenezb %v18,%v21,%v21  /* Find first zero in global-mask.  */
199         vlgvb   %r0,%v18,7      /* Get first found zero-index
200                                    (= first mismatch).  */
201         clrjl   %r0,%r6,.Lslow_next_acc /* Mismatch-index < min(lbc,zero-index)
202                                             -> Process this string-part
203                                                with next acc-part.  */
204         clrjhe  %r0,%r4,.Lslow_next_str /* Found-index >= loaded byte count
205                                            -> All loaded bytes are matching
206                                               any accept-character
207                                               and are not zero.  */
208         /* All bytes are matching any characters in accept-string
209            and search-string is fully processed (found-index == zero-index)  */
210 .Lslow_add_lbc_end:
211         algrk   %r2,%r1,%r0     /* Add matching characters to current_len.  */
212         /* Restore registers.  */
213         vlgvg   %r6,%v30,0
214         vlgvg   %r8,%v31,0
215         vlgvg   %r9,%v31,1
216         br      %r14
220 .Lslow_next_acc:
221         clijh   %r8,0,.Lslow_add_lbc_end /* There was a zero in last acc-part
222                                              -> Add found index to current len
223                                                 and end.  */
224         vlbb    %v17,16(%r5,%r3),6 /* Load next accept part.  */
225         aghi    %r5,16          /* Add current_len of accept-string.  */
226         lcbb    %r9,0(%r5,%r3),6 /* Get loaded byte count of accept-string.  */
227         jo      .Lslow_next_acc_onbb /* Jump away if accept-string is
228                                          on block-boundary.  */
229 .Lslow_next_acc_notonbb:
230         vistrbs %v17,%v17       /* Fill with zeros after first zero.  */
231         jo      .Lslow_loop_acc /* No zero found -> no preparation needed.  */
233 .Lslow_next_acc_prepare_zero:
234         /* Zero in accept-part: fill zeros with first-accept-character.  */
235         vlgvb   %r8,%v17,0      /* Load first element of acc-part.  */
236         clije   %r8,0,.Lslow_add_lbc_end /* End if zero is first character
237                                              in this part of accept-string.  */
238         /* r8>0 -> zero found in this acc-part.  */
239         vrepb   %v18,%v17,0     /* Replicate first char accross all chars.  */
240         vceqb   %v22,%v20,%v17  /* Create a mask (v22) of null chars
241                                    by comparing with 0 (v20).  */
242         vsel    %v17,%v18,%v17,%v22 /* Replace null chars with first char.  */
243         j       .Lslow_loop_acc /* Accept part is prepared -> process.  */
245 .Lslow_next_acc_onbb:
246         vfenezb %v18,%v17,%v17  /* Find zero in loaded bytes of accept part.  */
247         vlgvb   %r8,%v18,7      /* Load byte index of zero.  */
248         clrjl   %r8,%r9,.Lslow_next_acc_notonbb /* Found a zero in loaded bytes
249                                                     -> Prepare vr.  */
250         vl      %v17,0(%r5,%r3) /* Load over boundary ...  */
251         lghi    %r8,0           /* r8=0 -> no zero in this part of acc,
252                                    Check for zero is in jump-target.  */
253         j       .Lslow_next_acc_notonbb /* ... and search for zero in
254                                             fully loaded vreg again.  */
255 END(__strspn_vx)
256 #endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */