1 | /* Vector optimized 32/64 bit S/390 version of strcat. |
2 | Copyright (C) 2015-2022 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. |
4 | |
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. |
9 | |
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. |
14 | |
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/>. */ |
18 | |
19 | #include <ifunc-strcat.h> |
20 | #if HAVE_STRCAT_Z13 |
21 | |
22 | # include "sysdep.h" |
23 | # include "asm-syntax.h" |
24 | |
25 | .text |
26 | |
27 | /* char * strcat (const char *dest, const char *src) |
28 | Concatenate two strings. |
29 | |
30 | Register usage: |
31 | -r0=saved dest pointer for return |
32 | -r1=tmp |
33 | -r2=dest |
34 | -r3=src |
35 | -r4=tmp |
36 | -r5=current_len |
37 | -v16=part of src |
38 | -v17=index of zero |
39 | -v18=part of src |
40 | */ |
41 | ENTRY(STRCAT_Z13) |
42 | .machine "z13" |
43 | .machinemode "zarch_nohighgprs" |
44 | |
45 | lgr %r0,%r2 /* Save destination pointer for return. */ |
46 | |
47 | /* STRLEN |
48 | r1 = loaded bytes (tmp) |
49 | r4 = zero byte index (tmp) |
50 | r2 = dst |
51 | */ |
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. */ |
54 | |
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. */ |
58 | |
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. */ |
63 | |
64 | /* Find zero in 16byte aligned loop. */ |
65 | .Llen_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. */ |
69 | vl %v16,16(%r5,%r2) |
70 | vfenezbs %v16,%v16,%v16 |
71 | je .Llen_found16 |
72 | vl %v16,32(%r5,%r2) |
73 | vfenezbs %v16,%v16,%v16 |
74 | je .Llen_found32 |
75 | vl %v16,48(%r5,%r2) |
76 | vfenezbs %v16,%v16,%v16 |
77 | je .Llen_found48 |
78 | |
79 | aghi %r5,64 |
80 | j .Llen_loop /* No zero -> loop. */ |
81 | |
82 | .Llen_found48: |
83 | aghi %r5,16 |
84 | .Llen_found32: |
85 | aghi %r5,16 |
86 | .Llen_found16: |
87 | aghi %r5,16 |
88 | .Llen_found: |
89 | vlgvb %r4,%v16,7 /* Load byte index of zero. */ |
90 | algr %r5,%r4 |
91 | |
92 | .Llen_end: |
93 | /* STRCPY |
94 | %r1 = loaded bytes (tmp) |
95 | %r4 = zero byte index (tmp) |
96 | %r3 = curr src pointer |
97 | %r2 = curr dst pointer |
98 | */ |
99 | la %r2,0(%r5,%r2) /* strcpy at end of dst-string. */ |
100 | |
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. */ |
103 | |
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. */ |
108 | |
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. */ |
113 | |
114 | vstl %v16,%r5,0(%r2) /* Copy loaded characters - no zero. */ |
115 | ahi %r5,1 /* Start loop at next character. */ |
116 | |
117 | /* Find zero in 16byte aligned loop. */ |
118 | .Lcpy_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 |
126 | vl %v16,32(%r5,%r3) |
127 | vst %v18,16(%r5,%r2) |
128 | vfenezbs %v17,%v16,%v16 |
129 | je .Lcpy_found_v16_32 |
130 | vl %v18,48(%r5,%r3) |
131 | vst %v16,32(%r5,%r2) |
132 | vfenezbs %v17,%v18,%v18 |
133 | je .Lcpy_found_v18_48 |
134 | vst %v18,48(%r5,%r2) |
135 | |
136 | aghi %r5,64 |
137 | j .Lcpy_loop /* No zero -> loop. */ |
138 | |
139 | .Lcpy_found_v16_32: |
140 | aghi %r5,32 |
141 | .Lcpy_found_v16_0: |
142 | la %r4,0(%r5,%r2) |
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. */ |
146 | br %r14 |
147 | |
148 | .Lcpy_found_v18_48: |
149 | aghi %r5,32 |
150 | .Lcpy_found_v18_16: |
151 | la %r4,16(%r5,%r2) |
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. */ |
155 | br %r14 |
156 | |
157 | .Lcpy_found_align: |
158 | vstl %v16,%r5,0(%r2) /* Copy characters including zero. */ |
159 | lgr %r2,%r0 /* Load saved dest-ptr. */ |
160 | br %r14 |
161 | END(STRCAT_Z13) |
162 | |
163 | # if ! HAVE_STRCAT_IFUNC |
164 | strong_alias (STRCAT_Z13, strcat) |
165 | # endif |
166 | |
167 | # if ! HAVE_STRCAT_C && defined SHARED && IS_IN (libc) |
168 | strong_alias (STRCAT_Z13, __GI_strcat) |
169 | # endif |
170 | #endif |
171 | |