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