strchr.S 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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, see
  17. <http://www.gnu.org/licenses/>. */
  18. /* Normally, this uses ((xword - 0x01010101) & 0x80808080) test
  19. to find out if any byte in xword could be zero. This is fast, but
  20. also gives false alarm for any byte in range 0x81-0xff. It does
  21. not matter for correctness, as if this test tells us there could
  22. be some zero byte, we check it byte by byte, but if bytes with
  23. high bits set are common in the strings, then this will give poor
  24. performance. You can #define EIGHTBIT_NOT_RARE and the algorithm
  25. will use one tick slower, but more precise test
  26. ((xword - 0x01010101) & (~xword) & 0x80808080),
  27. which does not give any false alarms (but if some bits are set,
  28. one cannot assume from it which bytes are zero and which are not).
  29. It is yet to be measured, what is the correct default for glibc
  30. in these days for an average user.
  31. */
  32. #include <features.h>
  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. libc_hidden_def(strchr)
  209. #ifdef __UCLIBC_SUSV3_LEGACY__
  210. strong_alias(strchr,index)
  211. #endif
  212. ENTRY(strrchr)
  213. andcc %o1, 0xff, %o1
  214. clr %o5
  215. be 12b
  216. sll %o1, 8, %o2
  217. andcc %o0, 3, %g0
  218. or %o1, %o2, %o2
  219. sethi %hi(0x80808080), %o4
  220. sll %o2, 16, %o3
  221. bne 13b
  222. or %o3, %o2, %g2
  223. or %o4, %lo(0x80808080), %o3
  224. 4: sethi %hi(0x01010101), %o4
  225. 5: or %o4, %lo(0x01010101), %o2
  226. 6: ld [%o0], %g4
  227. 7: xor %g4, %g2, %g5
  228. sub %g4, %o2, %o4
  229. #ifdef EIGHTBIT_NOT_RARE
  230. sub %g5, %o2, %g6
  231. andn %o4, %g4, %o4
  232. andn %g6, %g5, %g5
  233. #else
  234. sub %g5, %o2, %g5
  235. #endif
  236. or %g5, %o4, %o4
  237. andcc %o4, %o3, %g0
  238. be 6b
  239. add %o0, 4, %o0
  240. /* Check every byte. */
  241. 3: srl %g4, 24, %g5
  242. 8: andcc %g5, 0xff, %g5
  243. be 9f
  244. cmp %g5, %o1
  245. be,a 1f
  246. sub %o0, 4, %o5
  247. 1: srl %g4, 16, %g5
  248. andcc %g5, 0xff, %g5
  249. be 9f
  250. cmp %g5, %o1
  251. be,a 1f
  252. sub %o0, 3, %o5
  253. 1: srl %g4, 8, %g5
  254. andcc %g5, 0xff, %g5
  255. be 9f
  256. cmp %g5, %o1
  257. be,a 1f
  258. sub %o0, 2, %o5
  259. 1: andcc %g4, 0xff, %g5
  260. be 9f
  261. cmp %g5, %o1
  262. be,a 1f
  263. sub %o0, 1, %o5
  264. 1: b 7b
  265. ld [%o0], %g4
  266. 9: retl
  267. mov %o5, %o0
  268. END(strrchr)
  269. libc_hidden_def(strrchr)
  270. #ifdef __UCLIBC_SUSV3_LEGACY__
  271. strong_alias(strrchr,rindex)
  272. #endif