string.h 57 KB

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