strcmp.S 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /* Compare two strings for differences.
  2. For SPARC v7.
  3. Copyright (C) 1996, 97, 99, 2003 Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. Contributed by Jakub Jelinek <jj@ultra.linux.cz>.
  6. The GNU C Library is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU Lesser General Public
  8. License as published by the Free Software Foundation; either
  9. version 2.1 of the License, or (at your option) any later version.
  10. The GNU C Library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public
  15. License along with the GNU C Library; if not, see
  16. <http://www.gnu.org/licenses/>. */
  17. /* Normally, this uses ((xword - 0x01010101) & 0x80808080) test
  18. to find out if any byte in xword could be zero. This is fast, but
  19. also gives false alarm for any byte in range 0x81-0xff. It does
  20. not matter for correctness, as if this test tells us there could
  21. be some zero byte, we check it byte by byte, but if bytes with
  22. high bits set are common in the strings, then this will give poor
  23. performance. You can #define EIGHTBIT_NOT_RARE and the algorithm
  24. will use one tick slower, but more precise test
  25. ((xword - 0x01010101) & (~xword) & 0x80808080),
  26. which does not give any false alarms (but if some bits are set,
  27. one cannot assume from it which bytes are zero and which are not).
  28. It is yet to be measured, what is the correct default for glibc
  29. in these days for an average user.
  30. */
  31. .text
  32. .align 4
  33. 10: ldub [%o0], %o4
  34. add %o0, 1, %o0
  35. ldub [%o1], %o5
  36. cmp %o4, 0
  37. add %o1, 1, %o1
  38. be 2f
  39. subcc %o4, %o5, %o4
  40. bne 2f
  41. andcc %o0, 3, %g0
  42. be 4f
  43. or %g1, %lo(0x80808080), %o3
  44. ldub [%o0], %o4
  45. add %o0, 1, %o0
  46. ldub [%o1], %o5
  47. cmp %o4, 0
  48. add %o1, 1, %o1
  49. be 2f
  50. subcc %o4, %o5, %o4
  51. bne 2f
  52. andcc %o0, 3, %g0
  53. be 5f
  54. sethi %hi(0x01010101), %g1
  55. ldub [%o0], %o4
  56. add %o0, 1, %o0
  57. ldub [%o1], %o5
  58. cmp %o4, 0
  59. add %o1, 1, %o1
  60. be 2f
  61. subcc %o4, %o5, %o4
  62. bne 2f
  63. andcc %o1, 3, %g2
  64. bne 12f
  65. or %g1, %lo(0x01010101), %o2
  66. b 1f
  67. ld [%o0], %o4
  68. 2: retl
  69. mov %o4, %o0
  70. ENTRY(strcmp)
  71. andcc %o0, 3, %g0
  72. bne 10b
  73. sethi %hi(0x80808080), %g1
  74. or %g1, %lo(0x80808080), %o3
  75. 4: sethi %hi(0x01010101), %g1
  76. 5: andcc %o1, 3, %g2
  77. bne 12f
  78. or %g1, %lo(0x01010101), %o2
  79. 0: ld [%o0], %o4
  80. 1: ld [%o1], %o5
  81. sub %o4, %o2, %g1
  82. add %o0, 4, %o0
  83. cmp %o4, %o5
  84. #ifdef EIGHTBIT_NOT_RARE
  85. andn %g1, %o4, %g1
  86. #endif
  87. bne 11f
  88. andcc %g1, %o3, %g0
  89. be 0b
  90. add %o1, 4, %o1
  91. srl %o4, 24, %g4
  92. andcc %g4, 0xff, %g0
  93. be 2f
  94. srl %o4, 16, %g4
  95. andcc %g4, 0xff, %g0
  96. be 2f
  97. srl %o4, 8, %g4
  98. andcc %g4, 0xff, %g0
  99. be 2f
  100. andcc %o4, 0xff, %g0
  101. bne,a 1b
  102. ld [%o0], %o4
  103. 2: retl
  104. clr %o0
  105. 11: srl %o4, 24, %g4
  106. srl %o5, 24, %g5
  107. andcc %g4, 0xff, %g0
  108. be 3f
  109. subcc %g4, %g5, %g4
  110. bne 3f
  111. srl %o5, 16, %g5
  112. srl %o4, 16, %g4
  113. andcc %g4, 0xff, %g0
  114. be 3f
  115. subcc %g4, %g5, %g4
  116. bne 3f
  117. srl %o5, 8, %g5
  118. srl %o4, 8, %g4
  119. andcc %g4, 0xff, %g0
  120. be 3f
  121. subcc %g4, %g5, %g4
  122. bne 3f
  123. subcc %o4, %o5, %o4
  124. retl
  125. mov %o4, %o0
  126. 3: retl
  127. mov %g4, %o0
  128. 12: save %sp, -64, %sp
  129. ld [%i0], %i4
  130. sll %g2, 3, %g3
  131. andn %i1, 3, %i1
  132. mov 32, %l1
  133. ld [%i1], %l2
  134. mov -1, %g6
  135. add %i1, 4, %i1
  136. sub %l1, %g3, %l1
  137. sll %g6, %g3, %g6
  138. 1: sll %l2, %g3, %g5
  139. and %i4, %g6, %l3
  140. sub %i4, %i2, %g1
  141. #ifdef EIGHTBIT_NOT_RARE
  142. andn %g1, %i4, %g1
  143. #endif
  144. andcc %g1, %i3, %g1
  145. bne 3f
  146. cmp %g5, %l3
  147. bne 2f
  148. add %i0, 4, %i0
  149. ld [%i1], %l2
  150. add %i1, 4, %i1
  151. srl %l2, %l1, %l4
  152. or %l4, %g5, %l4
  153. cmp %l4, %i4
  154. be,a 1b
  155. ld [%i0], %i4
  156. restore %l4, %g0, %o3
  157. retl
  158. sub %o4, %o3, %o0
  159. 2: sll %l2, %g3, %i2
  160. srl %i4, %g3, %i3
  161. srl %i2, %g3, %i2
  162. restore
  163. retl
  164. sub %o3, %o2, %o0
  165. 3: srl %i4, 24, %g4
  166. srl %g5, 24, %l6
  167. andcc %g4, 0xff, %g0
  168. be 4f
  169. subcc %g4, %l6, %g4
  170. bne 4f
  171. cmp %g2, 3
  172. be 6f
  173. srl %i4, 16, %g4
  174. srl %g5, 16, %l6
  175. andcc %g4, 0xff, %g0
  176. be 4f
  177. subcc %g4, %l6, %g4
  178. bne 4f
  179. cmp %g2, 2
  180. be 5f
  181. srl %i4, 8, %g4
  182. srl %g5, 8, %l6
  183. andcc %g4, 0xff, %g0
  184. be 4f
  185. subcc %g4, %l6, %g4
  186. bne 4f
  187. add %i0, 4, %i0
  188. ld [%i1], %l2
  189. add %i1, 4, %i1
  190. srl %l2, 24, %g5
  191. andcc %i4, 0xff, %g4
  192. be 4f
  193. subcc %g4, %g5, %g4
  194. be,a 1b
  195. ld [%i0], %i4
  196. 4: jmpl %i7 + 8, %g0
  197. restore %g4, %g0, %o0
  198. 5: ld [%i1], %l2
  199. add %i1, 4, %i1
  200. add %i0, 4, %i0
  201. srl %l2, 24, %l6
  202. andcc %g4, 0xff, %g4
  203. be 4b
  204. subcc %g4, %l6, %g4
  205. bne 4b
  206. srl %l2, 16, %l6
  207. andcc %i4, 0xff, %g4
  208. and %l6, 0xff, %l6
  209. be 4b
  210. subcc %g4, %l6, %g4
  211. be,a 1b
  212. ld [%i0], %i4
  213. jmpl %i7 + 8, %g0
  214. restore %g4, %g0, %o0
  215. 6: ld [%i1], %l2
  216. add %i1, 4, %i1
  217. add %i0, 4, %i0
  218. srl %l2, 24, %l6
  219. andcc %g4, 0xff, %g4
  220. be 4b
  221. subcc %g4, %l6, %g4
  222. bne 4b
  223. srl %l2, 16, %l6
  224. srl %i4, 8, %g4
  225. and %l6, 0xff, %l6
  226. andcc %g4, 0xff, %g4
  227. be 4b
  228. subcc %g4, %l6, %g4
  229. bne 4b
  230. srl %l2, 8, %l6
  231. andcc %i4, 0xff, %g4
  232. and %l6, 0xff, %l6
  233. be 4b
  234. subcc %g4, %l6, %g4
  235. be,a 1b
  236. ld [%i0], %i4
  237. jmpl %i7 + 8, %g0
  238. restore %g4, %g0, %o0
  239. END(strcmp)
  240. libc_hidden_def(strcmp)