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