]> sourceware.org Git - glibc.git/blob - sysdeps/sparc/sparc64/stpcpy.S
Sparc string routines from Jakub.
[glibc.git] / sysdeps / sparc / sparc64 / stpcpy.S
1 /* Copy SRC to DEST returning the address of the terminating '\0' in DEST.
2 For SPARC v9.
3 Copyright (C) 1998, 1999 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5 Contributed by Jan Vondrak <jvon4518@ss1000.ms.mff.cuni.cz> and
6 Jakub Jelinek <jj@ultra.linux.cz>.
7
8 The GNU C Library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version.
12
13 The GNU C Library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
17
18 You should have received a copy of the GNU Library General Public
19 License along with the GNU C Library; see the file COPYING.LIB. If not,
20 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
22
23 #include <sysdep.h>
24 #include <asm/asi.h>
25
26 /* Normally, this uses
27 ((xword - 0x0101010101010101) & 0x8080808080808080) test
28 to find out if any byte in xword could be zero. This is fast, but
29 also gives false alarm for any byte in range 0x81-0xff. It does
30 not matter for correctness, as if this test tells us there could
31 be some zero byte, we check it byte by byte, but if bytes with
32 high bits set are common in the strings, then this will give poor
33 performance. You can #define EIGHTBIT_NOT_RARE and the algorithm
34 will use one tick slower, but more precise test
35 ((xword - 0x0101010101010101) & (~xword) & 0x8080808080808080),
36 which does not give any false alarms (but if some bits are set,
37 one cannot assume from it which bytes are zero and which are not).
38 It is yet to be measured, what is the correct default for glibc
39 in these days for an average user.
40 */
41
42 .text
43 .align 32
44 ENTRY(__stpcpy)
45 sethi %hi(0x01010101), %g1 /* IEU0 Group */
46 or %g1, %lo(0x01010101), %g1 /* IEU0 Group */
47 andcc %o0, 7, %g0 /* IEU1 */
48 sllx %g1, 32, %g2 /* IEU0 Group */
49
50 bne,pn %icc, 12f /* CTI */
51 andcc %o1, 7, %g3 /* IEU1 */
52 or %g1, %g2, %g1 /* IEU0 Group */
53 bne,pn %icc, 14f /* CTI */
54
55 sllx %g1, 7, %g2 /* IEU0 Group */
56 1: ldx [%o1], %o3 /* Load */
57 add %o1, 8, %o1 /* IEU1 */
58 2: mov %o3, %g3 /* IEU0 Group */
59
60 sub %o3, %g1, %o2 /* IEU1 */
61 3: ldxa [%o1] ASI_PNF, %o3 /* Load */
62 #ifdef EIGHTBIT_NOT_RARE
63 andn %o2, %g3, %o2 /* IEU0 Group */
64 #endif
65 add %o0, 8, %o0 /* IEU0 Group */
66 andcc %o2, %g2, %g0 /* IEU1 */
67
68 add %o1, 8, %o1 /* IEU0 Group */
69 be,a,pt %xcc, 2b /* CTI */
70 stx %g3, [%o0 - 8] /* Store */
71 srlx %g3, 56, %g5 /* IEU0 Group */
72
73 andcc %g5, 0xff, %g0 /* IEU1 Group */
74 be,pn %icc, 11f /* CTI */
75 srlx %g3, 48, %g4 /* IEU0 */
76 andcc %g4, 0xff, %g0 /* IEU1 Group */
77
78 be,pn %icc, 10f /* CTI */
79 srlx %g3, 40, %g5 /* IEU0 */
80 andcc %g5, 0xff, %g0 /* IEU1 Group */
81 be,pn %icc, 9f /* CTI */
82
83 srlx %g3, 32, %g4 /* IEU0 */
84 andcc %g4, 0xff, %g0 /* IEU1 Group */
85 be,pn %icc, 8f /* CTI */
86 srlx %g3, 24, %g5 /* IEU0 */
87
88 andcc %g5, 0xff, %g0 /* IEU1 Group */
89 be,pn %icc, 7f /* CTI */
90 srlx %g3, 16, %g4 /* IEU0 */
91 andcc %g4, 0xff, %g0 /* IEU1 Group */
92
93 be,pn %icc, 6f /* CTI */
94 srlx %g3, 8, %g5 /* IEU0 */
95 andcc %g5, 0xff, %g0 /* IEU1 Group */
96 be,pn %icc, 5f /* CTI */
97
98 sub %o3, %g1, %o2 /* IEU0 */
99 stx %g3, [%o0 - 8] /* Store Group */
100 andcc %g3, 0xff, %g0 /* IEU1 */
101 bne,pt %icc, 3b /* CTI */
102
103 mov %o3, %g3 /* IEU0 Group */
104 4: retl /* CTI+IEU1 Group */
105 sub %o0, 1, %o0 /* IEU0 */
106
107 .align 16
108 6: ba,pt %xcc, 23f /* CTI Group */
109 sub %o0, 3, %g7 /* IEU0 */
110 5: sub %o0, 2, %g7 /* IEU0 Group */
111 stb %g5, [%o0 - 2] /* Store */
112
113 srlx %g3, 16, %g4 /* IEU0 Group */
114 23: sth %g4, [%o0 - 4] /* Store */
115 srlx %g3, 32, %g4 /* IEU0 Group */
116 stw %g4, [%o0 - 8] /* Store */
117
118 retl /* CTI+IEU1 Group */
119 mov %g7, %o0 /* IEU0 */
120 8: ba,pt %xcc, 24f /* CTI Group */
121 sub %o0, 5, %g7 /* IEU0 */
122
123 7: sub %o0, 4, %g7 /* IEU0 Group */
124 stb %g5, [%o0 - 4] /* Store */
125 srlx %g3, 32, %g4 /* IEU0 Group */
126 24: stw %g4, [%o0 - 8] /* Store */
127
128 retl /* CTI+IEU1 Group */
129 mov %g7, %o0 /* IEU0 */
130 10: ba,pt %xcc, 25f /* CTI Group */
131 sub %o0, 7, %g7 /* IEU0 */
132
133 9: sub %o0, 6, %g7 /* IEU0 Group */
134 stb %g5, [%o0 - 6] /* Store */
135 srlx %g3, 48, %g4 /* IEU0 */
136 25: sth %g4, [%o0 - 8] /* Store Group */
137
138 retl /* CTI+IEU1 Group */
139 mov %g7, %o0 /* IEU0 */
140 11: stb %g5, [%o0 - 8] /* Store Group */
141 retl /* CTI+IEU1 Group */
142
143 sub %o0, 8, %o0 /* IEU0 */
144
145 .align 16
146 12: or %g1, %g2, %g1 /* IEU0 Group */
147 ldub [%o1], %o3 /* Load */
148 sllx %g1, 7, %g2 /* IEU0 Group */
149 stb %o3, [%o0] /* Store Group */
150
151 13: add %o0, 1, %o0 /* IEU0 */
152 add %o1, 1, %o1 /* IEU1 */
153 andcc %o3, 0xff, %g0 /* IEU1 Group */
154 be,pn %icc, 4b /* CTI */
155
156 lduba [%o1] ASI_PNF, %o3 /* Load */
157 andcc %o0, 7, %g0 /* IEU1 Group */
158 bne,a,pt %icc, 13b /* CTI */
159 stb %o3, [%o0] /* Store */
160
161 andcc %o1, 7, %g3 /* IEU1 Group */
162 be,a,pt %icc, 1b /* CTI */
163 ldx [%o1], %o3 /* Load */
164 14: orcc %g0, 64, %g4 /* IEU1 Group */
165
166 sllx %g3, 3, %g5 /* IEU0 */
167 sub %o1, %g3, %o1 /* IEU0 Group */
168 sub %g4, %g5, %g4 /* IEU1 */
169 /* %g1 = 0101010101010101 *
170 * %g2 = 8080808080808080 *
171 * %g3 = source alignment *
172 * %g5 = number of bits to shift left *
173 * %g4 = number of bits to shift right */
174 ldxa [%o1] ASI_PNF, %o5 /* Load Group */
175
176 addcc %o1, 8, %o1 /* IEU1 */
177 15: sllx %o5, %g5, %o3 /* IEU0 Group */
178 ldxa [%o1] ASI_PNF, %o5 /* Load */
179 srlx %o5, %g4, %o4 /* IEU0 Group */
180
181 add %o0, 8, %o0 /* IEU1 */
182 or %o3, %o4, %o3 /* IEU0 Group */
183 add %o1, 8, %o1 /* IEU1 */
184 sub %o3, %g1, %o4 /* IEU0 Group */
185
186 #ifdef EIGHTBIT_NOT_RARE
187 andn %o4, %o3, %o4 /* IEU0 Group */
188 #endif
189 andcc %o4, %g2, %g0 /* IEU1 Group */
190 be,a,pt %xcc, 15b /* CTI */
191 stx %o3, [%o0 - 8] /* Store */
192 srlx %o3, 56, %o4 /* IEU0 Group */
193
194 andcc %o4, 0xff, %g0 /* IEU1 Group */
195 be,pn %icc, 22f /* CTI */
196 srlx %o3, 48, %o4 /* IEU0 */
197 andcc %o4, 0xff, %g0 /* IEU1 Group */
198
199 be,pn %icc, 21f /* CTI */
200 srlx %o3, 40, %o4 /* IEU0 */
201 andcc %o4, 0xff, %g0 /* IEU1 Group */
202 be,pn %icc, 20f /* CTI */
203
204 srlx %o3, 32, %o4 /* IEU0 */
205 andcc %o4, 0xff, %g0 /* IEU1 Group */
206 be,pn %icc, 19f /* CTI */
207 srlx %o3, 24, %o4 /* IEU0 */
208
209 andcc %o4, 0xff, %g0 /* IEU1 Group */
210 be,pn %icc, 18f /* CTI */
211 srlx %o3, 16, %o4 /* IEU0 */
212 andcc %o4, 0xff, %g0 /* IEU1 Group */
213
214 be,pn %icc, 17f /* CTI */
215 srlx %o3, 8, %o4 /* IEU0 */
216 andcc %o4, 0xff, %g0 /* IEU1 Group */
217 be,pn %icc, 16f /* CTI */
218
219 andcc %o3, 0xff, %g0 /* IEU1 Group */
220 bne,pn %icc, 15b /* CTI */
221 stx %o3, [%o0 - 8] /* Store */
222 retl /* CTI+IEU1 Group */
223
224 sub %o0, 1, %o0 /* IEU0 */
225
226 .align 16
227 17: ba,pt %xcc, 26f /* CTI Group */
228 subcc %o0, 3, %g7 /* IEU1 */
229 18: ba,pt %xcc, 27f /* CTI Group */
230 subcc %o0, 4, %g7 /* IEU1 */
231
232 19: ba,pt %xcc, 28f /* CTI Group */
233 subcc %o0, 5, %g7 /* IEU1 */
234 16: subcc %o0, 2, %g7 /* IEU1 Group */
235 srlx %o3, 8, %o4 /* IEU0 */
236
237 stb %o4, [%o0 - 2] /* Store */
238 26: srlx %o3, 16, %o4 /* IEU0 Group */
239 stb %o4, [%o0 - 3] /* Store */
240 27: srlx %o3, 24, %o4 /* IEU0 Group */
241
242 stb %o4, [%o0 - 4] /* Store */
243 28: srlx %o3, 32, %o4 /* IEU0 Group */
244 stw %o4, [%o0 - 8] /* Store */
245 retl /* CTI+IEU1 Group */
246
247 mov %g7, %o0 /* IEU0 */
248
249 .align 16
250 21: ba,pt %xcc, 29f /* CTI Group */
251 subcc %o0, 7, %g7 /* IEU1 */
252 22: ba,pt %xcc, 30f /* CTI Group */
253 subcc %o0, 8, %g7 /* IEU1 */
254
255 20: subcc %o0, 6, %g7 /* IEU1 Group */
256 srlx %o3, 40, %o4 /* IEU0 */
257 stb %o4, [%o0 - 6] /* Store */
258 29: srlx %o3, 48, %o4 /* IEU0 Group */
259
260 stb %o4, [%o0 - 7] /* Store */
261 30: srlx %o3, 56, %o4 /* IEU0 Group */
262 stb %o4, [%o0 - 8] /* Store */
263 retl /* CTI+IEU1 Group */
264
265 mov %g7, %o0 /* IEU0 */
266 END(__stpcpy)
267
268 weak_alias (__stpcpy, stpcpy)
This page took 0.056558 seconds and 6 git commands to generate.