(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / sysdeps / sparc / sparc32 / strcat.S
blob3709c8a69202b9469c100a0922ef81a478d8ef26
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
41 10:     cmp             %o4, 2
42         be              1f
43          cmp            %o4, 3
44         ldub            [%o1], %o5
45         add             %o1, 1, %o1
46         stb             %o5, [%o0]
47         be              3f
48          cmp            %o5, 0
49         be              0f
50          add            %o0, 1, %o0
51 1:      lduh            [%o1], %o5
52         add             %o1, 2, %o1
53         srl             %o5, 8, %o4
54         cmp             %o4, 0
55         stb             %o4, [%o0]
56         bne,a           2f
57          stb            %o5, [%o0 + 1]
58         retl
59          mov            %g2, %o0
60 2:      andcc           %o5, 0xff, %o5
61         bne             4f
62          add            %o0, 2, %o0
63         retl
64          mov            %g2, %o0
65 3:      bne             4f
66          add            %o0, 1, %o0
67         retl
68          mov            %g2, %o0
70 11:     ldub            [%o0], %o5
71         cmp             %o5, 0
72         be              1f
73          add            %o0, 1, %o0
74         andcc           %o0, 3, %g0
75         be              7f
76          or             %o4, %lo(0x80808080), %o3
77         ldub            [%o0], %o5
78         cmp             %o5, 0
79         be              2f
80          add            %o0, 1, %o0
81         andcc           %o0, 3, %g0
82         be              8f
83          sethi          %hi(0x01010101), %o4
84         ldub            [%o0], %o5
85         cmp             %o5, 0
86         be              3f
87          add            %o0, 1, %o0
88         b               9f
89          or             %o4, %lo(0x01010101), %o2
90 1:      or              %o4, %lo(0x80808080), %o3
91 2:      sethi           %hi(0x01010101), %o4
92 3:      or              %o4, %lo(0x01010101), %o2
93         b               3f
94          sub            %o0, 1, %o0
96 ENTRY(strcat)
97         mov             %o0, %g2
98         andcc           %o0, 3, %g0
99         bne             11b
100          sethi          %hi(0x80808080), %o4
101         or              %o4, %lo(0x80808080), %o3
102 7:      sethi           %hi(0x01010101), %o4
103 8:      or              %o4, %lo(0x01010101), %o2
104 9:      ld              [%o0], %o5
105 7:      sub             %o5, %o2, %o4
106 #ifdef EIGHTBIT_NOT_RARE
107         andn            %o4, %o5, %o4
108 #endif
109         andcc           %o4, %o3, %g0
110         be              9b
111          add            %o0, 4, %o0
113         srl             %o5, 24, %g5
114         andcc           %g5, 0xff, %g0
115         be              3f
116          add            %o0, -4, %o0
117         srl             %o5, 16, %g5
118         andcc           %g5, 0xff, %g0
119         be              3f
120          add            %o0, 1, %o0
121         srl             %o5, 8, %g5
122         andcc           %g5, 0xff, %g0
123         be              3f
124          add            %o0, 1, %o0
125         andcc           %o5, 0xff, %g0
126         add             %o0, 2, %o0
127         bne,a           7b
128          ld             [%o0], %o5
129         sub             %o0, 1, %o0
130 3:      andcc           %o1, 3, %o4
131         bne             10b
132 4:       andcc          %o0, 3, %g3
133         bne             12f
134 1:      ld              [%o1], %o5
135         add             %o1, 4, %o1
136         sub             %o5, %o2, %o4
137 #ifdef EIGHTBIT_NOT_RARE
138         andn            %o4, %o5, %o4
139 #endif
140         add             %o0, 4, %o0
141         andcc           %o4, %o3, %g0
142         be,a            1b
143          st             %o5, [%o0 - 4]
145         srl             %o5, 24, %g5
146         andcc           %g5, 0xff, %g0
147         be              1f
148          srl            %o5, 16, %g5
149         andcc           %g5, 0xff, %g0
150         be              2f
151          srl            %o5, 8, %g5
152         andcc           %g5, 0xff, %g0
153         be              3f
154          andcc          %o5, 0xff, %g0
155         bne             1b
156          st             %o5, [%o0 - 4]
157         retl
158          mov            %g2, %o0
159 3:      srl             %o5, 16, %o5
160         sth             %o5, [%o0 - 4]
161         stb             %g0, [%o0 - 2]
162         retl
163          mov            %g2, %o0
164 2:      srl             %o5, 16, %o5
165         sth             %o5, [%o0 - 4]
166         retl
167          mov            %g2, %o0
168 1:      stb             %g0, [%o0 - 4]
169         retl
170          mov            %g2, %o0
172 12:     add             %o1, 4, %o1
173         sub             %o5, %o2, %o4
174         cmp             %g3, 2
175         be              2f
176          cmp            %g3, 3
177         be              3f
178          andcc          %o4, %o3, %g0
179         bne             5f
180          srl            %o5, 24, %g5
181         stb             %g5, [%o0]
182         sub             %o0, 1, %o0
183         srl             %o5, 8, %g5
184         sth             %g5, [%o0 + 2]
185 1:      add             %o0, 4, %o0
186 4:      sll             %o5, 24, %g6
187         ld              [%o1], %o5
188         add             %o1, 4, %o1
189         srl             %o5, 8, %g5
190         sub             %o5, %o2, %o4
191 #ifdef EIGHTBIT_NOT_RARE
192         andn            %o4, %o5, %o4
193 #endif
194         or              %g5, %g6, %g5
195         andcc           %o4, %o3, %g0
196         be,a            1b
197          st             %g5, [%o0]
198         srl             %o5, 24, %o4
199         andcc           %o4, 0xff, %g0
200         be              6f
201          srl            %o5, 16, %o4
202         andcc           %o4, 0xff, %g0
203         be              7f
204          srl            %o5, 8, %o4
205         st              %g5, [%o0]
206         andcc           %o4, 0xff, %g0
207         be              0f
208          andcc          %o5, 0xff, %g0
209 1:      bne             4b
210          add            %o0, 4, %o0
211 9:      stb             %g0, [%o0]
212 0:      retl
213          mov            %g2, %o0
215 6:      srl             %g5, 16, %g5
216         sth             %g5, [%o0]
217         retl
218          mov            %g2, %o0
220 7:      srl             %g5, 16, %g5
221         sth             %g5, [%o0]
222         stb             %g0, [%o0 + 2]
223         retl
224          mov            %g2, %o0
226 5:      andcc           %g5, 0xff, %g4
227         be              9b
228          srl            %o5, 16, %g5
229         andcc           %g5, 0xff, %g0
230         be              7f
231          srl            %o5, 8, %g5
232         andcc           %g5, 0xff, %g0
233         stb             %g4, [%o0]
234         sth             %g5, [%o0 + 1]
235         sub             %o0, 1, %o0
236         bne             1b
237          andcc          %o5, 0xff, %g0
238         retl
239          mov            %g2, %o0
241 7:      stb             %g4, [%o0]
242         stb             %g0, [%o0 + 1]
243         retl
244          mov            %g2, %o0
246 2:      andcc           %o4, %o3, %g0
247         bne             5f
248          srl            %o5, 16, %g5
249         sth             %g5, [%o0]
250         sub             %o0, 2, %o0
251 1:      add             %o0, 4, %o0
252 4:      sll             %o5, 16, %g6
253         ld              [%o1], %o5
254         add             %o1, 4, %o1
255         srl             %o5, 16, %g5
256         sub             %o5, %o2, %o4
257 #ifdef EIGHTBIT_NOT_RARE
258         andn            %o4, %o5, %o4
259 #endif
260         or              %g5, %g6, %g5
261         andcc           %o4, %o3, %g0
262         be,a            1b
263          st             %g5, [%o0]
264         srl             %o5, 24, %o4
265         andcc           %o4, 0xff, %g0
266         be              7f
267          srl            %o5, 16, %o4
268         st              %g5, [%o0]
269         andcc           %o4, 0xff, %g0
270         be              0b
271          srl            %o5, 8, %o4
272 1:      andcc           %o4, 0xff, %g0
273         be              8f
274          andcc          %o5, 0xff, %g0
275         bne             4b
276          add            %o0, 4, %o0
277         sth             %o5, [%o0]
278         retl
279          mov            %g2, %o0
281 7:      srl             %g5, 16, %g5
282         sth             %g5, [%o0]
283         stb             %g0, [%o0 + 2]
284         retl
285          mov            %g2, %o0
287 8:      stb             %g0, [%o0 + 4]
288         retl
289          mov            %g2, %o0
291 5:      srl             %o5, 24, %g5
292         andcc           %g5, 0xff, %g0
293         be              9b
294          srl            %o5, 16, %g5
295         andcc           %g5, 0xff, %g0
296         sth             %g5, [%o0]
297         sub             %o0, 2, %o0
298         bne             1b
299          srl            %o5, 8, %o4
300         retl
301          mov            %g2, %o0
303 3:      bne             5f
304          srl            %o5, 24, %g5
305         stb             %g5, [%o0]
306         sub             %o0, 3, %o0
307 1:      add             %o0, 4, %o0
308 4:      sll             %o5, 8, %g6
309         ld              [%o1], %o5
310         add             %o1, 4, %o1
311         srl             %o5, 24, %g5
312         sub             %o5, %o2, %o4
313 #ifdef EIGHTBIT_NOT_RARE
314         andn            %o4, %o5, %o4
315 #endif
316         or              %g5, %g6, %g5
317         andcc           %o4, %o3, %g0
318         be              1b
319          st             %g5, [%o0]
320         srl             %o5, 24, %o4
321         andcc           %o4, 0xff, %g0
322         be              0b
323          srl            %o5, 16, %o4
324 1:      andcc           %o4, 0xff, %g0
325         be              8b
326          srl            %o5, 8, %o4
327         andcc           %o4, 0xff, %g0
328         be              9f
329          andcc          %o5, 0xff, %g0
330         bne             4b
331          add            %o0, 4, %o0
332         srl             %o5, 8, %o5
333         sth             %o5, [%o0]
334         stb             %g0, [%o0 + 2]
335         retl
336          mov            %g2, %o0
337 9:      srl             %o5, 8, %o5
338         sth             %o5, [%o0 + 4]
339         retl
340          mov            %g2, %o0
341 5:      andcc           %g5, 0xff, %g0
342         stb             %g5, [%o0]
343         sub             %o0, 3, %o0
344         bne             1b
345          srl            %o5, 16, %o4
346         retl
347          mov            %g2, %o0
348 END(strcat)
349 libc_hidden_builtin_def (strcat)