libdl: end must be bigger than start
[uclibc-ng.git] / libc / string / sparc / sparc32 / strcat.S
blobe968a18a3ac89cfdf0429b9822f4daecb5b8a903
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, see
19    <http://www.gnu.org/licenses/>.  */
21         /* Normally, this uses ((xword - 0x01010101) & 0x80808080) test
22            to find out if any byte in xword could be zero. This is fast, but
23            also gives false alarm for any byte in range 0x81-0xff. It does
24            not matter for correctness, as if this test tells us there could
25            be some zero byte, we check it byte by byte, but if bytes with
26            high bits set are common in the strings, then this will give poor
27            performance. You can #define EIGHTBIT_NOT_RARE and the algorithm
28            will use one tick slower, but more precise test
29            ((xword - 0x01010101) & (~xword) & 0x80808080),
30            which does not give any false alarms (but if some bits are set,
31            one cannot assume from it which bytes are zero and which are not).
32            It is yet to be measured, what is the correct default for glibc
33            in these days for an average user.
34          */
36         .text
37         .align          4
38 10:     cmp             %o4, 2
39         be              1f
40          cmp            %o4, 3
41         ldub            [%o1], %o5
42         add             %o1, 1, %o1
43         stb             %o5, [%o0]
44         be              3f
45          cmp            %o5, 0
46         be              0f
47          add            %o0, 1, %o0
48 1:      lduh            [%o1], %o5
49         add             %o1, 2, %o1
50         srl             %o5, 8, %o4
51         cmp             %o4, 0
52         stb             %o4, [%o0]
53         bne,a           2f
54          stb            %o5, [%o0 + 1]
55         retl
56          mov            %g2, %o0
57 2:      andcc           %o5, 0xff, %o5
58         bne             4f
59          add            %o0, 2, %o0
60         retl
61          mov            %g2, %o0
62 3:      bne             4f
63          add            %o0, 1, %o0
64         retl
65          mov            %g2, %o0
67 11:     ldub            [%o0], %o5
68         cmp             %o5, 0
69         be              1f
70          add            %o0, 1, %o0
71         andcc           %o0, 3, %g0
72         be              7f
73          or             %o4, %lo(0x80808080), %o3
74         ldub            [%o0], %o5
75         cmp             %o5, 0
76         be              2f
77          add            %o0, 1, %o0
78         andcc           %o0, 3, %g0
79         be              8f
80          sethi          %hi(0x01010101), %o4
81         ldub            [%o0], %o5
82         cmp             %o5, 0
83         be              3f
84          add            %o0, 1, %o0
85         b               9f
86          or             %o4, %lo(0x01010101), %o2
87 1:      or              %o4, %lo(0x80808080), %o3
88 2:      sethi           %hi(0x01010101), %o4
89 3:      or              %o4, %lo(0x01010101), %o2
90         b               3f
91          sub            %o0, 1, %o0
93 ENTRY(strcat)
94         mov             %o0, %g2
95         andcc           %o0, 3, %g0
96         bne             11b
97          sethi          %hi(0x80808080), %o4
98         or              %o4, %lo(0x80808080), %o3
99 7:      sethi           %hi(0x01010101), %o4
100 8:      or              %o4, %lo(0x01010101), %o2
101 9:      ld              [%o0], %o5
102 7:      sub             %o5, %o2, %o4
103 #ifdef EIGHTBIT_NOT_RARE
104         andn            %o4, %o5, %o4
105 #endif
106         andcc           %o4, %o3, %g0
107         be              9b
108          add            %o0, 4, %o0
110         srl             %o5, 24, %g5
111         andcc           %g5, 0xff, %g0
112         be              3f
113          add            %o0, -4, %o0
114         srl             %o5, 16, %g5
115         andcc           %g5, 0xff, %g0
116         be              3f
117          add            %o0, 1, %o0
118         srl             %o5, 8, %g5
119         andcc           %g5, 0xff, %g0
120         be              3f
121          add            %o0, 1, %o0
122         andcc           %o5, 0xff, %g0
123         add             %o0, 2, %o0
124         bne,a           7b
125          ld             [%o0], %o5
126         sub             %o0, 1, %o0
127 3:      andcc           %o1, 3, %o4
128         bne             10b
129 4:       andcc          %o0, 3, %g3
130         bne             12f
131 1:      ld              [%o1], %o5
132         add             %o1, 4, %o1
133         sub             %o5, %o2, %o4
134 #ifdef EIGHTBIT_NOT_RARE
135         andn            %o4, %o5, %o4
136 #endif
137         add             %o0, 4, %o0
138         andcc           %o4, %o3, %g0
139         be,a            1b
140          st             %o5, [%o0 - 4]
142         srl             %o5, 24, %g5
143         andcc           %g5, 0xff, %g0
144         be              1f
145          srl            %o5, 16, %g5
146         andcc           %g5, 0xff, %g0
147         be              2f
148          srl            %o5, 8, %g5
149         andcc           %g5, 0xff, %g0
150         be              3f
151          andcc          %o5, 0xff, %g0
152         bne             1b
153          st             %o5, [%o0 - 4]
154         retl
155          mov            %g2, %o0
156 3:      srl             %o5, 16, %o5
157         sth             %o5, [%o0 - 4]
158         stb             %g0, [%o0 - 2]
159         retl
160          mov            %g2, %o0
161 2:      srl             %o5, 16, %o5
162         sth             %o5, [%o0 - 4]
163         retl
164          mov            %g2, %o0
165 1:      stb             %g0, [%o0 - 4]
166         retl
167          mov            %g2, %o0
169 12:     add             %o1, 4, %o1
170         sub             %o5, %o2, %o4
171         cmp             %g3, 2
172         be              2f
173          cmp            %g3, 3
174         be              3f
175          andcc          %o4, %o3, %g0
176         bne             5f
177          srl            %o5, 24, %g5
178         stb             %g5, [%o0]
179         sub             %o0, 1, %o0
180         srl             %o5, 8, %g5
181         sth             %g5, [%o0 + 2]
182 1:      add             %o0, 4, %o0
183 4:      sll             %o5, 24, %g6
184         ld              [%o1], %o5
185         add             %o1, 4, %o1
186         srl             %o5, 8, %g5
187         sub             %o5, %o2, %o4
188 #ifdef EIGHTBIT_NOT_RARE
189         andn            %o4, %o5, %o4
190 #endif
191         or              %g5, %g6, %g5
192         andcc           %o4, %o3, %g0
193         be,a            1b
194          st             %g5, [%o0]
195         srl             %o5, 24, %o4
196         andcc           %o4, 0xff, %g0
197         be              6f
198          srl            %o5, 16, %o4
199         andcc           %o4, 0xff, %g0
200         be              7f
201          srl            %o5, 8, %o4
202         st              %g5, [%o0]
203         andcc           %o4, 0xff, %g0
204         be              0f
205          andcc          %o5, 0xff, %g0
206 1:      bne             4b
207          add            %o0, 4, %o0
208 9:      stb             %g0, [%o0]
209 0:      retl
210          mov            %g2, %o0
212 6:      srl             %g5, 16, %g5
213         sth             %g5, [%o0]
214         retl
215          mov            %g2, %o0
217 7:      srl             %g5, 16, %g5
218         sth             %g5, [%o0]
219         stb             %g0, [%o0 + 2]
220         retl
221          mov            %g2, %o0
223 5:      andcc           %g5, 0xff, %g4
224         be              9b
225          srl            %o5, 16, %g5
226         andcc           %g5, 0xff, %g0
227         be              7f
228          srl            %o5, 8, %g5
229         andcc           %g5, 0xff, %g0
230         stb             %g4, [%o0]
231         sth             %g5, [%o0 + 1]
232         sub             %o0, 1, %o0
233         bne             1b
234          andcc          %o5, 0xff, %g0
235         retl
236          mov            %g2, %o0
238 7:      stb             %g4, [%o0]
239         stb             %g0, [%o0 + 1]
240         retl
241          mov            %g2, %o0
243 2:      andcc           %o4, %o3, %g0
244         bne             5f
245          srl            %o5, 16, %g5
246         sth             %g5, [%o0]
247         sub             %o0, 2, %o0
248 1:      add             %o0, 4, %o0
249 4:      sll             %o5, 16, %g6
250         ld              [%o1], %o5
251         add             %o1, 4, %o1
252         srl             %o5, 16, %g5
253         sub             %o5, %o2, %o4
254 #ifdef EIGHTBIT_NOT_RARE
255         andn            %o4, %o5, %o4
256 #endif
257         or              %g5, %g6, %g5
258         andcc           %o4, %o3, %g0
259         be,a            1b
260          st             %g5, [%o0]
261         srl             %o5, 24, %o4
262         andcc           %o4, 0xff, %g0
263         be              7f
264          srl            %o5, 16, %o4
265         st              %g5, [%o0]
266         andcc           %o4, 0xff, %g0
267         be              0b
268          srl            %o5, 8, %o4
269 1:      andcc           %o4, 0xff, %g0
270         be              8f
271          andcc          %o5, 0xff, %g0
272         bne             4b
273          add            %o0, 4, %o0
274         sth             %o5, [%o0]
275         retl
276          mov            %g2, %o0
278 7:      srl             %g5, 16, %g5
279         sth             %g5, [%o0]
280         stb             %g0, [%o0 + 2]
281         retl
282          mov            %g2, %o0
284 8:      stb             %g0, [%o0 + 4]
285         retl
286          mov            %g2, %o0
288 5:      srl             %o5, 24, %g5
289         andcc           %g5, 0xff, %g0
290         be              9b
291          srl            %o5, 16, %g5
292         andcc           %g5, 0xff, %g0
293         sth             %g5, [%o0]
294         sub             %o0, 2, %o0
295         bne             1b
296          srl            %o5, 8, %o4
297         retl
298          mov            %g2, %o0
300 3:      bne             5f
301          srl            %o5, 24, %g5
302         stb             %g5, [%o0]
303         sub             %o0, 3, %o0
304 1:      add             %o0, 4, %o0
305 4:      sll             %o5, 8, %g6
306         ld              [%o1], %o5
307         add             %o1, 4, %o1
308         srl             %o5, 24, %g5
309         sub             %o5, %o2, %o4
310 #ifdef EIGHTBIT_NOT_RARE
311         andn            %o4, %o5, %o4
312 #endif
313         or              %g5, %g6, %g5
314         andcc           %o4, %o3, %g0
315         be              1b
316          st             %g5, [%o0]
317         srl             %o5, 24, %o4
318         andcc           %o4, 0xff, %g0
319         be              0b
320          srl            %o5, 16, %o4
321 1:      andcc           %o4, 0xff, %g0
322         be              8b
323          srl            %o5, 8, %o4
324         andcc           %o4, 0xff, %g0
325         be              9f
326          andcc          %o5, 0xff, %g0
327         bne             4b
328          add            %o0, 4, %o0
329         srl             %o5, 8, %o5
330         sth             %o5, [%o0]
331         stb             %g0, [%o0 + 2]
332         retl
333          mov            %g2, %o0
334 9:      srl             %o5, 8, %o5
335         sth             %o5, [%o0 + 4]
336         retl
337          mov            %g2, %o0
338 5:      andcc           %g5, 0xff, %g0
339         stb             %g5, [%o0]
340         sub             %o0, 3, %o0
341         bne             1b
342          srl            %o5, 16, %o4
343         retl
344          mov            %g2, %o0
345 END(strcat)
347 libc_hidden_def(strcat)