strchr.S 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /* strchr (str, ch) -- Return pointer to first occurrence of CH in STR.
  2. For SPARC v7.
  3. Copyright (C) 1996, 1999, 2003 Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. Contributed by Jakub Jelinek <jj@ultra.linux.cz> and
  6. David S. Miller <davem@caip.rutgers.edu>.
  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. /* Normally, this uses ((xword - 0x01010101) & 0x80808080) test
  20. to find out if any byte in xword could be zero. This is fast, but
  21. also gives false alarm for any byte in range 0x81-0xff. It does
  22. not matter for correctness, as if this test tells us there could
  23. be some zero byte, we check it byte by byte, but if bytes with
  24. high bits set are common in the strings, then this will give poor
  25. performance. You can #define EIGHTBIT_NOT_RARE and the algorithm
  26. will use one tick slower, but more precise test
  27. ((xword - 0x01010101) & (~xword) & 0x80808080),
  28. which does not give any false alarms (but if some bits are set,
  29. one cannot assume from it which bytes are zero and which are not).
  30. It is yet to be measured, what is the correct default for glibc
  31. in these days for an average user.
  32. */
  33. .text
  34. .align 4
  35. 10: ldub [%o0], %g4
  36. cmp %g4, %o1
  37. be 1f
  38. add %o0, 1, %o0
  39. cmp %g4, 0
  40. be 9f
  41. andcc %o0, 3, %g0
  42. be 4f
  43. or %o4, %lo(0x80808080), %o3
  44. ldub [%o0], %g4
  45. cmp %g4, %o1
  46. be 1f
  47. add %o0, 1, %o0
  48. cmp %g4, 0
  49. be 9f
  50. andcc %o0, 3, %g0
  51. be 5f
  52. sethi %hi(0x01010101), %o5
  53. ldub [%o0], %g4
  54. cmp %g4, %o1
  55. be 1f
  56. add %o0, 1, %o0
  57. cmp %g4, 0
  58. be 9f
  59. or %o5, %lo(0x01010101), %o2
  60. b 6f
  61. ld [%o0], %g4
  62. 1: retl
  63. sub %o0, 1, %o0
  64. ENTRY(__strchr)
  65. andcc %o1, 0xff, %o1
  66. be 12f
  67. sll %o1, 8, %o2
  68. andcc %o0, 3, %g0
  69. or %o1, %o2, %o2
  70. sethi %hi(0x80808080), %o4
  71. sll %o2, 16, %o3
  72. bne 10b
  73. or %o3, %o2, %g2
  74. or %o4, %lo(0x80808080), %o3
  75. 4: sethi %hi(0x01010101), %o5
  76. 5: or %o5, %lo(0x01010101), %o2
  77. 7: ld [%o0], %g4
  78. 6: xor %g4, %g2, %g5
  79. sub %g4, %o2, %o4
  80. #ifdef EIGHTBIT_NOT_RARE
  81. sub %g5, %o2, %g6
  82. andn %o4, %g4, %o4
  83. andn %g6, %g5, %g5
  84. #else
  85. sub %g5, %o2, %g5
  86. #endif
  87. or %g5, %o4, %o4
  88. andcc %o4, %o3, %g0
  89. be 7b
  90. add %o0, 4, %o0
  91. /* Check every byte. */
  92. 8: srl %g4, 24, %g5
  93. 7: andcc %g5, 0xff, %g5
  94. be 9f
  95. cmp %g5, %o1
  96. be 4f
  97. srl %g4, 16, %g5
  98. andcc %g5, 0xff, %g5
  99. be 9f
  100. cmp %g5, %o1
  101. be 3f
  102. srl %g4, 8, %g5
  103. andcc %g5, 0xff, %g5
  104. be 9f
  105. cmp %g5, %o1
  106. be 2f
  107. andcc %g4, 0xff, %g5
  108. be 9f
  109. cmp %g5, %o1
  110. bne,a 6b
  111. ld [%o0], %g4
  112. retl
  113. sub %o0, 1, %o0
  114. 2: retl
  115. sub %o0, 2, %o0
  116. 3: retl
  117. sub %o0, 3, %o0
  118. 4: retl
  119. sub %o0, 4, %o0
  120. 9: retl
  121. clr %o0
  122. 11: ldub [%o0], %o5
  123. cmp %o5, 0
  124. be 1f
  125. add %o0, 1, %o0
  126. andcc %o0, 3, %g0
  127. be 4f
  128. or %o4, %lo(0x80808080), %o3
  129. ldub [%o0], %o5
  130. cmp %o5, 0
  131. be 1f
  132. add %o0, 1, %o0
  133. andcc %o0, 3, %g0
  134. be 5f
  135. sethi %hi(0x01010101), %o4
  136. ldub [%o0], %o5
  137. cmp %o5, 0
  138. be 1f
  139. add %o0, 1, %o0
  140. b 6f
  141. or %o4, %lo(0x01010101), %o2
  142. 1: retl
  143. sub %o0, 1, %o0
  144. 12: andcc %o0, 3, %g0
  145. bne 11b
  146. sethi %hi(0x80808080), %o4
  147. or %o4, %lo(0x80808080), %o3
  148. 4: sethi %hi(0x01010101), %o4
  149. 5: or %o4, %lo(0x01010101), %o2
  150. 6: ld [%o0], %o5
  151. 7: sub %o5, %o2, %o4
  152. #ifdef EIGHTBIT_NOT_RARE
  153. andn %o4, %o5, %o4
  154. #endif
  155. andcc %o4, %o3, %g0
  156. be 6b
  157. add %o0, 4, %o0
  158. /* Check every byte. */
  159. srl %o5, 24, %g5
  160. andcc %g5, 0xff, %g0
  161. be 8f
  162. add %o0, -4, %o4
  163. srl %o5, 16, %g5
  164. andcc %g5, 0xff, %g0
  165. be 8f
  166. add %o4, 1, %o4
  167. srl %o5, 8, %g5
  168. andcc %g5, 0xff, %g0
  169. be 8f
  170. add %o4, 1, %o4
  171. andcc %o5, 0xff, %g0
  172. bne,a 7b
  173. ld [%o0], %o5
  174. add %o4, 1, %o4
  175. 8: retl
  176. mov %o4, %o0
  177. 13: ldub [%o0], %g4
  178. cmp %g4, %o1
  179. add %o0, 1, %o0
  180. be,a 1f
  181. sub %o0, 1, %o5
  182. cmp %g4, 0
  183. be 9f
  184. 1: andcc %o0, 3, %g0
  185. be 4f
  186. or %o4, %lo(0x80808080), %o3
  187. ldub [%o0], %g4
  188. cmp %g4, %o1
  189. add %o0, 1, %o0
  190. be,a 1f
  191. sub %o0, 1, %o5
  192. cmp %g4, 0
  193. be 9f
  194. 1: andcc %o0, 3, %g0
  195. be 5f
  196. sethi %hi(0x01010101), %o4
  197. ldub [%o0], %g4
  198. cmp %g4, %o1
  199. add %o0, 1, %o0
  200. be,a 1f
  201. sub %o0, 1, %o5
  202. cmp %g4, 0
  203. be 9f
  204. 1: or %o4, %lo(0x01010101), %o2
  205. b 7f
  206. ld [%o0], %g4
  207. END(__strchr)
  208. strong_alias(__strchr,strchr)
  209. strong_alias(__strchr,index)
  210. ENTRY(__strrchr)
  211. andcc %o1, 0xff, %o1
  212. clr %o5
  213. be 12b
  214. sll %o1, 8, %o2
  215. andcc %o0, 3, %g0
  216. or %o1, %o2, %o2
  217. sethi %hi(0x80808080), %o4
  218. sll %o2, 16, %o3
  219. bne 13b
  220. or %o3, %o2, %g2
  221. or %o4, %lo(0x80808080), %o3
  222. 4: sethi %hi(0x01010101), %o4
  223. 5: or %o4, %lo(0x01010101), %o2
  224. 6: ld [%o0], %g4
  225. 7: xor %g4, %g2, %g5
  226. sub %g4, %o2, %o4
  227. #ifdef EIGHTBIT_NOT_RARE
  228. sub %g5, %o2, %g6
  229. andn %o4, %g4, %o4
  230. andn %g6, %g5, %g5
  231. #else
  232. sub %g5, %o2, %g5
  233. #endif
  234. or %g5, %o4, %o4
  235. andcc %o4, %o3, %g0
  236. be 6b
  237. add %o0, 4, %o0
  238. /* Check every byte. */
  239. 3: srl %g4, 24, %g5
  240. 8: andcc %g5, 0xff, %g5
  241. be 9f
  242. cmp %g5, %o1
  243. be,a 1f
  244. sub %o0, 4, %o5
  245. 1: srl %g4, 16, %g5
  246. andcc %g5, 0xff, %g5
  247. be 9f
  248. cmp %g5, %o1
  249. be,a 1f
  250. sub %o0, 3, %o5
  251. 1: srl %g4, 8, %g5
  252. andcc %g5, 0xff, %g5
  253. be 9f
  254. cmp %g5, %o1
  255. be,a 1f
  256. sub %o0, 2, %o5
  257. 1: andcc %g4, 0xff, %g5
  258. be 9f
  259. cmp %g5, %o1
  260. be,a 1f
  261. sub %o0, 1, %o5
  262. 1: b 7b
  263. ld [%o0], %g4
  264. 9: retl
  265. mov %o5, %o0
  266. END(__strrchr)
  267. strong_alias(__strrchr,strrchr)
  268. strong_alias(__strrchr,rindex)