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