]>
Commit | Line | Data |
---|---|---|
6704c645 | 1 | /* Optimized, inlined string functions. i486/x86-64 version. |
d4697bc9 | 2 | Copyright (C) 2001-2014 Free Software Foundation, Inc. |
92f1da4d UD |
3 | This file is part of the GNU C Library. |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
92f1da4d UD |
9 | |
10 | The GNU C Library is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
92f1da4d | 14 | |
41bdb6e2 | 15 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
16 | License along with the GNU C Library; if not, see |
17 | <http://www.gnu.org/licenses/>. */ | |
92f1da4d UD |
18 | |
19 | #ifndef _STRING_H | |
61eb22d3 | 20 | # error "Never use <bits/string.h> directly; include <string.h> instead." |
92f1da4d UD |
21 | #endif |
22 | ||
61eb22d3 UD |
23 | /* The ix86 processors can access unaligned multi-byte variables. */ |
24 | #define _STRING_ARCH_unaligned 1 | |
25 | ||
3cc0cd4c | 26 | /* Enable inline functions only for i486 or better when compiling for |
6704c645 L |
27 | ia32. */ |
28 | #if !defined __x86_64__ && (defined __i486__ || defined __pentium__ \ | |
29 | || defined __pentiumpro__ || defined __pentium4__ \ | |
30 | || defined __nocona__ || defined __atom__ \ | |
31 | || defined __core2__ || defined __corei7__ \ | |
32 | || defined __k6__ || defined __geode__ \ | |
33 | || defined __k8__ || defined __athlon__ \ | |
34 | || defined __amdfam10__) | |
61eb22d3 UD |
35 | |
36 | /* We only provide optimizations if the user selects them and if | |
37 | GNU CC is used. */ | |
6704c645 | 38 | # if !defined __NO_STRING_INLINES && defined __USE_STRING_INLINES \ |
2bdd4ca6 | 39 | && defined __GNUC__ && __GNUC__ >= 2 |
92f1da4d | 40 | |
6704c645 L |
41 | # ifndef __STRING_INLINE |
42 | # ifndef __extern_inline | |
43 | # define __STRING_INLINE inline | |
44 | # else | |
45 | # define __STRING_INLINE __extern_inline | |
46 | # endif | |
9bbd7837 | 47 | # endif |
92f1da4d | 48 | |
61eb22d3 | 49 | /* The macros are used in some of the optimized implementations below. */ |
6704c645 | 50 | # define __STRING_SMALL_GET16(src, idx) \ |
a784e502 UD |
51 | ((((const unsigned char *) (src))[idx + 1] << 8) \ |
52 | | ((const unsigned char *) (src))[idx]) | |
6704c645 | 53 | # define __STRING_SMALL_GET32(src, idx) \ |
a784e502 UD |
54 | (((((const unsigned char *) (src))[idx + 3] << 8 \ |
55 | | ((const unsigned char *) (src))[idx + 2]) << 8 \ | |
56 | | ((const unsigned char *) (src))[idx + 1]) << 8 \ | |
57 | | ((const unsigned char *) (src))[idx]) | |
61eb22d3 | 58 | |
92f1da4d UD |
59 | |
60 | /* Copy N bytes of SRC to DEST. */ | |
6704c645 L |
61 | # define _HAVE_STRING_ARCH_memcpy 1 |
62 | # define memcpy(dest, src, n) \ | |
92f1da4d | 63 | (__extension__ (__builtin_constant_p (n) \ |
6876cdf8 RM |
64 | ? __memcpy_c ((dest), (src), (n)) \ |
65 | : __memcpy_g ((dest), (src), (n)))) | |
6704c645 | 66 | # define __memcpy_c(dest, src, n) \ |
9a0a462c UD |
67 | ((n) == 0 \ |
68 | ? (dest) \ | |
69 | : (((n) % 4 == 0) \ | |
70 | ? __memcpy_by4 (dest, src, n) \ | |
71 | : (((n) % 2 == 0) \ | |
72 | ? __memcpy_by2 (dest, src, n) \ | |
73 | : __memcpy_g (dest, src, n)))) | |
92f1da4d | 74 | |
a784e502 | 75 | __STRING_INLINE void *__memcpy_by4 (void *__dest, const void *__src, |
348ed515 UD |
76 | size_t __n); |
77 | ||
92f1da4d | 78 | __STRING_INLINE void * |
a784e502 | 79 | __memcpy_by4 (void *__dest, const void *__src, size_t __n) |
92f1da4d | 80 | { |
a44d2393 | 81 | register unsigned long int __d0, __d1; |
92f1da4d | 82 | register void *__tmp = __dest; |
92f1da4d UD |
83 | __asm__ __volatile__ |
84 | ("1:\n\t" | |
85 | "movl (%2),%0\n\t" | |
86 | "leal 4(%2),%2\n\t" | |
87 | "movl %0,(%1)\n\t" | |
88 | "leal 4(%1),%1\n\t" | |
89 | "decl %3\n\t" | |
90 | "jnz 1b" | |
a44d2393 | 91 | : "=&r" (__d0), "=&r" (__tmp), "=&r" (__src), "=&r" (__d1) |
92f1da4d UD |
92 | : "1" (__tmp), "2" (__src), "3" (__n / 4) |
93 | : "memory", "cc"); | |
94 | return __dest; | |
95 | } | |
96 | ||
a784e502 | 97 | __STRING_INLINE void *__memcpy_by2 (void *__dest, const void *__src, |
348ed515 UD |
98 | size_t __n); |
99 | ||
92f1da4d | 100 | __STRING_INLINE void * |
a784e502 | 101 | __memcpy_by2 (void *__dest, const void *__src, size_t __n) |
92f1da4d | 102 | { |
a44d2393 | 103 | register unsigned long int __d0, __d1; |
92f1da4d | 104 | register void *__tmp = __dest; |
92f1da4d UD |
105 | __asm__ __volatile__ |
106 | ("shrl $1,%3\n\t" | |
107 | "jz 2f\n" /* only a word */ | |
108 | "1:\n\t" | |
109 | "movl (%2),%0\n\t" | |
110 | "leal 4(%2),%2\n\t" | |
111 | "movl %0,(%1)\n\t" | |
112 | "leal 4(%1),%1\n\t" | |
113 | "decl %3\n\t" | |
114 | "jnz 1b\n" | |
115 | "2:\n\t" | |
116 | "movw (%2),%w0\n\t" | |
117 | "movw %w0,(%1)" | |
a44d2393 | 118 | : "=&q" (__d0), "=&r" (__tmp), "=&r" (__src), "=&r" (__d1) |
92f1da4d UD |
119 | : "1" (__tmp), "2" (__src), "3" (__n / 2) |
120 | : "memory", "cc"); | |
121 | return __dest; | |
122 | } | |
123 | ||
a784e502 | 124 | __STRING_INLINE void *__memcpy_g (void *__dest, const void *__src, size_t __n); |
348ed515 | 125 | |
2119c705 | 126 | __STRING_INLINE void * |
a784e502 | 127 | __memcpy_g (void *__dest, const void *__src, size_t __n) |
92f1da4d | 128 | { |
a44d2393 | 129 | register unsigned long int __d0, __d1, __d2; |
92f1da4d UD |
130 | register void *__tmp = __dest; |
131 | __asm__ __volatile__ | |
132 | ("cld\n\t" | |
133 | "shrl $1,%%ecx\n\t" | |
134 | "jnc 1f\n\t" | |
135 | "movsb\n" | |
136 | "1:\n\t" | |
137 | "shrl $1,%%ecx\n\t" | |
138 | "jnc 2f\n\t" | |
139 | "movsw\n" | |
140 | "2:\n\t" | |
141 | "rep; movsl" | |
49f8b030 AJ |
142 | : "=&c" (__d0), "=&D" (__d1), "=&S" (__d2), |
143 | "=m" ( *(struct { __extension__ char __x[__n]; } *)__dest) | |
144 | : "0" (__n), "1" (__tmp), "2" (__src), | |
145 | "m" ( *(struct { __extension__ char __x[__n]; } *)__src) | |
146 | : "cc"); | |
92f1da4d UD |
147 | return __dest; |
148 | } | |
149 | ||
6704c645 L |
150 | # define _HAVE_STRING_ARCH_memmove 1 |
151 | # ifndef _FORCE_INLINES | |
92f1da4d UD |
152 | /* Copy N bytes of SRC to DEST, guaranteeing |
153 | correct behavior for overlapping strings. */ | |
6704c645 | 154 | # define memmove(dest, src, n) __memmove_g (dest, src, n) |
a78814a9 | 155 | |
a784e502 | 156 | __STRING_INLINE void *__memmove_g (void *, const void *, size_t) |
a78814a9 UD |
157 | __asm__ ("memmove"); |
158 | ||
92f1da4d | 159 | __STRING_INLINE void * |
a784e502 | 160 | __memmove_g (void *__dest, const void *__src, size_t __n) |
92f1da4d | 161 | { |
a44d2393 | 162 | register unsigned long int __d0, __d1, __d2; |
92f1da4d UD |
163 | register void *__tmp = __dest; |
164 | if (__dest < __src) | |
165 | __asm__ __volatile__ | |
166 | ("cld\n\t" | |
167 | "rep; movsb" | |
49f8b030 AJ |
168 | : "=&c" (__d0), "=&S" (__d1), "=&D" (__d2), |
169 | "=m" ( *(struct { __extension__ char __x[__n]; } *)__dest) | |
170 | : "0" (__n), "1" (__src), "2" (__tmp), | |
171 | "m" ( *(struct { __extension__ char __x[__n]; } *)__src)); | |
92f1da4d UD |
172 | else |
173 | __asm__ __volatile__ | |
174 | ("std\n\t" | |
175 | "rep; movsb\n\t" | |
176 | "cld" | |
49f8b030 AJ |
177 | : "=&c" (__d0), "=&S" (__d1), "=&D" (__d2), |
178 | "=m" ( *(struct { __extension__ char __x[__n]; } *)__dest) | |
a784e502 | 179 | : "0" (__n), "1" (__n - 1 + (const char *) __src), |
49f8b030 AJ |
180 | "2" (__n - 1 + (char *) __tmp), |
181 | "m" ( *(struct { __extension__ char __x[__n]; } *)__src)); | |
92f1da4d UD |
182 | return __dest; |
183 | } | |
6704c645 | 184 | # endif |
92f1da4d UD |
185 | |
186 | /* Compare N bytes of S1 and S2. */ | |
6704c645 L |
187 | # define _HAVE_STRING_ARCH_memcmp 1 |
188 | # ifndef _FORCE_INLINES | |
189 | # ifndef __PIC__ | |
92f1da4d UD |
190 | /* gcc has problems to spill registers when using PIC. */ |
191 | __STRING_INLINE int | |
a784e502 | 192 | memcmp (const void *__s1, const void *__s2, size_t __n) |
92f1da4d | 193 | { |
a44d2393 | 194 | register unsigned long int __d0, __d1, __d2; |
92f1da4d UD |
195 | register int __res; |
196 | __asm__ __volatile__ | |
197 | ("cld\n\t" | |
7cd1708f | 198 | "testl %3,%3\n\t" |
92f1da4d UD |
199 | "repe; cmpsb\n\t" |
200 | "je 1f\n\t" | |
201 | "sbbl %0,%0\n\t" | |
cf546481 | 202 | "orl $1,%0\n" |
92f1da4d | 203 | "1:" |
b664d723 | 204 | : "=&a" (__res), "=&S" (__d0), "=&D" (__d1), "=&c" (__d2) |
49f8b030 AJ |
205 | : "0" (0), "1" (__s1), "2" (__s2), "3" (__n), |
206 | "m" ( *(struct { __extension__ char __x[__n]; } *)__s1), | |
207 | "m" ( *(struct { __extension__ char __x[__n]; } *)__s2) | |
a44d2393 | 208 | : "cc"); |
92f1da4d UD |
209 | return __res; |
210 | } | |
6704c645 | 211 | # endif |
9bbd7837 | 212 | # endif |
92f1da4d | 213 | |
92f1da4d | 214 | /* Set N bytes of S to C. */ |
6704c645 L |
215 | # define _HAVE_STRING_ARCH_memset 1 |
216 | # define _USE_STRING_ARCH_memset 1 | |
217 | # define memset(s, c, n) \ | |
cf546481 | 218 | (__extension__ (__builtin_constant_p (n) && (n) <= 16 \ |
0d3fe819 | 219 | ? ((n) == 1 \ |
6876cdf8 RM |
220 | ? __memset_c1 ((s), (c)) \ |
221 | : __memset_gc ((s), (c), (n))) \ | |
cf546481 UD |
222 | : (__builtin_constant_p (c) \ |
223 | ? (__builtin_constant_p (n) \ | |
6876cdf8 RM |
224 | ? __memset_ccn ((s), (c), (n)) \ |
225 | : memset ((s), (c), (n))) \ | |
cf546481 | 226 | : (__builtin_constant_p (n) \ |
6876cdf8 RM |
227 | ? __memset_gcn ((s), (c), (n)) \ |
228 | : memset ((s), (c), (n)))))) | |
cf546481 | 229 | |
6704c645 L |
230 | # define __memset_c1(s, c) ({ void *__s = (s); \ |
231 | *((unsigned char *) __s) = (unsigned char) (c); \ | |
232 | __s; }) | |
cf546481 | 233 | |
6704c645 | 234 | # define __memset_gc(s, c, n) \ |
cf546481 | 235 | ({ void *__s = (s); \ |
722c33bb UD |
236 | union { \ |
237 | unsigned int __ui; \ | |
238 | unsigned short int __usi; \ | |
239 | unsigned char __uc; \ | |
240 | } *__u = __s; \ | |
0d3fe819 | 241 | unsigned int __c = ((unsigned int) ((unsigned char) (c))) * 0x01010101; \ |
cf546481 UD |
242 | \ |
243 | /* We apply a trick here. `gcc' would implement the following \ | |
722c33bb UD |
244 | assignments using immediate operands. But this uses to much \ |
245 | memory (7, instead of 4 bytes). So we force the value in a \ | |
246 | registers. */ \ | |
642eb2a2 | 247 | if ((n) == 3 || (n) >= 5) \ |
cf546481 UD |
248 | __asm__ __volatile__ ("" : "=r" (__c) : "0" (__c)); \ |
249 | \ | |
250 | /* This `switch' statement will be removed at compile-time. */ \ | |
251 | switch (n) \ | |
252 | { \ | |
253 | case 15: \ | |
722c33bb | 254 | __u->__ui = __c; \ |
87843f15 | 255 | __u = __extension__ ((void *) __u + 4); \ |
cf546481 | 256 | case 11: \ |
722c33bb | 257 | __u->__ui = __c; \ |
87843f15 | 258 | __u = __extension__ ((void *) __u + 4); \ |
cf546481 | 259 | case 7: \ |
722c33bb | 260 | __u->__ui = __c; \ |
87843f15 | 261 | __u = __extension__ ((void *) __u + 4); \ |
cf546481 | 262 | case 3: \ |
722c33bb | 263 | __u->__usi = (unsigned short int) __c; \ |
87843f15 | 264 | __u = __extension__ ((void *) __u + 2); \ |
722c33bb | 265 | __u->__uc = (unsigned char) __c; \ |
cf546481 UD |
266 | break; \ |
267 | \ | |
268 | case 14: \ | |
722c33bb | 269 | __u->__ui = __c; \ |
87843f15 | 270 | __u = __extension__ ((void *) __u + 4); \ |
cf546481 | 271 | case 10: \ |
722c33bb | 272 | __u->__ui = __c; \ |
87843f15 | 273 | __u = __extension__ ((void *) __u + 4); \ |
cf546481 | 274 | case 6: \ |
722c33bb | 275 | __u->__ui = __c; \ |
87843f15 | 276 | __u = __extension__ ((void *) __u + 4); \ |
cf546481 | 277 | case 2: \ |
722c33bb | 278 | __u->__usi = (unsigned short int) __c; \ |
cf546481 UD |
279 | break; \ |
280 | \ | |
281 | case 13: \ | |
722c33bb | 282 | __u->__ui = __c; \ |
87843f15 | 283 | __u = __extension__ ((void *) __u + 4); \ |
cf546481 | 284 | case 9: \ |
722c33bb | 285 | __u->__ui = __c; \ |
87843f15 | 286 | __u = __extension__ ((void *) __u + 4); \ |
cf546481 | 287 | case 5: \ |
722c33bb | 288 | __u->__ui = __c; \ |
87843f15 | 289 | __u = __extension__ ((void *) __u + 4); \ |
cf546481 | 290 | case 1: \ |
722c33bb | 291 | __u->__uc = (unsigned char) __c; \ |
cf546481 UD |
292 | break; \ |
293 | \ | |
294 | case 16: \ | |
722c33bb | 295 | __u->__ui = __c; \ |
87843f15 | 296 | __u = __extension__ ((void *) __u + 4); \ |
cf546481 | 297 | case 12: \ |
722c33bb | 298 | __u->__ui = __c; \ |
87843f15 | 299 | __u = __extension__ ((void *) __u + 4); \ |
cf546481 | 300 | case 8: \ |
722c33bb | 301 | __u->__ui = __c; \ |
87843f15 | 302 | __u = __extension__ ((void *) __u + 4); \ |
cf546481 | 303 | case 4: \ |
722c33bb | 304 | __u->__ui = __c; \ |
cf546481 UD |
305 | case 0: \ |
306 | break; \ | |
307 | } \ | |
308 | \ | |
309 | __s; }) | |
310 | ||
6704c645 | 311 | # define __memset_ccn(s, c, n) \ |
cf546481 | 312 | (((n) % 4 == 0) \ |
0d3fe819 UD |
313 | ? __memset_ccn_by4 (s, ((unsigned int) ((unsigned char) (c))) * 0x01010101,\ |
314 | n) \ | |
cf546481 | 315 | : (((n) % 2 == 0) \ |
0d3fe819 UD |
316 | ? __memset_ccn_by2 (s, \ |
317 | ((unsigned int) ((unsigned char) (c))) * 0x01010101,\ | |
318 | n) \ | |
319 | : memset (s, c, n))) | |
cf546481 | 320 | |
0d3fe819 UD |
321 | __STRING_INLINE void *__memset_ccn_by4 (void *__s, unsigned int __c, |
322 | size_t __n); | |
cf546481 UD |
323 | |
324 | __STRING_INLINE void * | |
0d3fe819 | 325 | __memset_ccn_by4 (void *__s, unsigned int __c, size_t __n) |
cf546481 UD |
326 | { |
327 | register void *__tmp = __s; | |
328 | register unsigned long int __d0; | |
6704c645 | 329 | # ifdef __i686__ |
cf546481 UD |
330 | __asm__ __volatile__ |
331 | ("cld\n\t" | |
332 | "rep; stosl" | |
49f8b030 AJ |
333 | : "=&a" (__c), "=&D" (__tmp), "=&c" (__d0), |
334 | "=m" ( *(struct { __extension__ char __x[__n]; } *)__s) | |
cf546481 | 335 | : "0" ((unsigned int) __c), "1" (__tmp), "2" (__n / 4) |
49f8b030 | 336 | : "cc"); |
6704c645 | 337 | # else |
cf546481 UD |
338 | __asm__ __volatile__ |
339 | ("1:\n\t" | |
340 | "movl %0,(%1)\n\t" | |
341 | "addl $4,%1\n\t" | |
342 | "decl %2\n\t" | |
343 | "jnz 1b\n" | |
49f8b030 AJ |
344 | : "=&r" (__c), "=&r" (__tmp), "=&r" (__d0), |
345 | "=m" ( *(struct { __extension__ char __x[__n]; } *)__s) | |
cf546481 | 346 | : "0" ((unsigned int) __c), "1" (__tmp), "2" (__n / 4) |
49f8b030 | 347 | : "cc"); |
6704c645 | 348 | # endif |
cf546481 UD |
349 | return __s; |
350 | } | |
92f1da4d | 351 | |
0d3fe819 UD |
352 | __STRING_INLINE void *__memset_ccn_by2 (void *__s, unsigned int __c, |
353 | size_t __n); | |
348ed515 | 354 | |
92f1da4d | 355 | __STRING_INLINE void * |
0d3fe819 | 356 | __memset_ccn_by2 (void *__s, unsigned int __c, size_t __n) |
cf546481 UD |
357 | { |
358 | register unsigned long int __d0, __d1; | |
359 | register void *__tmp = __s; | |
6704c645 | 360 | # ifdef __i686__ |
cf546481 UD |
361 | __asm__ __volatile__ |
362 | ("cld\n\t" | |
363 | "rep; stosl\n" | |
364 | "stosw" | |
49f8b030 AJ |
365 | : "=&a" (__d0), "=&D" (__tmp), "=&c" (__d1), |
366 | "=m" ( *(struct { __extension__ char __x[__n]; } *)__s) | |
cf546481 | 367 | : "0" ((unsigned int) __c), "1" (__tmp), "2" (__n / 4) |
49f8b030 | 368 | : "cc"); |
6704c645 | 369 | # else |
cf546481 UD |
370 | __asm__ __volatile__ |
371 | ("1:\tmovl %0,(%1)\n\t" | |
372 | "leal 4(%1),%1\n\t" | |
373 | "decl %2\n\t" | |
374 | "jnz 1b\n" | |
375 | "movw %w0,(%1)" | |
49f8b030 AJ |
376 | : "=&q" (__d0), "=&r" (__tmp), "=&r" (__d1), |
377 | "=m" ( *(struct { __extension__ char __x[__n]; } *)__s) | |
cf546481 | 378 | : "0" ((unsigned int) __c), "1" (__tmp), "2" (__n / 4) |
49f8b030 | 379 | : "cc"); |
cf546481 UD |
380 | #endif |
381 | return __s; | |
382 | } | |
383 | ||
6704c645 | 384 | # define __memset_gcn(s, c, n) \ |
cf546481 UD |
385 | (((n) % 4 == 0) \ |
386 | ? __memset_gcn_by4 (s, c, n) \ | |
387 | : (((n) % 2 == 0) \ | |
388 | ? __memset_gcn_by2 (s, c, n) \ | |
0d3fe819 | 389 | : memset (s, c, n))) |
cf546481 UD |
390 | |
391 | __STRING_INLINE void *__memset_gcn_by4 (void *__s, int __c, size_t __n); | |
392 | ||
393 | __STRING_INLINE void * | |
394 | __memset_gcn_by4 (void *__s, int __c, size_t __n) | |
92f1da4d UD |
395 | { |
396 | register void *__tmp = __s; | |
a44d2393 | 397 | register unsigned long int __d0; |
92f1da4d UD |
398 | __asm__ __volatile__ |
399 | ("movb %b0,%h0\n" | |
400 | "pushw %w0\n\t" | |
401 | "shll $16,%0\n\t" | |
402 | "popw %w0\n" | |
403 | "1:\n\t" | |
404 | "movl %0,(%1)\n\t" | |
405 | "addl $4,%1\n\t" | |
406 | "decl %2\n\t" | |
407 | "jnz 1b\n" | |
49f8b030 AJ |
408 | : "=&q" (__c), "=&r" (__tmp), "=&r" (__d0), |
409 | "=m" ( *(struct { __extension__ char __x[__n]; } *)__s) | |
92f1da4d | 410 | : "0" ((unsigned int) __c), "1" (__tmp), "2" (__n / 4) |
49f8b030 | 411 | : "cc"); |
92f1da4d UD |
412 | return __s; |
413 | } | |
414 | ||
cf546481 | 415 | __STRING_INLINE void *__memset_gcn_by2 (void *__s, int __c, size_t __n); |
348ed515 | 416 | |
92f1da4d | 417 | __STRING_INLINE void * |
cf546481 | 418 | __memset_gcn_by2 (void *__s, int __c, size_t __n) |
92f1da4d | 419 | { |
a44d2393 | 420 | register unsigned long int __d0, __d1; |
92f1da4d | 421 | register void *__tmp = __s; |
92f1da4d UD |
422 | __asm__ __volatile__ |
423 | ("movb %b0,%h0\n\t" | |
92f1da4d UD |
424 | "pushw %w0\n\t" |
425 | "shll $16,%0\n\t" | |
426 | "popw %w0\n" | |
427 | "1:\n\t" | |
428 | "movl %0,(%1)\n\t" | |
429 | "leal 4(%1),%1\n\t" | |
430 | "decl %2\n\t" | |
431 | "jnz 1b\n" | |
92f1da4d | 432 | "movw %w0,(%1)" |
49f8b030 AJ |
433 | : "=&q" (__d0), "=&r" (__tmp), "=&r" (__d1), |
434 | "=m" ( *(struct { __extension__ char __x[__n]; } *)__s) | |
cf546481 | 435 | : "0" ((unsigned int) __c), "1" (__tmp), "2" (__n / 4) |
49f8b030 | 436 | : "cc"); |
92f1da4d UD |
437 | return __s; |
438 | } | |
439 | ||
92f1da4d UD |
440 | |
441 | /* Search N bytes of S for C. */ | |
6704c645 L |
442 | # define _HAVE_STRING_ARCH_memchr 1 |
443 | # ifndef _FORCE_INLINES | |
92f1da4d | 444 | __STRING_INLINE void * |
a784e502 | 445 | memchr (const void *__s, int __c, size_t __n) |
92f1da4d | 446 | { |
a44d2393 | 447 | register unsigned long int __d0; |
6704c645 | 448 | # ifdef __i686__ |
cf546481 | 449 | register unsigned long int __d1; |
6704c645 | 450 | # endif |
b39c6f8b | 451 | register unsigned char *__res; |
92f1da4d UD |
452 | if (__n == 0) |
453 | return NULL; | |
6704c645 | 454 | # ifdef __i686__ |
a44d2393 | 455 | __asm__ __volatile__ |
cf546481 | 456 | ("cld\n\t" |
a44d2393 | 457 | "repne; scasb\n\t" |
cf546481 UD |
458 | "cmovne %2,%0" |
459 | : "=D" (__res), "=&c" (__d0), "=&r" (__d1) | |
49f8b030 AJ |
460 | : "a" (__c), "0" (__s), "1" (__n), "2" (1), |
461 | "m" ( *(struct { __extension__ char __x[__n]; } *)__s) | |
cf546481 | 462 | : "cc"); |
6704c645 | 463 | # else |
92f1da4d UD |
464 | __asm__ __volatile__ |
465 | ("cld\n\t" | |
466 | "repne; scasb\n\t" | |
467 | "je 1f\n\t" | |
468 | "movl $1,%0\n" | |
a44d2393 UD |
469 | "1:" |
470 | : "=D" (__res), "=&c" (__d0) | |
49f8b030 AJ |
471 | : "a" (__c), "0" (__s), "1" (__n), |
472 | "m" ( *(struct { __extension__ char __x[__n]; } *)__s) | |
a44d2393 | 473 | : "cc"); |
6704c645 | 474 | # endif |
a44d2393 | 475 | return __res - 1; |
92f1da4d | 476 | } |
6704c645 | 477 | # endif |
92f1da4d | 478 | |
6704c645 L |
479 | # define _HAVE_STRING_ARCH_memrchr 1 |
480 | # ifndef _FORCE_INLINES | |
a784e502 | 481 | __STRING_INLINE void *__memrchr (const void *__s, int __c, size_t __n); |
b91703dc | 482 | |
22baad3c | 483 | __STRING_INLINE void * |
a784e502 | 484 | __memrchr (const void *__s, int __c, size_t __n) |
22baad3c UD |
485 | { |
486 | register unsigned long int __d0; | |
6704c645 | 487 | # ifdef __i686__ |
22baad3c | 488 | register unsigned long int __d1; |
6704c645 | 489 | # endif |
22baad3c UD |
490 | register void *__res; |
491 | if (__n == 0) | |
492 | return NULL; | |
6704c645 | 493 | # ifdef __i686__ |
22baad3c UD |
494 | __asm__ __volatile__ |
495 | ("std\n\t" | |
496 | "repne; scasb\n\t" | |
497 | "cmovne %2,%0\n\t" | |
b7f75e24 AJ |
498 | "cld\n\t" |
499 | "incl %0" | |
22baad3c | 500 | : "=D" (__res), "=&c" (__d0), "=&r" (__d1) |
49f8b030 AJ |
501 | : "a" (__c), "0" (__s + __n - 1), "1" (__n), "2" (-1), |
502 | "m" ( *(struct { __extension__ char __x[__n]; } *)__s) | |
22baad3c | 503 | : "cc"); |
6704c645 | 504 | # else |
22baad3c UD |
505 | __asm__ __volatile__ |
506 | ("std\n\t" | |
507 | "repne; scasb\n\t" | |
508 | "je 1f\n\t" | |
fbda91b1 | 509 | "orl $-1,%0\n" |
b7f75e24 AJ |
510 | "1:\tcld\n\t" |
511 | "incl %0" | |
22baad3c | 512 | : "=D" (__res), "=&c" (__d0) |
49f8b030 AJ |
513 | : "a" (__c), "0" (__s + __n - 1), "1" (__n), |
514 | "m" ( *(struct { __extension__ char __x[__n]; } *)__s) | |
22baad3c | 515 | : "cc"); |
6704c645 | 516 | # endif |
b7f75e24 | 517 | return __res; |
22baad3c | 518 | } |
6704c645 L |
519 | # ifdef __USE_GNU |
520 | # define memrchr(s, c, n) __memrchr ((s), (c), (n)) | |
521 | # endif | |
fbda91b1 | 522 | # endif |
22baad3c | 523 | |
482eec0d | 524 | /* Return pointer to C in S. */ |
6704c645 | 525 | # define _HAVE_STRING_ARCH_rawmemchr 1 |
73334e85 UD |
526 | __STRING_INLINE void *__rawmemchr (const void *__s, int __c); |
527 | ||
6704c645 | 528 | # ifndef _FORCE_INLINES |
482eec0d UD |
529 | __STRING_INLINE void * |
530 | __rawmemchr (const void *__s, int __c) | |
531 | { | |
532 | register unsigned long int __d0; | |
533 | register unsigned char *__res; | |
534 | __asm__ __volatile__ | |
535 | ("cld\n\t" | |
536 | "repne; scasb\n\t" | |
537 | : "=D" (__res), "=&c" (__d0) | |
49f8b030 AJ |
538 | : "a" (__c), "0" (__s), "1" (0xffffffff), |
539 | "m" ( *(struct { char __x[0xfffffff]; } *)__s) | |
482eec0d UD |
540 | : "cc"); |
541 | return __res - 1; | |
542 | } | |
6704c645 | 543 | # ifdef __USE_GNU |
482eec0d UD |
544 | __STRING_INLINE void * |
545 | rawmemchr (const void *__s, int __c) | |
546 | { | |
547 | return __rawmemchr (__s, __c); | |
548 | } | |
6704c645 L |
549 | # endif /* use GNU */ |
550 | # endif | |
482eec0d UD |
551 | |
552 | ||
92f1da4d | 553 | /* Return the length of S. */ |
6704c645 L |
554 | # define _HAVE_STRING_ARCH_strlen 1 |
555 | # define strlen(str) \ | |
9a0a462c | 556 | (__extension__ (__builtin_constant_p (str) \ |
650425ce | 557 | ? __builtin_strlen (str) \ |
9a0a462c | 558 | : __strlen_g (str))) |
a784e502 | 559 | __STRING_INLINE size_t __strlen_g (const char *__str); |
348ed515 | 560 | |
92f1da4d | 561 | __STRING_INLINE size_t |
a784e502 | 562 | __strlen_g (const char *__str) |
92f1da4d UD |
563 | { |
564 | register char __dummy; | |
a784e502 | 565 | register const char *__tmp = __str; |
92f1da4d UD |
566 | __asm__ __volatile__ |
567 | ("1:\n\t" | |
9a0a462c | 568 | "movb (%0),%b1\n\t" |
92f1da4d | 569 | "leal 1(%0),%0\n\t" |
9a0a462c | 570 | "testb %b1,%b1\n\t" |
92f1da4d | 571 | "jne 1b" |
a44d2393 | 572 | : "=r" (__tmp), "=&q" (__dummy) |
49f8b030 AJ |
573 | : "0" (__str), |
574 | "m" ( *(struct { char __x[0xfffffff]; } *)__str) | |
575 | : "cc" ); | |
92f1da4d UD |
576 | return __tmp - __str - 1; |
577 | } | |
578 | ||
579 | ||
580 | /* Copy SRC to DEST. */ | |
6704c645 L |
581 | # define _HAVE_STRING_ARCH_strcpy 1 |
582 | # define strcpy(dest, src) \ | |
9a0a462c | 583 | (__extension__ (__builtin_constant_p (src) \ |
a5a0310d | 584 | ? (sizeof ((src)[0]) == 1 && strlen (src) + 1 <= 8 \ |
6876cdf8 RM |
585 | ? __strcpy_a_small ((dest), (src), strlen (src) + 1) \ |
586 | : (char *) memcpy ((char *) (dest), \ | |
a784e502 | 587 | (const char *) (src), \ |
fab6d621 | 588 | strlen (src) + 1)) \ |
6876cdf8 | 589 | : __strcpy_g ((dest), (src)))) |
9a0a462c | 590 | |
6704c645 | 591 | # define __strcpy_a_small(dest, src, srclen) \ |
722c33bb UD |
592 | (__extension__ ({ char *__dest = (dest); \ |
593 | union { \ | |
594 | unsigned int __ui; \ | |
595 | unsigned short int __usi; \ | |
596 | unsigned char __uc; \ | |
597 | char __c; \ | |
598 | } *__u = (void *) __dest; \ | |
61eb22d3 UD |
599 | switch (srclen) \ |
600 | { \ | |
601 | case 1: \ | |
722c33bb | 602 | __u->__uc = '\0'; \ |
61eb22d3 UD |
603 | break; \ |
604 | case 2: \ | |
722c33bb | 605 | __u->__usi = __STRING_SMALL_GET16 (src, 0); \ |
61eb22d3 UD |
606 | break; \ |
607 | case 3: \ | |
722c33bb | 608 | __u->__usi = __STRING_SMALL_GET16 (src, 0); \ |
87843f15 | 609 | __u = __extension__ ((void *) __u + 2); \ |
722c33bb | 610 | __u->__uc = '\0'; \ |
61eb22d3 UD |
611 | break; \ |
612 | case 4: \ | |
722c33bb | 613 | __u->__ui = __STRING_SMALL_GET32 (src, 0); \ |
61eb22d3 UD |
614 | break; \ |
615 | case 5: \ | |
722c33bb | 616 | __u->__ui = __STRING_SMALL_GET32 (src, 0); \ |
87843f15 | 617 | __u = __extension__ ((void *) __u + 4); \ |
722c33bb | 618 | __u->__uc = '\0'; \ |
61eb22d3 UD |
619 | break; \ |
620 | case 6: \ | |
722c33bb | 621 | __u->__ui = __STRING_SMALL_GET32 (src, 0); \ |
87843f15 | 622 | __u = __extension__ ((void *) __u + 4); \ |
722c33bb | 623 | __u->__usi = __STRING_SMALL_GET16 (src, 4); \ |
61eb22d3 UD |
624 | break; \ |
625 | case 7: \ | |
722c33bb | 626 | __u->__ui = __STRING_SMALL_GET32 (src, 0); \ |
87843f15 | 627 | __u = __extension__ ((void *) __u + 4); \ |
722c33bb | 628 | __u->__usi = __STRING_SMALL_GET16 (src, 4); \ |
87843f15 | 629 | __u = __extension__ ((void *) __u + 2); \ |
722c33bb | 630 | __u->__uc = '\0'; \ |
61eb22d3 UD |
631 | break; \ |
632 | case 8: \ | |
722c33bb | 633 | __u->__ui = __STRING_SMALL_GET32 (src, 0); \ |
87843f15 | 634 | __u = __extension__ ((void *) __u + 4); \ |
722c33bb | 635 | __u->__ui = __STRING_SMALL_GET32 (src, 4); \ |
61eb22d3 UD |
636 | break; \ |
637 | } \ | |
650425ce | 638 | (char *) __dest; })) |
61eb22d3 | 639 | |
a784e502 | 640 | __STRING_INLINE char *__strcpy_g (char *__dest, const char *__src); |
348ed515 | 641 | |
92f1da4d | 642 | __STRING_INLINE char * |
a784e502 | 643 | __strcpy_g (char *__dest, const char *__src) |
92f1da4d UD |
644 | { |
645 | register char *__tmp = __dest; | |
646 | register char __dummy; | |
647 | __asm__ __volatile__ | |
648 | ( | |
649 | "1:\n\t" | |
9a0a462c UD |
650 | "movb (%0),%b2\n\t" |
651 | "leal 1(%0),%0\n\t" | |
652 | "movb %b2,(%1)\n\t" | |
653 | "leal 1(%1),%1\n\t" | |
654 | "testb %b2,%b2\n\t" | |
92f1da4d | 655 | "jne 1b" |
216455bc RM |
656 | : "=&r" (__src), "=&r" (__tmp), "=&q" (__dummy), |
657 | "=m" ( *(struct { char __x[0xfffffff]; } *)__dest) | |
49f8b030 | 658 | : "0" (__src), "1" (__tmp), |
216455bc | 659 | "m" ( *(struct { char __x[0xfffffff]; } *)__src) |
49f8b030 | 660 | : "cc"); |
92f1da4d UD |
661 | return __dest; |
662 | } | |
663 | ||
664 | ||
6704c645 L |
665 | # ifdef __USE_GNU |
666 | # define _HAVE_STRING_ARCH_stpcpy 1 | |
9a0a462c | 667 | /* Copy SRC to DEST. */ |
6704c645 | 668 | # define __stpcpy(dest, src) \ |
9a0a462c UD |
669 | (__extension__ (__builtin_constant_p (src) \ |
670 | ? (strlen (src) + 1 <= 8 \ | |
6876cdf8 RM |
671 | ? __stpcpy_a_small ((dest), (src), strlen (src) + 1) \ |
672 | : __stpcpy_c ((dest), (src), strlen (src) + 1)) \ | |
673 | : __stpcpy_g ((dest), (src)))) | |
6704c645 | 674 | # define __stpcpy_c(dest, src, srclen) \ |
9a0a462c | 675 | ((srclen) % 4 == 0 \ |
650425ce | 676 | ? __mempcpy_by4 (dest, src, srclen) - 1 \ |
9a0a462c | 677 | : ((srclen) % 2 == 0 \ |
650425ce UD |
678 | ? __mempcpy_by2 (dest, src, srclen) - 1 \ |
679 | : __mempcpy_byn (dest, src, srclen) - 1)) | |
9a0a462c UD |
680 | |
681 | /* In glibc itself we use this symbol for namespace reasons. */ | |
6704c645 | 682 | # define stpcpy(dest, src) __stpcpy ((dest), (src)) |
9a0a462c | 683 | |
6704c645 | 684 | # define __stpcpy_a_small(dest, src, srclen) \ |
722c33bb UD |
685 | (__extension__ ({ union { \ |
686 | unsigned int __ui; \ | |
687 | unsigned short int __usi; \ | |
688 | unsigned char __uc; \ | |
689 | char __c; \ | |
690 | } *__u = (void *) (dest); \ | |
61eb22d3 UD |
691 | switch (srclen) \ |
692 | { \ | |
693 | case 1: \ | |
722c33bb | 694 | __u->__uc = '\0'; \ |
61eb22d3 UD |
695 | break; \ |
696 | case 2: \ | |
722c33bb | 697 | __u->__usi = __STRING_SMALL_GET16 (src, 0); \ |
87843f15 | 698 | __u = __extension__ ((void *) __u + 1); \ |
61eb22d3 UD |
699 | break; \ |
700 | case 3: \ | |
722c33bb | 701 | __u->__usi = __STRING_SMALL_GET16 (src, 0); \ |
87843f15 | 702 | __u = __extension__ ((void *) __u + 2); \ |
722c33bb | 703 | __u->__uc = '\0'; \ |
61eb22d3 UD |
704 | break; \ |
705 | case 4: \ | |
722c33bb | 706 | __u->__ui = __STRING_SMALL_GET32 (src, 0); \ |
87843f15 | 707 | __u = __extension__ ((void *) __u + 3); \ |
61eb22d3 UD |
708 | break; \ |
709 | case 5: \ | |
722c33bb | 710 | __u->__ui = __STRING_SMALL_GET32 (src, 0); \ |
87843f15 | 711 | __u = __extension__ ((void *) __u + 4); \ |
722c33bb | 712 | __u->__uc = '\0'; \ |
61eb22d3 UD |
713 | break; \ |
714 | case 6: \ | |
722c33bb | 715 | __u->__ui = __STRING_SMALL_GET32 (src, 0); \ |
87843f15 | 716 | __u = __extension__ ((void *) __u + 4); \ |
722c33bb | 717 | __u->__usi = __STRING_SMALL_GET16 (src, 4); \ |
87843f15 | 718 | __u = __extension__ ((void *) __u + 1); \ |
61eb22d3 UD |
719 | break; \ |
720 | case 7: \ | |
722c33bb | 721 | __u->__ui = __STRING_SMALL_GET32 (src, 0); \ |
87843f15 | 722 | __u = __extension__ ((void *) __u + 4); \ |
722c33bb | 723 | __u->__usi = __STRING_SMALL_GET16 (src, 4); \ |
87843f15 | 724 | __u = __extension__ ((void *) __u + 2); \ |
722c33bb | 725 | __u->__uc = '\0'; \ |
61eb22d3 UD |
726 | break; \ |
727 | case 8: \ | |
722c33bb | 728 | __u->__ui = __STRING_SMALL_GET32 (src, 0); \ |
87843f15 | 729 | __u = __extension__ ((void *) __u + 4); \ |
722c33bb | 730 | __u->__ui = __STRING_SMALL_GET32 (src, 4); \ |
87843f15 | 731 | __u = __extension__ ((void *) __u + 3); \ |
61eb22d3 UD |
732 | break; \ |
733 | } \ | |
722c33bb | 734 | (char *) __u; })) |
9a0a462c | 735 | |
a784e502 | 736 | __STRING_INLINE char *__mempcpy_by4 (char *__dest, const char *__src, |
348ed515 UD |
737 | size_t __srclen); |
738 | ||
9a0a462c | 739 | __STRING_INLINE char * |
a784e502 | 740 | __mempcpy_by4 (char *__dest, const char *__src, size_t __srclen) |
9a0a462c UD |
741 | { |
742 | register char *__tmp = __dest; | |
a44d2393 | 743 | register unsigned long int __d0, __d1; |
9a0a462c UD |
744 | __asm__ __volatile__ |
745 | ("1:\n\t" | |
746 | "movl (%2),%0\n\t" | |
747 | "leal 4(%2),%2\n\t" | |
748 | "movl %0,(%1)\n\t" | |
749 | "leal 4(%1),%1\n\t" | |
750 | "decl %3\n\t" | |
751 | "jnz 1b" | |
b91703dc AJ |
752 | : "=&r" (__d0), "=r" (__tmp), "=&r" (__src), "=&r" (__d1) |
753 | : "1" (__tmp), "2" (__src), "3" (__srclen / 4) | |
754 | : "memory", "cc"); | |
650425ce | 755 | return __tmp; |
9a0a462c UD |
756 | } |
757 | ||
a784e502 | 758 | __STRING_INLINE char *__mempcpy_by2 (char *__dest, const char *__src, |
348ed515 UD |
759 | size_t __srclen); |
760 | ||
9a0a462c | 761 | __STRING_INLINE char * |
a784e502 | 762 | __mempcpy_by2 (char *__dest, const char *__src, size_t __srclen) |
9a0a462c UD |
763 | { |
764 | register char *__tmp = __dest; | |
a44d2393 | 765 | register unsigned long int __d0, __d1; |
9a0a462c UD |
766 | __asm__ __volatile__ |
767 | ("shrl $1,%3\n\t" | |
768 | "jz 2f\n" /* only a word */ | |
769 | "1:\n\t" | |
770 | "movl (%2),%0\n\t" | |
771 | "leal 4(%2),%2\n\t" | |
772 | "movl %0,(%1)\n\t" | |
773 | "leal 4(%1),%1\n\t" | |
774 | "decl %3\n\t" | |
775 | "jnz 1b\n" | |
776 | "2:\n\t" | |
777 | "movw (%2),%w0\n\t" | |
778 | "movw %w0,(%1)" | |
49f8b030 AJ |
779 | : "=&q" (__d0), "=r" (__tmp), "=&r" (__src), "=&r" (__d1), |
780 | "=m" ( *(struct { __extension__ char __x[__srclen]; } *)__dest) | |
781 | : "1" (__tmp), "2" (__src), "3" (__srclen / 2), | |
782 | "m" ( *(struct { __extension__ char __x[__srclen]; } *)__src) | |
783 | : "cc"); | |
650425ce | 784 | return __tmp + 2; |
9a0a462c UD |
785 | } |
786 | ||
a784e502 | 787 | __STRING_INLINE char *__mempcpy_byn (char *__dest, const char *__src, |
348ed515 UD |
788 | size_t __srclen); |
789 | ||
9a0a462c | 790 | __STRING_INLINE char * |
a784e502 | 791 | __mempcpy_byn (char *__dest, const char *__src, size_t __srclen) |
9a0a462c | 792 | { |
a44d2393 | 793 | register unsigned long __d0, __d1; |
9a0a462c UD |
794 | register char *__tmp = __dest; |
795 | __asm__ __volatile__ | |
796 | ("cld\n\t" | |
797 | "shrl $1,%%ecx\n\t" | |
798 | "jnc 1f\n\t" | |
799 | "movsb\n" | |
800 | "1:\n\t" | |
801 | "shrl $1,%%ecx\n\t" | |
802 | "jnc 2f\n\t" | |
803 | "movsw\n" | |
804 | "2:\n\t" | |
805 | "rep; movsl" | |
49f8b030 AJ |
806 | : "=D" (__tmp), "=&c" (__d0), "=&S" (__d1), |
807 | "=m" ( *(struct { __extension__ char __x[__srclen]; } *)__dest) | |
808 | : "0" (__tmp), "1" (__srclen), "2" (__src), | |
809 | "m" ( *(struct { __extension__ char __x[__srclen]; } *)__src) | |
810 | : "cc"); | |
650425ce | 811 | return __tmp; |
9a0a462c UD |
812 | } |
813 | ||
a784e502 | 814 | __STRING_INLINE char *__stpcpy_g (char *__dest, const char *__src); |
348ed515 | 815 | |
9a0a462c | 816 | __STRING_INLINE char * |
a784e502 | 817 | __stpcpy_g (char *__dest, const char *__src) |
9a0a462c UD |
818 | { |
819 | register char *__tmp = __dest; | |
820 | register char __dummy; | |
821 | __asm__ __volatile__ | |
822 | ( | |
823 | "1:\n\t" | |
824 | "movb (%0),%b2\n\t" | |
825 | "leal 1(%0),%0\n\t" | |
826 | "movb %b2,(%1)\n\t" | |
827 | "leal 1(%1),%1\n\t" | |
828 | "testb %b2,%b2\n\t" | |
829 | "jne 1b" | |
49f8b030 AJ |
830 | : "=&r" (__src), "=r" (__tmp), "=&q" (__dummy), |
831 | "=m" ( *(struct { char __x[0xfffffff]; } *)__dest) | |
832 | : "0" (__src), "1" (__tmp), | |
833 | "m" ( *(struct { char __x[0xfffffff]; } *)__src) | |
834 | : "cc"); | |
9a0a462c UD |
835 | return __tmp - 1; |
836 | } | |
6704c645 | 837 | # endif |
9a0a462c UD |
838 | |
839 | ||
92f1da4d | 840 | /* Copy no more than N characters of SRC to DEST. */ |
6704c645 L |
841 | # define _HAVE_STRING_ARCH_strncpy 1 |
842 | # define strncpy(dest, src, n) \ | |
9a0a462c UD |
843 | (__extension__ (__builtin_constant_p (src) \ |
844 | ? ((strlen (src) + 1 >= ((size_t) (n)) \ | |
6876cdf8 | 845 | ? (char *) memcpy ((char *) (dest), \ |
a784e502 | 846 | (const char *) (src), n) \ |
6876cdf8 RM |
847 | : __strncpy_cg ((dest), (src), strlen (src) + 1, n))) \ |
848 | : __strncpy_gg ((dest), (src), n))) | |
6704c645 | 849 | # define __strncpy_cg(dest, src, srclen, n) \ |
9a0a462c UD |
850 | (((srclen) % 4 == 0) \ |
851 | ? __strncpy_by4 (dest, src, srclen, n) \ | |
852 | : (((srclen) % 2 == 0) \ | |
853 | ? __strncpy_by2 (dest, src, srclen, n) \ | |
854 | : __strncpy_byn (dest, src, srclen, n))) | |
855 | ||
a784e502 | 856 | __STRING_INLINE char *__strncpy_by4 (char *__dest, const char __src[], |
348ed515 UD |
857 | size_t __srclen, size_t __n); |
858 | ||
9a0a462c | 859 | __STRING_INLINE char * |
a784e502 | 860 | __strncpy_by4 (char *__dest, const char __src[], size_t __srclen, size_t __n) |
9a0a462c UD |
861 | { |
862 | register char *__tmp = __dest; | |
863 | register int __dummy1, __dummy2; | |
864 | __asm__ __volatile__ | |
865 | ("1:\n\t" | |
866 | "movl (%2),%0\n\t" | |
867 | "leal 4(%2),%2\n\t" | |
868 | "movl %0,(%1)\n\t" | |
869 | "leal 4(%1),%1\n\t" | |
870 | "decl %3\n\t" | |
871 | "jnz 1b" | |
49f8b030 AJ |
872 | : "=&r" (__dummy1), "=r" (__tmp), "=&r" (__src), "=&r" (__dummy2), |
873 | "=m" ( *(struct { __extension__ char __x[__srclen]; } *)__dest) | |
874 | : "1" (__tmp), "2" (__src), "3" (__srclen / 4), | |
875 | "m" ( *(struct { __extension__ char __x[__srclen]; } *)__src) | |
876 | : "cc"); | |
9a0a462c UD |
877 | (void) memset (__tmp, '\0', __n - __srclen); |
878 | return __dest; | |
879 | } | |
880 | ||
a784e502 | 881 | __STRING_INLINE char *__strncpy_by2 (char *__dest, const char __src[], |
348ed515 UD |
882 | size_t __srclen, size_t __n); |
883 | ||
92f1da4d | 884 | __STRING_INLINE char * |
a784e502 | 885 | __strncpy_by2 (char *__dest, const char __src[], size_t __srclen, size_t __n) |
9a0a462c UD |
886 | { |
887 | register char *__tmp = __dest; | |
888 | register int __dummy1, __dummy2; | |
889 | __asm__ __volatile__ | |
890 | ("shrl $1,%3\n\t" | |
891 | "jz 2f\n" /* only a word */ | |
892 | "1:\n\t" | |
893 | "movl (%2),%0\n\t" | |
894 | "leal 4(%2),%2\n\t" | |
895 | "movl %0,(%1)\n\t" | |
896 | "leal 4(%1),%1\n\t" | |
897 | "decl %3\n\t" | |
898 | "jnz 1b\n" | |
899 | "2:\n\t" | |
900 | "movw (%2),%w0\n\t" | |
901 | "movw %w0,(%1)\n\t" | |
49f8b030 AJ |
902 | : "=&q" (__dummy1), "=r" (__tmp), "=&r" (__src), "=&r" (__dummy2), |
903 | "=m" ( *(struct { __extension__ char __x[__srclen]; } *)__dest) | |
904 | : "1" (__tmp), "2" (__src), "3" (__srclen / 2), | |
905 | "m" ( *(struct { __extension__ char __x[__srclen]; } *)__src) | |
906 | : "cc"); | |
9a0a462c UD |
907 | (void) memset (__tmp + 2, '\0', __n - __srclen); |
908 | return __dest; | |
909 | } | |
910 | ||
a784e502 | 911 | __STRING_INLINE char *__strncpy_byn (char *__dest, const char __src[], |
348ed515 UD |
912 | size_t __srclen, size_t __n); |
913 | ||
9a0a462c | 914 | __STRING_INLINE char * |
a784e502 | 915 | __strncpy_byn (char *__dest, const char __src[], size_t __srclen, size_t __n) |
9a0a462c | 916 | { |
a44d2393 | 917 | register unsigned long int __d0, __d1; |
9a0a462c UD |
918 | register char *__tmp = __dest; |
919 | __asm__ __volatile__ | |
920 | ("cld\n\t" | |
a44d2393 | 921 | "shrl $1,%1\n\t" |
9a0a462c UD |
922 | "jnc 1f\n\t" |
923 | "movsb\n" | |
924 | "1:\n\t" | |
a44d2393 | 925 | "shrl $1,%1\n\t" |
9a0a462c UD |
926 | "jnc 2f\n\t" |
927 | "movsw\n" | |
928 | "2:\n\t" | |
929 | "rep; movsl" | |
49f8b030 AJ |
930 | : "=D" (__tmp), "=&c" (__d0), "=&S" (__d1), |
931 | "=m" ( *(struct { __extension__ char __x[__srclen]; } *)__dest) | |
932 | : "1" (__srclen), "0" (__tmp),"2" (__src), | |
933 | "m" ( *(struct { __extension__ char __x[__srclen]; } *)__src) | |
934 | : "cc"); | |
9a0a462c UD |
935 | (void) memset (__tmp, '\0', __n - __srclen); |
936 | return __dest; | |
937 | } | |
938 | ||
a784e502 | 939 | __STRING_INLINE char *__strncpy_gg (char *__dest, const char *__src, |
348ed515 UD |
940 | size_t __n); |
941 | ||
9a0a462c | 942 | __STRING_INLINE char * |
a784e502 | 943 | __strncpy_gg (char *__dest, const char *__src, size_t __n) |
92f1da4d UD |
944 | { |
945 | register char *__tmp = __dest; | |
946 | register char __dummy; | |
947 | if (__n > 0) | |
948 | __asm__ __volatile__ | |
949 | ("1:\n\t" | |
950 | "movb (%0),%2\n\t" | |
951 | "incl %0\n\t" | |
952 | "movb %2,(%1)\n\t" | |
953 | "incl %1\n\t" | |
954 | "decl %3\n\t" | |
955 | "je 3f\n\t" | |
956 | "testb %2,%2\n\t" | |
957 | "jne 1b\n\t" | |
958 | "2:\n\t" | |
959 | "movb %2,(%1)\n\t" | |
960 | "incl %1\n\t" | |
961 | "decl %3\n\t" | |
962 | "jne 2b\n\t" | |
963 | "3:" | |
a44d2393 | 964 | : "=&r" (__src), "=&r" (__tmp), "=&q" (__dummy), "=&r" (__n) |
92f1da4d UD |
965 | : "0" (__src), "1" (__tmp), "3" (__n) |
966 | : "memory", "cc"); | |
967 | ||
968 | return __dest; | |
969 | } | |
970 | ||
971 | ||
972 | /* Append SRC onto DEST. */ | |
6704c645 L |
973 | # define _HAVE_STRING_ARCH_strcat 1 |
974 | # define strcat(dest, src) \ | |
9a0a462c | 975 | (__extension__ (__builtin_constant_p (src) \ |
6876cdf8 RM |
976 | ? __strcat_c ((dest), (src), strlen (src) + 1) \ |
977 | : __strcat_g ((dest), (src)))) | |
9a0a462c | 978 | |
a784e502 | 979 | __STRING_INLINE char *__strcat_c (char *__dest, const char __src[], |
348ed515 UD |
980 | size_t __srclen); |
981 | ||
9a0a462c | 982 | __STRING_INLINE char * |
a784e502 | 983 | __strcat_c (char *__dest, const char __src[], size_t __srclen) |
9a0a462c | 984 | { |
6704c645 | 985 | # ifdef __i686__ |
a44d2393 UD |
986 | register unsigned long int __d0; |
987 | register char *__tmp; | |
988 | __asm__ __volatile__ | |
9afc8a59 | 989 | ("repne; scasb" |
49f8b030 AJ |
990 | : "=D" (__tmp), "=&c" (__d0), |
991 | "=m" ( *(struct { char __x[0xfffffff]; } *)__dest) | |
992 | : "0" (__dest), "1" (0xffffffff), "a" (0), | |
993 | "m" ( *(struct { __extension__ char __x[__srclen]; } *)__src) | |
a44d2393 | 994 | : "cc"); |
9afc8a59 | 995 | --__tmp; |
6704c645 | 996 | # else |
9a0a462c UD |
997 | register char *__tmp = __dest - 1; |
998 | __asm__ __volatile__ | |
999 | ("1:\n\t" | |
1000 | "incl %0\n\t" | |
1001 | "cmpb $0,(%0)\n\t" | |
1002 | "jne 1b\n" | |
49f8b030 AJ |
1003 | : "=r" (__tmp), |
1004 | "=m" ( *(struct { char __x[0xfffffff]; } *)__dest) | |
1005 | : "0" (__tmp), | |
1006 | "m" ( *(struct { __extension__ char __x[__srclen]; } *)__src) | |
9a0a462c | 1007 | : "cc"); |
6704c645 | 1008 | # endif |
9a0a462c UD |
1009 | (void) memcpy (__tmp, __src, __srclen); |
1010 | return __dest; | |
1011 | } | |
1012 | ||
a784e502 | 1013 | __STRING_INLINE char *__strcat_g (char *__dest, const char *__src); |
348ed515 | 1014 | |
92f1da4d | 1015 | __STRING_INLINE char * |
a784e502 | 1016 | __strcat_g (char *__dest, const char *__src) |
92f1da4d UD |
1017 | { |
1018 | register char *__tmp = __dest - 1; | |
1019 | register char __dummy; | |
1020 | __asm__ __volatile__ | |
9a0a462c | 1021 | ("1:\n\t" |
92f1da4d UD |
1022 | "incl %1\n\t" |
1023 | "cmpb $0,(%1)\n\t" | |
1024 | "jne 1b\n" | |
1025 | "2:\n\t" | |
1026 | "movb (%2),%b0\n\t" | |
1027 | "incl %2\n\t" | |
1028 | "movb %b0,(%1)\n\t" | |
1029 | "incl %1\n\t" | |
1030 | "testb %b0,%b0\n\t" | |
1031 | "jne 2b\n" | |
49f8b030 AJ |
1032 | : "=&q" (__dummy), "=&r" (__tmp), "=&r" (__src), |
1033 | "=m" ( *(struct { char __x[0xfffffff]; } *)__dest) | |
1034 | : "1" (__tmp), "2" (__src), | |
1035 | "m" ( *(struct { char __x[0xfffffff]; } *)__src) | |
92f1da4d UD |
1036 | : "memory", "cc"); |
1037 | return __dest; | |
1038 | } | |
1039 | ||
1040 | ||
1041 | /* Append no more than N characters from SRC onto DEST. */ | |
6704c645 L |
1042 | # define _HAVE_STRING_ARCH_strncat 1 |
1043 | # define strncat(dest, src, n) \ | |
650425ce UD |
1044 | (__extension__ ({ char *__dest = (dest); \ |
1045 | __builtin_constant_p (src) && __builtin_constant_p (n) \ | |
1046 | ? (strlen (src) < ((size_t) (n)) \ | |
6876cdf8 RM |
1047 | ? strcat (__dest, (src)) \ |
1048 | : (*(char *)__mempcpy (strchr (__dest, '\0'), \ | |
a784e502 | 1049 | (const char *) (src), \ |
6876cdf8 RM |
1050 | (n)) = 0, __dest)) \ |
1051 | : __strncat_g (__dest, (src), (n)); })) | |
9a0a462c | 1052 | |
a784e502 | 1053 | __STRING_INLINE char *__strncat_g (char *__dest, const char __src[], |
348ed515 UD |
1054 | size_t __n); |
1055 | ||
92f1da4d | 1056 | __STRING_INLINE char * |
a784e502 | 1057 | __strncat_g (char *__dest, const char __src[], size_t __n) |
92f1da4d | 1058 | { |
9afc8a59 | 1059 | register char *__tmp = __dest; |
92f1da4d | 1060 | register char __dummy; |
6704c645 | 1061 | # ifdef __i686__ |
9afc8a59 UD |
1062 | __asm__ __volatile__ |
1063 | ("repne; scasb\n" | |
ca5d7882 | 1064 | "movl %4, %3\n\t" |
9afc8a59 UD |
1065 | "decl %1\n\t" |
1066 | "1:\n\t" | |
8c1a459f AS |
1067 | "subl $1,%3\n\t" |
1068 | "jc 2f\n\t" | |
9afc8a59 UD |
1069 | "movb (%2),%b0\n\t" |
1070 | "movsb\n\t" | |
1071 | "testb %b0,%b0\n\t" | |
1072 | "jne 1b\n\t" | |
1073 | "decl %1\n" | |
1074 | "2:\n\t" | |
1075 | "movb $0,(%1)" | |
68784f80 | 1076 | : "=&a" (__dummy), "=&D" (__tmp), "=&S" (__src), "=&c" (__n) |
ca5d7882 | 1077 | : "g" (__n), "0" (0), "1" (__tmp), "2" (__src), "3" (0xffffffff) |
9afc8a59 | 1078 | : "memory", "cc"); |
6704c645 | 1079 | # else |
9afc8a59 | 1080 | --__tmp; |
92f1da4d | 1081 | __asm__ __volatile__ |
9a0a462c UD |
1082 | ("1:\n\t" |
1083 | "cmpb $0,1(%1)\n\t" | |
1084 | "leal 1(%1),%1\n\t" | |
92f1da4d UD |
1085 | "jne 1b\n" |
1086 | "2:\n\t" | |
8c1a459f AS |
1087 | "subl $1,%3\n\t" |
1088 | "jc 3f\n\t" | |
92f1da4d UD |
1089 | "movb (%2),%b0\n\t" |
1090 | "leal 1(%2),%2\n\t" | |
1091 | "movb %b0,(%1)\n\t" | |
1092 | "leal 1(%1),%1\n\t" | |
1093 | "testb %b0,%b0\n\t" | |
9a0a462c UD |
1094 | "jne 2b\n\t" |
1095 | "decl %1\n" | |
92f1da4d | 1096 | "3:\n\t" |
9afc8a59 | 1097 | "movb $0,(%1)" |
a44d2393 | 1098 | : "=&q" (__dummy), "=&r" (__tmp), "=&r" (__src), "=&r" (__n) |
92f1da4d UD |
1099 | : "1" (__tmp), "2" (__src), "3" (__n) |
1100 | : "memory", "cc"); | |
9afc8a59 | 1101 | #endif |
92f1da4d UD |
1102 | return __dest; |
1103 | } | |
1104 | ||
1105 | ||
1106 | /* Compare S1 and S2. */ | |
6704c645 L |
1107 | # define _HAVE_STRING_ARCH_strcmp 1 |
1108 | # define strcmp(s1, s2) \ | |
650425ce | 1109 | (__extension__ (__builtin_constant_p (s1) && __builtin_constant_p (s2) \ |
a5a0310d UD |
1110 | && (sizeof ((s1)[0]) != 1 || strlen (s1) >= 4) \ |
1111 | && (sizeof ((s2)[0]) != 1 || strlen (s2) >= 4) \ | |
a784e502 | 1112 | ? memcmp ((const char *) (s1), (const char *) (s2), \ |
fab6d621 UD |
1113 | (strlen (s1) < strlen (s2) \ |
1114 | ? strlen (s1) : strlen (s2)) + 1) \ | |
a5a0310d UD |
1115 | : (__builtin_constant_p (s1) && sizeof ((s1)[0]) == 1 \ |
1116 | && sizeof ((s2)[0]) == 1 && strlen (s1) < 4 \ | |
1117 | ? (__builtin_constant_p (s2) && sizeof ((s2)[0]) == 1 \ | |
a784e502 UD |
1118 | ? __strcmp_cc ((const unsigned char *) (s1), \ |
1119 | (const unsigned char *) (s2), \ | |
17427edd | 1120 | strlen (s1)) \ |
a784e502 UD |
1121 | : __strcmp_cg ((const unsigned char *) (s1), \ |
1122 | (const unsigned char *) (s2), \ | |
17427edd | 1123 | strlen (s1))) \ |
a5a0310d UD |
1124 | : (__builtin_constant_p (s2) && sizeof ((s1)[0]) == 1 \ |
1125 | && sizeof ((s2)[0]) == 1 && strlen (s2) < 4 \ | |
1126 | ? (__builtin_constant_p (s1) \ | |
a784e502 UD |
1127 | ? __strcmp_cc ((const unsigned char *) (s1), \ |
1128 | (const unsigned char *) (s2), \ | |
cf37087a | 1129 | strlen (s2)) \ |
a784e502 UD |
1130 | : __strcmp_gc ((const unsigned char *) (s1), \ |
1131 | (const unsigned char *) (s2), \ | |
cf37087a | 1132 | strlen (s2))) \ |
6876cdf8 | 1133 | : __strcmp_gg ((s1), (s2)))))) |
650425ce | 1134 | |
6704c645 | 1135 | # define __strcmp_cc(s1, s2, l) \ |
cf37087a | 1136 | (__extension__ ({ register int __result = (s1)[0] - (s2)[0]; \ |
a5a0310d UD |
1137 | if (l > 0 && __result == 0) \ |
1138 | { \ | |
cf37087a | 1139 | __result = (s1)[1] - (s2)[1]; \ |
a5a0310d UD |
1140 | if (l > 1 && __result == 0) \ |
1141 | { \ | |
cf37087a | 1142 | __result = (s1)[2] - (s2)[2]; \ |
a5a0310d | 1143 | if (l > 2 && __result == 0) \ |
cf37087a | 1144 | __result = (s1)[3] - (s2)[3]; \ |
a5a0310d UD |
1145 | } \ |
1146 | } \ | |
1147 | __result; })) | |
1148 | ||
6704c645 | 1149 | # define __strcmp_cg(s1, s2, l1) \ |
a784e502 | 1150 | (__extension__ ({ const unsigned char *__s2 = (s2); \ |
cf37087a | 1151 | register int __result = (s1)[0] - __s2[0]; \ |
650425ce UD |
1152 | if (l1 > 0 && __result == 0) \ |
1153 | { \ | |
cf37087a | 1154 | __result = (s1)[1] - __s2[1]; \ |
650425ce UD |
1155 | if (l1 > 1 && __result == 0) \ |
1156 | { \ | |
cf37087a | 1157 | __result = (s1)[2] - __s2[2]; \ |
650425ce | 1158 | if (l1 > 2 && __result == 0) \ |
cf37087a | 1159 | __result = (s1)[3] - __s2[3]; \ |
650425ce UD |
1160 | } \ |
1161 | } \ | |
1162 | __result; })) | |
1163 | ||
6704c645 | 1164 | # define __strcmp_gc(s1, s2, l2) \ |
a784e502 | 1165 | (__extension__ ({ const unsigned char *__s1 = (s1); \ |
cf37087a | 1166 | register int __result = __s1[0] - (s2)[0]; \ |
650425ce UD |
1167 | if (l2 > 0 && __result == 0) \ |
1168 | { \ | |
cf37087a | 1169 | __result = __s1[1] - (s2)[1]; \ |
650425ce UD |
1170 | if (l2 > 1 && __result == 0) \ |
1171 | { \ | |
cf37087a | 1172 | __result = __s1[2] - (s2)[2]; \ |
650425ce | 1173 | if (l2 > 2 && __result == 0) \ |
cf37087a | 1174 | __result = __s1[3] - (s2)[3]; \ |
650425ce UD |
1175 | } \ |
1176 | } \ | |
1177 | __result; })) | |
1178 | ||
a784e502 | 1179 | __STRING_INLINE int __strcmp_gg (const char *__s1, const char *__s2); |
348ed515 | 1180 | |
92f1da4d | 1181 | __STRING_INLINE int |
a784e502 | 1182 | __strcmp_gg (const char *__s1, const char *__s2) |
92f1da4d UD |
1183 | { |
1184 | register int __res; | |
1185 | __asm__ __volatile__ | |
1186 | ("1:\n\t" | |
1187 | "movb (%1),%b0\n\t" | |
1188 | "leal 1(%1),%1\n\t" | |
1189 | "cmpb %b0,(%2)\n\t" | |
1190 | "jne 2f\n\t" | |
1191 | "leal 1(%2),%2\n\t" | |
1192 | "testb %b0,%b0\n\t" | |
1193 | "jne 1b\n\t" | |
1194 | "xorl %0,%0\n\t" | |
1195 | "jmp 3f\n" | |
1196 | "2:\n\t" | |
1197 | "movl $1,%0\n\t" | |
1198 | "jb 3f\n\t" | |
1199 | "negl %0\n" | |
1200 | "3:" | |
a44d2393 | 1201 | : "=q" (__res), "=&r" (__s1), "=&r" (__s2) |
49f8b030 AJ |
1202 | : "1" (__s1), "2" (__s2), |
1203 | "m" ( *(struct { char __x[0xfffffff]; } *)__s1), | |
1204 | "m" ( *(struct { char __x[0xfffffff]; } *)__s2) | |
92f1da4d UD |
1205 | : "cc"); |
1206 | return __res; | |
1207 | } | |
1208 | ||
1209 | ||
1210 | /* Compare N characters of S1 and S2. */ | |
6704c645 L |
1211 | # define _HAVE_STRING_ARCH_strncmp 1 |
1212 | # define strncmp(s1, s2, n) \ | |
9a0a462c | 1213 | (__extension__ (__builtin_constant_p (s1) && strlen (s1) < ((size_t) (n)) \ |
6876cdf8 | 1214 | ? strcmp ((s1), (s2)) \ |
9a0a462c | 1215 | : (__builtin_constant_p (s2) && strlen (s2) < ((size_t) (n))\ |
6876cdf8 RM |
1216 | ? strcmp ((s1), (s2)) \ |
1217 | : __strncmp_g ((s1), (s2), (n))))) | |
9a0a462c | 1218 | |
a784e502 | 1219 | __STRING_INLINE int __strncmp_g (const char *__s1, const char *__s2, |
133d3d30 | 1220 | size_t __n); |
348ed515 | 1221 | |
92f1da4d | 1222 | __STRING_INLINE int |
a784e502 | 1223 | __strncmp_g (const char *__s1, const char *__s2, size_t __n) |
92f1da4d UD |
1224 | { |
1225 | register int __res; | |
1226 | __asm__ __volatile__ | |
1227 | ("1:\n\t" | |
8c1a459f AS |
1228 | "subl $1,%3\n\t" |
1229 | "jc 2f\n\t" | |
92f1da4d UD |
1230 | "movb (%1),%b0\n\t" |
1231 | "incl %1\n\t" | |
1232 | "cmpb %b0,(%2)\n\t" | |
1233 | "jne 3f\n\t" | |
1234 | "incl %2\n\t" | |
1235 | "testb %b0,%b0\n\t" | |
1236 | "jne 1b\n" | |
1237 | "2:\n\t" | |
1238 | "xorl %0,%0\n\t" | |
1239 | "jmp 4f\n" | |
1240 | "3:\n\t" | |
1241 | "movl $1,%0\n\t" | |
1242 | "jb 4f\n\t" | |
1243 | "negl %0\n" | |
1244 | "4:" | |
a44d2393 | 1245 | : "=q" (__res), "=&r" (__s1), "=&r" (__s2), "=&r" (__n) |
49f8b030 AJ |
1246 | : "1" (__s1), "2" (__s2), "3" (__n), |
1247 | "m" ( *(struct { __extension__ char __x[__n]; } *)__s1), | |
1248 | "m" ( *(struct { __extension__ char __x[__n]; } *)__s2) | |
92f1da4d UD |
1249 | : "cc"); |
1250 | return __res; | |
1251 | } | |
1252 | ||
1253 | ||
1254 | /* Find the first occurrence of C in S. */ | |
6704c645 L |
1255 | # define _HAVE_STRING_ARCH_strchr 1 |
1256 | # define _USE_STRING_ARCH_strchr 1 | |
1257 | # define strchr(s, c) \ | |
92f1da4d | 1258 | (__extension__ (__builtin_constant_p (c) \ |
482eec0d | 1259 | ? ((c) == '\0' \ |
6876cdf8 RM |
1260 | ? (char *) __rawmemchr ((s), (c)) \ |
1261 | : __strchr_c ((s), ((c) & 0xff) << 8)) \ | |
1262 | : __strchr_g ((s), (c)))) | |
92f1da4d | 1263 | |
a784e502 | 1264 | __STRING_INLINE char *__strchr_c (const char *__s, int __c); |
348ed515 | 1265 | |
92f1da4d | 1266 | __STRING_INLINE char * |
a784e502 | 1267 | __strchr_c (const char *__s, int __c) |
92f1da4d | 1268 | { |
a44d2393 | 1269 | register unsigned long int __d0; |
92f1da4d UD |
1270 | register char *__res; |
1271 | __asm__ __volatile__ | |
9a0a462c | 1272 | ("1:\n\t" |
92f1da4d UD |
1273 | "movb (%0),%%al\n\t" |
1274 | "cmpb %%ah,%%al\n\t" | |
1275 | "je 2f\n\t" | |
1276 | "leal 1(%0),%0\n\t" | |
1277 | "testb %%al,%%al\n\t" | |
1278 | "jne 1b\n\t" | |
1279 | "xorl %0,%0\n" | |
1280 | "2:" | |
a44d2393 | 1281 | : "=r" (__res), "=&a" (__d0) |
49f8b030 AJ |
1282 | : "0" (__s), "1" (__c), |
1283 | "m" ( *(struct { char __x[0xfffffff]; } *)__s) | |
a44d2393 | 1284 | : "cc"); |
92f1da4d UD |
1285 | return __res; |
1286 | } | |
1287 | ||
a784e502 | 1288 | __STRING_INLINE char *__strchr_g (const char *__s, int __c); |
348ed515 | 1289 | |
92f1da4d | 1290 | __STRING_INLINE char * |
a784e502 | 1291 | __strchr_g (const char *__s, int __c) |
92f1da4d | 1292 | { |
a44d2393 | 1293 | register unsigned long int __d0; |
92f1da4d UD |
1294 | register char *__res; |
1295 | __asm__ __volatile__ | |
9a0a462c UD |
1296 | ("movb %%al,%%ah\n" |
1297 | "1:\n\t" | |
92f1da4d UD |
1298 | "movb (%0),%%al\n\t" |
1299 | "cmpb %%ah,%%al\n\t" | |
1300 | "je 2f\n\t" | |
1301 | "leal 1(%0),%0\n\t" | |
1302 | "testb %%al,%%al\n\t" | |
1303 | "jne 1b\n\t" | |
1304 | "xorl %0,%0\n" | |
1305 | "2:" | |
a44d2393 | 1306 | : "=r" (__res), "=&a" (__d0) |
49f8b030 AJ |
1307 | : "0" (__s), "1" (__c), |
1308 | "m" ( *(struct { char __x[0xfffffff]; } *)__s) | |
a44d2393 | 1309 | : "cc"); |
92f1da4d UD |
1310 | return __res; |
1311 | } | |
1312 | ||
1313 | ||
c4563d2d | 1314 | /* Find the first occurrence of C in S or the final NUL byte. */ |
6704c645 L |
1315 | # define _HAVE_STRING_ARCH_strchrnul 1 |
1316 | # define __strchrnul(s, c) \ | |
c4563d2d UD |
1317 | (__extension__ (__builtin_constant_p (c) \ |
1318 | ? ((c) == '\0' \ | |
6876cdf8 RM |
1319 | ? (char *) __rawmemchr ((s), c) \ |
1320 | : __strchrnul_c ((s), ((c) & 0xff) << 8)) \ | |
1321 | : __strchrnul_g ((s), c))) | |
c4563d2d | 1322 | |
a784e502 | 1323 | __STRING_INLINE char *__strchrnul_c (const char *__s, int __c); |
c4563d2d UD |
1324 | |
1325 | __STRING_INLINE char * | |
a784e502 | 1326 | __strchrnul_c (const char *__s, int __c) |
c4563d2d UD |
1327 | { |
1328 | register unsigned long int __d0; | |
1329 | register char *__res; | |
1330 | __asm__ __volatile__ | |
1331 | ("1:\n\t" | |
1332 | "movb (%0),%%al\n\t" | |
1333 | "cmpb %%ah,%%al\n\t" | |
1334 | "je 2f\n\t" | |
1335 | "leal 1(%0),%0\n\t" | |
1336 | "testb %%al,%%al\n\t" | |
1337 | "jne 1b\n\t" | |
1338 | "decl %0\n" | |
1339 | "2:" | |
1340 | : "=r" (__res), "=&a" (__d0) | |
49f8b030 AJ |
1341 | : "0" (__s), "1" (__c), |
1342 | "m" ( *(struct { char __x[0xfffffff]; } *)__s) | |
c4563d2d UD |
1343 | : "cc"); |
1344 | return __res; | |
1345 | } | |
1346 | ||
a784e502 | 1347 | __STRING_INLINE char *__strchrnul_g (const char *__s, int __c); |
c4563d2d UD |
1348 | |
1349 | __STRING_INLINE char * | |
a784e502 | 1350 | __strchrnul_g (const char *__s, int __c) |
c4563d2d UD |
1351 | { |
1352 | register unsigned long int __d0; | |
1353 | register char *__res; | |
1354 | __asm__ __volatile__ | |
1355 | ("movb %%al,%%ah\n" | |
1356 | "1:\n\t" | |
1357 | "movb (%0),%%al\n\t" | |
1358 | "cmpb %%ah,%%al\n\t" | |
1359 | "je 2f\n\t" | |
1360 | "leal 1(%0),%0\n\t" | |
1361 | "testb %%al,%%al\n\t" | |
1362 | "jne 1b\n\t" | |
1363 | "decl %0\n" | |
1364 | "2:" | |
1365 | : "=r" (__res), "=&a" (__d0) | |
49f8b030 AJ |
1366 | : "0" (__s), "1" (__c), |
1367 | "m" ( *(struct { char __x[0xfffffff]; } *)__s) | |
c4563d2d UD |
1368 | : "cc"); |
1369 | return __res; | |
1370 | } | |
6704c645 L |
1371 | # ifdef __USE_GNU |
1372 | # define strchrnul(s, c) __strchrnul ((s), (c)) | |
1373 | # endif | |
c4563d2d UD |
1374 | |
1375 | ||
498afc54 | 1376 | # if defined __USE_MISC || defined __USE_XOPEN_EXTENDED |
f2ea0f5b | 1377 | /* Find the first occurrence of C in S. This is the BSD name. */ |
6704c645 L |
1378 | # define _HAVE_STRING_ARCH_index 1 |
1379 | # define index(s, c) \ | |
f2ea0f5b | 1380 | (__extension__ (__builtin_constant_p (c) \ |
6876cdf8 RM |
1381 | ? __strchr_c ((s), ((c) & 0xff) << 8) \ |
1382 | : __strchr_g ((s), (c)))) | |
6704c645 | 1383 | # endif |
f2ea0f5b UD |
1384 | |
1385 | ||
92f1da4d | 1386 | /* Find the last occurrence of C in S. */ |
6704c645 L |
1387 | # define _HAVE_STRING_ARCH_strrchr 1 |
1388 | # define strrchr(s, c) \ | |
92f1da4d | 1389 | (__extension__ (__builtin_constant_p (c) \ |
6876cdf8 RM |
1390 | ? __strrchr_c ((s), ((c) & 0xff) << 8) \ |
1391 | : __strrchr_g ((s), (c)))) | |
92f1da4d | 1392 | |
6704c645 | 1393 | # ifdef __i686__ |
a784e502 | 1394 | __STRING_INLINE char *__strrchr_c (const char *__s, int __c); |
348ed515 | 1395 | |
9a0a462c | 1396 | __STRING_INLINE char * |
a784e502 | 1397 | __strrchr_c (const char *__s, int __c) |
9a0a462c | 1398 | { |
a44d2393 | 1399 | register unsigned long int __d0, __d1; |
9a0a462c UD |
1400 | register char *__res; |
1401 | __asm__ __volatile__ | |
1402 | ("cld\n" | |
1403 | "1:\n\t" | |
1404 | "lodsb\n\t" | |
a44d2393 UD |
1405 | "cmpb %h2,%b2\n\t" |
1406 | "cmove %1,%0\n\t" | |
1407 | "testb %b2,%b2\n\t" | |
9a0a462c | 1408 | "jne 1b" |
a44d2393 | 1409 | : "=d" (__res), "=&S" (__d0), "=&a" (__d1) |
49f8b030 AJ |
1410 | : "0" (1), "1" (__s), "2" (__c), |
1411 | "m" ( *(struct { char __x[0xfffffff]; } *)__s) | |
a44d2393 | 1412 | : "cc"); |
9a0a462c UD |
1413 | return __res - 1; |
1414 | } | |
1415 | ||
a784e502 | 1416 | __STRING_INLINE char *__strrchr_g (const char *__s, int __c); |
348ed515 | 1417 | |
92f1da4d | 1418 | __STRING_INLINE char * |
a784e502 | 1419 | __strrchr_g (const char *__s, int __c) |
92f1da4d | 1420 | { |
a44d2393 | 1421 | register unsigned long int __d0, __d1; |
92f1da4d UD |
1422 | register char *__res; |
1423 | __asm__ __volatile__ | |
a44d2393 | 1424 | ("movb %b2,%h2\n" |
9a0a462c UD |
1425 | "cld\n\t" |
1426 | "1:\n\t" | |
1427 | "lodsb\n\t" | |
a44d2393 UD |
1428 | "cmpb %h2,%b2\n\t" |
1429 | "cmove %1,%0\n\t" | |
1430 | "testb %b2,%b2\n\t" | |
9a0a462c | 1431 | "jne 1b" |
a44d2393 | 1432 | : "=d" (__res), "=&S" (__d0), "=&a" (__d1) |
49f8b030 AJ |
1433 | : "0" (1), "1" (__s), "2" (__c), |
1434 | "m" ( *(struct { char __x[0xfffffff]; } *)__s) | |
a44d2393 | 1435 | : "cc"); |
9a0a462c UD |
1436 | return __res - 1; |
1437 | } | |
6704c645 | 1438 | # else |
a784e502 | 1439 | __STRING_INLINE char *__strrchr_c (const char *__s, int __c); |
348ed515 | 1440 | |
9a0a462c | 1441 | __STRING_INLINE char * |
a784e502 | 1442 | __strrchr_c (const char *__s, int __c) |
9a0a462c | 1443 | { |
a44d2393 | 1444 | register unsigned long int __d0, __d1; |
9a0a462c UD |
1445 | register char *__res; |
1446 | __asm__ __volatile__ | |
1447 | ("cld\n" | |
92f1da4d UD |
1448 | "1:\n\t" |
1449 | "lodsb\n\t" | |
1450 | "cmpb %%ah,%%al\n\t" | |
1451 | "jne 2f\n\t" | |
1452 | "leal -1(%%esi),%0\n" | |
1453 | "2:\n\t" | |
1454 | "testb %%al,%%al\n\t" | |
1455 | "jne 1b" | |
a44d2393 | 1456 | : "=d" (__res), "=&S" (__d0), "=&a" (__d1) |
49f8b030 AJ |
1457 | : "0" (0), "1" (__s), "2" (__c), |
1458 | "m" ( *(struct { char __x[0xfffffff]; } *)__s) | |
a44d2393 | 1459 | : "cc"); |
92f1da4d UD |
1460 | return __res; |
1461 | } | |
1462 | ||
a784e502 | 1463 | __STRING_INLINE char *__strrchr_g (const char *__s, int __c); |
348ed515 | 1464 | |
92f1da4d | 1465 | __STRING_INLINE char * |
a784e502 | 1466 | __strrchr_g (const char *__s, int __c) |
92f1da4d | 1467 | { |
a44d2393 | 1468 | register unsigned long int __d0, __d1; |
92f1da4d UD |
1469 | register char *__res; |
1470 | __asm__ __volatile__ | |
9a0a462c UD |
1471 | ("movb %%al,%%ah\n" |
1472 | "cld\n\t" | |
92f1da4d UD |
1473 | "1:\n\t" |
1474 | "lodsb\n\t" | |
1475 | "cmpb %%ah,%%al\n\t" | |
1476 | "jne 2f\n\t" | |
1477 | "leal -1(%%esi),%0\n" | |
1478 | "2:\n\t" | |
1479 | "testb %%al,%%al\n\t" | |
1480 | "jne 1b" | |
a44d2393 | 1481 | : "=r" (__res), "=&S" (__d0), "=&a" (__d1) |
49f8b030 AJ |
1482 | : "0" (0), "1" (__s), "2" (__c), |
1483 | "m" ( *(struct { char __x[0xfffffff]; } *)__s) | |
a44d2393 | 1484 | : "cc"); |
92f1da4d UD |
1485 | return __res; |
1486 | } | |
6704c645 | 1487 | # endif |
92f1da4d UD |
1488 | |
1489 | ||
498afc54 | 1490 | # if defined __USE_MISC || defined __USE_XOPEN_EXTENDED |
f2ea0f5b | 1491 | /* Find the last occurrence of C in S. This is the BSD name. */ |
6704c645 L |
1492 | # define _HAVE_STRING_ARCH_rindex 1 |
1493 | # define rindex(s, c) \ | |
f2ea0f5b | 1494 | (__extension__ (__builtin_constant_p (c) \ |
6876cdf8 RM |
1495 | ? __strrchr_c ((s), ((c) & 0xff) << 8) \ |
1496 | : __strrchr_g ((s), (c)))) | |
6704c645 | 1497 | # endif |
f2ea0f5b UD |
1498 | |
1499 | ||
92f1da4d UD |
1500 | /* Return the length of the initial segment of S which |
1501 | consists entirely of characters not in REJECT. */ | |
6704c645 L |
1502 | # define _HAVE_STRING_ARCH_strcspn 1 |
1503 | # define strcspn(s, reject) \ | |
9a0a462c UD |
1504 | (__extension__ (__builtin_constant_p (reject) && sizeof ((reject)[0]) == 1 \ |
1505 | ? ((reject)[0] == '\0' \ | |
1506 | ? strlen (s) \ | |
1507 | : ((reject)[1] == '\0' \ | |
6876cdf8 RM |
1508 | ? __strcspn_c1 ((s), (((reject)[0] << 8) & 0xff00)) \ |
1509 | : __strcspn_cg ((s), (reject), strlen (reject)))) \ | |
1510 | : __strcspn_g ((s), (reject)))) | |
9a0a462c | 1511 | |
a784e502 | 1512 | __STRING_INLINE size_t __strcspn_c1 (const char *__s, int __reject); |
348ed515 | 1513 | |
6704c645 | 1514 | # ifndef _FORCE_INLINES |
92f1da4d | 1515 | __STRING_INLINE size_t |
a784e502 | 1516 | __strcspn_c1 (const char *__s, int __reject) |
92f1da4d | 1517 | { |
a44d2393 | 1518 | register unsigned long int __d0; |
92f1da4d UD |
1519 | register char *__res; |
1520 | __asm__ __volatile__ | |
9a0a462c UD |
1521 | ("1:\n\t" |
1522 | "movb (%0),%%al\n\t" | |
1523 | "leal 1(%0),%0\n\t" | |
1524 | "cmpb %%ah,%%al\n\t" | |
1525 | "je 2f\n\t" | |
1526 | "testb %%al,%%al\n\t" | |
1527 | "jne 1b\n" | |
1528 | "2:" | |
a44d2393 | 1529 | : "=r" (__res), "=&a" (__d0) |
49f8b030 AJ |
1530 | : "0" (__s), "1" (__reject), |
1531 | "m" ( *(struct { char __x[0xfffffff]; } *)__s) | |
a44d2393 | 1532 | : "cc"); |
9a0a462c UD |
1533 | return (__res - 1) - __s; |
1534 | } | |
6704c645 | 1535 | # endif |
9a0a462c | 1536 | |
a784e502 UD |
1537 | __STRING_INLINE size_t __strcspn_cg (const char *__s, const char __reject[], |
1538 | size_t __reject_len); | |
348ed515 | 1539 | |
9a0a462c | 1540 | __STRING_INLINE size_t |
a784e502 | 1541 | __strcspn_cg (const char *__s, const char __reject[], size_t __reject_len) |
9a0a462c | 1542 | { |
a44d2393 | 1543 | register unsigned long int __d0, __d1, __d2; |
a784e502 | 1544 | register const char *__res; |
9a0a462c | 1545 | __asm__ __volatile__ |
a5a0310d | 1546 | ("cld\n" |
9a0a462c UD |
1547 | "1:\n\t" |
1548 | "lodsb\n\t" | |
1549 | "testb %%al,%%al\n\t" | |
1550 | "je 2f\n\t" | |
a44d2393 UD |
1551 | "movl %5,%%edi\n\t" |
1552 | "movl %6,%%ecx\n\t" | |
9a0a462c UD |
1553 | "repne; scasb\n\t" |
1554 | "jne 1b\n" | |
a5a0310d | 1555 | "2:" |
a44d2393 | 1556 | : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2) |
b91703dc AJ |
1557 | : "0" (__s), "d" (__reject), "g" (__reject_len) |
1558 | : "memory", "cc"); | |
9a0a462c UD |
1559 | return (__res - 1) - __s; |
1560 | } | |
1561 | ||
a784e502 | 1562 | __STRING_INLINE size_t __strcspn_g (const char *__s, const char *__reject); |
6704c645 | 1563 | # ifdef __PIC__ |
348ed515 | 1564 | |
9a0a462c | 1565 | __STRING_INLINE size_t |
a784e502 | 1566 | __strcspn_g (const char *__s, const char *__reject) |
9a0a462c | 1567 | { |
a44d2393 | 1568 | register unsigned long int __d0, __d1, __d2; |
a784e502 | 1569 | register const char *__res; |
9a0a462c | 1570 | __asm__ __volatile__ |
a44d2393 UD |
1571 | ("pushl %%ebx\n\t" |
1572 | "movl %4,%%edi\n\t" | |
9a0a462c | 1573 | "cld\n\t" |
92f1da4d UD |
1574 | "repne; scasb\n\t" |
1575 | "notl %%ecx\n\t" | |
9a0a462c | 1576 | "leal -1(%%ecx),%%ebx\n" |
92f1da4d UD |
1577 | "1:\n\t" |
1578 | "lodsb\n\t" | |
1579 | "testb %%al,%%al\n\t" | |
1580 | "je 2f\n\t" | |
a44d2393 | 1581 | "movl %4,%%edi\n\t" |
92f1da4d UD |
1582 | "movl %%ebx,%%ecx\n\t" |
1583 | "repne; scasb\n\t" | |
1584 | "jne 1b\n" | |
1585 | "2:\n\t" | |
a44d2393 UD |
1586 | "popl %%ebx" |
1587 | : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2) | |
1588 | : "r" (__reject), "0" (__s), "1" (0), "2" (0xffffffff) | |
49f8b030 | 1589 | : "memory", "cc"); |
92f1da4d UD |
1590 | return (__res - 1) - __s; |
1591 | } | |
6704c645 | 1592 | # else |
9a0a462c | 1593 | __STRING_INLINE size_t |
a784e502 | 1594 | __strcspn_g (const char *__s, const char *__reject) |
9a0a462c | 1595 | { |
a44d2393 | 1596 | register unsigned long int __d0, __d1, __d2, __d3; |
a784e502 | 1597 | register const char *__res; |
92f1da4d UD |
1598 | __asm__ __volatile__ |
1599 | ("cld\n\t" | |
92f1da4d UD |
1600 | "repne; scasb\n\t" |
1601 | "notl %%ecx\n\t" | |
9a0a462c | 1602 | "leal -1(%%ecx),%%edx\n" |
92f1da4d UD |
1603 | "1:\n\t" |
1604 | "lodsb\n\t" | |
1605 | "testb %%al,%%al\n\t" | |
1606 | "je 2f\n\t" | |
9a0a462c | 1607 | "movl %%ebx,%%edi\n\t" |
92f1da4d UD |
1608 | "movl %%edx,%%ecx\n\t" |
1609 | "repne; scasb\n\t" | |
1610 | "jne 1b\n" | |
1611 | "2:" | |
a44d2393 UD |
1612 | : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2), "=&d" (__d3) |
1613 | : "0" (__s), "1" (0), "2" (0xffffffff), "3" (__reject), "b" (__reject) | |
49f8b030 AJ |
1614 | /* Clobber memory, otherwise GCC cannot handle this. */ |
1615 | : "memory", "cc"); | |
92f1da4d UD |
1616 | return (__res - 1) - __s; |
1617 | } | |
6704c645 | 1618 | # endif |
92f1da4d UD |
1619 | |
1620 | ||
1621 | /* Return the length of the initial segment of S which | |
1622 | consists entirely of characters in ACCEPT. */ | |
6704c645 L |
1623 | # define _HAVE_STRING_ARCH_strspn 1 |
1624 | # define strspn(s, accept) \ | |
9a0a462c UD |
1625 | (__extension__ (__builtin_constant_p (accept) && sizeof ((accept)[0]) == 1 \ |
1626 | ? ((accept)[0] == '\0' \ | |
9c3b1ceb | 1627 | ? ((void) (s), 0) \ |
9a0a462c | 1628 | : ((accept)[1] == '\0' \ |
6876cdf8 RM |
1629 | ? __strspn_c1 ((s), (((accept)[0] << 8 ) & 0xff00)) \ |
1630 | : __strspn_cg ((s), (accept), strlen (accept)))) \ | |
1631 | : __strspn_g ((s), (accept)))) | |
9a0a462c | 1632 | |
6704c645 | 1633 | # ifndef _FORCE_INLINES |
a784e502 | 1634 | __STRING_INLINE size_t __strspn_c1 (const char *__s, int __accept); |
348ed515 | 1635 | |
92f1da4d | 1636 | __STRING_INLINE size_t |
a784e502 | 1637 | __strspn_c1 (const char *__s, int __accept) |
92f1da4d | 1638 | { |
a44d2393 | 1639 | register unsigned long int __d0; |
92f1da4d | 1640 | register char *__res; |
9a0a462c | 1641 | /* Please note that __accept never can be '\0'. */ |
92f1da4d | 1642 | __asm__ __volatile__ |
9a0a462c | 1643 | ("1:\n\t" |
a44d2393 | 1644 | "movb (%0),%b1\n\t" |
9a0a462c | 1645 | "leal 1(%0),%0\n\t" |
a44d2393 | 1646 | "cmpb %h1,%b1\n\t" |
a5a0310d | 1647 | "je 1b" |
a44d2393 | 1648 | : "=r" (__res), "=&q" (__d0) |
49f8b030 AJ |
1649 | : "0" (__s), "1" (__accept), |
1650 | "m" ( *(struct { char __x[0xfffffff]; } *)__s) | |
a44d2393 | 1651 | : "cc"); |
9a0a462c UD |
1652 | return (__res - 1) - __s; |
1653 | } | |
6704c645 | 1654 | # endif |
9a0a462c | 1655 | |
a784e502 | 1656 | __STRING_INLINE size_t __strspn_cg (const char *__s, const char __accept[], |
348ed515 UD |
1657 | size_t __accept_len); |
1658 | ||
9a0a462c | 1659 | __STRING_INLINE size_t |
a784e502 | 1660 | __strspn_cg (const char *__s, const char __accept[], size_t __accept_len) |
9a0a462c | 1661 | { |
a44d2393 | 1662 | register unsigned long int __d0, __d1, __d2; |
a784e502 | 1663 | register const char *__res; |
9a0a462c | 1664 | __asm__ __volatile__ |
a5a0310d | 1665 | ("cld\n" |
9a0a462c UD |
1666 | "1:\n\t" |
1667 | "lodsb\n\t" | |
1668 | "testb %%al,%%al\n\t" | |
1669 | "je 2f\n\t" | |
642eb2a2 | 1670 | "movl %5,%%edi\n\t" |
a44d2393 | 1671 | "movl %6,%%ecx\n\t" |
9a0a462c UD |
1672 | "repne; scasb\n\t" |
1673 | "je 1b\n" | |
a5a0310d | 1674 | "2:" |
642eb2a2 UD |
1675 | : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2) |
1676 | : "0" (__s), "g" (__accept), "g" (__accept_len), | |
1677 | /* Since we do not know how large the memory we access it, use a | |
1678 | really large amount. */ | |
49f8b030 AJ |
1679 | "m" ( *(struct { char __x[0xfffffff]; } *)__s), |
1680 | "m" ( *(struct { __extension__ char __x[__accept_len]; } *)__accept) | |
a44d2393 | 1681 | : "cc"); |
9a0a462c UD |
1682 | return (__res - 1) - __s; |
1683 | } | |
1684 | ||
a784e502 | 1685 | __STRING_INLINE size_t __strspn_g (const char *__s, const char *__accept); |
6704c645 | 1686 | # ifdef __PIC__ |
348ed515 | 1687 | |
9a0a462c | 1688 | __STRING_INLINE size_t |
a784e502 | 1689 | __strspn_g (const char *__s, const char *__accept) |
9a0a462c | 1690 | { |
a44d2393 | 1691 | register unsigned long int __d0, __d1, __d2; |
a784e502 | 1692 | register const char *__res; |
9a0a462c | 1693 | __asm__ __volatile__ |
a44d2393 | 1694 | ("pushl %%ebx\n\t" |
92f1da4d | 1695 | "cld\n\t" |
92f1da4d UD |
1696 | "repne; scasb\n\t" |
1697 | "notl %%ecx\n\t" | |
9a0a462c | 1698 | "leal -1(%%ecx),%%ebx\n" |
92f1da4d UD |
1699 | "1:\n\t" |
1700 | "lodsb\n\t" | |
1701 | "testb %%al,%%al\n\t" | |
1702 | "je 2f\n\t" | |
9a0a462c | 1703 | "movl %%edx,%%edi\n\t" |
92f1da4d UD |
1704 | "movl %%ebx,%%ecx\n\t" |
1705 | "repne; scasb\n\t" | |
1706 | "je 1b\n" | |
1707 | "2:\n\t" | |
a44d2393 UD |
1708 | "popl %%ebx" |
1709 | : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2) | |
1710 | : "d" (__accept), "0" (__s), "1" (0), "2" (0xffffffff), "3" (__accept) | |
49f8b030 | 1711 | : "memory", "cc"); |
92f1da4d UD |
1712 | return (__res - 1) - __s; |
1713 | } | |
6704c645 | 1714 | # else |
9a0a462c | 1715 | __STRING_INLINE size_t |
a784e502 | 1716 | __strspn_g (const char *__s, const char *__accept) |
9a0a462c | 1717 | { |
a44d2393 | 1718 | register unsigned long int __d0, __d1, __d2, __d3; |
a784e502 | 1719 | register const char *__res; |
92f1da4d UD |
1720 | __asm__ __volatile__ |
1721 | ("cld\n\t" | |
92f1da4d UD |
1722 | "repne; scasb\n\t" |
1723 | "notl %%ecx\n\t" | |
9a0a462c | 1724 | "leal -1(%%ecx),%%edx\n" |
92f1da4d UD |
1725 | "1:\n\t" |
1726 | "lodsb\n\t" | |
1727 | "testb %%al,%%al\n\t" | |
1728 | "je 2f\n\t" | |
9a0a462c | 1729 | "movl %%ebx,%%edi\n\t" |
92f1da4d UD |
1730 | "movl %%edx,%%ecx\n\t" |
1731 | "repne; scasb\n\t" | |
1732 | "je 1b\n" | |
1733 | "2:" | |
a44d2393 UD |
1734 | : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2), "=&d" (__d3) |
1735 | : "0" (__s), "1" (0), "2" (0xffffffff), "3" (__accept), "b" (__accept) | |
49f8b030 | 1736 | : "memory", "cc"); |
92f1da4d UD |
1737 | return (__res - 1) - __s; |
1738 | } | |
6704c645 | 1739 | # endif |
92f1da4d UD |
1740 | |
1741 | ||
1742 | /* Find the first occurrence in S of any character in ACCEPT. */ | |
6704c645 L |
1743 | # define _HAVE_STRING_ARCH_strpbrk 1 |
1744 | # define strpbrk(s, accept) \ | |
9a0a462c UD |
1745 | (__extension__ (__builtin_constant_p (accept) && sizeof ((accept)[0]) == 1 \ |
1746 | ? ((accept)[0] == '\0' \ | |
495961c0 | 1747 | ? ((void) (s), (char *) 0) \ |
9a0a462c | 1748 | : ((accept)[1] == '\0' \ |
6876cdf8 RM |
1749 | ? strchr ((s), (accept)[0]) \ |
1750 | : __strpbrk_cg ((s), (accept), strlen (accept)))) \ | |
1751 | : __strpbrk_g ((s), (accept)))) | |
9a0a462c | 1752 | |
a784e502 | 1753 | __STRING_INLINE char *__strpbrk_cg (const char *__s, const char __accept[], |
348ed515 UD |
1754 | size_t __accept_len); |
1755 | ||
92f1da4d | 1756 | __STRING_INLINE char * |
a784e502 | 1757 | __strpbrk_cg (const char *__s, const char __accept[], size_t __accept_len) |
92f1da4d | 1758 | { |
a44d2393 | 1759 | register unsigned long int __d0, __d1, __d2; |
92f1da4d UD |
1760 | register char *__res; |
1761 | __asm__ __volatile__ | |
a5a0310d | 1762 | ("cld\n" |
9a0a462c UD |
1763 | "1:\n\t" |
1764 | "lodsb\n\t" | |
1765 | "testb %%al,%%al\n\t" | |
1766 | "je 2f\n\t" | |
a44d2393 UD |
1767 | "movl %5,%%edi\n\t" |
1768 | "movl %6,%%ecx\n\t" | |
9a0a462c UD |
1769 | "repne; scasb\n\t" |
1770 | "jne 1b\n\t" | |
1771 | "decl %0\n\t" | |
1772 | "jmp 3f\n" | |
1773 | "2:\n\t" | |
1774 | "xorl %0,%0\n" | |
a5a0310d | 1775 | "3:" |
a44d2393 | 1776 | : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2) |
b91703dc AJ |
1777 | : "0" (__s), "d" (__accept), "g" (__accept_len) |
1778 | : "memory", "cc"); | |
9a0a462c UD |
1779 | return __res; |
1780 | } | |
1781 | ||
a784e502 | 1782 | __STRING_INLINE char *__strpbrk_g (const char *__s, const char *__accept); |
6704c645 | 1783 | # ifdef __PIC__ |
348ed515 | 1784 | |
9a0a462c | 1785 | __STRING_INLINE char * |
a784e502 | 1786 | __strpbrk_g (const char *__s, const char *__accept) |
9a0a462c | 1787 | { |
a44d2393 | 1788 | register unsigned long int __d0, __d1, __d2; |
9a0a462c | 1789 | register char *__res; |
9a0a462c | 1790 | __asm__ __volatile__ |
a44d2393 | 1791 | ("pushl %%ebx\n\t" |
9a0a462c | 1792 | "movl %%edx,%%edi\n\t" |
92f1da4d | 1793 | "cld\n\t" |
92f1da4d UD |
1794 | "repne; scasb\n\t" |
1795 | "notl %%ecx\n\t" | |
9a0a462c | 1796 | "leal -1(%%ecx),%%ebx\n" |
92f1da4d UD |
1797 | "1:\n\t" |
1798 | "lodsb\n\t" | |
1799 | "testb %%al,%%al\n\t" | |
1800 | "je 2f\n\t" | |
9a0a462c | 1801 | "movl %%edx,%%edi\n\t" |
92f1da4d UD |
1802 | "movl %%ebx,%%ecx\n\t" |
1803 | "repne; scasb\n\t" | |
1804 | "jne 1b\n\t" | |
1805 | "decl %0\n\t" | |
1806 | "jmp 3f\n" | |
1807 | "2:\n\t" | |
1808 | "xorl %0,%0\n" | |
1809 | "3:\n\t" | |
a44d2393 UD |
1810 | "popl %%ebx" |
1811 | : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2) | |
1812 | : "d" (__accept), "0" (__s), "1" (0), "2" (0xffffffff) | |
49f8b030 | 1813 | : "memory", "cc"); |
92f1da4d UD |
1814 | return __res; |
1815 | } | |
6704c645 | 1816 | # else |
9a0a462c | 1817 | __STRING_INLINE char * |
a784e502 | 1818 | __strpbrk_g (const char *__s, const char *__accept) |
9a0a462c | 1819 | { |
a44d2393 | 1820 | register unsigned long int __d0, __d1, __d2, __d3; |
9a0a462c UD |
1821 | register char *__res; |
1822 | __asm__ __volatile__ | |
1823 | ("movl %%ebx,%%edi\n\t" | |
1824 | "cld\n\t" | |
92f1da4d UD |
1825 | "repne; scasb\n\t" |
1826 | "notl %%ecx\n\t" | |
9a0a462c | 1827 | "leal -1(%%ecx),%%edx\n" |
92f1da4d UD |
1828 | "1:\n\t" |
1829 | "lodsb\n\t" | |
1830 | "testb %%al,%%al\n\t" | |
1831 | "je 2f\n\t" | |
9a0a462c | 1832 | "movl %%ebx,%%edi\n\t" |
92f1da4d UD |
1833 | "movl %%edx,%%ecx\n\t" |
1834 | "repne; scasb\n\t" | |
1835 | "jne 1b\n\t" | |
1836 | "decl %0\n\t" | |
1837 | "jmp 3f\n" | |
1838 | "2:\n\t" | |
1839 | "xorl %0,%0\n" | |
1840 | "3:" | |
a44d2393 UD |
1841 | : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&d" (__d2), "=&D" (__d3) |
1842 | : "0" (__s), "1" (0), "2" (0xffffffff), "b" (__accept) | |
49f8b030 | 1843 | : "memory", "cc"); |
92f1da4d UD |
1844 | return __res; |
1845 | } | |
6704c645 | 1846 | # endif |
92f1da4d UD |
1847 | |
1848 | ||
1849 | /* Find the first occurrence of NEEDLE in HAYSTACK. */ | |
6704c645 L |
1850 | # define _HAVE_STRING_ARCH_strstr 1 |
1851 | # define strstr(haystack, needle) \ | |
9a0a462c UD |
1852 | (__extension__ (__builtin_constant_p (needle) && sizeof ((needle)[0]) == 1 \ |
1853 | ? ((needle)[0] == '\0' \ | |
6876cdf8 | 1854 | ? (haystack) \ |
9a0a462c | 1855 | : ((needle)[1] == '\0' \ |
6876cdf8 RM |
1856 | ? strchr ((haystack), (needle)[0]) \ |
1857 | : __strstr_cg ((haystack), (needle), \ | |
1858 | strlen (needle)))) \ | |
1859 | : __strstr_g ((haystack), (needle)))) | |
9a0a462c | 1860 | |
9a0a462c UD |
1861 | /* Please note that this function need not handle NEEDLEs with a |
1862 | length shorter than two. */ | |
a784e502 UD |
1863 | __STRING_INLINE char *__strstr_cg (const char *__haystack, |
1864 | const char __needle[], | |
348ed515 UD |
1865 | size_t __needle_len); |
1866 | ||
92f1da4d | 1867 | __STRING_INLINE char * |
a784e502 | 1868 | __strstr_cg (const char *__haystack, const char __needle[], |
9a0a462c | 1869 | size_t __needle_len) |
92f1da4d | 1870 | { |
a44d2393 | 1871 | register unsigned long int __d0, __d1, __d2; |
92f1da4d UD |
1872 | register char *__res; |
1873 | __asm__ __volatile__ | |
a5a0310d | 1874 | ("cld\n" \ |
9a0a462c | 1875 | "1:\n\t" |
a44d2393 UD |
1876 | "movl %6,%%edi\n\t" |
1877 | "movl %5,%%eax\n\t" | |
1878 | "movl %4,%%ecx\n\t" | |
9a0a462c UD |
1879 | "repe; cmpsb\n\t" |
1880 | "je 2f\n\t" | |
1881 | "cmpb $0,-1(%%esi)\n\t" | |
a44d2393 | 1882 | "leal 1(%%eax),%5\n\t" |
9a0a462c UD |
1883 | "jne 1b\n\t" |
1884 | "xorl %%eax,%%eax\n" | |
a5a0310d | 1885 | "2:" |
b664d723 | 1886 | : "=&a" (__res), "=&S" (__d0), "=&D" (__d1), "=&c" (__d2) |
b91703dc AJ |
1887 | : "g" (__needle_len), "1" (__haystack), "d" (__needle) |
1888 | : "memory", "cc"); | |
9a0a462c UD |
1889 | return __res; |
1890 | } | |
1891 | ||
a784e502 UD |
1892 | __STRING_INLINE char *__strstr_g (const char *__haystack, |
1893 | const char *__needle); | |
6704c645 | 1894 | # ifdef __PIC__ |
348ed515 | 1895 | |
9a0a462c | 1896 | __STRING_INLINE char * |
a784e502 | 1897 | __strstr_g (const char *__haystack, const char *__needle) |
9a0a462c | 1898 | { |
a44d2393 | 1899 | register unsigned long int __d0, __d1, __d2; |
9a0a462c | 1900 | register char *__res; |
9a0a462c | 1901 | __asm__ __volatile__ |
a44d2393 | 1902 | ("cld\n\t" |
92f1da4d UD |
1903 | "repne; scasb\n\t" |
1904 | "notl %%ecx\n\t" | |
a44d2393 | 1905 | "pushl %%ebx\n\t" |
92f1da4d UD |
1906 | "decl %%ecx\n\t" /* NOTE! This also sets Z if searchstring='' */ |
1907 | "movl %%ecx,%%ebx\n" | |
1908 | "1:\n\t" | |
9a0a462c | 1909 | "movl %%edx,%%edi\n\t" |
92f1da4d UD |
1910 | "movl %%esi,%%eax\n\t" |
1911 | "movl %%ebx,%%ecx\n\t" | |
1912 | "repe; cmpsb\n\t" | |
1913 | "je 2f\n\t" /* also works for empty string, see above */ | |
9a0a462c UD |
1914 | "cmpb $0,-1(%%esi)\n\t" |
1915 | "leal 1(%%eax),%%esi\n\t" | |
92f1da4d | 1916 | "jne 1b\n\t" |
9a0a462c | 1917 | "xorl %%eax,%%eax\n" |
92f1da4d | 1918 | "2:\n\t" |
a44d2393 | 1919 | "popl %%ebx" |
b664d723 | 1920 | : "=&a" (__res), "=&c" (__d0), "=&S" (__d1), "=&D" (__d2) |
685cb06a UD |
1921 | : "0" (0), "1" (0xffffffff), "2" (__haystack), "3" (__needle), |
1922 | "d" (__needle) | |
49f8b030 | 1923 | : "memory", "cc"); |
92f1da4d UD |
1924 | return __res; |
1925 | } | |
6704c645 | 1926 | # else |
9a0a462c | 1927 | __STRING_INLINE char * |
a784e502 | 1928 | __strstr_g (const char *__haystack, const char *__needle) |
9a0a462c | 1929 | { |
cb343854 | 1930 | register unsigned long int __d0, __d1, __d2, __d3; |
9a0a462c UD |
1931 | register char *__res; |
1932 | __asm__ __volatile__ | |
a44d2393 | 1933 | ("cld\n\t" |
92f1da4d UD |
1934 | "repne; scasb\n\t" |
1935 | "notl %%ecx\n\t" | |
1936 | "decl %%ecx\n\t" /* NOTE! This also sets Z if searchstring='' */ | |
1937 | "movl %%ecx,%%edx\n" | |
1938 | "1:\n\t" | |
9a0a462c | 1939 | "movl %%ebx,%%edi\n\t" |
92f1da4d UD |
1940 | "movl %%esi,%%eax\n\t" |
1941 | "movl %%edx,%%ecx\n\t" | |
1942 | "repe; cmpsb\n\t" | |
1943 | "je 2f\n\t" /* also works for empty string, see above */ | |
9a0a462c UD |
1944 | "cmpb $0,-1(%%esi)\n\t" |
1945 | "leal 1(%%eax),%%esi\n\t" | |
92f1da4d | 1946 | "jne 1b\n\t" |
9a0a462c | 1947 | "xorl %%eax,%%eax\n" |
92f1da4d | 1948 | "2:" |
b664d723 | 1949 | : "=&a" (__res), "=&c" (__d0), "=&S" (__d1), "=&D" (__d2), "=&d" (__d3) |
685cb06a UD |
1950 | : "0" (0), "1" (0xffffffff), "2" (__haystack), "3" (__needle), |
1951 | "b" (__needle) | |
49f8b030 | 1952 | : "memory", "cc"); |
92f1da4d UD |
1953 | return __res; |
1954 | } | |
6704c645 | 1955 | # endif |
92f1da4d UD |
1956 | |
1957 | ||
bdd421cc UD |
1958 | /* Bit find functions. We define only the i686 version since for the other |
1959 | processors gcc generates good code. */ | |
498afc54 | 1960 | # if defined __USE_MISC || defined __USE_XOPEN_EXTENDED |
6704c645 L |
1961 | # ifdef __i686__ |
1962 | # define _HAVE_STRING_ARCH_ffs 1 | |
1963 | # define ffs(word) (__builtin_constant_p (word) \ | |
1964 | ? __builtin_ffs (word) \ | |
1965 | : ({ int __cnt, __tmp; \ | |
1966 | __asm__ __volatile__ \ | |
1967 | ("bsfl %2,%0\n\t" \ | |
1968 | "cmovel %1,%0" \ | |
1969 | : "=&r" (__cnt), "=r" (__tmp) \ | |
1970 | : "rm" (word), "1" (-1)); \ | |
1971 | __cnt + 1; })) | |
1972 | ||
1973 | # ifndef ffsl | |
1974 | # define ffsl(word) ffs(word) | |
1975 | # endif | |
1976 | # endif /* i686 */ | |
1977 | # endif /* BSD || X/Open */ | |
1978 | ||
1979 | # ifndef _FORCE_INLINES | |
1980 | # undef __STRING_INLINE | |
1981 | # endif | |
bdd421cc | 1982 | |
6704c645 | 1983 | # endif /* use string inlines && GNU CC */ |
92f1da4d | 1984 | |
6704c645 | 1985 | #endif |