1 | /* Copy SRC to DEST returning DEST. |
2 | For SPARC v7. |
3 | Copyright (C) 1996-2024 Free Software Foundation, Inc. |
4 | This file is part of the GNU C Library. |
5 | |
6 | The GNU C Library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Lesser General Public |
8 | License as published by the Free Software Foundation; either |
9 | version 2.1 of the License, or (at your option) any later version. |
10 | |
11 | The GNU C Library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Lesser General Public License for more details. |
15 | |
16 | You should have received a copy of the GNU Lesser General Public |
17 | License along with the GNU C Library; if not, see |
18 | <https://www.gnu.org/licenses/>. */ |
19 | |
20 | #include <sysdep.h> |
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 |
39 | |
40 | ENTRY(strcpy) |
41 | mov %o0, %g2 |
42 | andcc %o1, 3, %g0 |
43 | be 10f |
44 | sethi %hi(0x80808080), %o4 |
45 | |
46 | ldub [%o1], %o5 |
47 | stb %o5, [%o0] |
48 | cmp %o5, 0 |
49 | add %o0, 1, %o0 |
50 | be 0f |
51 | add %o1, 1, %o1 |
52 | andcc %o1, 3, %g0 |
53 | be 4f |
54 | or %o4, %lo(0x80808080), %o3 |
55 | ldub [%o1], %o5 |
56 | stb %o5, [%o0] |
57 | cmp %o5, 0 |
58 | add %o0, 1, %o0 |
59 | be 0f |
60 | add %o1, 1, %o1 |
61 | andcc %o1, 3, %g0 |
62 | be 5f |
63 | sethi %hi(0x01010101), %o4 |
64 | ldub [%o1], %o5 |
65 | stb %o5, [%o0] |
66 | cmp %o5, 0 |
67 | add %o0, 1, %o0 |
68 | be 0f |
69 | add %o1, 1, %o1 |
70 | b 6f |
71 | andcc %o0, 3, %g3 |
72 | |
73 | 10: 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] |
85 | |
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 |
112 | |
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 |
180 | |
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 |
231 | |
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) |
276 | |