1 /* Vector optimized 32/64 bit S/390 version of strcat.
2 Copyright (C) 2015-2023 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-strcat.h>
23 # include "asm-syntax.h"
27 /* char * strcat (const char *dest, const char *src)
28 Concatenate two strings.
31 -r0=saved dest pointer for return
43 .machinemode "zarch_nohighgprs"
45 lgr %r0,%r2 /* Save destination pointer for return. */
48 r1 = loaded bytes (tmp)
49 r4 = zero byte index (tmp)
52 vlbb %v16,0(%r2),6 /* Load s until next 4k-byte boundary. */
53 lcbb %r1,0(%r2),6 /* Get bytes to 4k-byte boundary or 16. */
55 vfenezb %v16,%v16,%v16 /* Find element not equal with zero search. */
56 vlgvb %r5,%v16,7 /* Load zero index or 16 if not found. */
57 clrjl %r5,%r1,.Llen_end /* Found zero within loaded bytes, end. */
59 /* Align s to 16 byte. */
60 risbgn %r1,%r2,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15. */
61 lghi %r5,16 /* current_len = 16. */
62 slr %r5,%r1 /* Compute bytes to 16bytes boundary. */
64 /* Find zero in 16byte aligned loop. */
66 vl %v16,0(%r5,%r2) /* Load s. */
67 vfenezbs %v16,%v16,%v16 /* Find element not equal with zero search. */
68 je .Llen_found /* Jump away if zero was found. */
70 vfenezbs %v16,%v16,%v16
73 vfenezbs %v16,%v16,%v16
76 vfenezbs %v16,%v16,%v16
80 j .Llen_loop /* No zero -> loop. */
89 vlgvb %r4,%v16,7 /* Load byte index of zero. */
94 %r1 = loaded bytes (tmp)
95 %r4 = zero byte index (tmp)
96 %r3 = curr src pointer
97 %r2 = curr dst pointer
99 la %r2,0(%r5,%r2) /* strcpy at end of dst-string. */
101 vlbb %v16,0(%r3),6 /* Load s until next 4k-byte boundary. */
102 lcbb %r1,0(%r3),6 /* Get bytes to 4k-byte boundary or 16. */
104 vfenezb %v17,%v16,%v16 /* Find element not equal with zero search. */
105 vlgvb %r5,%v17,7 /* Load zero index or 16 if not found. */
106 clrjl %r5,%r1,.Lcpy_found_align /* If found zero within loaded bytes,
107 copy bytes before and return. */
109 /* Align s to 16 byte. */
110 risbgn %r4,%r3,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15. */
111 lghi %r5,15 /* current_len = 15. */
112 slr %r5,%r4 /* Compute highest index to 16byte boundary. */
114 vstl %v16,%r5,0(%r2) /* Copy loaded characters - no zero. */
115 ahi %r5,1 /* Start loop at next character. */
117 /* Find zero in 16byte aligned loop. */
119 vl %v16,0(%r5,%r3) /* Load s. */
120 vfenezbs %v17,%v16,%v16 /* Find element not equal with zero search. */
121 je .Lcpy_found_v16_0 /* Jump away if zero was found. */
122 vl %v18,16(%r5,%r3)/* Load next part of s. */
123 vst %v16,0(%r5,%r2) /* Store previous part without zero to dst. */
124 vfenezbs %v17,%v18,%v18
125 je .Lcpy_found_v18_16
128 vfenezbs %v17,%v16,%v16
129 je .Lcpy_found_v16_32
132 vfenezbs %v17,%v18,%v18
133 je .Lcpy_found_v18_48
137 j .Lcpy_loop /* No zero -> loop. */
143 vlgvb %r1,%v17,7 /* Load byte index of zero. */
144 vstl %v16,%r1,0(%r4) /* Copy characters including zero. */
145 lgr %r2,%r0 /* Load saved dest-ptr. */
152 vlgvb %r1,%v17,7 /* Load byte index of zero. */
153 vstl %v18,%r1,0(%r4) /* Copy characters including zero. */
154 lgr %r2,%r0 /* Load saved dest-ptr. */
158 vstl %v16,%r5,0(%r2) /* Copy characters including zero. */
159 lgr %r2,%r0 /* Load saved dest-ptr. */
163 # if ! HAVE_STRCAT_IFUNC
164 strong_alias (STRCAT_Z13, strcat)
167 # if ! HAVE_STRCAT_C && defined SHARED && IS_IN (libc)
168 strong_alias (STRCAT_Z13, __GI_strcat)