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