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.
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.
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.
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
22 # error "Never use <bits/string.h> directly; include <string.h> instead."
25 /* The ix86 processors can access unaligned multi-byte variables. */
26 #define _STRING_ARCH_unaligned 1
29 /* We only provide optimizations if the user selects them and if
31 #if !defined __NO_STRING_INLINES && defined __USE_STRING_INLINES \
32 && defined __GNUC__ && __GNUC__ >= 2 && !__BOUNDED_POINTERS__
34 #ifndef __STRING_INLINE
35 # ifndef __extern_inline
36 # define __STRING_INLINE inline
38 # define __STRING_INLINE __extern_inline
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])
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) \
63 ? __memcpy_by4 (dest, src, n) \
65 ? __memcpy_by2 (dest, src, n) \
66 : __memcpy_g (dest, src, n))))
68 __STRING_INLINE void *__memcpy_by4 (void *__dest, const void *__src,
71 __STRING_INLINE void *
72 __memcpy_by4 (void *__dest, const void *__src, size_t __n)
74 register unsigned long int __d0, __d1;
75 register void *__tmp = __dest;
84 : "=&r" (__d0), "=&r" (__tmp), "=&r" (__src), "=&r" (__d1)
85 : "1" (__tmp), "2" (__src), "3" (__n / 4)
90 __STRING_INLINE void *__memcpy_by2 (void *__dest, const void *__src,
93 __STRING_INLINE void *
94 __memcpy_by2 (void *__dest, const void *__src, size_t __n)
96 register unsigned long int __d0, __d1;
97 register void *__tmp = __dest;
100 "jz 2f\n" /* only a word */
111 : "=&q" (__d0), "=&r" (__tmp), "=&r" (__src), "=&r" (__d1)
112 : "1" (__tmp), "2" (__src), "3" (__n / 2)
117 __STRING_INLINE void *__memcpy_g (void *__dest, const void *__src, size_t __n);
119 __STRING_INLINE void *
120 __memcpy_g (void *__dest, const void *__src, size_t __n)
122 register unsigned long int __d0, __d1, __d2;
123 register void *__tmp = __dest;
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)
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)
149 __STRING_INLINE void *__memmove_g (void *, const void *, size_t)
152 __STRING_INLINE void *
153 __memmove_g (void *__dest, const void *__src, size_t __n)
155 register unsigned long int __d0, __d1, __d2;
156 register void *__tmp = __dest;
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));
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));
179 /* Compare N bytes of S1 and S2. */
180 #define _HAVE_STRING_ARCH_memcmp 1
181 #ifndef _FORCE_INLINES
183 /* gcc has problems to spill registers when using PIC. */
185 memcmp (const void *__s1, const void *__s2, size_t __n)
187 register unsigned long int __d0, __d1, __d2;
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)
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 \
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))))))
223 #define __memset_c1(s, c) ({ void *__s = (s); \
224 *((unsigned char *) __s) = (unsigned char) (c); \
227 #define __memset_gc(s, c, n) \
228 ({ void *__s = (s); \
231 unsigned short int __usi; \
232 unsigned char __uc; \
234 unsigned int __c = ((unsigned int) ((unsigned char) (c))) * 0x01010101; \
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 \
240 if ((n) == 3 || (n) >= 5) \
241 __asm__ __volatile__ ("" : "=r" (__c) : "0" (__c)); \
243 /* This `switch' statement will be removed at compile-time. */ \
248 __u = __extension__ ((void *) __u + 4); \
251 __u = __extension__ ((void *) __u + 4); \
254 __u = __extension__ ((void *) __u + 4); \
256 __u->__usi = (unsigned short int) __c; \
257 __u = __extension__ ((void *) __u + 2); \
258 __u->__uc = (unsigned char) __c; \
263 __u = __extension__ ((void *) __u + 4); \
266 __u = __extension__ ((void *) __u + 4); \
269 __u = __extension__ ((void *) __u + 4); \
271 __u->__usi = (unsigned short int) __c; \
276 __u = __extension__ ((void *) __u + 4); \
279 __u = __extension__ ((void *) __u + 4); \
282 __u = __extension__ ((void *) __u + 4); \
284 __u->__uc = (unsigned char) __c; \
289 __u = __extension__ ((void *) __u + 4); \
292 __u = __extension__ ((void *) __u + 4); \
295 __u = __extension__ ((void *) __u + 4); \
304 #define __memset_ccn(s, c, n) \
306 ? __memset_ccn_by4 (s, ((unsigned int) ((unsigned char) (c))) * 0x01010101,\
309 ? __memset_ccn_by2 (s, \
310 ((unsigned int) ((unsigned char) (c))) * 0x01010101,\
314 __STRING_INLINE void *__memset_ccn_by4 (void *__s, unsigned int __c,
317 __STRING_INLINE void *
318 __memset_ccn_by4 (void *__s, unsigned int __c, size_t __n)
320 register void *__tmp = __s;
321 register unsigned long int __d0;
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)
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)
345 __STRING_INLINE void *__memset_ccn_by2 (void *__s, unsigned int __c,
348 __STRING_INLINE void *
349 __memset_ccn_by2 (void *__s, unsigned int __c, size_t __n)
351 register unsigned long int __d0, __d1;
352 register void *__tmp = __s;
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)
364 ("1:\tmovl %0,(%1)\n\t"
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)
377 #define __memset_gcn(s, c, n) \
379 ? __memset_gcn_by4 (s, c, n) \
381 ? __memset_gcn_by2 (s, c, n) \
384 __STRING_INLINE void *__memset_gcn_by4 (void *__s, int __c, size_t __n);
386 __STRING_INLINE void *
387 __memset_gcn_by4 (void *__s, int __c, size_t __n)
389 register void *__tmp = __s;
390 register unsigned long int __d0;
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)
408 __STRING_INLINE void *__memset_gcn_by2 (void *__s, int __c, size_t __n);
410 __STRING_INLINE void *
411 __memset_gcn_by2 (void *__s, int __c, size_t __n)
413 register unsigned long int __d0, __d1;
414 register void *__tmp = __s;
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)
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)
440 register unsigned long int __d0;
442 register unsigned long int __d1;
444 register unsigned char *__res;
452 : "=D" (__res), "=&c" (__d0), "=&r" (__d1)
453 : "a" (__c), "0" (__s), "1" (__n), "2" (1),
454 "m" ( *(struct { __extension__ char __x[__n]; } *)__s)
463 : "=D" (__res), "=&c" (__d0)
464 : "a" (__c), "0" (__s), "1" (__n),
465 "m" ( *(struct { __extension__ char __x[__n]; } *)__s)
472 #define _HAVE_STRING_ARCH_memrchr 1
473 #ifndef _FORCE_INLINES
474 __STRING_INLINE void *__memrchr (const void *__s, int __c, size_t __n);
476 __STRING_INLINE void *
477 __memrchr (const void *__s, int __c, size_t __n)
479 register unsigned long int __d0;
481 register unsigned long int __d1;
483 register void *__res;
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)
505 : "=D" (__res), "=&c" (__d0)
506 : "a" (__c), "0" (__s + __n - 1), "1" (__n),
507 "m" ( *(struct { __extension__ char __x[__n]; } *)__s)
513 # define memrchr(s, c, n) __memrchr ((s), (c), (n))
517 /* Return pointer to C in S. */
518 #define _HAVE_STRING_ARCH_rawmemchr 1
519 __STRING_INLINE void *__rawmemchr (const void *__s, int __c);
521 #ifndef _FORCE_INLINES
522 __STRING_INLINE void *
523 __rawmemchr (const void *__s, int __c)
525 register unsigned long int __d0;
526 register unsigned char *__res;
530 : "=D" (__res), "=&c" (__d0)
531 : "a" (__c), "0" (__s), "1" (0xffffffff),
532 "m" ( *(struct { char __x[0xfffffff]; } *)__s)
537 __STRING_INLINE void *
538 rawmemchr (const void *__s, int __c)
540 return __rawmemchr (__s, __c);
542 # endif /* use GNU */
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) \
552 __STRING_INLINE size_t __strlen_g (const char *__str);
554 __STRING_INLINE size_t
555 __strlen_g (const char *__str)
557 register char __dummy;
558 register const char *__tmp = __str;
565 : "=r" (__tmp), "=&q" (__dummy)
567 "m" ( *(struct { char __x[0xfffffff]; } *)__str)
569 return __tmp - __str - 1;
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), \
582 : __strcpy_g ((dest), (src))))
584 #define __strcpy_a_small(dest, src, srclen) \
585 (__extension__ ({ char *__dest = (dest); \
588 unsigned short int __usi; \
589 unsigned char __uc; \
591 } *__u = (void *) __dest; \
598 __u->__usi = __STRING_SMALL_GET16 (src, 0); \
601 __u->__usi = __STRING_SMALL_GET16 (src, 0); \
602 __u = __extension__ ((void *) __u + 2); \
606 __u->__ui = __STRING_SMALL_GET32 (src, 0); \
609 __u->__ui = __STRING_SMALL_GET32 (src, 0); \
610 __u = __extension__ ((void *) __u + 4); \
614 __u->__ui = __STRING_SMALL_GET32 (src, 0); \
615 __u = __extension__ ((void *) __u + 4); \
616 __u->__usi = __STRING_SMALL_GET16 (src, 4); \
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); \
626 __u->__ui = __STRING_SMALL_GET32 (src, 0); \
627 __u = __extension__ ((void *) __u + 4); \
628 __u->__ui = __STRING_SMALL_GET32 (src, 4); \
633 __STRING_INLINE char *__strcpy_g (char *__dest, const char *__src);
635 __STRING_INLINE char *
636 __strcpy_g (char *__dest, const char *__src)
638 register char *__tmp = __dest;
639 register char __dummy;
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)
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) \
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))
674 /* In glibc itself we use this symbol for namespace reasons. */
675 # define stpcpy(dest, src) __stpcpy ((dest), (src))
677 # define __stpcpy_a_small(dest, src, srclen) \
678 (__extension__ ({ union { \
680 unsigned short int __usi; \
681 unsigned char __uc; \
683 } *__u = (void *) (dest); \
690 __u->__usi = __STRING_SMALL_GET16 (src, 0); \
691 __u = __extension__ ((void *) __u + 1); \
694 __u->__usi = __STRING_SMALL_GET16 (src, 0); \
695 __u = __extension__ ((void *) __u + 2); \
699 __u->__ui = __STRING_SMALL_GET32 (src, 0); \
700 __u = __extension__ ((void *) __u + 3); \
703 __u->__ui = __STRING_SMALL_GET32 (src, 0); \
704 __u = __extension__ ((void *) __u + 4); \
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); \
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); \
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); \
729 __STRING_INLINE char *__mempcpy_by4 (char *__dest, const char *__src,
732 __STRING_INLINE char *
733 __mempcpy_by4 (char *__dest, const char *__src, size_t __srclen)
735 register char *__tmp = __dest;
736 register unsigned long int __d0, __d1;
745 : "=&r" (__d0), "=r" (__tmp), "=&r" (__src), "=&r" (__d1)
746 : "1" (__tmp), "2" (__src), "3" (__srclen / 4)
751 __STRING_INLINE char *__mempcpy_by2 (char *__dest, const char *__src,
754 __STRING_INLINE char *
755 __mempcpy_by2 (char *__dest, const char *__src, size_t __srclen)
757 register char *__tmp = __dest;
758 register unsigned long int __d0, __d1;
761 "jz 2f\n" /* only a word */
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)
780 __STRING_INLINE char *__mempcpy_byn (char *__dest, const char *__src,
783 __STRING_INLINE char *
784 __mempcpy_byn (char *__dest, const char *__src, size_t __srclen)
786 register unsigned long __d0, __d1;
787 register char *__tmp = __dest;
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)
807 __STRING_INLINE char *__stpcpy_g (char *__dest, const char *__src);
809 __STRING_INLINE char *
810 __stpcpy_g (char *__dest, const char *__src)
812 register char *__tmp = __dest;
813 register char __dummy;
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)
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)))
849 __STRING_INLINE char *__strncpy_by4 (char *__dest, const char __src[],
850 size_t __srclen, size_t __n);
852 __STRING_INLINE char *
853 __strncpy_by4 (char *__dest, const char __src[], size_t __srclen, size_t __n)
855 register char *__tmp = __dest;
856 register int __dummy1, __dummy2;
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)
870 (void) memset (__tmp, '\0', __n - __srclen);
874 __STRING_INLINE char *__strncpy_by2 (char *__dest, const char __src[],
875 size_t __srclen, size_t __n);
877 __STRING_INLINE char *
878 __strncpy_by2 (char *__dest, const char __src[], size_t __srclen, size_t __n)
880 register char *__tmp = __dest;
881 register int __dummy1, __dummy2;
884 "jz 2f\n" /* only a word */
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)
900 (void) memset (__tmp + 2, '\0', __n - __srclen);
904 __STRING_INLINE char *__strncpy_byn (char *__dest, const char __src[],
905 size_t __srclen, size_t __n);
907 __STRING_INLINE char *
908 __strncpy_byn (char *__dest, const char __src[], size_t __srclen, size_t __n)
910 register unsigned long int __d0, __d1;
911 register char *__tmp = __dest;
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)
928 (void) memset (__tmp, '\0', __n - __srclen);
932 __STRING_INLINE char *__strncpy_gg (char *__dest, const char *__src,
935 __STRING_INLINE char *
936 __strncpy_gg (char *__dest, const char *__src, size_t __n)
938 register char *__tmp = __dest;
939 register char __dummy;
957 : "=&r" (__src), "=&r" (__tmp), "=&q" (__dummy), "=&r" (__n)
958 : "0" (__src), "1" (__tmp), "3" (__n)
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))))
972 __STRING_INLINE char *__strcat_c (char *__dest, const char __src[],
975 __STRING_INLINE char *
976 __strcat_c (char *__dest, const char __src[], size_t __srclen)
979 register unsigned long int __d0;
980 register char *__tmp;
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)
990 register char *__tmp = __dest - 1;
997 "=m" ( *(struct { char __x[0xfffffff]; } *)__dest)
999 "m" ( *(struct { __extension__ char __x[__srclen]; } *)__src)
1002 (void) memcpy (__tmp, __src, __srclen);
1006 __STRING_INLINE char *__strcat_g (char *__dest, const char *__src);
1008 __STRING_INLINE char *
1009 __strcat_g (char *__dest, const char *__src)
1011 register char *__tmp = __dest - 1;
1012 register char __dummy;
1013 __asm__ __volatile__
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)
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)); }))
1046 __STRING_INLINE char *__strncat_g (char *__dest, const char __src[],
1049 __STRING_INLINE char *
1050 __strncat_g (char *__dest, const char __src[], size_t __n)
1052 register char *__tmp = __dest;
1053 register char __dummy;
1055 __asm__ __volatile__
1069 : "=&a" (__dummy), "=&D" (__tmp), "=&S" (__src), "=&c" (__n)
1070 : "g" (__n), "0" (0), "1" (__tmp), "2" (__src), "3" (0xffffffff)
1074 __asm__ __volatile__
1091 : "=&q" (__dummy), "=&r" (__tmp), "=&r" (__src), "=&r" (__n)
1092 : "1" (__tmp), "2" (__src), "3" (__n)
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), \
1114 : __strcmp_cg ((const unsigned char *) (s1), \
1115 (const unsigned char *) (s2), \
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), \
1123 : __strcmp_gc ((const unsigned char *) (s1), \
1124 (const unsigned char *) (s2), \
1126 : __strcmp_gg ((s1), (s2))))))
1128 #define __strcmp_cc(s1, s2, l) \
1129 (__extension__ ({ register int __result = (s1)[0] - (s2)[0]; \
1130 if (l > 0 && __result == 0) \
1132 __result = (s1)[1] - (s2)[1]; \
1133 if (l > 1 && __result == 0) \
1135 __result = (s1)[2] - (s2)[2]; \
1136 if (l > 2 && __result == 0) \
1137 __result = (s1)[3] - (s2)[3]; \
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) \
1147 __result = (s1)[1] - __s2[1]; \
1148 if (l1 > 1 && __result == 0) \
1150 __result = (s1)[2] - __s2[2]; \
1151 if (l1 > 2 && __result == 0) \
1152 __result = (s1)[3] - __s2[3]; \
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) \
1162 __result = __s1[1] - (s2)[1]; \
1163 if (l2 > 1 && __result == 0) \
1165 __result = __s1[2] - (s2)[2]; \
1166 if (l2 > 2 && __result == 0) \
1167 __result = __s1[3] - (s2)[3]; \
1172 __STRING_INLINE int __strcmp_gg (const char *__s1, const char *__s2);
1175 __strcmp_gg (const char *__s1, const char *__s2)
1178 __asm__ __volatile__
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)
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)))))
1212 __STRING_INLINE int __strncmp_g (const char *__s1, const char *__s2,
1216 __strncmp_g (const char *__s1, const char *__s2, size_t __n)
1219 __asm__ __volatile__
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)
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) \
1253 ? (char *) __rawmemchr ((s), (c)) \
1254 : __strchr_c ((s), ((c) & 0xff) << 8)) \
1255 : __strchr_g ((s), (c))))
1257 __STRING_INLINE char *__strchr_c (const char *__s, int __c);
1259 __STRING_INLINE char *
1260 __strchr_c (const char *__s, int __c)
1262 register unsigned long int __d0;
1263 register char *__res;
1264 __asm__ __volatile__
1266 "movb (%0),%%al\n\t"
1267 "cmpb %%ah,%%al\n\t"
1270 "testb %%al,%%al\n\t"
1274 : "=r" (__res), "=&a" (__d0)
1275 : "0" (__s), "1" (__c),
1276 "m" ( *(struct { char __x[0xfffffff]; } *)__s)
1281 __STRING_INLINE char *__strchr_g (const char *__s, int __c);
1283 __STRING_INLINE char *
1284 __strchr_g (const char *__s, int __c)
1286 register unsigned long int __d0;
1287 register char *__res;
1288 __asm__ __volatile__
1291 "movb (%0),%%al\n\t"
1292 "cmpb %%ah,%%al\n\t"
1295 "testb %%al,%%al\n\t"
1299 : "=r" (__res), "=&a" (__d0)
1300 : "0" (__s), "1" (__c),
1301 "m" ( *(struct { char __x[0xfffffff]; } *)__s)
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) \
1312 ? (char *) __rawmemchr ((s), c) \
1313 : __strchrnul_c ((s), ((c) & 0xff) << 8)) \
1314 : __strchrnul_g ((s), c)))
1316 __STRING_INLINE char *__strchrnul_c (const char *__s, int __c);
1318 __STRING_INLINE char *
1319 __strchrnul_c (const char *__s, int __c)
1321 register unsigned long int __d0;
1322 register char *__res;
1323 __asm__ __volatile__
1325 "movb (%0),%%al\n\t"
1326 "cmpb %%ah,%%al\n\t"
1329 "testb %%al,%%al\n\t"
1333 : "=r" (__res), "=&a" (__d0)
1334 : "0" (__s), "1" (__c),
1335 "m" ( *(struct { char __x[0xfffffff]; } *)__s)
1340 __STRING_INLINE char *__strchrnul_g (const char *__s, int __c);
1342 __STRING_INLINE char *
1343 __strchrnul_g (const char *__s, int __c)
1345 register unsigned long int __d0;
1346 register char *__res;
1347 __asm__ __volatile__
1350 "movb (%0),%%al\n\t"
1351 "cmpb %%ah,%%al\n\t"
1354 "testb %%al,%%al\n\t"
1358 : "=r" (__res), "=&a" (__d0)
1359 : "0" (__s), "1" (__c),
1360 "m" ( *(struct { char __x[0xfffffff]; } *)__s)
1365 # define strchrnul(s, c) __strchrnul ((s), (c))
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))))
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))))
1387 __STRING_INLINE char *__strrchr_c (const char *__s, int __c);
1389 __STRING_INLINE char *
1390 __strrchr_c (const char *__s, int __c)
1392 register unsigned long int __d0, __d1;
1393 register char *__res;
1394 __asm__ __volatile__
1402 : "=d" (__res), "=&S" (__d0), "=&a" (__d1)
1403 : "0" (1), "1" (__s), "2" (__c),
1404 "m" ( *(struct { char __x[0xfffffff]; } *)__s)
1409 __STRING_INLINE char *__strrchr_g (const char *__s, int __c);
1411 __STRING_INLINE char *
1412 __strrchr_g (const char *__s, int __c)
1414 register unsigned long int __d0, __d1;
1415 register char *__res;
1416 __asm__ __volatile__
1425 : "=d" (__res), "=&S" (__d0), "=&a" (__d1)
1426 : "0" (1), "1" (__s), "2" (__c),
1427 "m" ( *(struct { char __x[0xfffffff]; } *)__s)
1432 __STRING_INLINE char *__strrchr_c (const char *__s, int __c);
1434 __STRING_INLINE char *
1435 __strrchr_c (const char *__s, int __c)
1437 register unsigned long int __d0, __d1;
1438 register char *__res;
1439 __asm__ __volatile__
1443 "cmpb %%ah,%%al\n\t"
1445 "leal -1(%%esi),%0\n"
1447 "testb %%al,%%al\n\t"
1449 : "=d" (__res), "=&S" (__d0), "=&a" (__d1)
1450 : "0" (0), "1" (__s), "2" (__c),
1451 "m" ( *(struct { char __x[0xfffffff]; } *)__s)
1456 __STRING_INLINE char *__strrchr_g (const char *__s, int __c);
1458 __STRING_INLINE char *
1459 __strrchr_g (const char *__s, int __c)
1461 register unsigned long int __d0, __d1;
1462 register char *__res;
1463 __asm__ __volatile__
1468 "cmpb %%ah,%%al\n\t"
1470 "leal -1(%%esi),%0\n"
1472 "testb %%al,%%al\n\t"
1474 : "=r" (__res), "=&S" (__d0), "=&a" (__d1)
1475 : "0" (0), "1" (__s), "2" (__c),
1476 "m" ( *(struct { char __x[0xfffffff]; } *)__s)
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))))
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' \
1500 : ((reject)[1] == '\0' \
1501 ? __strcspn_c1 ((s), (((reject)[0] << 8) & 0xff00)) \
1502 : __strcspn_cg ((s), (reject), strlen (reject)))) \
1503 : __strcspn_g ((s), (reject))))
1505 __STRING_INLINE size_t __strcspn_c1 (const char *__s, int __reject);
1507 #ifndef _FORCE_INLINES
1508 __STRING_INLINE size_t
1509 __strcspn_c1 (const char *__s, int __reject)
1511 register unsigned long int __d0;
1512 register char *__res;
1513 __asm__ __volatile__
1515 "movb (%0),%%al\n\t"
1517 "cmpb %%ah,%%al\n\t"
1519 "testb %%al,%%al\n\t"
1522 : "=r" (__res), "=&a" (__d0)
1523 : "0" (__s), "1" (__reject),
1524 "m" ( *(struct { char __x[0xfffffff]; } *)__s)
1526 return (__res - 1) - __s;
1530 __STRING_INLINE size_t __strcspn_cg (const char *__s, const char __reject[],
1531 size_t __reject_len);
1533 __STRING_INLINE size_t
1534 __strcspn_cg (const char *__s, const char __reject[], size_t __reject_len)
1536 register unsigned long int __d0, __d1, __d2;
1537 register const char *__res;
1538 __asm__ __volatile__
1542 "testb %%al,%%al\n\t"
1549 : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2)
1550 : "0" (__s), "d" (__reject), "g" (__reject_len)
1552 return (__res - 1) - __s;
1555 __STRING_INLINE size_t __strcspn_g (const char *__s, const char *__reject);
1558 __STRING_INLINE size_t
1559 __strcspn_g (const char *__s, const char *__reject)
1561 register unsigned long int __d0, __d1, __d2;
1562 register const char *__res;
1563 __asm__ __volatile__
1569 "leal -1(%%ecx),%%ebx\n"
1572 "testb %%al,%%al\n\t"
1575 "movl %%ebx,%%ecx\n\t"
1580 : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2)
1581 : "r" (__reject), "0" (__s), "1" (0), "2" (0xffffffff)
1583 return (__res - 1) - __s;
1586 __STRING_INLINE size_t
1587 __strcspn_g (const char *__s, const char *__reject)
1589 register unsigned long int __d0, __d1, __d2, __d3;
1590 register const char *__res;
1591 __asm__ __volatile__
1595 "leal -1(%%ecx),%%edx\n"
1598 "testb %%al,%%al\n\t"
1600 "movl %%ebx,%%edi\n\t"
1601 "movl %%edx,%%ecx\n\t"
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. */
1609 return (__res - 1) - __s;
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' \
1621 : ((accept)[1] == '\0' \
1622 ? __strspn_c1 ((s), (((accept)[0] << 8 ) & 0xff00)) \
1623 : __strspn_cg ((s), (accept), strlen (accept)))) \
1624 : __strspn_g ((s), (accept))))
1626 #ifndef _FORCE_INLINES
1627 __STRING_INLINE size_t __strspn_c1 (const char *__s, int __accept);
1629 __STRING_INLINE size_t
1630 __strspn_c1 (const char *__s, int __accept)
1632 register unsigned long int __d0;
1633 register char *__res;
1634 /* Please note that __accept never can be '\0'. */
1635 __asm__ __volatile__
1641 : "=r" (__res), "=&q" (__d0)
1642 : "0" (__s), "1" (__accept),
1643 "m" ( *(struct { char __x[0xfffffff]; } *)__s)
1645 return (__res - 1) - __s;
1649 __STRING_INLINE size_t __strspn_cg (const char *__s, const char __accept[],
1650 size_t __accept_len);
1652 __STRING_INLINE size_t
1653 __strspn_cg (const char *__s, const char __accept[], size_t __accept_len)
1655 register unsigned long int __d0, __d1, __d2;
1656 register const char *__res;
1657 __asm__ __volatile__
1661 "testb %%al,%%al\n\t"
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)
1675 return (__res - 1) - __s;
1678 __STRING_INLINE size_t __strspn_g (const char *__s, const char *__accept);
1681 __STRING_INLINE size_t
1682 __strspn_g (const char *__s, const char *__accept)
1684 register unsigned long int __d0, __d1, __d2;
1685 register const char *__res;
1686 __asm__ __volatile__
1691 "leal -1(%%ecx),%%ebx\n"
1694 "testb %%al,%%al\n\t"
1696 "movl %%edx,%%edi\n\t"
1697 "movl %%ebx,%%ecx\n\t"
1702 : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2)
1703 : "d" (__accept), "0" (__s), "1" (0), "2" (0xffffffff), "3" (__accept)
1705 return (__res - 1) - __s;
1708 __STRING_INLINE size_t
1709 __strspn_g (const char *__s, const char *__accept)
1711 register unsigned long int __d0, __d1, __d2, __d3;
1712 register const char *__res;
1713 __asm__ __volatile__
1717 "leal -1(%%ecx),%%edx\n"
1720 "testb %%al,%%al\n\t"
1722 "movl %%ebx,%%edi\n\t"
1723 "movl %%edx,%%ecx\n\t"
1727 : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2), "=&d" (__d3)
1728 : "0" (__s), "1" (0), "2" (0xffffffff), "3" (__accept), "b" (__accept)
1730 return (__res - 1) - __s;
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))))
1746 __STRING_INLINE char *__strpbrk_cg (const char *__s, const char __accept[],
1747 size_t __accept_len);
1749 __STRING_INLINE char *
1750 __strpbrk_cg (const char *__s, const char __accept[], size_t __accept_len)
1752 register unsigned long int __d0, __d1, __d2;
1753 register char *__res;
1754 __asm__ __volatile__
1758 "testb %%al,%%al\n\t"
1769 : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2)
1770 : "0" (__s), "d" (__accept), "g" (__accept_len)
1775 __STRING_INLINE char *__strpbrk_g (const char *__s, const char *__accept);
1778 __STRING_INLINE char *
1779 __strpbrk_g (const char *__s, const char *__accept)
1781 register unsigned long int __d0, __d1, __d2;
1782 register char *__res;
1783 __asm__ __volatile__
1785 "movl %%edx,%%edi\n\t"
1789 "leal -1(%%ecx),%%ebx\n"
1792 "testb %%al,%%al\n\t"
1794 "movl %%edx,%%edi\n\t"
1795 "movl %%ebx,%%ecx\n\t"
1804 : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2)
1805 : "d" (__accept), "0" (__s), "1" (0), "2" (0xffffffff)
1810 __STRING_INLINE char *
1811 __strpbrk_g (const char *__s, const char *__accept)
1813 register unsigned long int __d0, __d1, __d2, __d3;
1814 register char *__res;
1815 __asm__ __volatile__
1816 ("movl %%ebx,%%edi\n\t"
1820 "leal -1(%%ecx),%%edx\n"
1823 "testb %%al,%%al\n\t"
1825 "movl %%ebx,%%edi\n\t"
1826 "movl %%edx,%%ecx\n\t"
1834 : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&d" (__d2), "=&D" (__d3)
1835 : "0" (__s), "1" (0), "2" (0xffffffff), "b" (__accept)
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' \
1848 : ((needle)[1] == '\0' \
1849 ? strchr ((haystack), (needle)[0]) \
1850 : __strstr_cg ((haystack), (needle), \
1851 strlen (needle)))) \
1852 : __strstr_g ((haystack), (needle))))
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);
1860 __STRING_INLINE char *
1861 __strstr_cg (const char *__haystack, const char __needle[],
1862 size_t __needle_len)
1864 register unsigned long int __d0, __d1, __d2;
1865 register char *__res;
1866 __asm__ __volatile__
1874 "cmpb $0,-1(%%esi)\n\t"
1875 "leal 1(%%eax),%5\n\t"
1877 "xorl %%eax,%%eax\n"
1879 : "=&a" (__res), "=&S" (__d0), "=&D" (__d1), "=&c" (__d2)
1880 : "g" (__needle_len), "1" (__haystack), "d" (__needle)
1885 __STRING_INLINE char *__strstr_g (const char *__haystack,
1886 const char *__needle);
1889 __STRING_INLINE char *
1890 __strstr_g (const char *__haystack, const char *__needle)
1892 register unsigned long int __d0, __d1, __d2;
1893 register char *__res;
1894 __asm__ __volatile__
1899 "decl %%ecx\n\t" /* NOTE! This also sets Z if searchstring='' */
1900 "movl %%ecx,%%ebx\n"
1902 "movl %%edx,%%edi\n\t"
1903 "movl %%esi,%%eax\n\t"
1904 "movl %%ebx,%%ecx\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"
1910 "xorl %%eax,%%eax\n"
1913 : "=&a" (__res), "=&c" (__d0), "=&S" (__d1), "=&D" (__d2)
1914 : "0" (0), "1" (0xffffffff), "2" (__haystack), "3" (__needle),
1920 __STRING_INLINE char *
1921 __strstr_g (const char *__haystack, const char *__needle)
1923 register unsigned long int __d0, __d1, __d2, __d3;
1924 register char *__res;
1925 __asm__ __volatile__
1929 "decl %%ecx\n\t" /* NOTE! This also sets Z if searchstring='' */
1930 "movl %%ecx,%%edx\n"
1932 "movl %%ebx,%%edi\n\t"
1933 "movl %%esi,%%eax\n\t"
1934 "movl %%edx,%%ecx\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"
1940 "xorl %%eax,%%eax\n"
1942 : "=&a" (__res), "=&c" (__d0), "=&S" (__d1), "=&D" (__d2), "=&d" (__d3)
1943 : "0" (0), "1" (0xffffffff), "2" (__haystack), "3" (__needle),
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
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__ \
1962 : "=&r" (__cnt), "=r" (__tmp) \
1963 : "rm" (word), "1" (-1)); \
1967 # define ffsl(word) ffs(word)
1970 #endif /* BSD || X/Open */
1972 #ifndef _FORCE_INLINES
1973 # undef __STRING_INLINE
1976 #endif /* use string inlines && GNU CC */