1 /* Optimized, inlined string functions. i486/x86-64 version.
2 Copyright (C) 2001-2014 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
20 # error "Never use <bits/string.h> directly; include <string.h> instead."
23 /* The ix86 processors can access unaligned multi-byte variables. */
24 #define _STRING_ARCH_unaligned 1
26 /* Enable inline functions only for i486 or better when compiling for
28 #if !defined __x86_64__ && (defined __i486__ || defined __pentium__ \
29 || defined __pentiumpro__ || defined __pentium4__ \
30 || defined __nocona__ || defined __atom__ \
31 || defined __core2__ || defined __corei7__ \
32 || defined __k6__ || defined __geode__ \
33 || defined __k8__ || defined __athlon__ \
34 || defined __amdfam10__)
36 /* We only provide optimizations if the user selects them and if
38 # if !defined __NO_STRING_INLINES && defined __USE_STRING_INLINES \
39 && defined __GNUC__ && __GNUC__ >= 2
41 # ifndef __STRING_INLINE
42 # ifndef __extern_inline
43 # define __STRING_INLINE inline
45 # define __STRING_INLINE __extern_inline
49 /* The macros are used in some of the optimized implementations below. */
50 # define __STRING_SMALL_GET16(src, idx) \
51 ((((const unsigned char *) (src))[idx + 1] << 8) \
52 | ((const unsigned char *) (src))[idx])
53 # define __STRING_SMALL_GET32(src, idx) \
54 (((((const unsigned char *) (src))[idx + 3] << 8 \
55 | ((const unsigned char *) (src))[idx + 2]) << 8 \
56 | ((const unsigned char *) (src))[idx + 1]) << 8 \
57 | ((const unsigned char *) (src))[idx])
60 /* Copy N bytes of SRC to DEST. */
61 # define _HAVE_STRING_ARCH_memcpy 1
62 # define memcpy(dest, src, n) \
63 (__extension__ (__builtin_constant_p (n) \
64 ? __memcpy_c ((dest), (src), (n)) \
65 : __memcpy_g ((dest), (src), (n))))
66 # define __memcpy_c(dest, src, n) \
70 ? __memcpy_by4 (dest, src, n) \
72 ? __memcpy_by2 (dest, src, n) \
73 : __memcpy_g (dest, src, n))))
75 __STRING_INLINE void *__memcpy_by4 (void *__dest, const void *__src,
78 __STRING_INLINE void *
79 __memcpy_by4 (void *__dest, const void *__src, size_t __n)
81 register unsigned long int __d0, __d1;
82 register void *__tmp = __dest;
91 : "=&r" (__d0), "=&r" (__tmp), "=&r" (__src), "=&r" (__d1)
92 : "1" (__tmp), "2" (__src), "3" (__n / 4)
97 __STRING_INLINE void *__memcpy_by2 (void *__dest, const void *__src,
100 __STRING_INLINE void *
101 __memcpy_by2 (void *__dest, const void *__src, size_t __n)
103 register unsigned long int __d0, __d1;
104 register void *__tmp = __dest;
107 "jz 2f\n" /* only a word */
118 : "=&q" (__d0), "=&r" (__tmp), "=&r" (__src), "=&r" (__d1)
119 : "1" (__tmp), "2" (__src), "3" (__n / 2)
124 __STRING_INLINE void *__memcpy_g (void *__dest, const void *__src, size_t __n);
126 __STRING_INLINE void *
127 __memcpy_g (void *__dest, const void *__src, size_t __n)
129 register unsigned long int __d0, __d1, __d2;
130 register void *__tmp = __dest;
142 : "=&c" (__d0), "=&D" (__d1), "=&S" (__d2),
143 "=m" ( *(struct { __extension__ char __x[__n]; } *)__dest)
144 : "0" (__n), "1" (__tmp), "2" (__src),
145 "m" ( *(struct { __extension__ char __x[__n]; } *)__src)
150 # define _HAVE_STRING_ARCH_memmove 1
151 # ifndef _FORCE_INLINES
152 /* Copy N bytes of SRC to DEST, guaranteeing
153 correct behavior for overlapping strings. */
154 # define memmove(dest, src, n) __memmove_g (dest, src, n)
156 __STRING_INLINE void *__memmove_g (void *, const void *, size_t)
159 __STRING_INLINE void *
160 __memmove_g (void *__dest, const void *__src, size_t __n)
162 register unsigned long int __d0, __d1, __d2;
163 register void *__tmp = __dest;
168 : "=&c" (__d0), "=&S" (__d1), "=&D" (__d2),
169 "=m" ( *(struct { __extension__ char __x[__n]; } *)__dest)
170 : "0" (__n), "1" (__src), "2" (__tmp),
171 "m" ( *(struct { __extension__ char __x[__n]; } *)__src));
177 : "=&c" (__d0), "=&S" (__d1), "=&D" (__d2),
178 "=m" ( *(struct { __extension__ char __x[__n]; } *)__dest)
179 : "0" (__n), "1" (__n - 1 + (const char *) __src),
180 "2" (__n - 1 + (char *) __tmp),
181 "m" ( *(struct { __extension__ char __x[__n]; } *)__src));
186 /* Compare N bytes of S1 and S2. */
187 # define _HAVE_STRING_ARCH_memcmp 1
188 # ifndef _FORCE_INLINES
190 /* gcc has problems to spill registers when using PIC. */
192 memcmp (const void *__s1, const void *__s2, size_t __n)
194 register unsigned long int __d0, __d1, __d2;
204 : "=&a" (__res), "=&S" (__d0), "=&D" (__d1), "=&c" (__d2)
205 : "0" (0), "1" (__s1), "2" (__s2), "3" (__n),
206 "m" ( *(struct { __extension__ char __x[__n]; } *)__s1),
207 "m" ( *(struct { __extension__ char __x[__n]; } *)__s2)
214 /* Set N bytes of S to C. */
215 # define _HAVE_STRING_ARCH_memset 1
216 # define _USE_STRING_ARCH_memset 1
217 # define memset(s, c, n) \
218 (__extension__ (__builtin_constant_p (n) && (n) <= 16 \
220 ? __memset_c1 ((s), (c)) \
221 : __memset_gc ((s), (c), (n))) \
222 : (__builtin_constant_p (c) \
223 ? (__builtin_constant_p (n) \
224 ? __memset_ccn ((s), (c), (n)) \
225 : memset ((s), (c), (n))) \
226 : (__builtin_constant_p (n) \
227 ? __memset_gcn ((s), (c), (n)) \
228 : memset ((s), (c), (n))))))
230 # define __memset_c1(s, c) ({ void *__s = (s); \
231 *((unsigned char *) __s) = (unsigned char) (c); \
234 # define __memset_gc(s, c, n) \
235 ({ void *__s = (s); \
238 unsigned short int __usi; \
239 unsigned char __uc; \
241 unsigned int __c = ((unsigned int) ((unsigned char) (c))) * 0x01010101; \
243 /* We apply a trick here. `gcc' would implement the following \
244 assignments using immediate operands. But this uses to much \
245 memory (7, instead of 4 bytes). So we force the value in a \
247 if ((n) == 3 || (n) >= 5) \
248 __asm__ __volatile__ ("" : "=r" (__c) : "0" (__c)); \
250 /* This `switch' statement will be removed at compile-time. */ \
255 __u = __extension__ ((void *) __u + 4); \
258 __u = __extension__ ((void *) __u + 4); \
261 __u = __extension__ ((void *) __u + 4); \
263 __u->__usi = (unsigned short int) __c; \
264 __u = __extension__ ((void *) __u + 2); \
265 __u->__uc = (unsigned char) __c; \
270 __u = __extension__ ((void *) __u + 4); \
273 __u = __extension__ ((void *) __u + 4); \
276 __u = __extension__ ((void *) __u + 4); \
278 __u->__usi = (unsigned short int) __c; \
283 __u = __extension__ ((void *) __u + 4); \
286 __u = __extension__ ((void *) __u + 4); \
289 __u = __extension__ ((void *) __u + 4); \
291 __u->__uc = (unsigned char) __c; \
296 __u = __extension__ ((void *) __u + 4); \
299 __u = __extension__ ((void *) __u + 4); \
302 __u = __extension__ ((void *) __u + 4); \
311 # define __memset_ccn(s, c, n) \
313 ? __memset_ccn_by4 (s, ((unsigned int) ((unsigned char) (c))) * 0x01010101,\
316 ? __memset_ccn_by2 (s, \
317 ((unsigned int) ((unsigned char) (c))) * 0x01010101,\
321 __STRING_INLINE void *__memset_ccn_by4 (void *__s, unsigned int __c,
324 __STRING_INLINE void *
325 __memset_ccn_by4 (void *__s, unsigned int __c, size_t __n)
327 register void *__tmp = __s;
328 register unsigned long int __d0;
333 : "=&a" (__c), "=&D" (__tmp), "=&c" (__d0),
334 "=m" ( *(struct { __extension__ char __x[__n]; } *)__s)
335 : "0" ((unsigned int) __c), "1" (__tmp), "2" (__n / 4)
344 : "=&r" (__c), "=&r" (__tmp), "=&r" (__d0),
345 "=m" ( *(struct { __extension__ char __x[__n]; } *)__s)
346 : "0" ((unsigned int) __c), "1" (__tmp), "2" (__n / 4)
352 __STRING_INLINE void *__memset_ccn_by2 (void *__s, unsigned int __c,
355 __STRING_INLINE void *
356 __memset_ccn_by2 (void *__s, unsigned int __c, size_t __n)
358 register unsigned long int __d0, __d1;
359 register void *__tmp = __s;
365 : "=&a" (__d0), "=&D" (__tmp), "=&c" (__d1),
366 "=m" ( *(struct { __extension__ char __x[__n]; } *)__s)
367 : "0" ((unsigned int) __c), "1" (__tmp), "2" (__n / 4)
371 ("1:\tmovl %0,(%1)\n\t"
376 : "=&q" (__d0), "=&r" (__tmp), "=&r" (__d1),
377 "=m" ( *(struct { __extension__ char __x[__n]; } *)__s)
378 : "0" ((unsigned int) __c), "1" (__tmp), "2" (__n / 4)
384 # define __memset_gcn(s, c, n) \
386 ? __memset_gcn_by4 (s, c, n) \
388 ? __memset_gcn_by2 (s, c, n) \
391 __STRING_INLINE void *__memset_gcn_by4 (void *__s, int __c, size_t __n);
393 __STRING_INLINE void *
394 __memset_gcn_by4 (void *__s, int __c, size_t __n)
396 register void *__tmp = __s;
397 register unsigned long int __d0;
408 : "=&q" (__c), "=&r" (__tmp), "=&r" (__d0),
409 "=m" ( *(struct { __extension__ char __x[__n]; } *)__s)
410 : "0" ((unsigned int) __c), "1" (__tmp), "2" (__n / 4)
415 __STRING_INLINE void *__memset_gcn_by2 (void *__s, int __c, size_t __n);
417 __STRING_INLINE void *
418 __memset_gcn_by2 (void *__s, int __c, size_t __n)
420 register unsigned long int __d0, __d1;
421 register void *__tmp = __s;
433 : "=&q" (__d0), "=&r" (__tmp), "=&r" (__d1),
434 "=m" ( *(struct { __extension__ char __x[__n]; } *)__s)
435 : "0" ((unsigned int) __c), "1" (__tmp), "2" (__n / 4)
441 /* Search N bytes of S for C. */
442 # define _HAVE_STRING_ARCH_memchr 1
443 # ifndef _FORCE_INLINES
444 __STRING_INLINE void *
445 memchr (const void *__s, int __c, size_t __n)
447 register unsigned long int __d0;
449 register unsigned long int __d1;
451 register unsigned char *__res;
459 : "=D" (__res), "=&c" (__d0), "=&r" (__d1)
460 : "a" (__c), "0" (__s), "1" (__n), "2" (1),
461 "m" ( *(struct { __extension__ char __x[__n]; } *)__s)
470 : "=D" (__res), "=&c" (__d0)
471 : "a" (__c), "0" (__s), "1" (__n),
472 "m" ( *(struct { __extension__ char __x[__n]; } *)__s)
479 # define _HAVE_STRING_ARCH_memrchr 1
480 # ifndef _FORCE_INLINES
481 __STRING_INLINE void *__memrchr (const void *__s, int __c, size_t __n);
483 __STRING_INLINE void *
484 __memrchr (const void *__s, int __c, size_t __n)
486 register unsigned long int __d0;
488 register unsigned long int __d1;
490 register void *__res;
500 : "=D" (__res), "=&c" (__d0), "=&r" (__d1)
501 : "a" (__c), "0" (__s + __n - 1), "1" (__n), "2" (-1),
502 "m" ( *(struct { __extension__ char __x[__n]; } *)__s)
512 : "=D" (__res), "=&c" (__d0)
513 : "a" (__c), "0" (__s + __n - 1), "1" (__n),
514 "m" ( *(struct { __extension__ char __x[__n]; } *)__s)
520 # define memrchr(s, c, n) __memrchr ((s), (c), (n))
524 /* Return pointer to C in S. */
525 # define _HAVE_STRING_ARCH_rawmemchr 1
526 __STRING_INLINE void *__rawmemchr (const void *__s, int __c);
528 # ifndef _FORCE_INLINES
529 __STRING_INLINE void *
530 __rawmemchr (const void *__s, int __c)
532 register unsigned long int __d0;
533 register unsigned char *__res;
537 : "=D" (__res), "=&c" (__d0)
538 : "a" (__c), "0" (__s), "1" (0xffffffff),
539 "m" ( *(struct { char __x[0xfffffff]; } *)__s)
544 __STRING_INLINE void *
545 rawmemchr (const void *__s, int __c)
547 return __rawmemchr (__s, __c);
549 # endif /* use GNU */
553 /* Return the length of S. */
554 # define _HAVE_STRING_ARCH_strlen 1
555 # define strlen(str) \
556 (__extension__ (__builtin_constant_p (str) \
557 ? __builtin_strlen (str) \
559 __STRING_INLINE size_t __strlen_g (const char *__str);
561 __STRING_INLINE size_t
562 __strlen_g (const char *__str)
564 register char __dummy;
565 register const char *__tmp = __str;
572 : "=r" (__tmp), "=&q" (__dummy)
574 "m" ( *(struct { char __x[0xfffffff]; } *)__str)
576 return __tmp - __str - 1;
580 /* Copy SRC to DEST. */
581 # define _HAVE_STRING_ARCH_strcpy 1
582 # define strcpy(dest, src) \
583 (__extension__ (__builtin_constant_p (src) \
584 ? (sizeof ((src)[0]) == 1 && strlen (src) + 1 <= 8 \
585 ? __strcpy_a_small ((dest), (src), strlen (src) + 1) \
586 : (char *) memcpy ((char *) (dest), \
587 (const char *) (src), \
589 : __strcpy_g ((dest), (src))))
591 # define __strcpy_a_small(dest, src, srclen) \
592 (__extension__ ({ char *__dest = (dest); \
595 unsigned short int __usi; \
596 unsigned char __uc; \
598 } *__u = (void *) __dest; \
605 __u->__usi = __STRING_SMALL_GET16 (src, 0); \
608 __u->__usi = __STRING_SMALL_GET16 (src, 0); \
609 __u = __extension__ ((void *) __u + 2); \
613 __u->__ui = __STRING_SMALL_GET32 (src, 0); \
616 __u->__ui = __STRING_SMALL_GET32 (src, 0); \
617 __u = __extension__ ((void *) __u + 4); \
621 __u->__ui = __STRING_SMALL_GET32 (src, 0); \
622 __u = __extension__ ((void *) __u + 4); \
623 __u->__usi = __STRING_SMALL_GET16 (src, 4); \
626 __u->__ui = __STRING_SMALL_GET32 (src, 0); \
627 __u = __extension__ ((void *) __u + 4); \
628 __u->__usi = __STRING_SMALL_GET16 (src, 4); \
629 __u = __extension__ ((void *) __u + 2); \
633 __u->__ui = __STRING_SMALL_GET32 (src, 0); \
634 __u = __extension__ ((void *) __u + 4); \
635 __u->__ui = __STRING_SMALL_GET32 (src, 4); \
640 __STRING_INLINE char *__strcpy_g (char *__dest, const char *__src);
642 __STRING_INLINE char *
643 __strcpy_g (char *__dest, const char *__src)
645 register char *__tmp = __dest;
646 register char __dummy;
656 : "=&r" (__src), "=&r" (__tmp), "=&q" (__dummy),
657 "=m" ( *(struct { char __x[0xfffffff]; } *)__dest)
658 : "0" (__src), "1" (__tmp),
659 "m" ( *(struct { char __x[0xfffffff]; } *)__src)
666 # define _HAVE_STRING_ARCH_stpcpy 1
667 /* Copy SRC to DEST. */
668 # define __stpcpy(dest, src) \
669 (__extension__ (__builtin_constant_p (src) \
670 ? (strlen (src) + 1 <= 8 \
671 ? __stpcpy_a_small ((dest), (src), strlen (src) + 1) \
672 : __stpcpy_c ((dest), (src), strlen (src) + 1)) \
673 : __stpcpy_g ((dest), (src))))
674 # define __stpcpy_c(dest, src, srclen) \
676 ? __mempcpy_by4 (dest, src, srclen) - 1 \
677 : ((srclen) % 2 == 0 \
678 ? __mempcpy_by2 (dest, src, srclen) - 1 \
679 : __mempcpy_byn (dest, src, srclen) - 1))
681 /* In glibc itself we use this symbol for namespace reasons. */
682 # define stpcpy(dest, src) __stpcpy ((dest), (src))
684 # define __stpcpy_a_small(dest, src, srclen) \
685 (__extension__ ({ union { \
687 unsigned short int __usi; \
688 unsigned char __uc; \
690 } *__u = (void *) (dest); \
697 __u->__usi = __STRING_SMALL_GET16 (src, 0); \
698 __u = __extension__ ((void *) __u + 1); \
701 __u->__usi = __STRING_SMALL_GET16 (src, 0); \
702 __u = __extension__ ((void *) __u + 2); \
706 __u->__ui = __STRING_SMALL_GET32 (src, 0); \
707 __u = __extension__ ((void *) __u + 3); \
710 __u->__ui = __STRING_SMALL_GET32 (src, 0); \
711 __u = __extension__ ((void *) __u + 4); \
715 __u->__ui = __STRING_SMALL_GET32 (src, 0); \
716 __u = __extension__ ((void *) __u + 4); \
717 __u->__usi = __STRING_SMALL_GET16 (src, 4); \
718 __u = __extension__ ((void *) __u + 1); \
721 __u->__ui = __STRING_SMALL_GET32 (src, 0); \
722 __u = __extension__ ((void *) __u + 4); \
723 __u->__usi = __STRING_SMALL_GET16 (src, 4); \
724 __u = __extension__ ((void *) __u + 2); \
728 __u->__ui = __STRING_SMALL_GET32 (src, 0); \
729 __u = __extension__ ((void *) __u + 4); \
730 __u->__ui = __STRING_SMALL_GET32 (src, 4); \
731 __u = __extension__ ((void *) __u + 3); \
736 __STRING_INLINE char *__mempcpy_by4 (char *__dest, const char *__src,
739 __STRING_INLINE char *
740 __mempcpy_by4 (char *__dest, const char *__src, size_t __srclen)
742 register char *__tmp = __dest;
743 register unsigned long int __d0, __d1;
752 : "=&r" (__d0), "=r" (__tmp), "=&r" (__src), "=&r" (__d1)
753 : "1" (__tmp), "2" (__src), "3" (__srclen / 4)
758 __STRING_INLINE char *__mempcpy_by2 (char *__dest, const char *__src,
761 __STRING_INLINE char *
762 __mempcpy_by2 (char *__dest, const char *__src, size_t __srclen)
764 register char *__tmp = __dest;
765 register unsigned long int __d0, __d1;
768 "jz 2f\n" /* only a word */
779 : "=&q" (__d0), "=r" (__tmp), "=&r" (__src), "=&r" (__d1),
780 "=m" ( *(struct { __extension__ char __x[__srclen]; } *)__dest)
781 : "1" (__tmp), "2" (__src), "3" (__srclen / 2),
782 "m" ( *(struct { __extension__ char __x[__srclen]; } *)__src)
787 __STRING_INLINE char *__mempcpy_byn (char *__dest, const char *__src,
790 __STRING_INLINE char *
791 __mempcpy_byn (char *__dest, const char *__src, size_t __srclen)
793 register unsigned long __d0, __d1;
794 register char *__tmp = __dest;
806 : "=D" (__tmp), "=&c" (__d0), "=&S" (__d1),
807 "=m" ( *(struct { __extension__ char __x[__srclen]; } *)__dest)
808 : "0" (__tmp), "1" (__srclen), "2" (__src),
809 "m" ( *(struct { __extension__ char __x[__srclen]; } *)__src)
814 __STRING_INLINE char *__stpcpy_g (char *__dest, const char *__src);
816 __STRING_INLINE char *
817 __stpcpy_g (char *__dest, const char *__src)
819 register char *__tmp = __dest;
820 register char __dummy;
830 : "=&r" (__src), "=r" (__tmp), "=&q" (__dummy),
831 "=m" ( *(struct { char __x[0xfffffff]; } *)__dest)
832 : "0" (__src), "1" (__tmp),
833 "m" ( *(struct { char __x[0xfffffff]; } *)__src)
840 /* Copy no more than N characters of SRC to DEST. */
841 # define _HAVE_STRING_ARCH_strncpy 1
842 # define strncpy(dest, src, n) \
843 (__extension__ (__builtin_constant_p (src) \
844 ? ((strlen (src) + 1 >= ((size_t) (n)) \
845 ? (char *) memcpy ((char *) (dest), \
846 (const char *) (src), n) \
847 : __strncpy_cg ((dest), (src), strlen (src) + 1, n))) \
848 : __strncpy_gg ((dest), (src), n)))
849 # define __strncpy_cg(dest, src, srclen, n) \
850 (((srclen) % 4 == 0) \
851 ? __strncpy_by4 (dest, src, srclen, n) \
852 : (((srclen) % 2 == 0) \
853 ? __strncpy_by2 (dest, src, srclen, n) \
854 : __strncpy_byn (dest, src, srclen, n)))
856 __STRING_INLINE char *__strncpy_by4 (char *__dest, const char __src[],
857 size_t __srclen, size_t __n);
859 __STRING_INLINE char *
860 __strncpy_by4 (char *__dest, const char __src[], size_t __srclen, size_t __n)
862 register char *__tmp = __dest;
863 register int __dummy1, __dummy2;
872 : "=&r" (__dummy1), "=r" (__tmp), "=&r" (__src), "=&r" (__dummy2),
873 "=m" ( *(struct { __extension__ char __x[__srclen]; } *)__dest)
874 : "1" (__tmp), "2" (__src), "3" (__srclen / 4),
875 "m" ( *(struct { __extension__ char __x[__srclen]; } *)__src)
877 (void) memset (__tmp, '\0', __n - __srclen);
881 __STRING_INLINE char *__strncpy_by2 (char *__dest, const char __src[],
882 size_t __srclen, size_t __n);
884 __STRING_INLINE char *
885 __strncpy_by2 (char *__dest, const char __src[], size_t __srclen, size_t __n)
887 register char *__tmp = __dest;
888 register int __dummy1, __dummy2;
891 "jz 2f\n" /* only a word */
902 : "=&q" (__dummy1), "=r" (__tmp), "=&r" (__src), "=&r" (__dummy2),
903 "=m" ( *(struct { __extension__ char __x[__srclen]; } *)__dest)
904 : "1" (__tmp), "2" (__src), "3" (__srclen / 2),
905 "m" ( *(struct { __extension__ char __x[__srclen]; } *)__src)
907 (void) memset (__tmp + 2, '\0', __n - __srclen);
911 __STRING_INLINE char *__strncpy_byn (char *__dest, const char __src[],
912 size_t __srclen, size_t __n);
914 __STRING_INLINE char *
915 __strncpy_byn (char *__dest, const char __src[], size_t __srclen, size_t __n)
917 register unsigned long int __d0, __d1;
918 register char *__tmp = __dest;
930 : "=D" (__tmp), "=&c" (__d0), "=&S" (__d1),
931 "=m" ( *(struct { __extension__ char __x[__srclen]; } *)__dest)
932 : "1" (__srclen), "0" (__tmp),"2" (__src),
933 "m" ( *(struct { __extension__ char __x[__srclen]; } *)__src)
935 (void) memset (__tmp, '\0', __n - __srclen);
939 __STRING_INLINE char *__strncpy_gg (char *__dest, const char *__src,
942 __STRING_INLINE char *
943 __strncpy_gg (char *__dest, const char *__src, size_t __n)
945 register char *__tmp = __dest;
946 register char __dummy;
964 : "=&r" (__src), "=&r" (__tmp), "=&q" (__dummy), "=&r" (__n)
965 : "0" (__src), "1" (__tmp), "3" (__n)
972 /* Append SRC onto DEST. */
973 # define _HAVE_STRING_ARCH_strcat 1
974 # define strcat(dest, src) \
975 (__extension__ (__builtin_constant_p (src) \
976 ? __strcat_c ((dest), (src), strlen (src) + 1) \
977 : __strcat_g ((dest), (src))))
979 __STRING_INLINE char *__strcat_c (char *__dest, const char __src[],
982 __STRING_INLINE char *
983 __strcat_c (char *__dest, const char __src[], size_t __srclen)
986 register unsigned long int __d0;
987 register char *__tmp;
990 : "=D" (__tmp), "=&c" (__d0),
991 "=m" ( *(struct { char __x[0xfffffff]; } *)__dest)
992 : "0" (__dest), "1" (0xffffffff), "a" (0),
993 "m" ( *(struct { __extension__ char __x[__srclen]; } *)__src)
997 register char *__tmp = __dest - 1;
1004 "=m" ( *(struct { char __x[0xfffffff]; } *)__dest)
1006 "m" ( *(struct { __extension__ char __x[__srclen]; } *)__src)
1009 (void) memcpy (__tmp, __src, __srclen);
1013 __STRING_INLINE char *__strcat_g (char *__dest, const char *__src);
1015 __STRING_INLINE char *
1016 __strcat_g (char *__dest, const char *__src)
1018 register char *__tmp = __dest - 1;
1019 register char __dummy;
1020 __asm__ __volatile__
1032 : "=&q" (__dummy), "=&r" (__tmp), "=&r" (__src),
1033 "=m" ( *(struct { char __x[0xfffffff]; } *)__dest)
1034 : "1" (__tmp), "2" (__src),
1035 "m" ( *(struct { char __x[0xfffffff]; } *)__src)
1041 /* Append no more than N characters from SRC onto DEST. */
1042 # define _HAVE_STRING_ARCH_strncat 1
1043 # define strncat(dest, src, n) \
1044 (__extension__ ({ char *__dest = (dest); \
1045 __builtin_constant_p (src) && __builtin_constant_p (n) \
1046 ? (strlen (src) < ((size_t) (n)) \
1047 ? strcat (__dest, (src)) \
1048 : (*(char *)__mempcpy (strchr (__dest, '\0'), \
1049 (const char *) (src), \
1050 (n)) = 0, __dest)) \
1051 : __strncat_g (__dest, (src), (n)); }))
1053 __STRING_INLINE char *__strncat_g (char *__dest, const char __src[],
1056 __STRING_INLINE char *
1057 __strncat_g (char *__dest, const char __src[], size_t __n)
1059 register char *__tmp = __dest;
1060 register char __dummy;
1062 __asm__ __volatile__
1076 : "=&a" (__dummy), "=&D" (__tmp), "=&S" (__src), "=&c" (__n)
1077 : "g" (__n), "0" (0), "1" (__tmp), "2" (__src), "3" (0xffffffff)
1081 __asm__ __volatile__
1098 : "=&q" (__dummy), "=&r" (__tmp), "=&r" (__src), "=&r" (__n)
1099 : "1" (__tmp), "2" (__src), "3" (__n)
1106 /* Compare S1 and S2. */
1107 # define _HAVE_STRING_ARCH_strcmp 1
1108 # define strcmp(s1, s2) \
1109 (__extension__ (__builtin_constant_p (s1) && __builtin_constant_p (s2) \
1110 && (sizeof ((s1)[0]) != 1 || strlen (s1) >= 4) \
1111 && (sizeof ((s2)[0]) != 1 || strlen (s2) >= 4) \
1112 ? memcmp ((const char *) (s1), (const char *) (s2), \
1113 (strlen (s1) < strlen (s2) \
1114 ? strlen (s1) : strlen (s2)) + 1) \
1115 : (__builtin_constant_p (s1) && sizeof ((s1)[0]) == 1 \
1116 && sizeof ((s2)[0]) == 1 && strlen (s1) < 4 \
1117 ? (__builtin_constant_p (s2) && sizeof ((s2)[0]) == 1 \
1118 ? __strcmp_cc ((const unsigned char *) (s1), \
1119 (const unsigned char *) (s2), \
1121 : __strcmp_cg ((const unsigned char *) (s1), \
1122 (const unsigned char *) (s2), \
1124 : (__builtin_constant_p (s2) && sizeof ((s1)[0]) == 1 \
1125 && sizeof ((s2)[0]) == 1 && strlen (s2) < 4 \
1126 ? (__builtin_constant_p (s1) \
1127 ? __strcmp_cc ((const unsigned char *) (s1), \
1128 (const unsigned char *) (s2), \
1130 : __strcmp_gc ((const unsigned char *) (s1), \
1131 (const unsigned char *) (s2), \
1133 : __strcmp_gg ((s1), (s2))))))
1135 # define __strcmp_cc(s1, s2, l) \
1136 (__extension__ ({ register int __result = (s1)[0] - (s2)[0]; \
1137 if (l > 0 && __result == 0) \
1139 __result = (s1)[1] - (s2)[1]; \
1140 if (l > 1 && __result == 0) \
1142 __result = (s1)[2] - (s2)[2]; \
1143 if (l > 2 && __result == 0) \
1144 __result = (s1)[3] - (s2)[3]; \
1149 # define __strcmp_cg(s1, s2, l1) \
1150 (__extension__ ({ const unsigned char *__s2 = (s2); \
1151 register int __result = (s1)[0] - __s2[0]; \
1152 if (l1 > 0 && __result == 0) \
1154 __result = (s1)[1] - __s2[1]; \
1155 if (l1 > 1 && __result == 0) \
1157 __result = (s1)[2] - __s2[2]; \
1158 if (l1 > 2 && __result == 0) \
1159 __result = (s1)[3] - __s2[3]; \
1164 # define __strcmp_gc(s1, s2, l2) \
1165 (__extension__ ({ const unsigned char *__s1 = (s1); \
1166 register int __result = __s1[0] - (s2)[0]; \
1167 if (l2 > 0 && __result == 0) \
1169 __result = __s1[1] - (s2)[1]; \
1170 if (l2 > 1 && __result == 0) \
1172 __result = __s1[2] - (s2)[2]; \
1173 if (l2 > 2 && __result == 0) \
1174 __result = __s1[3] - (s2)[3]; \
1179 __STRING_INLINE int __strcmp_gg (const char *__s1, const char *__s2);
1182 __strcmp_gg (const char *__s1, const char *__s2)
1185 __asm__ __volatile__
1201 : "=q" (__res), "=&r" (__s1), "=&r" (__s2)
1202 : "1" (__s1), "2" (__s2),
1203 "m" ( *(struct { char __x[0xfffffff]; } *)__s1),
1204 "m" ( *(struct { char __x[0xfffffff]; } *)__s2)
1210 /* Compare N characters of S1 and S2. */
1211 # define _HAVE_STRING_ARCH_strncmp 1
1212 # define strncmp(s1, s2, n) \
1213 (__extension__ (__builtin_constant_p (s1) && strlen (s1) < ((size_t) (n)) \
1214 ? strcmp ((s1), (s2)) \
1215 : (__builtin_constant_p (s2) && strlen (s2) < ((size_t) (n))\
1216 ? strcmp ((s1), (s2)) \
1217 : __strncmp_g ((s1), (s2), (n)))))
1219 __STRING_INLINE int __strncmp_g (const char *__s1, const char *__s2,
1223 __strncmp_g (const char *__s1, const char *__s2, size_t __n)
1226 __asm__ __volatile__
1245 : "=q" (__res), "=&r" (__s1), "=&r" (__s2), "=&r" (__n)
1246 : "1" (__s1), "2" (__s2), "3" (__n),
1247 "m" ( *(struct { __extension__ char __x[__n]; } *)__s1),
1248 "m" ( *(struct { __extension__ char __x[__n]; } *)__s2)
1254 /* Find the first occurrence of C in S. */
1255 # define _HAVE_STRING_ARCH_strchr 1
1256 # define _USE_STRING_ARCH_strchr 1
1257 # define strchr(s, c) \
1258 (__extension__ (__builtin_constant_p (c) \
1260 ? (char *) __rawmemchr ((s), (c)) \
1261 : __strchr_c ((s), ((c) & 0xff) << 8)) \
1262 : __strchr_g ((s), (c))))
1264 __STRING_INLINE char *__strchr_c (const char *__s, int __c);
1266 __STRING_INLINE char *
1267 __strchr_c (const char *__s, int __c)
1269 register unsigned long int __d0;
1270 register char *__res;
1271 __asm__ __volatile__
1273 "movb (%0),%%al\n\t"
1274 "cmpb %%ah,%%al\n\t"
1277 "testb %%al,%%al\n\t"
1281 : "=r" (__res), "=&a" (__d0)
1282 : "0" (__s), "1" (__c),
1283 "m" ( *(struct { char __x[0xfffffff]; } *)__s)
1288 __STRING_INLINE char *__strchr_g (const char *__s, int __c);
1290 __STRING_INLINE char *
1291 __strchr_g (const char *__s, int __c)
1293 register unsigned long int __d0;
1294 register char *__res;
1295 __asm__ __volatile__
1298 "movb (%0),%%al\n\t"
1299 "cmpb %%ah,%%al\n\t"
1302 "testb %%al,%%al\n\t"
1306 : "=r" (__res), "=&a" (__d0)
1307 : "0" (__s), "1" (__c),
1308 "m" ( *(struct { char __x[0xfffffff]; } *)__s)
1314 /* Find the first occurrence of C in S or the final NUL byte. */
1315 # define _HAVE_STRING_ARCH_strchrnul 1
1316 # define __strchrnul(s, c) \
1317 (__extension__ (__builtin_constant_p (c) \
1319 ? (char *) __rawmemchr ((s), c) \
1320 : __strchrnul_c ((s), ((c) & 0xff) << 8)) \
1321 : __strchrnul_g ((s), c)))
1323 __STRING_INLINE char *__strchrnul_c (const char *__s, int __c);
1325 __STRING_INLINE char *
1326 __strchrnul_c (const char *__s, int __c)
1328 register unsigned long int __d0;
1329 register char *__res;
1330 __asm__ __volatile__
1332 "movb (%0),%%al\n\t"
1333 "cmpb %%ah,%%al\n\t"
1336 "testb %%al,%%al\n\t"
1340 : "=r" (__res), "=&a" (__d0)
1341 : "0" (__s), "1" (__c),
1342 "m" ( *(struct { char __x[0xfffffff]; } *)__s)
1347 __STRING_INLINE char *__strchrnul_g (const char *__s, int __c);
1349 __STRING_INLINE char *
1350 __strchrnul_g (const char *__s, int __c)
1352 register unsigned long int __d0;
1353 register char *__res;
1354 __asm__ __volatile__
1357 "movb (%0),%%al\n\t"
1358 "cmpb %%ah,%%al\n\t"
1361 "testb %%al,%%al\n\t"
1365 : "=r" (__res), "=&a" (__d0)
1366 : "0" (__s), "1" (__c),
1367 "m" ( *(struct { char __x[0xfffffff]; } *)__s)
1372 # define strchrnul(s, c) __strchrnul ((s), (c))
1376 # if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
1377 /* Find the first occurrence of C in S. This is the BSD name. */
1378 # define _HAVE_STRING_ARCH_index 1
1379 # define index(s, c) \
1380 (__extension__ (__builtin_constant_p (c) \
1381 ? __strchr_c ((s), ((c) & 0xff) << 8) \
1382 : __strchr_g ((s), (c))))
1386 /* Find the last occurrence of C in S. */
1387 # define _HAVE_STRING_ARCH_strrchr 1
1388 # define strrchr(s, c) \
1389 (__extension__ (__builtin_constant_p (c) \
1390 ? __strrchr_c ((s), ((c) & 0xff) << 8) \
1391 : __strrchr_g ((s), (c))))
1394 __STRING_INLINE char *__strrchr_c (const char *__s, int __c);
1396 __STRING_INLINE char *
1397 __strrchr_c (const char *__s, int __c)
1399 register unsigned long int __d0, __d1;
1400 register char *__res;
1401 __asm__ __volatile__
1409 : "=d" (__res), "=&S" (__d0), "=&a" (__d1)
1410 : "0" (1), "1" (__s), "2" (__c),
1411 "m" ( *(struct { char __x[0xfffffff]; } *)__s)
1416 __STRING_INLINE char *__strrchr_g (const char *__s, int __c);
1418 __STRING_INLINE char *
1419 __strrchr_g (const char *__s, int __c)
1421 register unsigned long int __d0, __d1;
1422 register char *__res;
1423 __asm__ __volatile__
1432 : "=d" (__res), "=&S" (__d0), "=&a" (__d1)
1433 : "0" (1), "1" (__s), "2" (__c),
1434 "m" ( *(struct { char __x[0xfffffff]; } *)__s)
1439 __STRING_INLINE char *__strrchr_c (const char *__s, int __c);
1441 __STRING_INLINE char *
1442 __strrchr_c (const char *__s, int __c)
1444 register unsigned long int __d0, __d1;
1445 register char *__res;
1446 __asm__ __volatile__
1450 "cmpb %%ah,%%al\n\t"
1452 "leal -1(%%esi),%0\n"
1454 "testb %%al,%%al\n\t"
1456 : "=d" (__res), "=&S" (__d0), "=&a" (__d1)
1457 : "0" (0), "1" (__s), "2" (__c),
1458 "m" ( *(struct { char __x[0xfffffff]; } *)__s)
1463 __STRING_INLINE char *__strrchr_g (const char *__s, int __c);
1465 __STRING_INLINE char *
1466 __strrchr_g (const char *__s, int __c)
1468 register unsigned long int __d0, __d1;
1469 register char *__res;
1470 __asm__ __volatile__
1475 "cmpb %%ah,%%al\n\t"
1477 "leal -1(%%esi),%0\n"
1479 "testb %%al,%%al\n\t"
1481 : "=r" (__res), "=&S" (__d0), "=&a" (__d1)
1482 : "0" (0), "1" (__s), "2" (__c),
1483 "m" ( *(struct { char __x[0xfffffff]; } *)__s)
1490 # if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
1491 /* Find the last occurrence of C in S. This is the BSD name. */
1492 # define _HAVE_STRING_ARCH_rindex 1
1493 # define rindex(s, c) \
1494 (__extension__ (__builtin_constant_p (c) \
1495 ? __strrchr_c ((s), ((c) & 0xff) << 8) \
1496 : __strrchr_g ((s), (c))))
1500 /* Return the length of the initial segment of S which
1501 consists entirely of characters not in REJECT. */
1502 # define _HAVE_STRING_ARCH_strcspn 1
1503 # define strcspn(s, reject) \
1504 (__extension__ (__builtin_constant_p (reject) && sizeof ((reject)[0]) == 1 \
1505 ? ((reject)[0] == '\0' \
1507 : ((reject)[1] == '\0' \
1508 ? __strcspn_c1 ((s), (((reject)[0] << 8) & 0xff00)) \
1509 : __strcspn_cg ((s), (reject), strlen (reject)))) \
1510 : __strcspn_g ((s), (reject))))
1512 __STRING_INLINE size_t __strcspn_c1 (const char *__s, int __reject);
1514 # ifndef _FORCE_INLINES
1515 __STRING_INLINE size_t
1516 __strcspn_c1 (const char *__s, int __reject)
1518 register unsigned long int __d0;
1519 register char *__res;
1520 __asm__ __volatile__
1522 "movb (%0),%%al\n\t"
1524 "cmpb %%ah,%%al\n\t"
1526 "testb %%al,%%al\n\t"
1529 : "=r" (__res), "=&a" (__d0)
1530 : "0" (__s), "1" (__reject),
1531 "m" ( *(struct { char __x[0xfffffff]; } *)__s)
1533 return (__res - 1) - __s;
1537 __STRING_INLINE size_t __strcspn_cg (const char *__s, const char __reject[],
1538 size_t __reject_len);
1540 __STRING_INLINE size_t
1541 __strcspn_cg (const char *__s, const char __reject[], size_t __reject_len)
1543 register unsigned long int __d0, __d1, __d2;
1544 register const char *__res;
1545 __asm__ __volatile__
1549 "testb %%al,%%al\n\t"
1556 : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2)
1557 : "0" (__s), "d" (__reject), "g" (__reject_len)
1559 return (__res - 1) - __s;
1562 __STRING_INLINE size_t __strcspn_g (const char *__s, const char *__reject);
1565 __STRING_INLINE size_t
1566 __strcspn_g (const char *__s, const char *__reject)
1568 register unsigned long int __d0, __d1, __d2;
1569 register const char *__res;
1570 __asm__ __volatile__
1576 "leal -1(%%ecx),%%ebx\n"
1579 "testb %%al,%%al\n\t"
1582 "movl %%ebx,%%ecx\n\t"
1587 : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2)
1588 : "r" (__reject), "0" (__s), "1" (0), "2" (0xffffffff)
1590 return (__res - 1) - __s;
1593 __STRING_INLINE size_t
1594 __strcspn_g (const char *__s, const char *__reject)
1596 register unsigned long int __d0, __d1, __d2, __d3;
1597 register const char *__res;
1598 __asm__ __volatile__
1602 "leal -1(%%ecx),%%edx\n"
1605 "testb %%al,%%al\n\t"
1607 "movl %%ebx,%%edi\n\t"
1608 "movl %%edx,%%ecx\n\t"
1612 : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2), "=&d" (__d3)
1613 : "0" (__s), "1" (0), "2" (0xffffffff), "3" (__reject), "b" (__reject)
1614 /* Clobber memory, otherwise GCC cannot handle this. */
1616 return (__res - 1) - __s;
1621 /* Return the length of the initial segment of S which
1622 consists entirely of characters in ACCEPT. */
1623 # define _HAVE_STRING_ARCH_strspn 1
1624 # define strspn(s, accept) \
1625 (__extension__ (__builtin_constant_p (accept) && sizeof ((accept)[0]) == 1 \
1626 ? ((accept)[0] == '\0' \
1628 : ((accept)[1] == '\0' \
1629 ? __strspn_c1 ((s), (((accept)[0] << 8 ) & 0xff00)) \
1630 : __strspn_cg ((s), (accept), strlen (accept)))) \
1631 : __strspn_g ((s), (accept))))
1633 # ifndef _FORCE_INLINES
1634 __STRING_INLINE size_t __strspn_c1 (const char *__s, int __accept);
1636 __STRING_INLINE size_t
1637 __strspn_c1 (const char *__s, int __accept)
1639 register unsigned long int __d0;
1640 register char *__res;
1641 /* Please note that __accept never can be '\0'. */
1642 __asm__ __volatile__
1648 : "=r" (__res), "=&q" (__d0)
1649 : "0" (__s), "1" (__accept),
1650 "m" ( *(struct { char __x[0xfffffff]; } *)__s)
1652 return (__res - 1) - __s;
1656 __STRING_INLINE size_t __strspn_cg (const char *__s, const char __accept[],
1657 size_t __accept_len);
1659 __STRING_INLINE size_t
1660 __strspn_cg (const char *__s, const char __accept[], size_t __accept_len)
1662 register unsigned long int __d0, __d1, __d2;
1663 register const char *__res;
1664 __asm__ __volatile__
1668 "testb %%al,%%al\n\t"
1675 : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2)
1676 : "0" (__s), "g" (__accept), "g" (__accept_len),
1677 /* Since we do not know how large the memory we access it, use a
1678 really large amount. */
1679 "m" ( *(struct { char __x[0xfffffff]; } *)__s),
1680 "m" ( *(struct { __extension__ char __x[__accept_len]; } *)__accept)
1682 return (__res - 1) - __s;
1685 __STRING_INLINE size_t __strspn_g (const char *__s, const char *__accept);
1688 __STRING_INLINE size_t
1689 __strspn_g (const char *__s, const char *__accept)
1691 register unsigned long int __d0, __d1, __d2;
1692 register const char *__res;
1693 __asm__ __volatile__
1698 "leal -1(%%ecx),%%ebx\n"
1701 "testb %%al,%%al\n\t"
1703 "movl %%edx,%%edi\n\t"
1704 "movl %%ebx,%%ecx\n\t"
1709 : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2)
1710 : "d" (__accept), "0" (__s), "1" (0), "2" (0xffffffff), "3" (__accept)
1712 return (__res - 1) - __s;
1715 __STRING_INLINE size_t
1716 __strspn_g (const char *__s, const char *__accept)
1718 register unsigned long int __d0, __d1, __d2, __d3;
1719 register const char *__res;
1720 __asm__ __volatile__
1724 "leal -1(%%ecx),%%edx\n"
1727 "testb %%al,%%al\n\t"
1729 "movl %%ebx,%%edi\n\t"
1730 "movl %%edx,%%ecx\n\t"
1734 : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2), "=&d" (__d3)
1735 : "0" (__s), "1" (0), "2" (0xffffffff), "3" (__accept), "b" (__accept)
1737 return (__res - 1) - __s;
1742 /* Find the first occurrence in S of any character in ACCEPT. */
1743 # define _HAVE_STRING_ARCH_strpbrk 1
1744 # define strpbrk(s, accept) \
1745 (__extension__ (__builtin_constant_p (accept) && sizeof ((accept)[0]) == 1 \
1746 ? ((accept)[0] == '\0' \
1747 ? ((void) (s), (char *) 0) \
1748 : ((accept)[1] == '\0' \
1749 ? strchr ((s), (accept)[0]) \
1750 : __strpbrk_cg ((s), (accept), strlen (accept)))) \
1751 : __strpbrk_g ((s), (accept))))
1753 __STRING_INLINE char *__strpbrk_cg (const char *__s, const char __accept[],
1754 size_t __accept_len);
1756 __STRING_INLINE char *
1757 __strpbrk_cg (const char *__s, const char __accept[], size_t __accept_len)
1759 register unsigned long int __d0, __d1, __d2;
1760 register char *__res;
1761 __asm__ __volatile__
1765 "testb %%al,%%al\n\t"
1776 : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2)
1777 : "0" (__s), "d" (__accept), "g" (__accept_len)
1782 __STRING_INLINE char *__strpbrk_g (const char *__s, const char *__accept);
1785 __STRING_INLINE char *
1786 __strpbrk_g (const char *__s, const char *__accept)
1788 register unsigned long int __d0, __d1, __d2;
1789 register char *__res;
1790 __asm__ __volatile__
1792 "movl %%edx,%%edi\n\t"
1796 "leal -1(%%ecx),%%ebx\n"
1799 "testb %%al,%%al\n\t"
1801 "movl %%edx,%%edi\n\t"
1802 "movl %%ebx,%%ecx\n\t"
1811 : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2)
1812 : "d" (__accept), "0" (__s), "1" (0), "2" (0xffffffff)
1817 __STRING_INLINE char *
1818 __strpbrk_g (const char *__s, const char *__accept)
1820 register unsigned long int __d0, __d1, __d2, __d3;
1821 register char *__res;
1822 __asm__ __volatile__
1823 ("movl %%ebx,%%edi\n\t"
1827 "leal -1(%%ecx),%%edx\n"
1830 "testb %%al,%%al\n\t"
1832 "movl %%ebx,%%edi\n\t"
1833 "movl %%edx,%%ecx\n\t"
1841 : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&d" (__d2), "=&D" (__d3)
1842 : "0" (__s), "1" (0), "2" (0xffffffff), "b" (__accept)
1849 /* Find the first occurrence of NEEDLE in HAYSTACK. */
1850 # define _HAVE_STRING_ARCH_strstr 1
1851 # define strstr(haystack, needle) \
1852 (__extension__ (__builtin_constant_p (needle) && sizeof ((needle)[0]) == 1 \
1853 ? ((needle)[0] == '\0' \
1855 : ((needle)[1] == '\0' \
1856 ? strchr ((haystack), (needle)[0]) \
1857 : __strstr_cg ((haystack), (needle), \
1858 strlen (needle)))) \
1859 : __strstr_g ((haystack), (needle))))
1861 /* Please note that this function need not handle NEEDLEs with a
1862 length shorter than two. */
1863 __STRING_INLINE char *__strstr_cg (const char *__haystack,
1864 const char __needle[],
1865 size_t __needle_len);
1867 __STRING_INLINE char *
1868 __strstr_cg (const char *__haystack, const char __needle[],
1869 size_t __needle_len)
1871 register unsigned long int __d0, __d1, __d2;
1872 register char *__res;
1873 __asm__ __volatile__
1881 "cmpb $0,-1(%%esi)\n\t"
1882 "leal 1(%%eax),%5\n\t"
1884 "xorl %%eax,%%eax\n"
1886 : "=&a" (__res), "=&S" (__d0), "=&D" (__d1), "=&c" (__d2)
1887 : "g" (__needle_len), "1" (__haystack), "d" (__needle)
1892 __STRING_INLINE char *__strstr_g (const char *__haystack,
1893 const char *__needle);
1896 __STRING_INLINE char *
1897 __strstr_g (const char *__haystack, const char *__needle)
1899 register unsigned long int __d0, __d1, __d2;
1900 register char *__res;
1901 __asm__ __volatile__
1906 "decl %%ecx\n\t" /* NOTE! This also sets Z if searchstring='' */
1907 "movl %%ecx,%%ebx\n"
1909 "movl %%edx,%%edi\n\t"
1910 "movl %%esi,%%eax\n\t"
1911 "movl %%ebx,%%ecx\n\t"
1913 "je 2f\n\t" /* also works for empty string, see above */
1914 "cmpb $0,-1(%%esi)\n\t"
1915 "leal 1(%%eax),%%esi\n\t"
1917 "xorl %%eax,%%eax\n"
1920 : "=&a" (__res), "=&c" (__d0), "=&S" (__d1), "=&D" (__d2)
1921 : "0" (0), "1" (0xffffffff), "2" (__haystack), "3" (__needle),
1927 __STRING_INLINE char *
1928 __strstr_g (const char *__haystack, const char *__needle)
1930 register unsigned long int __d0, __d1, __d2, __d3;
1931 register char *__res;
1932 __asm__ __volatile__
1936 "decl %%ecx\n\t" /* NOTE! This also sets Z if searchstring='' */
1937 "movl %%ecx,%%edx\n"
1939 "movl %%ebx,%%edi\n\t"
1940 "movl %%esi,%%eax\n\t"
1941 "movl %%edx,%%ecx\n\t"
1943 "je 2f\n\t" /* also works for empty string, see above */
1944 "cmpb $0,-1(%%esi)\n\t"
1945 "leal 1(%%eax),%%esi\n\t"
1947 "xorl %%eax,%%eax\n"
1949 : "=&a" (__res), "=&c" (__d0), "=&S" (__d1), "=&D" (__d2), "=&d" (__d3)
1950 : "0" (0), "1" (0xffffffff), "2" (__haystack), "3" (__needle),
1958 /* Bit find functions. We define only the i686 version since for the other
1959 processors gcc generates good code. */
1960 # if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
1962 # define _HAVE_STRING_ARCH_ffs 1
1963 # define ffs(word) (__builtin_constant_p (word) \
1964 ? __builtin_ffs (word) \
1965 : ({ int __cnt, __tmp; \
1966 __asm__ __volatile__ \
1969 : "=&r" (__cnt), "=r" (__tmp) \
1970 : "rm" (word), "1" (-1)); \
1974 # define ffsl(word) ffs(word)
1977 # endif /* BSD || X/Open */
1979 # ifndef _FORCE_INLINES
1980 # undef __STRING_INLINE
1983 # endif /* use string inlines && GNU CC */