1 /* Vector optimized 32/64 bit S/390 version of wcscat.
2 Copyright (C) 2015-2022 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 <https://www.gnu.org/licenses/>. */
19 #include <ifunc-wcscat.h>
23 # include "asm-syntax.h"
27 /* wchar_t * wcscat (wchar_t *dest, const wchar_t *src)
28 Concatenate two strings.
31 -r0=saved dest pointer for return
43 .machinemode "zarch_nohighgprs"
45 vlbb %v16,0(%r2),6 /* Load s until next 4k-byte boundary. */
46 lcbb %r1,0(%r2),6 /* Get bytes to 4k-byte boundary or 16. */
48 /* __wcslen_c can handle non 4byte aligned pointers,
49 but __wcscpy_c not. Thus if either src or dest is
50 not 4byte aligned, use __wcscat_c. */
51 tmll %r2,3 /* Test if s is 4-byte aligned? */
52 jne .Lfallback /* And use common-code variant if not. */
53 tmll %r3,3 /* Test if src is 4-byte aligned? */
54 jne .Lfallback /* And use common-code variant if not. */
56 lgr %r0,%r2 /* Save destination pointer for return. */
59 r1 = loaded bytes (tmp)
60 r4 = zero byte index (tmp)
64 vfenezf %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 vfenezfs %v16,%v16,%v16 /* Find element not equal with zero search. */
77 je .Llen_found /* Jump away if zero was found. */
79 vfenezfs %v16,%v16,%v16
82 vfenezfs %v16,%v16,%v16
85 vfenezfs %v16,%v16,%v16
89 j .Llen_loop /* No zero -> loop. */
98 vlgvb %r4,%v16,7 /* Load byte index of zero. */
103 %r1 = loaded bytes (tmp)
104 %r4 = zero byte index (tmp)
105 %r3 = curr src pointer
106 %r2 = curr dst pointer
108 la %r2,0(%r5,%r2) /* strcpy at end of dst-string. */
110 vlbb %v16,0(%r3),6 /* Load s until next 4k-byte boundary. */
111 lcbb %r1,0(%r3),6 /* Get bytes to 4k-byte boundary or 16. */
113 vfenezf %v17,%v16,%v16 /* Find element not equal with zero search. */
114 vlgvb %r5,%v17,7 /* Load zero index or 16 if not found. */
115 clrjl %r5,%r1,.Lcpy_found_align /* If found zero within loaded bytes,
116 copy bytes before and return. */
118 /* Align s to 16 byte. */
119 risbgn %r4,%r3,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15. */
120 lghi %r5,15 /* current_len = 15. */
121 slr %r5,%r4 /* Compute highest index to 16byte boundary. */
123 vstl %v16,%r5,0(%r2) /* Copy loaded characters - no zero. */
124 ahi %r5,1 /* Start loop at next character. */
126 /* Find zero in 16byte aligned loop. */
128 vl %v16,0(%r5,%r3) /* Load s. */
129 vfenezfs %v17,%v16,%v16 /* Find element not equal with zero search. */
130 je .Lcpy_found_v16_0 /* Jump away if zero was found. */
131 vl %v18,16(%r5,%r3) /* Load next part of s. */
132 vst %v16,0(%r5,%r2) /* Save previous part without zero to dst. */
133 vfenezfs %v17,%v18,%v18
134 je .Lcpy_found_v18_16
137 vfenezfs %v17,%v16,%v16
138 je .Lcpy_found_v16_32
141 vfenezfs %v17,%v18,%v18
142 je .Lcpy_found_v18_48
146 j .Lcpy_loop /* No zero -> loop. */
152 vlgvb %r1,%v17,7 /* Load byte index of zero. */
153 aghi %r1,3 /* Also copy remaining bytes of zero. */
154 vstl %v16,%r1,0(%r4) /* Copy characters including zero. */
155 lgr %r2,%r0 /* Load saved dest-ptr. */
162 vlgvb %r1,%v17,7 /* Load byte index of zero. */
163 aghi %r1,3 /* Also copy remaining bytes of zero. */
164 vstl %v18,%r1,0(%r4) /* Copy characters including zero. */
165 lgr %r2,%r0 /* Load saved dest-ptr. */
169 aghi %r5,3 /* Also copy remaining bytes of found zero. */
170 vstl %v16,%r5,0(%r2) /* Copy characters including zero. */
171 lgr %r2,%r0 /* Load saved dest-ptr. */
177 # if ! HAVE_WCSCAT_IFUNC
178 strong_alias (WCSCAT_Z13, __wcscat)
179 weak_alias (__wcscat, wcscat)