Support mcount/gprof test with GCC defaulting to PIE
[glibc.git] / sysdeps / s390 / multiarch / wcsncmp-vx.S
blobe44c53a1a92f5b47da8c5ed7bc46d7a785e55a3a
1 /* Vector optimized 32/64 bit S/390 version of wcsncmp.
2    Copyright (C) 2015-2017 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 /* int wcsncmp (const wchar_t *s1, const wchar_t *s2, size_t n)
27    Compare at most n characters of two strings.
29    Register usage:
30    -r0=tmp
31    -r1=tmp
32    -r2=s1
33    -r3=s2
34    -r4=n
35    -r5=current_len
36    -v16=part of s1
37    -v17=part of s2
38    -v18=index of unequal
40 ENTRY(__wcsncmp_vx)
41         .machine "z13"
42         .machinemode "zarch_nohighgprs"
44 # if !defined __s390x__
45         llgfr   %r4,%r4
46 # endif /* !defined __s390x__ */
48         clgije  %r4,0,.Lend_equal /* Nothing to do if n == 0.  */
50         /* Check range of n and convert to byte-count.  */
51 # ifdef __s390x__
52         tmhh    %r4,49152       /* Test bit 0 or 1 of maxlen.  */
53         lghi    %r1,-4          /* Max byte-count is 18446744073709551612.  */
54 # else
55         tmlh    %r4,49152       /* Test bit 0 or 1 of maxlen.  */
56         llilf   %r1,4294967292  /* Max byte-count is 4294967292.  */
57 # endif /* !__s390x__ */
58         sllg    %r4,%r4,2       /* Convert character-count to byte-count.  */
59         locgrne %r4,%r1         /* Use max byte-count, if bit 0/1 was one.  */
61         /* Check first character without vector load.  */
62         lghi    %r5,4           /* current_len = 4 bytes.  */
63         /* Check s1/2[0].  */
64         lt      %r0,0(%r2)
65         l       %r1,0(%r3)
66         je      .Lend_cmp_one_char
67         crjne   %r0,%r1,.Lend_cmp_one_char
69 .Lloop:
70         vlbb    %v17,0(%r5,%r3),6 /* Load s2 to block boundary.  */
71         vlbb    %v16,0(%r5,%r2),6 /* Load s1 to block boundary.  */
72         lcbb    %r0,0(%r5,%r2),6 /* Get loaded byte count of s1.  */
73         jo      .Llt16_1        /* Jump away if vector not fully loaded.  */
74         lcbb    %r1,0(%r5,%r3),6 /* Get loaded byte count of s2.  */
75         jo      .Llt16_2        /* Jump away if vector not fully loaded.  */
76         aghi    %r5,16          /* Both vectors are fully loaded.  */
77         vfenezfs %v18,%v16,%v17 /* Compare not equal with zero search.  */
78         clgrjhe %r5,%r4,.Llastcmp /* If current_len >= n ->last compare.  */
79         jno     .Lfound
81         vlbb    %v17,0(%r5,%r3),6
82         vlbb    %v16,0(%r5,%r2),6
83         lcbb    %r0,0(%r5,%r2),6
84         jo      .Llt16_1
85         lcbb    %r1,0(%r5,%r3),6
86         jo      .Llt16_2
87         aghi    %r5,16
88         vfenezfs %v18,%v16,%v17
89         clgrjhe %r5,%r4,.Llastcmp
90         jno     .Lfound
92         vlbb    %v17,0(%r5,%r3),6
93         vlbb    %v16,0(%r5,%r2),6
94         lcbb    %r0,0(%r5,%r2),6
95         jo      .Llt16_1
96         lcbb    %r1,0(%r5,%r3),6
97         jo      .Llt16_2
98         aghi    %r5,16
99         vfenezfs %v18,%v16,%v17
100         clgrjhe %r5,%r4,.Llastcmp
101         jno     .Lfound
103         vlbb    %v17,0(%r5,%r3),6
104         vlbb    %v16,0(%r5,%r2),6
105         lcbb    %r0,0(%r5,%r2),6
106         jo      .Llt16_1
107         lcbb    %r1,0(%r5,%r3),6
108         jo      .Llt16_2
109         aghi    %r5,16
110         vfenezfs %v18,%v16,%v17
111         clgrjhe %r5,%r4,.Llastcmp
112         jno     .Lfound
114         j       .Lloop
116 .Llt16_1:
117         lcbb    %r1,0(%r5,%r3),6 /* Get loaded byte count of s2.  */
118 .Llt16_2:
119         clr     %r0,%r1         /* Compare logical.  */
120         locrh   %r0,%r1         /* Compute minimum of bytes loaded.  */
121         nill    %r0,65532       /* Align bytes loaded to full characters.  */
122         jz      .Lcmp_one_char  /* Jump away if no full char is available.  */
123 .Llt_cmp:
124         algfr   %r5,%r0         /* Add smallest loaded bytes to current_len.  */
125         vfenezfs %v18,%v16,%v17 /* Compare not equal with zero search.  */
126         clgrj   %r5,%r4,10,.Llastcmp /* If current_len >= n -> last compare  */
127         vlgvb   %r1,%v18,7      /* Get not equal index or 16 if all equal.  */
128         clrjl   %r1,%r0,.Lfound /* Jump away if miscompare is within
129                                    loaded bytes; (index < loaded-bytes) */
130         j       .Lloop
132 .Lcmp_one_char:
133         /* At least one of both strings is not 4-byte aligned
134            and there is no full character before next block-boundary.
135            Compare one character to get over the boundary and
136            proceed with normal loop!  */
137         vlef    %v16,0(%r5,%r2),0 /* Load one character.  */
138         lghi    %r0,4           /* Loaded byte count is 4.  */
139         vlef    %v17,0(%r5,%r3),0
140         j       .Llt_cmp        /* Proceed with comparision.  */
142 .Llastcmp:
143         /* Use comparision result only if located within first n characters.
144            %r0: loaded byte count in vreg;
145            %r5: current_len;
146            %r4: n;
147            (current_len - n): [0...16[
148            First ignored match index: loaded bytes - (current_len-n): ]0...16]
149         */
150         slgr    %r5,%r4         /* %r5 = current_len - n.  */
151         slr     %r0,%r5         /* %r0 = first ignored match index.  */
152         vlgvb   %r4,%v18,7      /* Get not equal index or 16 if all equal.  */
153         clrjl   %r4,%r0,.Lfound2 /* Jump away if miscompare is within
154                                      loaded bytes and below n bytes.  */
155 .Lend_equal:
156         lghi    %r2,0
157         br      %r14
159 .Lfound:
160         /* Difference or end of string.  */
161         /* vfenezf found an unequal element or zero.
162            This instruction compares unsigned words, but wchar_t is signed.
163            Thus we have to compare the found element again.  */
164         vlgvb   %r4,%v18,7      /* Extract not equal byte-index.  */
165 .Lfound2:
166         srl     %r4,2           /* And convert it to character-index.  */
167         vlgvf   %r0,%v16,0(%r4) /* Load character-values.  */
168         vlgvf   %r1,%v17,0(%r4)
169 .Lend_cmp_one_char:
170         cr      %r0,%r1
171         je      .Lend_equal
172         lghi    %r2,1
173         lghi    %r1,-1
174         locgrl  %r2,%r1
175         br      %r14
176 END(__wcsncmp_vx)
177 #endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */