strcmp.S 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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, write to the Free
  16. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  17. 02111-1307 USA. */
  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. .text
  33. .align 4
  34. 10: ldub [%o0], %o4
  35. add %o0, 1, %o0
  36. ldub [%o1], %o5
  37. cmp %o4, 0
  38. add %o1, 1, %o1
  39. be 2f
  40. subcc %o4, %o5, %o4
  41. bne 2f
  42. andcc %o0, 3, %g0
  43. be 4f
  44. or %g1, %lo(0x80808080), %o3
  45. ldub [%o0], %o4
  46. add %o0, 1, %o0
  47. ldub [%o1], %o5
  48. cmp %o4, 0
  49. add %o1, 1, %o1
  50. be 2f
  51. subcc %o4, %o5, %o4
  52. bne 2f
  53. andcc %o0, 3, %g0
  54. be 5f
  55. sethi %hi(0x01010101), %g1
  56. ldub [%o0], %o4
  57. add %o0, 1, %o0
  58. ldub [%o1], %o5
  59. cmp %o4, 0
  60. add %o1, 1, %o1
  61. be 2f
  62. subcc %o4, %o5, %o4
  63. bne 2f
  64. andcc %o1, 3, %g2
  65. bne 12f
  66. or %g1, %lo(0x01010101), %o2
  67. b 1f
  68. ld [%o0], %o4
  69. 2: retl
  70. mov %o4, %o0
  71. .globl strcmp
  72. .set strcmp,__strcmp
  73. .hidden __strcmp
  74. ENTRY(__strcmp)
  75. andcc %o0, 3, %g0
  76. bne 10b
  77. sethi %hi(0x80808080), %g1
  78. or %g1, %lo(0x80808080), %o3
  79. 4: sethi %hi(0x01010101), %g1
  80. 5: andcc %o1, 3, %g2
  81. bne 12f
  82. or %g1, %lo(0x01010101), %o2
  83. 0: ld [%o0], %o4
  84. 1: ld [%o1], %o5
  85. sub %o4, %o2, %g1
  86. add %o0, 4, %o0
  87. cmp %o4, %o5
  88. #ifdef EIGHTBIT_NOT_RARE
  89. andn %g1, %o4, %g1
  90. #endif
  91. bne 11f
  92. andcc %g1, %o3, %g0
  93. be 0b
  94. add %o1, 4, %o1
  95. srl %o4, 24, %g4
  96. andcc %g4, 0xff, %g0
  97. be 2f
  98. srl %o4, 16, %g4
  99. andcc %g4, 0xff, %g0
  100. be 2f
  101. srl %o4, 8, %g4
  102. andcc %g4, 0xff, %g0
  103. be 2f
  104. andcc %o4, 0xff, %g0
  105. bne,a 1b
  106. ld [%o0], %o4
  107. 2: retl
  108. clr %o0
  109. 11: srl %o4, 24, %g4
  110. srl %o5, 24, %g5
  111. andcc %g4, 0xff, %g0
  112. be 3f
  113. subcc %g4, %g5, %g4
  114. bne 3f
  115. srl %o5, 16, %g5
  116. srl %o4, 16, %g4
  117. andcc %g4, 0xff, %g0
  118. be 3f
  119. subcc %g4, %g5, %g4
  120. bne 3f
  121. srl %o5, 8, %g5
  122. srl %o4, 8, %g4
  123. andcc %g4, 0xff, %g0
  124. be 3f
  125. subcc %g4, %g5, %g4
  126. bne 3f
  127. subcc %o4, %o5, %o4
  128. retl
  129. mov %o4, %o0
  130. 3: retl
  131. mov %g4, %o0
  132. 12: save %sp, -64, %sp
  133. ld [%i0], %i4
  134. sll %g2, 3, %g3
  135. andn %i1, 3, %i1
  136. mov 32, %l1
  137. ld [%i1], %l2
  138. mov -1, %g6
  139. add %i1, 4, %i1
  140. sub %l1, %g3, %l1
  141. sll %g6, %g3, %g6
  142. 1: sll %l2, %g3, %g5
  143. and %i4, %g6, %l3
  144. sub %i4, %i2, %g1
  145. #ifdef EIGHTBIT_NOT_RARE
  146. andn %g1, %i4, %g1
  147. #endif
  148. andcc %g1, %i3, %g1
  149. bne 3f
  150. cmp %g5, %l3
  151. bne 2f
  152. add %i0, 4, %i0
  153. ld [%i1], %l2
  154. add %i1, 4, %i1
  155. srl %l2, %l1, %l4
  156. or %l4, %g5, %l4
  157. cmp %l4, %i4
  158. be,a 1b
  159. ld [%i0], %i4
  160. restore %l4, %g0, %o3
  161. retl
  162. sub %o4, %o3, %o0
  163. 2: sll %l2, %g3, %i2
  164. srl %i4, %g3, %i3
  165. srl %i2, %g3, %i2
  166. restore
  167. retl
  168. sub %o3, %o2, %o0
  169. 3: srl %i4, 24, %g4
  170. srl %g5, 24, %l6
  171. andcc %g4, 0xff, %g0
  172. be 4f
  173. subcc %g4, %l6, %g4
  174. bne 4f
  175. cmp %g2, 3
  176. be 6f
  177. srl %i4, 16, %g4
  178. srl %g5, 16, %l6
  179. andcc %g4, 0xff, %g0
  180. be 4f
  181. subcc %g4, %l6, %g4
  182. bne 4f
  183. cmp %g2, 2
  184. be 5f
  185. srl %i4, 8, %g4
  186. srl %g5, 8, %l6
  187. andcc %g4, 0xff, %g0
  188. be 4f
  189. subcc %g4, %l6, %g4
  190. bne 4f
  191. add %i0, 4, %i0
  192. ld [%i1], %l2
  193. add %i1, 4, %i1
  194. srl %l2, 24, %g5
  195. andcc %i4, 0xff, %g4
  196. be 4f
  197. subcc %g4, %g5, %g4
  198. be,a 1b
  199. ld [%i0], %i4
  200. 4: jmpl %i7 + 8, %g0
  201. restore %g4, %g0, %o0
  202. 5: ld [%i1], %l2
  203. add %i1, 4, %i1
  204. add %i0, 4, %i0
  205. srl %l2, 24, %l6
  206. andcc %g4, 0xff, %g4
  207. be 4b
  208. subcc %g4, %l6, %g4
  209. bne 4b
  210. srl %l2, 16, %l6
  211. andcc %i4, 0xff, %g4
  212. and %l6, 0xff, %l6
  213. be 4b
  214. subcc %g4, %l6, %g4
  215. be,a 1b
  216. ld [%i0], %i4
  217. jmpl %i7 + 8, %g0
  218. restore %g4, %g0, %o0
  219. 6: ld [%i1], %l2
  220. add %i1, 4, %i1
  221. add %i0, 4, %i0
  222. srl %l2, 24, %l6
  223. andcc %g4, 0xff, %g4
  224. be 4b
  225. subcc %g4, %l6, %g4
  226. bne 4b
  227. srl %l2, 16, %l6
  228. srl %i4, 8, %g4
  229. and %l6, 0xff, %l6
  230. andcc %g4, 0xff, %g4
  231. be 4b
  232. subcc %g4, %l6, %g4
  233. bne 4b
  234. srl %l2, 8, %l6
  235. andcc %i4, 0xff, %g4
  236. and %l6, 0xff, %l6
  237. be 4b
  238. subcc %g4, %l6, %g4
  239. be,a 1b
  240. ld [%i0], %i4
  241. jmpl %i7 + 8, %g0
  242. restore %g4, %g0, %o0
  243. END(__strcmp)