(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / sysdeps / sparc / sparc32 / strcpy.S
blob787ac9f7c81186f0eb1f3148c098c3bfdb0634e8
1 /* Copy SRC to DEST returning 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 1:      ldub            [%o1], %o5
42         stb             %o5, [%o0]
43         cmp             %o5, 0
44         add             %o0, 1, %o0
45         be              0f
46          add            %o1, 1, %o1
47         andcc           %o1, 3, %g0
48         be              4f
49          or             %o4, %lo(0x80808080), %o3
50         ldub            [%o1], %o5
51         stb             %o5, [%o0]
52         cmp             %o5, 0
53         add             %o0, 1, %o0
54         be              0f
55          add            %o1, 1, %o1
56         andcc           %o1, 3, %g0
57         be              5f
58          sethi          %hi(0x01010101), %o4
59         ldub            [%o1], %o5
60         stb             %o5, [%o0]
61         cmp             %o5, 0
62         add             %o0, 1, %o0
63         be              0f
64          add            %o1, 1, %o1
65         b               6f
66          andcc          %o0, 3, %g3
68 ENTRY(strcpy)
69         mov             %o0, %g2
70         andcc           %o1, 3, %g0
71         bne             1b
72          sethi          %hi(0x80808080), %o4
73         or              %o4, %lo(0x80808080), %o3
74 4:      sethi           %hi(0x01010101), %o4
75 5:      andcc           %o0, 3, %g3
76 6:      bne             10f
77          or             %o4, %lo(0x01010101), %o2
78 1:      ld              [%o1], %o5
79         add             %o1, 4, %o1
80         sub             %o5, %o2, %o4
81         add             %o0, 4, %o0
82         andcc           %o4, %o3, %g0
83         be,a            1b
84          st             %o5, [%o0 - 4]
86         srl             %o5, 24, %g5
87         andcc           %g5, 0xff, %g0
88         be              1f
89          srl            %o5, 16, %g5
90         andcc           %g5, 0xff, %g0
91         be              2f
92          srl            %o5, 8, %g5
93         andcc           %g5, 0xff, %g0
94         be              3f
95          andcc          %o5, 0xff, %g0
96         bne             1b
97          st             %o5, [%o0 - 4]
98         retl
99          mov            %g2, %o0
100 3:      srl             %o5, 16, %o5
101         sth             %o5, [%o0 - 4]
102         stb             %g0, [%o0 - 2]
103         retl
104          mov            %g2, %o0
105 2:      srl             %o5, 16, %o5
106         sth             %o5, [%o0 - 4]
107         retl
108          mov            %g2, %o0
109 1:      stb             %g0, [%o0 - 4]
110         retl
111          mov            %g2, %o0
113 10:     ld              [%o1], %o5
114         add             %o1, 4, %o1
115         sub             %o5, %o2, %o4
116         cmp             %g3, 2
117         be              2f
118          cmp            %g3, 3
119         be              3f
120          andcc          %o4, %o3, %g0
121         bne             5f
122          srl            %o5, 24, %g5
123         stb             %g5, [%o0]
124         sub             %o0, 1, %o0
125         srl             %o5, 8, %g5
126         sth             %g5, [%o0 + 2]
127 1:      add             %o0, 4, %o0
128 4:      sll             %o5, 24, %g6
129         ld              [%o1], %o5
130         add             %o1, 4, %o1
131         srl             %o5, 8, %g5
132         sub             %o5, %o2, %o4
133         or              %g5, %g6, %g5
134         andcc           %o4, %o3, %g0
135         be,a            1b
136          st             %g5, [%o0]
137         srl             %o5, 24, %o4
138         andcc           %o4, 0xff, %g0
139         be              6f
140          srl            %o5, 16, %o4
141         andcc           %o4, 0xff, %g0
142         be              7f
143          srl            %o5, 8, %o4
144         st              %g5, [%o0]
145         andcc           %o4, 0xff, %g0
146         be              0f
147          andcc          %o5, 0xff, %g0
148 1:      bne             4b
149          add            %o0, 4, %o0
150 9:      stb             %g0, [%o0]
151 0:      retl
152          mov            %g2, %o0
153 6:      srl             %g5, 16, %g5
154         sth             %g5, [%o0]
155         retl
156          mov            %g2, %o0
157 7:      srl             %g5, 16, %g5
158         sth             %g5, [%o0]
159         stb             %g0, [%o0 + 2]
160         retl
161          mov            %g2, %o0
162 5:      andcc           %g5, 0xff, %g4
163         be              9b
164          srl            %o5, 16, %g5
165         andcc           %g5, 0xff, %g0
166         be              7f
167          srl            %o5, 8, %g5
168         andcc           %g5, 0xff, %g0
169         stb             %g4, [%o0]
170         sth             %g5, [%o0 + 1]
171         sub             %o0, 1, %o0
172         bne             1b
173          andcc          %o5, 0xff, %g0
174         retl
175          mov            %g2, %o0
176 7:      stb             %g4, [%o0]
177         stb             %g0, [%o0 + 1]
178         retl
179          mov            %g2, %o0
181 2:      andcc           %o4, %o3, %g0
182         bne             5f
183          srl            %o5, 16, %g5
184         sth             %g5, [%o0]
185         sub             %o0, 2, %o0
186 1:      add             %o0, 4, %o0
187 4:      sll             %o5, 16, %g6
188         ld              [%o1], %o5
189         add             %o1, 4, %o1
190         srl             %o5, 16, %g5
191         sub             %o5, %o2, %o4
192         or              %g5, %g6, %g5
193         andcc           %o4, %o3, %g0
194         be,a            1b
195          st             %g5, [%o0]
196         srl             %o5, 24, %o4
197         andcc           %o4, 0xff, %g0
198         be              7f
199          srl            %o5, 16, %o4
200         st              %g5, [%o0]
201         andcc           %o4, 0xff, %g0
202         be              0b
203          srl            %o5, 8, %o4
204 1:      andcc           %o4, 0xff, %g0
205         be              8f
206          andcc          %o5, 0xff, %g0
207         bne             4b
208          add            %o0, 4, %o0
209         sth             %o5, [%o0]
210         retl
211          mov            %g2, %o0
212 7:      srl             %g5, 16, %g5
213         sth             %g5, [%o0]
214         stb             %g0, [%o0 + 2]
215         retl
216          mov            %g2, %o0
217 8:      stb             %g0, [%o0 + 4]
218         retl
219          mov            %g2, %o0
220 5:      srl             %o5, 24, %g5
221         andcc           %g5, 0xff, %g0
222         be              9b
223          srl            %o5, 16, %g5
224         andcc           %g5, 0xff, %g0
225         sth             %g5, [%o0]
226         sub             %o0, 2, %o0
227         bne             1b
228          srl            %o5, 8, %o4
229         retl
230          mov            %g2, %o0
232 3:      bne             5f
233          srl            %o5, 24, %g5
234         stb             %g5, [%o0]
235         sub             %o0, 3, %o0
236 1:      add             %o0, 4, %o0
237 4:      sll             %o5, 8, %g6
238         ld              [%o1], %o5
239         add             %o1, 4, %o1
240         srl             %o5, 24, %g5
241         sub             %o5, %o2, %o4
242         or              %g5, %g6, %g5
243         andcc           %o4, %o3, %g0
244         be              1b
245          st             %g5, [%o0]
246         srl             %o5, 24, %o4
247         andcc           %o4, 0xff, %g0
248         be              0b
249          srl            %o5, 16, %o4
250 1:      andcc           %o4, 0xff, %g0
251         be              8b
252          srl            %o5, 8, %o4
253         andcc           %o4, 0xff, %g0
254         be              9f
255          andcc          %o5, 0xff, %g0
256         bne             4b
257          add            %o0, 4, %o0
258         srl             %o5, 8, %o5
259         sth             %o5, [%o0]
260         stb             %g0, [%o0 + 2]
261         retl
262          mov            %g2, %o0
263 9:      srl             %o5, 8, %o5
264         sth             %o5, [%o0 + 4]
265         retl
266          mov            %g2, %o0
267 5:      andcc           %g5, 0xff, %g0
268         stb             %g5, [%o0]
269         sub             %o0, 3, %o0
270         bne             1b
271          srl            %o5, 16, %o4
272         retl
273          mov            %g2, %o0
274 END(strcpy)
275 libc_hidden_builtin_def (strcpy)