string.h 22 KB

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