]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/sparc/sparc32/strcat.S
dcd660788ce4b8f24226d1b626ca870bf39a5d25
[thirdparty/glibc.git] / sysdeps / sparc / sparc32 / strcat.S
1 /* strcat (dest, src) -- Append SRC on the end of DEST.
2 For SPARC v7.
3 Copyright (C) 1996-2019 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5 Contributed by Jakub Jelinek <jj@ultra.linux.cz>.
6
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, see
19 <http://www.gnu.org/licenses/>. */
20
21 #include <sysdep.h>
22
23 /* Normally, this uses ((xword - 0x01010101) & 0x80808080) test
24 to find out if any byte in xword could be zero. This is fast, but
25 also gives false alarm for any byte in range 0x81-0xff. It does
26 not matter for correctness, as if this test tells us there could
27 be some zero byte, we check it byte by byte, but if bytes with
28 high bits set are common in the strings, then this will give poor
29 performance. You can #define EIGHTBIT_NOT_RARE and the algorithm
30 will use one tick slower, but more precise test
31 ((xword - 0x01010101) & (~xword) & 0x80808080),
32 which does not give any false alarms (but if some bits are set,
33 one cannot assume from it which bytes are zero and which are not).
34 It is yet to be measured, what is the correct default for glibc
35 in these days for an average user.
36 */
37
38 .text
39 .align 4
40
41 ENTRY(strcat)
42 mov %o0, %g2
43 andcc %o0, 3, %g0
44 be 30f
45 sethi %hi(0x80808080), %o4
46
47 ldub [%o0], %o5
48 cmp %o5, 0
49 be 1f
50 add %o0, 1, %o0
51 andcc %o0, 3, %g0
52 be 7f
53 or %o4, %lo(0x80808080), %o3
54 ldub [%o0], %o5
55 cmp %o5, 0
56 be 2f
57 add %o0, 1, %o0
58 andcc %o0, 3, %g0
59 be 8f
60 sethi %hi(0x01010101), %o4
61 ldub [%o0], %o5
62 cmp %o5, 0
63 be 3f
64 add %o0, 1, %o0
65 b 9f
66 or %o4, %lo(0x01010101), %o2
67 1: or %o4, %lo(0x80808080), %o3
68 2: sethi %hi(0x01010101), %o4
69 3: or %o4, %lo(0x01010101), %o2
70 b 3f
71 sub %o0, 1, %o0
72
73 30: or %o4, %lo(0x80808080), %o3
74 7: sethi %hi(0x01010101), %o4
75 8: or %o4, %lo(0x01010101), %o2
76 9: ld [%o0], %o5
77 7: sub %o5, %o2, %o4
78 #ifdef EIGHTBIT_NOT_RARE
79 andn %o4, %o5, %o4
80 #endif
81 andcc %o4, %o3, %g0
82 be 9b
83 add %o0, 4, %o0
84
85 srl %o5, 24, %g5
86 andcc %g5, 0xff, %g0
87 be 3f
88 add %o0, -4, %o0
89 srl %o5, 16, %g5
90 andcc %g5, 0xff, %g0
91 be 3f
92 add %o0, 1, %o0
93 srl %o5, 8, %g5
94 andcc %g5, 0xff, %g0
95 be 3f
96 add %o0, 1, %o0
97 andcc %o5, 0xff, %g0
98 add %o0, 2, %o0
99 bne,a 7b
100 ld [%o0], %o5
101 sub %o0, 1, %o0
102 3: andcc %o1, 3, %o4
103 be 4f
104 nop
105
106 cmp %o4, 2
107 be 11f
108 cmp %o4, 3
109 ldub [%o1], %o5
110 add %o1, 1, %o1
111 stb %o5, [%o0]
112 be 13f
113 cmp %o5, 0
114 be 0f
115 add %o0, 1, %o0
116 11: lduh [%o1], %o5
117 add %o1, 2, %o1
118 srl %o5, 8, %o4
119 cmp %o4, 0
120 stb %o4, [%o0]
121 bne,a 12f
122 stb %o5, [%o0 + 1]
123 retl
124 mov %g2, %o0
125 12: andcc %o5, 0xff, %o5
126 bne 4f
127 add %o0, 2, %o0
128 retl
129 mov %g2, %o0
130 13: bne 4f
131 add %o0, 1, %o0
132 retl
133 mov %g2, %o0
134
135 4: andcc %o0, 3, %g3
136 bne 12f
137 1: ld [%o1], %o5
138 add %o1, 4, %o1
139 sub %o5, %o2, %o4
140 #ifdef EIGHTBIT_NOT_RARE
141 andn %o4, %o5, %o4
142 #endif
143 add %o0, 4, %o0
144 andcc %o4, %o3, %g0
145 be,a 1b
146 st %o5, [%o0 - 4]
147
148 srl %o5, 24, %g5
149 andcc %g5, 0xff, %g0
150 be 1f
151 srl %o5, 16, %g5
152 andcc %g5, 0xff, %g0
153 be 2f
154 srl %o5, 8, %g5
155 andcc %g5, 0xff, %g0
156 be 3f
157 andcc %o5, 0xff, %g0
158 bne 1b
159 st %o5, [%o0 - 4]
160 retl
161 mov %g2, %o0
162 3: srl %o5, 16, %o5
163 sth %o5, [%o0 - 4]
164 stb %g0, [%o0 - 2]
165 retl
166 mov %g2, %o0
167 2: srl %o5, 16, %o5
168 sth %o5, [%o0 - 4]
169 retl
170 mov %g2, %o0
171 1: stb %g0, [%o0 - 4]
172 retl
173 mov %g2, %o0
174
175 12: add %o1, 4, %o1
176 sub %o5, %o2, %o4
177 cmp %g3, 2
178 be 2f
179 cmp %g3, 3
180 be 3f
181 andcc %o4, %o3, %g0
182 bne 5f
183 srl %o5, 24, %g5
184 stb %g5, [%o0]
185 sub %o0, 1, %o0
186 srl %o5, 8, %g5
187 sth %g5, [%o0 + 2]
188 1: add %o0, 4, %o0
189 4: sll %o5, 24, %g6
190 ld [%o1], %o5
191 add %o1, 4, %o1
192 srl %o5, 8, %g5
193 sub %o5, %o2, %o4
194 #ifdef EIGHTBIT_NOT_RARE
195 andn %o4, %o5, %o4
196 #endif
197 or %g5, %g6, %g5
198 andcc %o4, %o3, %g0
199 be,a 1b
200 st %g5, [%o0]
201 srl %o5, 24, %o4
202 andcc %o4, 0xff, %g0
203 be 6f
204 srl %o5, 16, %o4
205 andcc %o4, 0xff, %g0
206 be 7f
207 srl %o5, 8, %o4
208 st %g5, [%o0]
209 andcc %o4, 0xff, %g0
210 be 0f
211 andcc %o5, 0xff, %g0
212 1: bne 4b
213 add %o0, 4, %o0
214 9: stb %g0, [%o0]
215 0: retl
216 mov %g2, %o0
217
218 6: srl %g5, 16, %g5
219 sth %g5, [%o0]
220 retl
221 mov %g2, %o0
222
223 7: srl %g5, 16, %g5
224 sth %g5, [%o0]
225 stb %g0, [%o0 + 2]
226 retl
227 mov %g2, %o0
228
229 5: andcc %g5, 0xff, %g4
230 be 9b
231 srl %o5, 16, %g5
232 andcc %g5, 0xff, %g0
233 be 7f
234 srl %o5, 8, %g5
235 andcc %g5, 0xff, %g0
236 stb %g4, [%o0]
237 sth %g5, [%o0 + 1]
238 sub %o0, 1, %o0
239 bne 1b
240 andcc %o5, 0xff, %g0
241 retl
242 mov %g2, %o0
243
244 7: stb %g4, [%o0]
245 stb %g0, [%o0 + 1]
246 retl
247 mov %g2, %o0
248
249 2: andcc %o4, %o3, %g0
250 bne 5f
251 srl %o5, 16, %g5
252 sth %g5, [%o0]
253 sub %o0, 2, %o0
254 1: add %o0, 4, %o0
255 4: sll %o5, 16, %g6
256 ld [%o1], %o5
257 add %o1, 4, %o1
258 srl %o5, 16, %g5
259 sub %o5, %o2, %o4
260 #ifdef EIGHTBIT_NOT_RARE
261 andn %o4, %o5, %o4
262 #endif
263 or %g5, %g6, %g5
264 andcc %o4, %o3, %g0
265 be,a 1b
266 st %g5, [%o0]
267 srl %o5, 24, %o4
268 andcc %o4, 0xff, %g0
269 be 7f
270 srl %o5, 16, %o4
271 st %g5, [%o0]
272 andcc %o4, 0xff, %g0
273 be 0b
274 srl %o5, 8, %o4
275 1: andcc %o4, 0xff, %g0
276 be 8f
277 andcc %o5, 0xff, %g0
278 bne 4b
279 add %o0, 4, %o0
280 sth %o5, [%o0]
281 retl
282 mov %g2, %o0
283
284 7: srl %g5, 16, %g5
285 sth %g5, [%o0]
286 stb %g0, [%o0 + 2]
287 retl
288 mov %g2, %o0
289
290 8: stb %g0, [%o0 + 4]
291 retl
292 mov %g2, %o0
293
294 5: srl %o5, 24, %g5
295 andcc %g5, 0xff, %g0
296 be 9b
297 srl %o5, 16, %g5
298 andcc %g5, 0xff, %g0
299 sth %g5, [%o0]
300 sub %o0, 2, %o0
301 bne 1b
302 srl %o5, 8, %o4
303 retl
304 mov %g2, %o0
305
306 3: bne 5f
307 srl %o5, 24, %g5
308 stb %g5, [%o0]
309 sub %o0, 3, %o0
310 1: add %o0, 4, %o0
311 4: sll %o5, 8, %g6
312 ld [%o1], %o5
313 add %o1, 4, %o1
314 srl %o5, 24, %g5
315 sub %o5, %o2, %o4
316 #ifdef EIGHTBIT_NOT_RARE
317 andn %o4, %o5, %o4
318 #endif
319 or %g5, %g6, %g5
320 andcc %o4, %o3, %g0
321 be 1b
322 st %g5, [%o0]
323 srl %o5, 24, %o4
324 andcc %o4, 0xff, %g0
325 be 0b
326 srl %o5, 16, %o4
327 1: andcc %o4, 0xff, %g0
328 be 8b
329 srl %o5, 8, %o4
330 andcc %o4, 0xff, %g0
331 be 9f
332 andcc %o5, 0xff, %g0
333 bne 4b
334 add %o0, 4, %o0
335 srl %o5, 8, %o5
336 sth %o5, [%o0]
337 stb %g0, [%o0 + 2]
338 retl
339 mov %g2, %o0
340 9: srl %o5, 8, %o5
341 sth %o5, [%o0 + 4]
342 retl
343 mov %g2, %o0
344 5: andcc %g5, 0xff, %g0
345 stb %g5, [%o0]
346 sub %o0, 3, %o0
347 bne 1b
348 srl %o5, 16, %o4
349 retl
350 mov %g2, %o0
351 END(strcat)
352 libc_hidden_builtin_def (strcat)