strchr.S 15 KB

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