blob: 4d7742ebc841207f410c2f32f117b392b5c5df07 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/* 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, write to the Free
19 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307 USA. */
21
22 /* Normally, this uses ((xword - 0x01010101) & 0x80808080) test
23 to find out if any byte in xword could be zero. This is fast, but
24 also gives false alarm for any byte in range 0x81-0xff. It does
25 not matter for correctness, as if this test tells us there could
26 be some zero byte, we check it byte by byte, but if bytes with
27 high bits set are common in the strings, then this will give poor
28 performance. You can #define EIGHTBIT_NOT_RARE and the algorithm
29 will use one tick slower, but more precise test
30 ((xword - 0x01010101) & (~xword) & 0x80808080),
31 which does not give any false alarms (but if some bits are set,
32 one cannot assume from it which bytes are zero and which are not).
33 It is yet to be measured, what is the correct default for glibc
34 in these days for an average user.
35 */
36
37 .text
38 .align 4
391: ldub [%o1], %o5
40 stb %o5, [%o0]
41 cmp %o5, 0
42 add %o0, 1, %o0
43 be 0f
44 add %o1, 1, %o1
45 andcc %o1, 3, %g0
46 be 4f
47 or %o4, %lo(0x80808080), %o3
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 5f
56 sethi %hi(0x01010101), %o4
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 b 6f
64 andcc %o0, 3, %g3
65
66ENTRY(strcpy)
67 mov %o0, %g2
68 andcc %o1, 3, %g0
69 bne 1b
70 sethi %hi(0x80808080), %o4
71 or %o4, %lo(0x80808080), %o3
724: sethi %hi(0x01010101), %o4
735: andcc %o0, 3, %g3
746: bne 10f
75 or %o4, %lo(0x01010101), %o2
761: ld [%o1], %o5
77 add %o1, 4, %o1
78 sub %o5, %o2, %o4
79 add %o0, 4, %o0
80 andcc %o4, %o3, %g0
81 be,a 1b
82 st %o5, [%o0 - 4]
83
84 srl %o5, 24, %g5
85 andcc %g5, 0xff, %g0
86 be 1f
87 srl %o5, 16, %g5
88 andcc %g5, 0xff, %g0
89 be 2f
90 srl %o5, 8, %g5
91 andcc %g5, 0xff, %g0
92 be 3f
93 andcc %o5, 0xff, %g0
94 bne 1b
95 st %o5, [%o0 - 4]
96 retl
97 mov %g2, %o0
983: srl %o5, 16, %o5
99 sth %o5, [%o0 - 4]
100 stb %g0, [%o0 - 2]
101 retl
102 mov %g2, %o0
1032: srl %o5, 16, %o5
104 sth %o5, [%o0 - 4]
105 retl
106 mov %g2, %o0
1071: stb %g0, [%o0 - 4]
108 retl
109 mov %g2, %o0
110
11110: ld [%o1], %o5
112 add %o1, 4, %o1
113 sub %o5, %o2, %o4
114 cmp %g3, 2
115 be 2f
116 cmp %g3, 3
117 be 3f
118 andcc %o4, %o3, %g0
119 bne 5f
120 srl %o5, 24, %g5
121 stb %g5, [%o0]
122 sub %o0, 1, %o0
123 srl %o5, 8, %g5
124 sth %g5, [%o0 + 2]
1251: add %o0, 4, %o0
1264: sll %o5, 24, %g6
127 ld [%o1], %o5
128 add %o1, 4, %o1
129 srl %o5, 8, %g5
130 sub %o5, %o2, %o4
131 or %g5, %g6, %g5
132 andcc %o4, %o3, %g0
133 be,a 1b
134 st %g5, [%o0]
135 srl %o5, 24, %o4
136 andcc %o4, 0xff, %g0
137 be 6f
138 srl %o5, 16, %o4
139 andcc %o4, 0xff, %g0
140 be 7f
141 srl %o5, 8, %o4
142 st %g5, [%o0]
143 andcc %o4, 0xff, %g0
144 be 0f
145 andcc %o5, 0xff, %g0
1461: bne 4b
147 add %o0, 4, %o0
1489: stb %g0, [%o0]
1490: retl
150 mov %g2, %o0
1516: srl %g5, 16, %g5
152 sth %g5, [%o0]
153 retl
154 mov %g2, %o0
1557: srl %g5, 16, %g5
156 sth %g5, [%o0]
157 stb %g0, [%o0 + 2]
158 retl
159 mov %g2, %o0
1605: andcc %g5, 0xff, %g4
161 be 9b
162 srl %o5, 16, %g5
163 andcc %g5, 0xff, %g0
164 be 7f
165 srl %o5, 8, %g5
166 andcc %g5, 0xff, %g0
167 stb %g4, [%o0]
168 sth %g5, [%o0 + 1]
169 sub %o0, 1, %o0
170 bne 1b
171 andcc %o5, 0xff, %g0
172 retl
173 mov %g2, %o0
1747: stb %g4, [%o0]
175 stb %g0, [%o0 + 1]
176 retl
177 mov %g2, %o0
178
1792: andcc %o4, %o3, %g0
180 bne 5f
181 srl %o5, 16, %g5
182 sth %g5, [%o0]
183 sub %o0, 2, %o0
1841: add %o0, 4, %o0
1854: sll %o5, 16, %g6
186 ld [%o1], %o5
187 add %o1, 4, %o1
188 srl %o5, 16, %g5
189 sub %o5, %o2, %o4
190 or %g5, %g6, %g5
191 andcc %o4, %o3, %g0
192 be,a 1b
193 st %g5, [%o0]
194 srl %o5, 24, %o4
195 andcc %o4, 0xff, %g0
196 be 7f
197 srl %o5, 16, %o4
198 st %g5, [%o0]
199 andcc %o4, 0xff, %g0
200 be 0b
201 srl %o5, 8, %o4
2021: andcc %o4, 0xff, %g0
203 be 8f
204 andcc %o5, 0xff, %g0
205 bne 4b
206 add %o0, 4, %o0
207 sth %o5, [%o0]
208 retl
209 mov %g2, %o0
2107: srl %g5, 16, %g5
211 sth %g5, [%o0]
212 stb %g0, [%o0 + 2]
213 retl
214 mov %g2, %o0
2158: stb %g0, [%o0 + 4]
216 retl
217 mov %g2, %o0
2185: srl %o5, 24, %g5
219 andcc %g5, 0xff, %g0
220 be 9b
221 srl %o5, 16, %g5
222 andcc %g5, 0xff, %g0
223 sth %g5, [%o0]
224 sub %o0, 2, %o0
225 bne 1b
226 srl %o5, 8, %o4
227 retl
228 mov %g2, %o0
229
2303: bne 5f
231 srl %o5, 24, %g5
232 stb %g5, [%o0]
233 sub %o0, 3, %o0
2341: add %o0, 4, %o0
2354: sll %o5, 8, %g6
236 ld [%o1], %o5
237 add %o1, 4, %o1
238 srl %o5, 24, %g5
239 sub %o5, %o2, %o4
240 or %g5, %g6, %g5
241 andcc %o4, %o3, %g0
242 be 1b
243 st %g5, [%o0]
244 srl %o5, 24, %o4
245 andcc %o4, 0xff, %g0
246 be 0b
247 srl %o5, 16, %o4
2481: andcc %o4, 0xff, %g0
249 be 8b
250 srl %o5, 8, %o4
251 andcc %o4, 0xff, %g0
252 be 9f
253 andcc %o5, 0xff, %g0
254 bne 4b
255 add %o0, 4, %o0
256 srl %o5, 8, %o5
257 sth %o5, [%o0]
258 stb %g0, [%o0 + 2]
259 retl
260 mov %g2, %o0
2619: srl %o5, 8, %o5
262 sth %o5, [%o0 + 4]
263 retl
264 mov %g2, %o0
2655: andcc %g5, 0xff, %g0
266 stb %g5, [%o0]
267 sub %o0, 3, %o0
268 bne 1b
269 srl %o5, 16, %o4
270 retl
271 mov %g2, %o0
272END(strcpy)
273libc_hidden_def(strcpy)