strchr.S 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. /* strchr (str, ch) -- Return pointer to first occurrence of CH in STR.
  2. For SPARC v9.
  3. Copyright (C) 1998, 1999, 2003 Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. Contributed by Jan Vondrak <jvon4518@ss1000.ms.mff.cuni.cz> and
  6. Jakub Jelinek <jj@ultra.linux.cz>.
  7. The GNU C Library is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU Lesser General Public
  9. License as published by the Free Software Foundation; either
  10. version 2.1 of the License, or (at your option) any later version.
  11. The GNU C Library is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. Lesser General Public License for more details.
  15. You should have received a copy of the GNU Lesser General Public
  16. License along with the GNU C Library; if not, write to the Free
  17. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  18. 02111-1307 USA. */
  19. #include <features.h>
  20. #include <asm/asi.h>
  21. #ifndef XCC
  22. #define XCC xcc
  23. #define USE_BPR
  24. .register %g2, #scratch
  25. .register %g3, #scratch
  26. .register %g6, #scratch
  27. #endif
  28. /* Normally, this uses
  29. ((xword - 0x0101010101010101) & 0x8080808080808080) test
  30. to find out if any byte in xword could be zero. This is fast, but
  31. also gives false alarm for any byte in range 0x81-0xff. It does
  32. not matter for correctness, as if this test tells us there could
  33. be some zero byte, we check it byte by byte, but if bytes with
  34. high bits set are common in the strings, then this will give poor
  35. performance. You can #define EIGHTBIT_NOT_RARE and the algorithm
  36. will use one tick slower, but more precise test
  37. ((xword - 0x0101010101010101) & (~xword) & 0x8080808080808080),
  38. which does not give any false alarms (but if some bits are set,
  39. one cannot assume from it which bytes are zero and which are not).
  40. It is yet to be measured, what is the correct default for glibc
  41. in these days for an average user.
  42. */
  43. .text
  44. .align 32
  45. ENTRY(strchr)
  46. andcc %o1, 0xff, %o1 /* IEU1 Group */
  47. be,pn %icc, 17f /* CTI */
  48. sllx %o1, 8, %g3 /* IEU0 Group */
  49. sethi %hi(0x01010101), %g1 /* IEU1 */
  50. or %g3, %o1, %g3 /* IEU0 Group */
  51. ldub [%o0], %o3 /* Load */
  52. sllx %g3, 16, %g5 /* IEU0 Group */
  53. or %g1, %lo(0x01010101), %g1 /* IEU1 */
  54. sllx %g1, 32, %g2 /* IEU0 Group */
  55. brz,pn %o3, 5f /* CTI+IEU1 */
  56. orcc %g3, %g5, %g3 /* IEU1 Group */
  57. sllx %g3, 32, %g5 /* IEU0 */
  58. cmp %o3, %o1 /* IEU1 Group */
  59. be,pn %xcc, 14f /* CTI */
  60. or %g1, %g2, %g1 /* IEU0 */
  61. andcc %o0, 7, %g0 /* IEU1 Group */
  62. bne,a,pn %icc, 15f /* CTI */
  63. add %o0, 1, %o0 /* IEU0 */
  64. ldx [%o0], %o3 /* Load Group */
  65. 1: sllx %g1, 7, %g2 /* IEU0 */
  66. or %g3, %g5, %g3 /* IEU1 */
  67. add %o0, 8, %o0 /* IEU0 Group */
  68. xor %o3, %g3, %o4 /* IEU1 */
  69. /* %g1 = 0101010101010101 *
  70. * %g2 = 8080088080808080 *
  71. * %g3 = c c c c c c c c *
  72. * %o3 = value *
  73. * %o4 = value XOR c */
  74. 2: sub %o3, %g1, %o2 /* IEU0 Group */
  75. sub %o4, %g1, %o5 /* IEU1 */
  76. #ifdef EIGHTBIT_NOT_RARE
  77. andn %o2, %o3, %g6 /* IEU0 Group */
  78. andn %o5, %o4, %o5 /* IEU1 */
  79. ldxa [%o0] ASI_PNF, %o3 /* Load */
  80. or %o5, %g6, %o5 /* IEU0 Group */
  81. #else
  82. ldxa [%o0] ASI_PNF, %o3 /* Load */
  83. or %o5, %o2, %o5 /* IEU0 Group */
  84. #endif
  85. add %o0, 8, %o0 /* IEU1 */
  86. andcc %o5, %g2, %g0 /* IEU1 Group */
  87. be,a,pt %xcc, 2b /* CTI */
  88. xor %o3, %g3, %o4 /* IEU0 */
  89. srlx %o5, 32, %g5 /* IEU0 Group */
  90. add %o2, %g1, %o2 /* IEU1 */
  91. 3: andcc %g5, %g2, %g0 /* IEU1 Group */
  92. be,pn %xcc, 4f /* CTI */
  93. srlx %o2, 56, %g5 /* IEU0 */
  94. andcc %g5, 0xff, %g0 /* IEU1 Group */
  95. be,pn %icc, 5f /* CTI */
  96. srlx %o4, 56, %g5 /* IEU0 */
  97. andcc %g5, 0xff, %g0 /* IEU1 Group */
  98. be,pn %icc, 6f /* CTI */
  99. srlx %o2, 48, %g5 /* IEU0 */
  100. andcc %g5, 0xff, %g0 /* IEU1 Group */
  101. be,pn %icc, 5f /* CTI */
  102. srlx %o4, 48, %g5 /* IEU0 */
  103. andcc %g5, 0xff, %g0 /* IEU1 Group */
  104. be,pn %icc, 7f /* CTI */
  105. srlx %o2, 40, %g5 /* IEU0 */
  106. andcc %g5, 0xff, %g0 /* IEU1 Group */
  107. be,pn %icc, 5f /* CTI */
  108. srlx %o4, 40, %g5 /* IEU0 */
  109. andcc %g5, 0xff, %g0 /* IEU1 Group */
  110. be,pn %icc, 8f /* CTI */
  111. srlx %o2, 32, %g5 /* IEU0 */
  112. andcc %g5, 0xff, %g0 /* IEU1 Group */
  113. be,pn %icc, 5f /* CTI */
  114. srlx %o4, 32, %g5 /* IEU0 */
  115. andcc %g5, 0xff, %g0 /* IEU1 Group */
  116. be,pn %icc, 9f /* CTI */
  117. 4: srlx %o2, 24, %g5 /* IEU0 */
  118. andcc %g5, 0xff, %g0 /* IEU1 Group */
  119. be,pn %icc, 5f /* CTI */
  120. srlx %o4, 24, %g5 /* IEU0 */
  121. andcc %g5, 0xff, %g0 /* IEU1 Group */
  122. be,pn %icc, 10f /* CTI */
  123. srlx %o2, 16, %g5 /* IEU0 */
  124. andcc %g5, 0xff, %g0 /* IEU1 Group */
  125. be,pn %icc, 5f /* CTI */
  126. srlx %o4, 16, %g5 /* IEU0 */
  127. andcc %g5, 0xff, %g0 /* IEU1 Group */
  128. be,pn %icc, 11f /* CTI */
  129. srlx %o2, 8, %g5 /* IEU0 */
  130. andcc %g5, 0xff, %g0 /* IEU1 Group */
  131. be,pn %icc, 5f /* CTI */
  132. srlx %o4, 8, %g5 /* IEU0 */
  133. andcc %g5, 0xff, %g0 /* IEU1 Group */
  134. be,pn %icc, 12f /* CTI */
  135. andcc %o2, 0xff, %g0 /* IEU1 Group */
  136. be,pn %icc, 5f /* CTI */
  137. sub %o3, %g1, %o2 /* IEU0 */
  138. andcc %o4, 0xff, %g0 /* IEU1 Group */
  139. be,pn %icc, 13f /* CTI */
  140. xor %o3, %g3, %o4 /* IEU0 */
  141. ldxa [%o0] ASI_PNF, %o3 /* Load Group */
  142. sub %o4, %g1, %o5 /* IEU0 */
  143. or %o5, %o2, %o5 /* IEU1 */
  144. add %o0, 8, %o0 /* IEU0 Group */
  145. andcc %o5, %g2, %g0 /* IEU1 */
  146. be,a,pt %xcc, 2b /* CTI */
  147. xor %o3, %g3, %o4 /* IEU0 Group */
  148. srlx %o5, 32, %g5 /* IEU0 Group */
  149. ba,pt %xcc, 3b /* CTI */
  150. add %o2, %g1, %o2 /* IEU1 */
  151. .align 16
  152. 5: retl /* CTI+IEU1 Group */
  153. clr %o0 /* IEU0 */
  154. 6: retl /* CTI+IEU1 Group */
  155. add %o0, -16, %o0 /* IEU0 */
  156. 7: retl /* CTI+IEU1 Group */
  157. add %o0, -15, %o0 /* IEU0 */
  158. 8: retl /* CTI+IEU1 Group */
  159. add %o0, -14, %o0 /* IEU0 */
  160. 9: retl /* CTI+IEU1 Group */
  161. add %o0, -13, %o0 /* IEU0 */
  162. 10: retl /* CTI+IEU1 Group */
  163. add %o0, -12, %o0 /* IEU0 */
  164. 11: retl /* CTI+IEU1 Group */
  165. add %o0, -11, %o0 /* IEU0 */
  166. 12: retl /* CTI+IEU1 Group */
  167. add %o0, -10, %o0 /* IEU0 */
  168. 13: retl /* CTI+IEU1 Group */
  169. add %o0, -9, %o0 /* IEU0 */
  170. 14: retl /* CTI+IEU1 Group */
  171. nop /* IEU0 */
  172. .align 16
  173. 15: ldub [%o0], %o3 /* Load Group */
  174. 16: andcc %o0, 7, %g0 /* IEU1 */
  175. be,a,pn %icc, 1b /* CTI */
  176. ldx [%o0], %o3 /* Load Group */
  177. andcc %o3, 0xff, %g0 /* IEU1 Group */
  178. be,pn %icc, 5b /* CTI */
  179. add %o0, 1, %o0 /* IEU0 */
  180. cmp %o3, %o1 /* IEU1 Group */
  181. bne,a,pn %icc, 16b /* CTI */
  182. ldub [%o0], %o3 /* Load */
  183. retl /* CTI+IEU1 Group */
  184. add %o0, -1, %o0 /* IEU0 */
  185. /* strchr (str, 0) */
  186. .align 32
  187. nop
  188. .align 16
  189. 17: sethi %hi(0x01010101), %g1 /* IEU0 Group */
  190. ldub [%o0], %o3 /* Load */
  191. or %g1, %lo(0x01010101), %g1 /* IEU0 Group */
  192. sllx %g1, 32, %g2 /* IEU0 Group */
  193. andcc %o0, 7, %g0 /* IEU1 */
  194. or %g1, %g2, %g1 /* IEU0 Group */
  195. bne,pn %icc, 32f /* CTI */
  196. sllx %g1, 7, %g2 /* IEU0 Group */
  197. brz,pn %o3, 30f /* CTI+IEU1 */
  198. ldx [%o0], %o3 /* Load */
  199. 18: add %o0, 8, %o0 /* IEU0 Group */
  200. 19: sub %o3, %g1, %o2 /* IEU0 Group */
  201. #ifdef EIGHTBIT_NOT_RARE
  202. andn %o2, %o3, %g6 /* IEU0 Group */
  203. ldxa [%o0] ASI_PNF, %o3 /* Load */
  204. andcc %g6, %g2, %g0 /* IEU1 Group */
  205. #else
  206. ldxa [%o0] ASI_PNF, %o3 /* Load */
  207. andcc %o2, %g2, %g0 /* IEU1 Group */
  208. #endif
  209. be,pt %xcc, 19b /* CTI */
  210. add %o0, 8, %o0 /* IEU0 */
  211. addcc %o2, %g1, %g3 /* IEU1 Group */
  212. srlx %o2, 32, %o2 /* IEU0 */
  213. 20: andcc %o2, %g2, %g0 /* IEU1 Group */
  214. be,pn %xcc, 21f /* CTI */
  215. srlx %g3, 56, %o2 /* IEU0 */
  216. andcc %o2, 0xff, %g0 /* IEU1 Group */
  217. be,pn %icc, 29f /* CTI */
  218. srlx %g3, 48, %o2 /* IEU0 */
  219. andcc %o2, 0xff, %g0 /* IEU1 Group */
  220. be,pn %icc, 28f /* CTI */
  221. srlx %g3, 40, %o2 /* IEU0 */
  222. andcc %o2, 0xff, %g0 /* IEU1 Group */
  223. be,pn %icc, 27f /* CTI */
  224. srlx %g3, 32, %o2 /* IEU0 */
  225. andcc %o2, 0xff, %g0 /* IEU1 Group */
  226. be,pn %icc, 26f /* CTI */
  227. 21: srlx %g3, 24, %o2 /* IEU0 */
  228. andcc %o2, 0xff, %g0 /* IEU1 Group */
  229. be,pn %icc, 25f /* CTI */
  230. srlx %g3, 16, %o2 /* IEU0 */
  231. andcc %o2, 0xff, %g0 /* IEU1 Group */
  232. be,pn %icc, 24f /* CTI */
  233. srlx %g3, 8, %o2 /* IEU0 */
  234. andcc %o2, 0xff, %g0 /* IEU1 Group */
  235. be,pn %icc, 23f /* CTI */
  236. sub %o3, %g1, %o2 /* IEU0 */
  237. andcc %g3, 0xff, %g0 /* IEU1 Group */
  238. be,pn %icc, 22f /* CTI */
  239. ldxa [%o0] ASI_PNF, %o3 /* Load */
  240. andcc %o2, %g2, %g0 /* IEU1 Group */
  241. be,pt %xcc, 19b /* CTI */
  242. add %o0, 8, %o0 /* IEU0 */
  243. addcc %o2, %g1, %g3 /* IEU1 Group */
  244. ba,pt %xcc, 20b /* CTI */
  245. srlx %o2, 32, %o2 /* IEU0 */
  246. .align 16
  247. 22: retl /* CTI+IEU1 Group */
  248. add %o0, -9, %o0 /* IEU0 */
  249. 23: retl /* CTI+IEU1 Group */
  250. add %o0, -10, %o0 /* IEU0 */
  251. 24: retl /* CTI+IEU1 Group */
  252. add %o0, -11, %o0 /* IEU0 */
  253. 25: retl /* CTI+IEU1 Group */
  254. add %o0, -12, %o0 /* IEU0 */
  255. 26: retl /* CTI+IEU1 Group */
  256. add %o0, -13, %o0 /* IEU0 */
  257. 27: retl /* CTI+IEU1 Group */
  258. add %o0, -14, %o0 /* IEU0 */
  259. 28: retl /* CTI+IEU1 Group */
  260. add %o0, -15, %o0 /* IEU0 */
  261. 29: retl /* CTI+IEU1 Group */
  262. add %o0, -16, %o0 /* IEU0 */
  263. 30: retl /* CTI+IEU1 Group */
  264. nop /* IEU0 */
  265. .align 16
  266. 32: andcc %o0, 7, %g0 /* IEU1 Group */
  267. be,a,pn %icc, 18b /* CTI */
  268. ldx [%o0], %o3 /* Load */
  269. add %o0, 1, %o0 /* IEU0 Group */
  270. brnz,a,pt %o3, 32b /* CTI+IEU1 */
  271. lduba [%o0] ASI_PNF, %o3 /* Load */
  272. retl /* CTI+IEU1 Group */
  273. add %o0, -1, %o0 /* IEU0 */
  274. END(strchr)
  275. libc_hidden_def(strchr)
  276. #ifdef __UCLIBC_SUSV3_LEGACY__
  277. strong_alias(strchr,index)
  278. #endif
  279. .align 32
  280. ENTRY(strrchr)
  281. andcc %o1, 0xff, %o1 /* IEU1 Group */
  282. be,pn %icc, 17b /* CTI */
  283. clr %g4 /* IEU0 */
  284. andcc %o0, 7, %g0 /* IEU1 Group */
  285. bne,pn %icc, 13f /* CTI */
  286. sllx %o1, 8, %g3 /* IEU0 */
  287. ldx [%o0], %o3 /* Load Group */
  288. 1: sethi %hi(0x01010101), %g1 /* IEU0 */
  289. or %g3, %o1, %g3 /* IEU1 */
  290. sllx %g3, 16, %g5 /* IEU0 Group */
  291. or %g1, %lo(0x01010101), %g1 /* IEU1 */
  292. sllx %g1, 32, %g2 /* IEU0 Group */
  293. or %g3, %g5, %g3 /* IEU1 */
  294. sllx %g3, 32, %g5 /* IEU0 Group */
  295. or %g1, %g2, %g1 /* IEU1 */
  296. sllx %g1, 7, %g2 /* IEU0 Group */
  297. or %g3, %g5, %g3 /* IEU1 */
  298. add %o0, 8, %o0 /* IEU0 Group */
  299. xor %o3, %g3, %o4 /* IEU1 */
  300. /* %g1 = 0101010101010101 *
  301. * %g2 = 8080088080808080 *
  302. * %g3 = c c c c c c c c *
  303. * %o3 = value *
  304. * %o4 = value XOR c */
  305. 2: sub %o3, %g1, %o2 /* IEU0 Group */
  306. 3: sub %o4, %g1, %o5 /* IEU1 */
  307. #ifdef EIGHTBIT_NOT_RARE
  308. andn %o2, %o3, %g6 /* IEU0 Group */
  309. andn %o5, %o4, %o5 /* IEU1 */
  310. ldxa [%o0] ASI_PNF, %o3 /* Load */
  311. or %o5, %g6, %o5 /* IEU0 Group */
  312. #else
  313. ldxa [%o0] ASI_PNF, %o3 /* Load */
  314. or %o5, %o2, %o5 /* IEU0 Group */
  315. #endif
  316. add %o0, 8, %o0 /* IEU1 */
  317. andcc %o5, %g2, %g0 /* IEU1 Group */
  318. be,a,pt %xcc, 2b /* CTI */
  319. xor %o3, %g3, %o4 /* IEU0 */
  320. srlx %o5, 32, %g5 /* IEU0 Group */
  321. add %o2, %g1, %o2 /* IEU1 */
  322. andcc %g5, %g2, %g0 /* IEU1 Group */
  323. be,pn %xcc, 7f /* CTI */
  324. srlx %o2, 56, %g5 /* IEU0 */
  325. andcc %g5, 0xff, %g0 /* IEU1 Group */
  326. be,pn %icc, 12f /* CTI */
  327. srlx %o4, 56, %g5 /* IEU0 */
  328. andcc %g5, 0xff, %g0 /* IEU1 Group */
  329. srlx %o2, 48, %g5 /* IEU0 */
  330. be,a,pn %icc, 4f /* CTI */
  331. add %o0, -16, %g4 /* IEU0 Group */
  332. 4: andcc %g5, 0xff, %g0 /* IEU1 Group */
  333. be,pn %icc, 12f /* CTI */
  334. srlx %o4, 48, %g5 /* IEU0 */
  335. andcc %g5, 0xff, %g0 /* IEU1 Group */
  336. srlx %o2, 40, %g5 /* IEU0 */
  337. be,a,pn %icc, 5f /* CTI */
  338. add %o0, -15, %g4 /* IEU0 Group */
  339. 5: andcc %g5, 0xff, %g0 /* IEU1 Group */
  340. be,pn %icc, 12f /* CTI */
  341. srlx %o4, 40, %g5 /* IEU0 */
  342. andcc %g5, 0xff, %g0 /* IEU1 Group */
  343. srlx %o2, 32, %g5 /* IEU0 */
  344. be,a,pn %icc, 6f /* CTI */
  345. add %o0, -14, %g4 /* IEU0 Group */
  346. 6: andcc %g5, 0xff, %g0 /* IEU1 Group */
  347. be,pn %icc, 12f /* CTI */
  348. srlx %o4, 32, %g5 /* IEU0 */
  349. andcc %g5, 0xff, %g0 /* IEU1 Group */
  350. be,a,pn %icc, 7f /* CTI */
  351. add %o0, -13, %g4 /* IEU0 */
  352. 7: srlx %o2, 24, %g5 /* IEU0 */
  353. andcc %g5, 0xff, %g0 /* IEU1 Group */
  354. be,pn %icc, 12f /* CTI */
  355. srlx %o4, 24, %g5 /* IEU0 */
  356. andcc %g5, 0xff, %g0 /* IEU1 Group */
  357. srlx %o2, 16, %g5 /* IEU0 */
  358. be,a,pn %icc, 8f /* CTI */
  359. add %o0, -12, %g4 /* IEU0 Group */
  360. 8: andcc %g5, 0xff, %g0 /* IEU1 Group */
  361. be,pn %icc, 12f /* CTI */
  362. srlx %o4, 16, %g5 /* IEU0 */
  363. andcc %g5, 0xff, %g0 /* IEU1 Group */
  364. srlx %o2, 8, %g5 /* IEU0 */
  365. be,a,pn %icc, 9f /* CTI */
  366. add %o0, -11, %g4 /* IEU0 Group */
  367. 9: andcc %g5, 0xff, %g0 /* IEU1 Group */
  368. be,pn %icc, 12f /* CTI */
  369. srlx %o4, 8, %g5 /* IEU0 */
  370. andcc %g5, 0xff, %g0 /* IEU1 Group */
  371. be,a,pn %icc, 10f /* CTI */
  372. add %o0, -10, %g4 /* IEU0 */
  373. 10: andcc %o2, 0xff, %g0 /* IEU1 Group */
  374. be,pn %icc, 12f /* CTI */
  375. sub %o3, %g1, %o2 /* IEU0 */
  376. andcc %o4, 0xff, %g0 /* IEU1 Group */
  377. be,a,pn %icc, 11f /* CTI */
  378. add %o0, -9, %g4 /* IEU0 */
  379. 11: ba,pt %xcc, 3b /* CTI Group */
  380. xor %o3, %g3, %o4 /* IEU0 Group */
  381. 12: retl /* CTI+IEU1 Group */
  382. mov %g4, %o0 /* IEU0 */
  383. .align 16
  384. 13: ldub [%o0], %o3 /* Load Group */
  385. add %o0, 1, %o0 /* IEU0 */
  386. 14: andcc %o3, 0xff, %g0 /* IEU1 Group */
  387. be,pn %icc, 12b /* CTI */
  388. cmp %o3, %o1 /* IEU1 Group */
  389. ldub [%o0], %o3 /* Load */
  390. be,a,pn %icc, 15f /* CTI */
  391. add %o0, -1, %g4 /* IEU0 Group */
  392. 15: andcc %o0, 7, %g0 /* IEU1 Group */
  393. bne,a,pt %icc, 14b /* CTI */
  394. add %o0, 1, %o0 /* IEU0 */
  395. ba,pt %xcc, 1b /* CTI Group */
  396. ldx [%o0], %o3 /* Load */
  397. END(strrchr)
  398. libc_hidden_def(strrchr)
  399. #ifdef __UCLIBC_SUSV3_LEGACY__
  400. strong_alias(strrchr,rindex)
  401. #endif