OSDN Git Service

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