1 /* Copy SRC to DEST returning the address of the terminating '\0' in DEST.
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>.
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.
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.
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. */
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.
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 */
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 */
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 */
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 */
65 add %o0, 8, %o0 /* IEU0 Group */
66 andcc %o2, %g2, %g0 /* IEU1 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
103 mov %o3, %g3 /* IEU0 Group */
104 4: retl /* CTI+IEU1 Group */
105 sub %o0, 1, %o0 /* IEU0 */
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 */
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 */
118 retl /* CTI+IEU1 Group */
119 mov %g7, %o0 /* IEU0 */
120 8: ba,pt %xcc, 24f /* CTI Group */
121 sub %o0, 5, %g7 /* IEU0 */
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 */
128 retl /* CTI+IEU1 Group */
129 mov %g7, %o0 /* IEU0 */
130 10: ba,pt %xcc, 25f /* CTI Group */
131 sub %o0, 7, %g7 /* IEU0 */
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 */
138 retl /* CTI+IEU1 Group */
139 mov %g7, %o0 /* IEU0 */
140 11: stb %g5, [%o0 - 8] /* Store Group */
141 retl /* CTI+IEU1 Group */
143 sub %o0, 8, %o0 /* IEU0 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
186 #ifdef EIGHTBIT_NOT_RARE
187 andn %o4, %o3, %o4 /* IEU0 Group */
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 */
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 */
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 */
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 */
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 */
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 */
219 andcc %o3, 0xff, %g0 /* IEU1 Group */
220 bne,pn %icc, 15b /* CTI */
221 stx %o3, [%o0 - 8] /* Store */
222 retl /* CTI+IEU1 Group */
224 sub %o0, 1, %o0 /* IEU0 */
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 */
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 */
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 */
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 */
247 mov %g7, %o0 /* IEU0 */
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 */
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 */
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 */
265 mov %g7, %o0 /* IEU0 */
268 weak_alias (__stpcpy, stpcpy)