Support mcount/gprof test with GCC defaulting to PIE
[glibc.git] / sysdeps / s390 / multiarch / wcsncat-vx.S
blob5c49a1e4999b401166e9e1e8abcc95beb0f22adb
1 /* Vector optimized 32/64 bit S/390 version of wcsncat.
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 /* wchar_t * wcsncat (wchar_t *dest, const wchar_t *src, size_t n)
27    Concatenate two strings - at most n characters of src.
29    Register usage:
30    -r0=saved dest pointer for return
31    -r1=tmp
32    -r2=dest
33    -r3=src
34    -r4=n
35    -r5=current_len
36    -r6=tmp
37    -r7=tmp
38    -v16=part of src
39    -v17=index of zero
40    -v18=part of src
41    -v31=register save area for r6, r7
43 ENTRY(__wcsncat_vx)
44         .machine "z13"
45         .machinemode "zarch_nohighgprs"
47 # if !defined __s390x__
48         llgfr   %r4,%r4
49 # endif /* !defined __s390x__ */
51         clgfi   %r4,0
52         ber     %r14            /* Nothing to do, if n == 0.  */
54         vlbb    %v16,0(%r2),6   /* Load s until next 4k-byte boundary.  */
55         lcbb    %r1,0(%r2),6    /* Get bytes to 4k-byte boundary or 16.  */
57         /* If either src or dest is not 4byte aligned, use __wcsncat_c.  */
58         tmll    %r2,3           /* Test if s is 4-byte aligned?   */
59         jne     .Lfallback      /* And use common-code variant if not.  */
60         tmll    %r3,3           /* Test if src is 4-byte aligned?   */
61         jne     .Lfallback      /* And use common-code variant if not.  */
63         lgr     %r0,%r2         /* Save destination pointer for return.  */
64         vlvgp   %v31,%r6,%r7    /* Save registers.  */
66         /* WCSLEN
67            %r1 = loaded bytes (tmp)
68            %r6 = zero byte index (tmp)
69            %r2 = dst
70         */
71         vfenezf %v16,%v16,%v16  /* Find element not equal with zero search.  */
72         vlgvb   %r5,%v16,7      /* Load zero index or 16 if not found.  */
73         clrjl   %r5,%r1,.Llen_end /* Found zero within loaded bytes, end.  */
75         /* Align s to 16 byte.  */
76         risbgn  %r1,%r2,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15.  */
77         lghi    %r5,16          /* current_len = 16.  */
78         slr     %r5,%r1         /* Compute bytes to 16bytes boundary.  */
80         /* Find zero in 16byte aligned loop.  */
81 .Llen_loop:
82         vl      %v16,0(%r5,%r2) /* Load s.  */
83         vfenezfs %v16,%v16,%v16 /* Find element not equal with zero search.  */
84         je      .Llen_found     /* Jump away if zero was found.  */
85         vl      %v16,16(%r5,%r2)
86         vfenezfs %v16,%v16,%v16
87         je      .Llen_found16
88         vl      %v16,32(%r5,%r2)
89         vfenezfs %v16,%v16,%v16
90         je      .Llen_found32
91         vl      %v16,48(%r5,%r2)
92         vfenezfs %v16,%v16,%v16
93         je      .Llen_found48
95         aghi    %r5,64
96         j       .Llen_loop      /* No zero -> loop.  */
98 .Llen_found48:
99         aghi    %r5,16
100 .Llen_found32:
101         aghi    %r5,16
102 .Llen_found16:
103         aghi    %r5,16
104 .Llen_found:
105         vlgvb   %r1,%v16,7      /* Load byte index of zero.  */
106         algr    %r5,%r1
108 .Llen_end:
109         /* WCSNCPY
110            %r1 = zero byte index (tmp)
111            %r6 = loaded bytes (tmp)
112            %r3 = curr src pointer
113            %r2 = curr dst pointer
114            %r7 = border, tmp
115         */
116         la      %r2,0(%r5,%r2)  /* strcpy at end of dst-string.  */
118         vlbb    %v16,0(%r3),6   /* Load s until next 4k-byte boundary.  */
119         lcbb    %r6,0(%r3),6    /* Get bytes to 4k-byte boundary or 16.  */
120         llgfr   %r6,%r6         /* Convert 32bit to 64bit.  */
122         lghi    %r5,0           /* current_len = 0.  */
124         /* Check range of maxlen and convert to byte-count.  */
125 # ifdef __s390x__
126         tmhh    %r4,49152       /* Test bit 0 or 1 of maxlen.  */
127         lghi    %r1,-4          /* Max byte-count is 18446744073709551612.  */
128 # else
129         tmlh    %r4,49152       /* Test bit 0 or 1 of maxlen.  */
130         llilf   %r1,4294967292  /* Max byte-count is 4294967292.  */
131 # endif /* !__s390x__ */
132         sllg    %r4,%r4,2       /* Convert character-count to byte-count.  */
133         locgrne %r4,%r1         /* Use max byte-count, if bit 0/1 was one.  */
135         clgrjle %r4,%r6,.Lcpy_remaining_v16 /* If n <= loaded-bytes
136                                                -> process remaining.  */
138         /* n > loaded-byte-count.  */
139         vfenezf %v17,%v16,%v16  /* Find element not equal with zero search.  */
140         vlgvb   %r1,%v17,7      /* Load zero index or 16 if not found.  */
141         clrjl   %r1,%r6,.Lcpy_found_v16_store /* Found zero within loaded bytes,
142                                                  copy and return.  */
144         /* Align s to 16 byte.  */
145         risbgn  %r1,%r3,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15.  */
146         lghi    %r5,15          /* current_len = 15.  */
147         slr     %r5,%r1         /* Compute highest index to 16byte boundary.  *
149         /* Zero not found and maxlen > loaded-byte-count.  */
150         vstl    %v16,%r5,0(%r2) /* Copy loaded characters - no zero.  */
151         ahi     %r5,1           /* Start loop at next character.  */
153         /*
154           Now we are 16byte aligned, so we can load a full vreg
155           without page fault.
156          */
157         lgr     %r1,%r5         /* If %r5 + 64 < maxlen? -> loop64.  */
158         aghi    %r1,64
159         clgrjl  %r1,%r4,.Lcpy_loop64
161         vl      %v16,0(%r5,%r3) /* Load s.  */
162         clgijl  %r4,17,.Lcpy_remaining_v16 /* If n <=16,
163                                                process remaining bytes.  */
164 .Lcpy_lt64:
165         lgr     %r7,%r4
166         slgfi   %r7,16          /* border_len = n - 16.  */
168         clgrjhe %r5,%r7,.Lcpy_remaining_v16
169         vfenezfs %v17,%v16,%v16 /* Find element not equal with zero search.  */
170         je      .Lcpy_found_v16 /* Jump away if zero was found.  */
171         vl      %v18,16(%r5,%r3) /* Load next part of s.  */
172         vst     %v16,0(%r5,%r2) /* Save previous part without zero to dst.  */
173         aghi    %r5,16
175         clgrjhe %r5,%r7,.Lcpy_remaining_v18
176         vfenezfs %v17,%v18,%v18
177         je      .Lcpy_found_v18
178         vl      %v16,16(%r5,%r3)
179         vst     %v18,0(%r5,%r2)
180         aghi    %r5,16
182         clgrjhe %r5,%r7,.Lcpy_remaining_v16
183         vfenezfs %v17,%v16,%v16
184         je      .Lcpy_found_v16
185         vl      %v18,16(%r5,%r3)
186         vst     %v16,0(%r5,%r2)
187         aghi    %r5,16
189 .Lcpy_remaining_v18:
190         vlr     %v16,%v18
191 .Lcpy_remaining_v16:
192         /* v16 contains the remaining bytes [1...16].
193            Store remaining bytes and append string-termination.  */
194         vfenezf %v17,%v16,%v16  /* Find element not equal with zero search.  */
195         slgrk   %r7,%r4,%r5     /* Remaining bytes = maxlen - current_len.  */
196         aghi    %r7,-1          /* vstl needs highest index.  */
197         vlgvb   %r1,%v17,7      /* Load zero index or 16 if not found.  */
198         la      %r2,0(%r5,%r2)  /* vstl has no index register.  */
199         /* Zero-index within remaining-bytes, store up to zero and end.  */
200         clgrjle %r1,%r7,.Lcpy_found_v16_store
201         vstl    %v16,%r7,0(%r2) /* Store remaining bytes.  */
202         lghi    %r1,0
203         st      %r1,1(%r7,%r2)  /* Store string-null-termination beyond n.  */
204 .Lcpy_end:
205         /* Restore saved registers.  */
206         vlgvg   %r6,%v31,0
207         vlgvg   %r7,%v31,1
208         lgr     %r2,%r0         /* Load saved dest-ptr.  */
209         br      %r14
211 .Lcpy_found_v16_32:
212         aghi    %r5,32
213         j       .Lcpy_found_v16
214 .Lcpy_found_v18_48:
215         aghi    %r5,32
216 .Lcpy_found_v18_16:
217         aghi    %r5,16
218 .Lcpy_found_v18:
219         vlr     %v16,%v18
220 .Lcpy_found_v16:
221         /* v16 contains a zero. Store remaining bytes to zero. current_len
222            has not reached border, thus checking for n is not needed!  */
223         vlgvb   %r1,%v17,7      /* Load byte index of zero.  */
224         la      %r2,0(%r5,%r2)
225 .Lcpy_found_v16_store:
226         aghi    %r1,3           /* Also copy remaining bytes of zero.  */
227         vstl    %v16,%r1,0(%r2) /* Copy characters including zero.  */
228         j       .Lcpy_end
230         /* Find zero in 16byte aligned loop.  */
231 .Lcpy_loop2:
232         vl      %v16,16(%r5,%r3)
233         vst     %v18,0(%r5,%r2)
234         aghi    %r5,16
236 .Lcpy_loop64:
237         vl      %v16,0(%r5,%r3)
238         vfenezfs %v17,%v16,%v16 /* Find element not equal with zero search.  */
239         je      .Lcpy_found_v16 /* Jump away if zero was found.  */
240         vl      %v18,16(%r5,%r3) /* Load next part of s.  */
241         vst     %v16,0(%r5,%r2) /* Save previous part without zero to dst.  */
242         vfenezfs %v17,%v18,%v18
243         je      .Lcpy_found_v18_16
244         vl      %v16,32(%r5,%r3)
245         vst     %v18,16(%r5,%r2)
246         vfenezfs %v17,%v16,%v16
247         je      .Lcpy_found_v16_32
248         vl      %v18,48(%r5,%r3)
249         vst     %v16,32(%r5,%r2)
250         vfenezfs %v17,%v18,%v18
251         je      .Lcpy_found_v18_48
252         vst     %v18,48(%r5,%r2)
254         aghi    %r5,64
255         lgr     %r1,%r5         /* If %r5 + 64 < maxlen? -> loop64.  */
256         aghi    %r1,64
257         clgrjl  %r1,%r4,.Lcpy_loop64
259         vl      %v16,0(%r5,%r3) /* Load s.  */
260         j       .Lcpy_lt64
262 .Lfallback:
263         jg      __wcsncat_c
264 END(__wcsncat_vx)
265 #endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */