strchr.S 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  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, see
  17. <http://www.gnu.org/licenses/>. */
  18. #include <features.h>
  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. libc_hidden_def(strchr)
  275. #ifdef __UCLIBC_SUSV3_LEGACY__
  276. strong_alias(strchr,index)
  277. #endif
  278. .align 32
  279. ENTRY(strrchr)
  280. andcc %o1, 0xff, %o1 /* IEU1 Group */
  281. be,pn %icc, 17b /* CTI */
  282. clr %g4 /* IEU0 */
  283. andcc %o0, 7, %g0 /* IEU1 Group */
  284. bne,pn %icc, 13f /* CTI */
  285. sllx %o1, 8, %g3 /* IEU0 */
  286. ldx [%o0], %o3 /* Load Group */
  287. 1: sethi %hi(0x01010101), %g1 /* IEU0 */
  288. or %g3, %o1, %g3 /* IEU1 */
  289. sllx %g3, 16, %g5 /* IEU0 Group */
  290. or %g1, %lo(0x01010101), %g1 /* IEU1 */
  291. sllx %g1, 32, %g2 /* IEU0 Group */
  292. or %g3, %g5, %g3 /* IEU1 */
  293. sllx %g3, 32, %g5 /* IEU0 Group */
  294. or %g1, %g2, %g1 /* IEU1 */
  295. sllx %g1, 7, %g2 /* IEU0 Group */
  296. or %g3, %g5, %g3 /* IEU1 */
  297. add %o0, 8, %o0 /* IEU0 Group */
  298. xor %o3, %g3, %o4 /* IEU1 */
  299. /* %g1 = 0101010101010101 *
  300. * %g2 = 8080088080808080 *
  301. * %g3 = c c c c c c c c *
  302. * %o3 = value *
  303. * %o4 = value XOR c */
  304. 2: sub %o3, %g1, %o2 /* IEU0 Group */
  305. 3: sub %o4, %g1, %o5 /* IEU1 */
  306. #ifdef EIGHTBIT_NOT_RARE
  307. andn %o2, %o3, %g6 /* IEU0 Group */
  308. andn %o5, %o4, %o5 /* IEU1 */
  309. ldxa [%o0] ASI_PNF, %o3 /* Load */
  310. or %o5, %g6, %o5 /* IEU0 Group */
  311. #else
  312. ldxa [%o0] ASI_PNF, %o3 /* Load */
  313. or %o5, %o2, %o5 /* IEU0 Group */
  314. #endif
  315. add %o0, 8, %o0 /* IEU1 */
  316. andcc %o5, %g2, %g0 /* IEU1 Group */
  317. be,a,pt %xcc, 2b /* CTI */
  318. xor %o3, %g3, %o4 /* IEU0 */
  319. srlx %o5, 32, %g5 /* IEU0 Group */
  320. add %o2, %g1, %o2 /* IEU1 */
  321. andcc %g5, %g2, %g0 /* IEU1 Group */
  322. be,pn %xcc, 7f /* CTI */
  323. srlx %o2, 56, %g5 /* IEU0 */
  324. andcc %g5, 0xff, %g0 /* IEU1 Group */
  325. be,pn %icc, 12f /* CTI */
  326. srlx %o4, 56, %g5 /* IEU0 */
  327. andcc %g5, 0xff, %g0 /* IEU1 Group */
  328. srlx %o2, 48, %g5 /* IEU0 */
  329. be,a,pn %icc, 4f /* CTI */
  330. add %o0, -16, %g4 /* IEU0 Group */
  331. 4: andcc %g5, 0xff, %g0 /* IEU1 Group */
  332. be,pn %icc, 12f /* CTI */
  333. srlx %o4, 48, %g5 /* IEU0 */
  334. andcc %g5, 0xff, %g0 /* IEU1 Group */
  335. srlx %o2, 40, %g5 /* IEU0 */
  336. be,a,pn %icc, 5f /* CTI */
  337. add %o0, -15, %g4 /* IEU0 Group */
  338. 5: andcc %g5, 0xff, %g0 /* IEU1 Group */
  339. be,pn %icc, 12f /* CTI */
  340. srlx %o4, 40, %g5 /* IEU0 */
  341. andcc %g5, 0xff, %g0 /* IEU1 Group */
  342. srlx %o2, 32, %g5 /* IEU0 */
  343. be,a,pn %icc, 6f /* CTI */
  344. add %o0, -14, %g4 /* IEU0 Group */
  345. 6: andcc %g5, 0xff, %g0 /* IEU1 Group */
  346. be,pn %icc, 12f /* CTI */
  347. srlx %o4, 32, %g5 /* IEU0 */
  348. andcc %g5, 0xff, %g0 /* IEU1 Group */
  349. be,a,pn %icc, 7f /* CTI */
  350. add %o0, -13, %g4 /* IEU0 */
  351. 7: srlx %o2, 24, %g5 /* IEU0 */
  352. andcc %g5, 0xff, %g0 /* IEU1 Group */
  353. be,pn %icc, 12f /* CTI */
  354. srlx %o4, 24, %g5 /* IEU0 */
  355. andcc %g5, 0xff, %g0 /* IEU1 Group */
  356. srlx %o2, 16, %g5 /* IEU0 */
  357. be,a,pn %icc, 8f /* CTI */
  358. add %o0, -12, %g4 /* IEU0 Group */
  359. 8: andcc %g5, 0xff, %g0 /* IEU1 Group */
  360. be,pn %icc, 12f /* CTI */
  361. srlx %o4, 16, %g5 /* IEU0 */
  362. andcc %g5, 0xff, %g0 /* IEU1 Group */
  363. srlx %o2, 8, %g5 /* IEU0 */
  364. be,a,pn %icc, 9f /* CTI */
  365. add %o0, -11, %g4 /* IEU0 Group */
  366. 9: andcc %g5, 0xff, %g0 /* IEU1 Group */
  367. be,pn %icc, 12f /* CTI */
  368. srlx %o4, 8, %g5 /* IEU0 */
  369. andcc %g5, 0xff, %g0 /* IEU1 Group */
  370. be,a,pn %icc, 10f /* CTI */
  371. add %o0, -10, %g4 /* IEU0 */
  372. 10: andcc %o2, 0xff, %g0 /* IEU1 Group */
  373. be,pn %icc, 12f /* CTI */
  374. sub %o3, %g1, %o2 /* IEU0 */
  375. andcc %o4, 0xff, %g0 /* IEU1 Group */
  376. be,a,pn %icc, 11f /* CTI */
  377. add %o0, -9, %g4 /* IEU0 */
  378. 11: ba,pt %xcc, 3b /* CTI Group */
  379. xor %o3, %g3, %o4 /* IEU0 Group */
  380. 12: retl /* CTI+IEU1 Group */
  381. mov %g4, %o0 /* IEU0 */
  382. .align 16
  383. 13: ldub [%o0], %o3 /* Load Group */
  384. add %o0, 1, %o0 /* IEU0 */
  385. 14: andcc %o3, 0xff, %g0 /* IEU1 Group */
  386. be,pn %icc, 12b /* CTI */
  387. cmp %o3, %o1 /* IEU1 Group */
  388. ldub [%o0], %o3 /* Load */
  389. be,a,pn %icc, 15f /* CTI */
  390. add %o0, -1, %g4 /* IEU0 Group */
  391. 15: andcc %o0, 7, %g0 /* IEU1 Group */
  392. bne,a,pt %icc, 14b /* CTI */
  393. add %o0, 1, %o0 /* IEU0 */
  394. ba,pt %xcc, 1b /* CTI Group */
  395. ldx [%o0], %o3 /* Load */
  396. END(strrchr)
  397. libc_hidden_def(strrchr)
  398. #ifdef __UCLIBC_SUSV3_LEGACY__
  399. strong_alias(strrchr,rindex)
  400. #endif