1 /* Vector optimized 32/64 bit S/390 version of strncat.
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)
22 # include "asm-syntax.h"
26 /* char * strncat (const char *dest, const char *src, size_t n)
27 Concatenate two strings - at most n characters of src.
30 -r0=saved dest pointer for return
41 -v31=register save area for r6, r7
45 .machinemode "zarch_nohighgprs"
47 # if !defined __s390x__
49 # endif /* !defined __s390x__ */
52 ber %r14 /* Nothing to do, if n == 0. */
53 lgr %r0,%r2 /* Save destination pointer for return. */
54 vlvgp %v31,%r6,%r7 /* Save registers. */
57 %r1 = loaded bytes (tmp)
58 %r6 = zero byte index (tmp)
61 vlbb %v16,0(%r2),6 /* Load s until next 4k-byte boundary. */
62 lcbb %r1,0(%r2),6 /* Get bytes to 4k-byte boundary or 16. */
64 vfenezb %v16,%v16,%v16 /* Find element not equal with zero search. */
65 vlgvb %r5,%v16,7 /* Load zero index or 16 if not found. */
66 clrjl %r5,%r1,.Llen_end /* Found zero within loaded bytes, end. */
68 /* Align s to 16 byte. */
69 risbgn %r1,%r2,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15. */
70 lghi %r5,16 /* current_len = 16. */
71 slr %r5,%r1 /* Compute bytes to 16bytes boundary. */
73 /* Find zero in 16byte aligned loop. */
75 vl %v16,0(%r5,%r2) /* Load s. */
76 vfenezbs %v16,%v16,%v16 /* Find element not equal with zero search. */
77 je .Llen_found /* Jump away if zero was found. */
79 vfenezbs %v16,%v16,%v16
82 vfenezbs %v16,%v16,%v16
85 vfenezbs %v16,%v16,%v16
89 j .Llen_loop /* No zero -> loop. */
98 vlgvb %r1,%v16,7 /* Load byte index of zero. */
103 %r1 = zero byte index (tmp)
104 %r6 = loaded bytes (tmp)
105 %r3 = curr src pointer
106 %r2 = curr dst pointer
109 la %r2,0(%r5,%r2) /* strcpy at end of dst-string. */
111 vlbb %v16,0(%r3),6 /* Load s until next 4k-byte boundary. */
112 lcbb %r6,0(%r3),6 /* Get bytes to 4k-byte boundary or 16. */
113 llgfr %r6,%r6 /* Convert 32bit to 64bit. */
115 lghi %r5,0 /* current_len = 0. */
117 clgrjle %r4,%r6,.Lcpy_remaining_v16 /* If n <= loaded-bytes
118 -> process remaining. */
120 /* n > loaded-byte-count. */
121 vfenezb %v17,%v16,%v16 /* Find element not equal with zero search. */
122 vlgvb %r1,%v17,7 /* Load zero index or 16 if not found. */
123 clrjl %r1,%r6,.Lcpy_found_v16_store /* Found zero within loaded
124 bytes, copy and return. */
126 /* Align s to 16 byte. */
127 risbgn %r7,%r3,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15. */
128 lghi %r5,15 /* current_len = 15. */
129 slr %r5,%r7 /* Compute highest index to 16byte boundary. */
131 /* Zero not found and n > loaded-byte-count. */
132 vstl %v16,%r5,0(%r2) /* Copy loaded characters - no zero. */
133 ahi %r5,1 /* Start loop at next character. */
136 Now we are 16byte aligned, so we can load a full vreg
139 lgr %r1,%r5 /* If %r5 + 64 < maxlen? -> loop64. */
141 clgrjl %r1,%r4,.Lcpy_loop64
143 vl %v16,0(%r5,%r3) /* Load s. */
144 clgijl %r4,17,.Lcpy_remaining_v16 /* If n <=16,
145 process remaining bytes. */
148 slgfi %r7,16 /* border_len = n - 16. */
150 /* If current_len >= border then process remaining bytes. */
151 clgrjhe %r5,%r7,.Lcpy_remaining_v16
152 vfenezbs %v17,%v16,%v16 /* Find element not equal with zero search. */
153 je .Lcpy_found_v16 /* Jump away if zero was found. */
154 vl %v18,16(%r5,%r3) /* Load next part of s. */
155 vst %v16,0(%r5,%r2) /* Store previous part without zero to dst. */
158 clgrjhe %r5,%r7,.Lcpy_remaining_v18
159 vfenezbs %v17,%v18,%v18
165 clgrjhe %r5,%r7,.Lcpy_remaining_v16
166 vfenezbs %v17,%v16,%v16
175 /* v16 contains the remaining bytes [1...16].
176 Store remaining bytes and append string-termination. */
177 vfenezb %v17,%v16,%v16 /* Find element not equal with zero search. */
178 slgrk %r7,%r4,%r5 /* Remaining bytes = maxlen - current_len. */
179 aghi %r7,-1 /* vstl needs highest index. */
180 vlgvb %r1,%v17,7 /* Load zero index or 16 if not found. */
181 la %r2,0(%r5,%r2) /* vstl has no index register. */
182 /* Zero-index within remaining-bytes, store up to zero and end. */
183 clgrjle %r1,%r7,.Lcpy_found_v16_store
184 vstl %v16,%r7,0(%r2) /* Store remaining bytes. */
186 stc %r1,1(%r7,%r2) /* Store string-null-termination beyond n. */
188 /* Restore saved registers. */
191 lgr %r2,%r0 /* Load saved dest-ptr. */
204 /* v16 contains a zero. Store remaining bytes to zero. current_len
205 has not reached border, thus checking for n is not needed! */
206 vlgvb %r1,%v17,7 /* Load byte index of zero. */
208 .Lcpy_found_v16_store:
209 vstl %v16,%r1,0(%r2) /* Copy characters including zero. */
212 /* Find zero in 16byte aligned loop. */
214 vl %v16,0(%r5,%r3) /* Load s. */
215 vfenezbs %v17,%v16,%v16 /* Find element not equal with zero search. */
216 je .Lcpy_found_v16 /* Jump away if zero was found. */
217 vl %v18,16(%r5,%r3) /* Load next part of s. */
218 vst %v16,0(%r5,%r2) /* Store previous part without zero to dst. */
219 vfenezbs %v17,%v18,%v18
220 je .Lcpy_found_v18_16
223 vfenezbs %v17,%v16,%v16
224 je .Lcpy_found_v16_32
227 vfenezbs %v17,%v18,%v18
228 je .Lcpy_found_v18_48
232 lgr %r1,%r5 /* If %r5 + 64 < maxlen? -> loop64. */
234 clgrjl %r1,%r4,.Lcpy_loop64
236 vl %v16,0(%r5,%r3) /* Load s. */
239 #endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */