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