Update.
[platform/upstream/glibc.git] / sysdeps / i386 / bits / string.h
1 /* Optimized, inlined string functions.  i386 version.
2    Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc.
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
6    modify it under the terms of the GNU Library General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
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
13    Library General Public License for more details.
14
15    You should have received a copy of the GNU Library General Public
16    License along with the GNU C Library; see the file COPYING.LIB.  If not,
17    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18    Boston, MA 02111-1307, USA.  */
19
20 #ifndef _STRING_H
21 # error "Never use <bits/string.h> directly; include <string.h> instead."
22 #endif
23
24 /* The ix86 processors can access unaligned multi-byte variables.  */
25 #define _STRING_ARCH_unaligned  1
26
27
28 /* We only provide optimizations if the user selects them and if
29    GNU CC is used.  */
30 #if !defined __NO_STRING_INLINES && defined __USE_STRING_INLINES \
31     && defined __GNUC__ && __GNUC__ >= 2
32
33 #ifndef __STRING_INLINE
34 # ifdef __cplusplus
35 #  define __STRING_INLINE inline
36 # else
37 #  define __STRING_INLINE extern __inline
38 # endif
39 #endif
40
41
42 /* Copy N bytes of SRC to DEST.  */
43 #define _HAVE_STRING_ARCH_memcpy 1
44 #define memcpy(dest, src, n) \
45   (__extension__ (__builtin_constant_p (n)                                    \
46                   ? __memcpy_c (dest, src, n)                                 \
47                   : memcpy (dest, src, n)))
48 /* This looks horribly ugly, but the compiler can optimize it totally,
49    as the count is constant.  */
50 __STRING_INLINE void *__memcpy_c (void *__dest, __const void *__src,
51                                   size_t __n);
52
53 __STRING_INLINE void *
54 __memcpy_c (void *__dest, __const void *__src, size_t __n)
55 {
56   register unsigned long int __d0, __d1, __d2;
57   union {
58     unsigned int __ui;
59     unsigned short int __usi;
60     unsigned char __uc;
61   } *__u = __dest;
62   switch (__n)
63     {
64     case 0:
65       return __dest;
66     case 1:
67       __u->__uc = *(const unsigned char *) __src;
68       return __dest;
69     case 2:
70       __u->__usi = *(const unsigned short int *) __src;
71       return __dest;
72     case 3:
73       __u->__usi = *(const unsigned short int *) __src;
74       __u = (void *) __u + 2;
75       __u->__uc = *(2 + (const unsigned char *) __src);
76       return __dest;
77     case 4:
78       __u->__ui = *(const unsigned int *) __src;
79       return __dest;
80     case 6:
81       __u->__ui = *(const unsigned int *) __src;
82       __u = (void *) __u + 4;
83       __u->__usi = *(2 + (const unsigned short int *) __src);
84       return __dest;
85     case 8:
86       __u->__ui = *(const unsigned int *) __src;
87       __u = (void *) __u + 4;
88       __u->__ui = *(1 + (const unsigned int *) __src);
89       return __dest;
90     case 12:
91       __u->__ui = *(const unsigned int *) __src;
92       __u = (void *) __u + 4;
93       __u->__ui = *(1 + (const unsigned int *) __src);
94       __u = (void *) __u + 4;
95       __u->__ui = *(2 + (const unsigned int *) __src);
96       return __dest;
97     case 16:
98       __u->__ui = *(const unsigned int *) __src;
99       __u = (void *) __u + 4;
100       __u->__ui = *(1 + (const unsigned int *) __src);
101       __u = (void *) __u + 4;
102       __u->__ui = *(2 + (const unsigned int *) __src);
103       __u = (void *) __u + 4;
104       __u->__ui = *(3 + (const unsigned int *) __src);
105       return __dest;
106     case 20:
107       __u->__ui = *(const unsigned int *) __src;
108       __u = (void *) __u + 4;
109       __u->__ui = *(1 + (const unsigned int *) __src);
110       __u = (void *) __u + 4;
111       __u->__ui = *(2 + (const unsigned int *) __src);
112       __u = (void *) __u + 4;
113       __u->__ui = *(3 + (const unsigned int *) __src);
114       __u = (void *) __u + 4;
115       __u->__ui = *(4 + (const unsigned int *) __src);
116       return __dest;
117     }
118 #define __COMMON_CODE(x) \
119   __asm__ __volatile__                                                        \
120     ("cld\n\t"                                                                \
121      "rep; movsl"                                                             \
122      x                                                                        \
123      : "=&c" (__d0), "=&D" (__d1), "=&S" (__d2)                               \
124      : "0" (__n / 4), "1" (&__u->__uc), "2" (__src)                           \
125      : "memory");
126
127   switch (__n % 4)
128     {
129     case 0:
130       __COMMON_CODE ("");
131       break;
132     case 1:
133       __COMMON_CODE ("\n\tmovsb");
134       break;
135     case 2:
136       __COMMON_CODE ("\n\tmovsw");
137       break;
138     case 3:
139       __COMMON_CODE ("\n\tmovsw\n\tmovsb");
140       break;
141   }
142   return __dest;
143 #undef __COMMON_CODE
144 }
145
146
147 /* Copy N bytes of SRC to DEST, guaranteeing
148    correct behavior for overlapping strings.  */
149 #define _HAVE_STRING_ARCH_memmove 1
150 #ifndef _FORCE_INLINES
151 __STRING_INLINE void *
152 memmove (void *__dest, __const void *__src, size_t __n)
153 {
154   register unsigned long int __d0, __d1, __d2;
155   if (__dest < __src)
156     __asm__ __volatile__
157       ("cld\n\t"
158        "rep\n\t"
159        "movsb"
160        : "=&c" (__d0), "=&S" (__d1), "=&D" (__d2)
161        : "0" (__n), "1" (__src), "2" (__dest)
162        : "memory");
163   else
164     __asm__ __volatile__
165       ("std\n\t"
166        "rep\n\t"
167        "movsb\n\t"
168        "cld"
169        : "=&c" (__d0), "=&S" (__d1), "=&D" (__d2)
170        : "0" (__n), "1" (__n - 1 + (const char *) __src),
171          "2" (__n - 1 + (char *) __dest)
172        : "memory");
173   return __dest;
174 }
175 #endif
176
177 /* Set N bytes of S to C.  */
178 #define _HAVE_STRING_ARCH_memset 1
179 #define memset(s, c, n) \
180   (__extension__ (__builtin_constant_p (c)                                    \
181                   ? (__builtin_constant_p (n)                                 \
182                      ? __memset_cc (s, 0x01010101UL * (unsigned char) (c), n) \
183                      : __memset_cg (s, 0x01010101UL * (unsigned char) (c), n))\
184                   : __memset_gg (s, c, n)))
185
186 __STRING_INLINE void *__memset_cc (void *__s, unsigned long int __pattern,
187                                    size_t __n);
188
189 __STRING_INLINE void *
190 __memset_cc (void *__s, unsigned long int __pattern, size_t __n)
191 {
192   register unsigned long int __d0, __d1;
193   union {
194     unsigned int __ui;
195     unsigned short int __usi;
196     unsigned char __uc;
197   } *__u = __s;
198   switch (__n)
199     {
200     case 0:
201       return __s;
202     case 1:
203       __u->__uc = __pattern;
204       return __s;
205     case 2:
206       __u->__usi = __pattern;
207       return __s;
208     case 3:
209       __u->__usi = __pattern;
210       __u = __extension__ ((void *) __u + 2);
211       __u->__uc = __pattern;
212       return __s;
213     case 4:
214       __u->__ui = __pattern;
215       return __s;
216         }
217 #define __COMMON_CODE(x) \
218   __asm__ __volatile__                                                        \
219     ("cld\n\t"                                                                \
220      "rep; stosl"                                                             \
221      x                                                                        \
222      : "=&c" (__d0), "=&D" (__d1)                                             \
223      : "a" (__pattern), "0" (__n / 4), "1" (&__u->__uc)                       \
224      : "memory")
225
226   switch (__n % 4)
227     {
228     case 0:
229       __COMMON_CODE ("");
230       break;
231     case 1:
232       __COMMON_CODE ("\n\tstosb");
233       break;
234     case 2:
235       __COMMON_CODE ("\n\tstosw");
236       break;
237     case 3:
238       __COMMON_CODE ("\n\tstosw\n\tstosb");
239       break;
240     }
241   return __s;
242 #undef __COMMON_CODE
243 }
244
245 __STRING_INLINE void *__memset_cg (void *__s, unsigned long __c, size_t __n);
246
247 __STRING_INLINE void *
248 __memset_cg (void *__s, unsigned long __c, size_t __n)
249 {
250   register unsigned long int __d0, __d1;
251   __asm__ __volatile__
252     ("cld\n\t"
253      "rep; stosl\n\t"
254      "testb     $2,%b3\n\t"
255      "je        1f\n\t"
256      "stosw\n"
257      "1:\n\t"
258      "testb     $1,%b3\n\t"
259      "je        2f\n\t"
260      "stosb\n"
261      "2:"
262      : "=&c" (__d0), "=&D" (__d1)
263      : "a" (__c), "q" (__n), "0" (__n / 4), "1" (__s)
264      : "memory");
265   return __s;
266 }
267
268 __STRING_INLINE void *__memset_gg (void *__s, char __c, size_t __n);
269
270 __STRING_INLINE void *
271 __memset_gg (void *__s, char __c, size_t __n)
272 {
273   register unsigned long int __d0, __d1;
274   __asm__ __volatile__
275     ("cld\n\t"
276      "rep; stosb"
277      : "=&D" (__d0), "=&c" (__d1)
278      : "a" (__c), "0" (__s), "1" (__n)
279      : "memory");
280   return __s;
281 }
282
283
284
285
286 /* Search N bytes of S for C.  */
287 #define _HAVE_STRING_ARCH_memchr 1
288 #ifndef _FORCE_INLINES
289 __STRING_INLINE void *
290 memchr (__const void *__s, int __c, size_t __n)
291 {
292   register unsigned long int __d0;
293   register void *__res;
294   if (__n == 0)
295     return NULL;
296   __asm__ __volatile__
297     ("cld\n\t"
298      "repne; scasb\n\t"
299      "je 1f\n\t"
300      "movl $1,%0\n"
301      "1:"
302      : "=D" (__res), "=&c" (__d0)
303      : "a" (__c), "0" (__s), "1" (__n)
304      : "cc");
305   return __res - 1;
306 }
307 #endif
308
309 #define _HAVE_STRING_ARCH_memrchr 1
310 #ifndef _FORCE_INLINES
311 __STRING_INLINE void *
312 __memrchr (__const void *__s, int __c, size_t __n)
313 {
314   register unsigned long int __d0;
315   register void *__res;
316   if (__n == 0)
317     return NULL;
318   __asm__ __volatile__
319     ("std\n\t"
320      "repne; scasb\n\t"
321      "je 1f\n\t"
322      "orl $-1,%0\n"
323      "1:\tcld"
324      : "=D" (__res), "=&c" (__d0)
325      : "a" (__c), "0" (__s + __n - 1), "1" (__n)
326      : "cc");
327   return __res + 1;
328 }
329 # ifdef __USE_GNU
330 #  define memrchr(s, c, n) __memrchr (s, c, n)
331 # endif
332 #endif
333
334 /* Return the length of S.  */
335 #define _HAVE_STRING_ARCH_strlen 1
336 #ifndef _FORCE_INLINES
337 __STRING_INLINE size_t
338 strlen (__const char *__str)
339 {
340   register unsigned long int __d0;
341   register size_t __res;
342   __asm__ __volatile__
343     ("cld\n\t"
344      "repne; scasb\n\t"
345      "notl %0"
346      : "=c" (__res), "=&D" (__d0)
347      : "1" (__str), "a" (0), "0" (0xffffffff)
348      : "cc");
349   return __res - 1;
350 }
351 #endif
352
353 /* Copy SRC to DEST.  */
354 #define _HAVE_STRING_ARCH_strcpy 1
355 #ifndef _FORCE_INLINES
356 __STRING_INLINE char *
357 strcpy (char *__dest, __const char *__src)
358 {
359   register unsigned long int __d0, __d1;
360   __asm__ __volatile__
361     ("cld\n"
362      "1:\n\t"
363      "lodsb\n\t"
364      "stosb\n\t"
365      "testb     %%al,%%al\n\t"
366      "jne       1b"
367      : "=&S" (__d0), "=&D" (__d1)
368      : "0" (__src), "1" (__dest)
369      : "ax", "memory", "cc");
370   return __dest;
371 }
372 #endif
373
374 /* Copy no more than N characters of SRC to DEST.  */
375 #define _HAVE_STRING_ARCH_strncpy 1
376 #ifndef _FORCE_INLINES
377 __STRING_INLINE char *
378 strncpy (char *__dest, __const char *__src, size_t __n)
379 {
380   register unsigned long int __d0, __d1, __d2;
381   __asm__ __volatile__
382     ("cld\n"
383      "1:\n\t"
384      "decl      %2\n\t"
385      "js        2f\n\t"
386      "lodsb\n\t"
387      "stosb\n\t"
388      "testb     %%al,%%al\n\t"
389      "jne       1b\n\t"
390      "rep; stosb\n"
391      "2:"
392      : "=&S" (__d0), "=&D" (__d1), "=&c" (__d2)
393      : "0" (__src), "1" (__dest), "2" (__n)
394      : "ax", "memory", "cc");
395   return __dest;
396 }
397 #endif
398
399 /* Append SRC onto DEST.  */
400 #define _HAVE_STRING_ARCH_strcat 1
401 #ifndef _FORCE_INLINES
402 __STRING_INLINE char *
403 strcat (char *__dest, __const char *__src)
404 {
405   register unsigned long int __d0, __d1, __d2, __d3;
406   __asm__ __volatile__
407     ("cld\n\t"
408      "repne; scasb\n\t"
409      "decl      %1\n"
410      "1:\n\t"
411      "lodsb\n\t"
412      "stosb\n\t"
413      "testb     %%al,%%al\n\t"
414      "jne       1b"
415      : "=&S" (__d0), "=&D" (__d1), "=&c" (__d2), "=&a" (__d3)
416      : "0" (__src), "1" (__dest), "2" (0xffffffff), "3" (0)
417      : "memory", "cc");
418   return __dest;
419 }
420 #endif
421
422 /* Append no more than N characters from SRC onto DEST.  */
423 #define _HAVE_STRING_ARCH_strncat 1
424 #ifndef _FORCE_INLINES
425 __STRING_INLINE char *
426 strncat (char *__dest, __const char *__src, size_t __n)
427 {
428   register unsigned long int __d0, __d1, __d2, __d3;
429   __asm__ __volatile__
430     ("cld\n\t"
431      "repne; scasb\n\t"
432      "decl      %1\n\t"
433      "movl      %4,%2\n"
434      "1:\n\t"
435      "decl      %2\n\t"
436      "js        2f\n\t"
437      "lodsb\n\t"
438      "stosb\n\t"
439      "testb     %%al,%%al\n\t"
440      "jne       1b\n\t"
441      "jmp       3f\n"
442      "2:\n\t"
443      "xorl      %3,%3\n\t"
444      "stosb\n"
445      "3:"
446      : "=&S" (__d0), "=&D" (__d1), "=&c" (__d2), "=&a" (__d3)
447      : "g" (__n), "0" (__src), "1" (__dest), "2" (0xffffffff), "3" (0)
448      : "memory", "cc");
449   return __dest;
450 }
451 #endif
452
453 /* Compare S1 and S2.  */
454 #define _HAVE_STRING_ARCH_strcmp 1
455 #ifndef _FORCE_INLINES
456 __STRING_INLINE int
457 strcmp (__const char *__s1, __const char *__s2)
458 {
459   register unsigned long int __d0, __d1;
460   register int __res;
461   __asm__ __volatile__
462     ("cld\n"
463      "1:\n\t"
464      "lodsb\n\t"
465      "scasb\n\t"
466      "jne       2f\n\t"
467      "testb     %%al,%%al\n\t"
468      "jne       1b\n\t"
469      "xorl      %%eax,%%eax\n\t"
470      "jmp       3f\n"
471      "2:\n\t"
472      "sbbl      %%eax,%%eax\n\t"
473      "orb       $1,%%eax\n"
474      "3:"
475      : "=a" (__res), "=&S" (__d0), "=&D" (__d1)
476      : "1" (__s1), "2" (__s2)
477      : "cc");
478   return __res;
479 }
480 #endif
481
482 /* Compare N characters of S1 and S2.  */
483 #define _HAVE_STRING_ARCH_strncmp 1
484 #ifndef _FORCE_INLINES
485 __STRING_INLINE int
486 strncmp (__const char *__s1, __const char *__s2, size_t __n)
487 {
488   register unsigned long int __d0, __d1, __d2;
489   register int __res;
490   __asm__ __volatile__
491     ("cld\n"
492      "1:\n\t"
493      "decl      %3\n\t"
494      "js        2f\n\t"
495      "lodsb\n\t"
496      "scasb\n\t"
497      "jne       3f\n\t"
498      "testb     %%al,%%al\n\t"
499      "jne       1b\n"
500      "2:\n\t"
501      "xorl      %%eax,%%eax\n\t"
502      "jmp       4f\n"
503      "3:\n\t"
504      "sbbl      %%eax,%%eax\n\t"
505      "orb       $1,%%al\n"
506      "4:"
507      : "=a" (__res), "=&S" (__d0), "=&D" (__d1), "=&c" (__d2)
508      : "1" (__s1), "2" (__s2), "3" (__n)
509      : "cc");
510   return __res;
511 }
512 #endif
513
514 /* Find the first occurrence of C in S.  */
515 #define _HAVE_STRING_ARCH_strchr 1
516 #define strchr(s, c) \
517   (__extension__ (__builtin_constant_p (c)                                    \
518                   ? __strchr_c (s, ((c) & 0xff) << 8)                         \
519                   : __strchr_g (s, c)))
520
521 __STRING_INLINE char *__strchr_g (__const char *__s, int __c);
522
523 __STRING_INLINE char *
524 __strchr_g (__const char *__s, int __c)
525 {
526   register unsigned long int __d0;
527   register char *__res;
528   __asm__ __volatile__
529     ("cld\n\t"
530      "movb      %%al,%%ah\n"
531      "1:\n\t"
532      "lodsb\n\t"
533      "cmpb      %%ah,%%al\n\t"
534      "je        2f\n\t"
535      "testb     %%al,%%al\n\t"
536      "jne       1b\n\t"
537      "movl      $1,%1\n"
538      "2:\n\t"
539      "movl      %1,%0"
540      : "=a" (__res), "=&S" (__d0)
541      : "0" (__c), "1" (__s)
542      : "cc");
543   return __res - 1;
544 }
545
546 __STRING_INLINE char *__strchr_c (__const char *__s, int __c);
547
548 __STRING_INLINE char *
549 __strchr_c (__const char *__s, int __c)
550 {
551   register unsigned long int __d0;
552   register char *__res;
553   __asm__ __volatile__
554     ("cld\n\t"
555      "1:\n\t"
556      "lodsb\n\t"
557      "cmpb      %%ah,%%al\n\t"
558      "je        2f\n\t"
559      "testb     %%al,%%al\n\t"
560      "jne       1b\n\t"
561      "movl      $1,%1\n"
562      "2:\n\t"
563      "movl      %1,%0"
564      : "=a" (__res), "=&S" (__d0)
565      : "0" (__c), "1" (__s)
566      : "cc");
567   return __res - 1;
568 }
569
570
571 /* Find the first occurrence of C in S or the final NUL byte.  */
572 #define _HAVE_STRING_ARCH_strchrnul 1
573 #define __strchrnul(s, c) \
574   (__extension__ (__builtin_constant_p (c)                                    \
575                   ? ((c) == '\0'                                              \
576                      ? (char *) __rawmemchr (s, c)                            \
577                      : __strchrnul_c (s, ((c) & 0xff) << 8))                  \
578                   : __strchrnul_g (s, c)))
579
580 __STRING_INLINE char *__strchrnul_g (__const char *__s, int __c);
581
582 __STRING_INLINE char *
583 __strchrnul_g (__const char *__s, int __c)
584 {
585   register unsigned long int __d0;
586   register char *__res;
587   __asm__ __volatile__
588     ("cld\n\t"
589      "movb      %%al,%%ah\n"
590      "1:\n\t"
591      "lodsb\n\t"
592      "cmpb      %%ah,%%al\n\t"
593      "je        2f\n\t"
594      "testb     %%al,%%al\n\t"
595      "jne       1b\n\t"
596      "2:\n\t"
597      "movl      %1,%0"
598      : "=a" (__res), "=&S" (__d0)
599      : "0" (__c), "1" (__s)
600      : "cc");
601   return __res - 1;
602 }
603
604 __STRING_INLINE char *__strchrnul_c (__const char *__s, int __c);
605
606 __STRING_INLINE char *
607 __strchrnul_c (__const char *__s, int __c)
608 {
609   register unsigned long int __d0;
610   register char *__res;
611   __asm__ __volatile__
612     ("cld\n\t"
613      "1:\n\t"
614      "lodsb\n\t"
615      "cmpb      %%ah,%%al\n\t"
616      "je        2f\n\t"
617      "testb     %%al,%%al\n\t"
618      "jne       1b\n\t"
619      "2:\n\t"
620      "movl      %1,%0"
621      : "=a" (__res), "=&S" (__d0)
622      : "0" (__c), "1" (__s)
623      : "cc");
624   return __res - 1;
625 }
626 #ifdef __USE_GNU
627 # define strchrnul(s, c) __strchrnul (s, c)
628 #endif
629
630
631 /* Return the length of the initial segment of S which
632    consists entirely of characters not in REJECT.  */
633 #define _HAVE_STRING_ARCH_strcspn 1
634 #ifndef _FORCE_INLINES
635 # ifdef __PIC__
636 __STRING_INLINE size_t
637 strcspn (__const char *__s, __const char *__reject)
638 {
639   register unsigned long int __d0, __d1, __d2;
640   register char *__res;
641   __asm__ __volatile__
642     ("pushl     %%ebx\n\t"
643      "cld\n\t"
644      "movl      %4,%%edi\n\t"
645      "repne; scasb\n\t"
646      "notl      %%ecx\n\t"
647      "decl      %%ecx\n\t"
648      "movl      %%ecx,%%ebx\n"
649      "1:\n\t"
650      "lodsb\n\t"
651      "testb     %%al,%%al\n\t"
652      "je        2f\n\t"
653      "movl      %4,%%edi\n\t"
654      "movl      %%ebx,%%ecx\n\t"
655      "repne; scasb\n\t"
656      "jne       1b\n"
657      "2:\n\t"
658      "popl      %%ebx"
659      : "=&S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2)
660      : "d" (__reject), "0" (__s), "1" (0), "2" (0xffffffff)
661      : "cc");
662   return (__res - 1) - __s;
663 }
664 # else
665 __STRING_INLINE size_t
666 strcspn (__const char *__s, __const char *__reject)
667 {
668   register unsigned long int __d0, __d1, __d2, __d3;
669   register char *__res;
670   __asm__ __volatile__
671     ("cld\n\t"
672      "movl      %5,%%edi\n\t"
673      "repne; scasb\n\t"
674      "notl      %%ecx\n\t"
675      "decl      %%ecx\n\t"
676      "movl      %%ecx,%%edx\n"
677      "1:\n\t"
678      "lodsb\n\t"
679      "testb     %%al,%%al\n\t"
680      "je        2f\n\t"
681      "movl      %5,%%edi\n\t"
682      "movl      %%edx,%%ecx\n\t"
683      "repne; scasb\n\t"
684      "jne       1b\n"
685      "2:"
686      : "=&S" (__res), "=&a" (__d0), "=&c" (__d1), "=&d" (__d2), "=&D" (__d3)
687      : "g" (__reject), "0" (__s), "1" (0), "2" (0xffffffff)
688      : "cc");
689   return (__res - 1) - __s;
690 }
691 # endif
692 #endif
693
694
695 /* Return the length of the initial segment of S which
696    consists entirely of characters in ACCEPT.  */
697 #define _HAVE_STRING_ARCH_strspn 1
698 #ifndef _FORCE_INLINES
699 # ifdef __PIC__
700 __STRING_INLINE size_t
701 strspn (__const char *__s, __const char *__accept)
702 {
703   register unsigned long int __d0, __d1, __d2;
704   register char *__res;
705   __asm__ __volatile__
706     ("pushl     %%ebx\n\t"
707      "cld\n\t"
708      "movl      %4,%%edi\n\t"
709      "repne; scasb\n\t"
710      "notl      %%ecx\n\t"
711      "decl      %%ecx\n\t"
712      "movl      %%ecx,%%ebx\n"
713      "1:\n\t"
714      "lodsb\n\t"
715      "testb     %%al,%%al\n\t"
716      "je        2f\n\t"
717      "movl      %4,%%edi\n\t"
718      "movl      %%ebx,%%ecx\n\t"
719      "repne; scasb\n\t"
720      "je        1b\n"
721      "2:\n\t"
722      "popl      %%ebx"
723      : "=&S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2)
724      : "r" (__accept), "0" (__s), "1" (0), "2" (0xffffffff)
725      : "cc");
726   return (__res - 1) - __s;
727 }
728 # else
729 __STRING_INLINE size_t
730 strspn (__const char *__s, __const char *__accept)
731 {
732   register unsigned long int __d0, __d1, __d2, __d3;
733   register char *__res;
734   __asm__ __volatile__
735     ("cld\n\t"
736      "movl      %5,%%edi\n\t"
737      "repne; scasb\n\t"
738      "notl      %%ecx\n\t"
739      "decl      %%ecx\n\t"
740      "movl      %%ecx,%%edx\n"
741      "1:\n\t"
742      "lodsb\n\t"
743      "testb     %%al,%%al\n\t"
744      "je        2f\n\t"
745      "movl      %5,%%edi\n\t"
746      "movl      %%edx,%%ecx\n\t"
747      "repne; scasb\n\t"
748      "je        1b\n"
749      "2:"
750      : "=&S" (__res), "=&a" (__d0), "=&c" (__d1), "=&d" (__d2), "=&D" (__d3)
751      : "g" (__accept), "0" (__s), "1" (0), "2" (0xffffffff)
752      : "cc");
753   return (__res - 1) - __s;
754 }
755 # endif
756 #endif
757
758
759 /* Find the first occurrence in S of any character in ACCEPT.  */
760 #define _HAVE_STRING_ARCH_strpbrk 1
761 #ifndef _FORCE_INLINES
762 # ifdef __PIC__
763 __STRING_INLINE char *
764 strpbrk (__const char *__s, __const char *__accept)
765 {
766   unsigned long int __d0, __d1, __d2;
767   register char *__res;
768   __asm__ __volatile__
769     ("pushl     %%ebx\n\t"
770      "cld\n\t"
771      "movl      %4,%%edi\n\t"
772      "repne; scasb\n\t"
773      "notl      %%ecx\n\t"
774      "decl      %%ecx\n\t"
775      "movl      %%ecx,%%ebx\n"
776      "1:\n\t"
777      "lodsb\n\t"
778      "testb     %%al,%%al\n\t"
779      "je        2f\n\t"
780      "movl      %4,%%edi\n\t"
781      "movl      %%ebx,%%ecx\n\t"
782      "repne; scasb\n\t"
783      "jne       1b\n\t"
784      "decl      %0\n\t"
785      "jmp       3f\n"
786      "2:\n\t"
787      "xorl      %0,%0\n"
788      "3:\n\t"
789      "popl      %%ebx"
790      : "=&S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2)
791      : "r" (__accept), "0" (__s), "1" (0), "2" (0xffffffff)
792      : "cc");
793   return __res;
794 }
795 # else
796 __STRING_INLINE char *
797 strpbrk (__const char *__s, __const char *__accept)
798 {
799   register unsigned long int __d0, __d1, __d2, __d3;
800   register char *__res;
801   __asm__ __volatile__
802     ("cld\n\t"
803      "movl      %5,%%edi\n\t"
804      "repne; scasb\n\t"
805      "notl      %%ecx\n\t"
806      "decl      %%ecx\n\t"
807      "movl      %%ecx,%%edx\n"
808      "1:\n\t"
809      "lodsb\n\t"
810      "testb     %%al,%%al\n\t"
811      "je        2f\n\t"
812      "movl      %5,%%edi\n\t"
813      "movl      %%edx,%%ecx\n\t"
814      "repne; scasb\n\t"
815      "jne       1b\n\t"
816      "decl      %0\n\t"
817      "jmp       3f\n"
818      "2:\n\t"
819      "xorl      %0,%0\n"
820      "3:"
821      : "=&S" (__res), "=&a" (__d0), "=&c" (__d1), "=&d" (__d2), "=&D" (__d3)
822      : "g" (__accept), "0" (__s), "1" (0), "2" (0xffffffff)
823      : "cc");
824   return __res;
825 }
826 # endif
827 #endif
828
829
830 /* Find the first occurrence of NEEDLE in HAYSTACK.  */
831 #define _HAVE_STRING_ARCH_strstr 1
832 #ifndef _FORCE_INLINES
833 # ifdef __PIC__
834 __STRING_INLINE char *
835 strstr (__const char *__haystack, __const char *__needle)
836 {
837   register unsigned long int __d0, __d1, __d2;
838   register char *__res;
839   __asm__ __volatile__
840     ("pushl     %%ebx\n\t"
841      "cld\n\t" \
842      "movl      %4,%%edi\n\t"
843      "repne; scasb\n\t"
844      "notl      %%ecx\n\t"
845      "decl      %%ecx\n\t"      /* NOTE! This also sets Z if searchstring='' */
846      "movl      %%ecx,%%ebx\n"
847      "1:\n\t"
848      "movl      %4,%%edi\n\t"
849      "movl      %%esi,%%eax\n\t"
850      "movl      %%ebx,%%ecx\n\t"
851      "repe; cmpsb\n\t"
852      "je        2f\n\t"         /* also works for empty string, see above */
853      "xchgl     %%eax,%%esi\n\t"
854      "incl      %%esi\n\t"
855      "cmpb      $0,-1(%%eax)\n\t"
856      "jne       1b\n\t"
857      "xorl      %%eax,%%eax\n\t"
858      "2:\n\t"
859      "popl      %%ebx"
860      : "=&a" (__res), "=&c" (__d0), "=&S" (__d1), "=&D" (__d2)
861      : "r" (__needle), "0" (0), "1" (0xffffffff), "2" (__haystack)
862      : "cc");
863   return __res;
864 }
865 # else
866 __STRING_INLINE char *
867 strstr (__const char *__haystack, __const char *__needle)
868 {
869   register unsigned long int __d0, __d1, __d2, __d3;
870   register char *__res;
871   __asm__ __volatile__
872     ("cld\n\t" \
873      "movl      %5,%%edi\n\t"
874      "repne; scasb\n\t"
875      "notl      %%ecx\n\t"
876      "decl      %%ecx\n\t"      /* NOTE! This also sets Z if searchstring='' */
877      "movl      %%ecx,%%edx\n"
878      "1:\n\t"
879      "movl      %5,%%edi\n\t"
880      "movl      %%esi,%%eax\n\t"
881      "movl      %%edx,%%ecx\n\t"
882      "repe; cmpsb\n\t"
883      "je        2f\n\t"         /* also works for empty string, see above */
884      "xchgl     %%eax,%%esi\n\t"
885      "incl      %%esi\n\t"
886      "cmpb      $0,-1(%%eax)\n\t"
887      "jne       1b\n\t"
888      "xorl      %%eax,%%eax\n\t"
889      "2:"
890      : "=&a" (__res), "=&c" (__d0), "=&S" (__d1), "=&d" (__d2), "=&D" (__d3)
891      : "g" (__needle), "0" (0), "1" (0xffffffff), "2" (__haystack)
892      : "cc");
893   return __res;
894 }
895 # endif
896 #endif
897
898 #ifndef _FORCE_INLINES
899 # undef __STRING_INLINE
900 #endif
901
902 #endif  /* use string inlines && GNU CC */