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, 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. ENTRY(strcmp)
  72. andcc %o0, 3, %g0
  73. bne 10b
  74. sethi %hi(0x80808080), %g1
  75. or %g1, %lo(0x80808080), %o3
  76. 4: sethi %hi(0x01010101), %g1
  77. 5: andcc %o1, 3, %g2
  78. bne 12f
  79. or %g1, %lo(0x01010101), %o2
  80. 0: ld [%o0], %o4
  81. 1: ld [%o1], %o5
  82. sub %o4, %o2, %g1
  83. add %o0, 4, %o0
  84. cmp %o4, %o5
  85. #ifdef EIGHTBIT_NOT_RARE
  86. andn %g1, %o4, %g1
  87. #endif
  88. bne 11f
  89. andcc %g1, %o3, %g0
  90. be 0b
  91. add %o1, 4, %o1
  92. srl %o4, 24, %g4
  93. andcc %g4, 0xff, %g0
  94. be 2f
  95. srl %o4, 16, %g4
  96. andcc %g4, 0xff, %g0
  97. be 2f
  98. srl %o4, 8, %g4
  99. andcc %g4, 0xff, %g0
  100. be 2f
  101. andcc %o4, 0xff, %g0
  102. bne,a 1b
  103. ld [%o0], %o4
  104. 2: retl
  105. clr %o0
  106. 11: srl %o4, 24, %g4
  107. srl %o5, 24, %g5
  108. andcc %g4, 0xff, %g0
  109. be 3f
  110. subcc %g4, %g5, %g4
  111. bne 3f
  112. srl %o5, 16, %g5
  113. srl %o4, 16, %g4
  114. andcc %g4, 0xff, %g0
  115. be 3f
  116. subcc %g4, %g5, %g4
  117. bne 3f
  118. srl %o5, 8, %g5
  119. srl %o4, 8, %g4
  120. andcc %g4, 0xff, %g0
  121. be 3f
  122. subcc %g4, %g5, %g4
  123. bne 3f
  124. subcc %o4, %o5, %o4
  125. retl
  126. mov %o4, %o0
  127. 3: retl
  128. mov %g4, %o0
  129. 12: save %sp, -64, %sp
  130. ld [%i0], %i4
  131. sll %g2, 3, %g3
  132. andn %i1, 3, %i1
  133. mov 32, %l1
  134. ld [%i1], %l2
  135. mov -1, %g6
  136. add %i1, 4, %i1
  137. sub %l1, %g3, %l1
  138. sll %g6, %g3, %g6
  139. 1: sll %l2, %g3, %g5
  140. and %i4, %g6, %l3
  141. sub %i4, %i2, %g1
  142. #ifdef EIGHTBIT_NOT_RARE
  143. andn %g1, %i4, %g1
  144. #endif
  145. andcc %g1, %i3, %g1
  146. bne 3f
  147. cmp %g5, %l3
  148. bne 2f
  149. add %i0, 4, %i0
  150. ld [%i1], %l2
  151. add %i1, 4, %i1
  152. srl %l2, %l1, %l4
  153. or %l4, %g5, %l4
  154. cmp %l4, %i4
  155. be,a 1b
  156. ld [%i0], %i4
  157. restore %l4, %g0, %o3
  158. retl
  159. sub %o4, %o3, %o0
  160. 2: sll %l2, %g3, %i2
  161. srl %i4, %g3, %i3
  162. srl %i2, %g3, %i2
  163. restore
  164. retl
  165. sub %o3, %o2, %o0
  166. 3: srl %i4, 24, %g4
  167. srl %g5, 24, %l6
  168. andcc %g4, 0xff, %g0
  169. be 4f
  170. subcc %g4, %l6, %g4
  171. bne 4f
  172. cmp %g2, 3
  173. be 6f
  174. srl %i4, 16, %g4
  175. srl %g5, 16, %l6
  176. andcc %g4, 0xff, %g0
  177. be 4f
  178. subcc %g4, %l6, %g4
  179. bne 4f
  180. cmp %g2, 2
  181. be 5f
  182. srl %i4, 8, %g4
  183. srl %g5, 8, %l6
  184. andcc %g4, 0xff, %g0
  185. be 4f
  186. subcc %g4, %l6, %g4
  187. bne 4f
  188. add %i0, 4, %i0
  189. ld [%i1], %l2
  190. add %i1, 4, %i1
  191. srl %l2, 24, %g5
  192. andcc %i4, 0xff, %g4
  193. be 4f
  194. subcc %g4, %g5, %g4
  195. be,a 1b
  196. ld [%i0], %i4
  197. 4: jmpl %i7 + 8, %g0
  198. restore %g4, %g0, %o0
  199. 5: ld [%i1], %l2
  200. add %i1, 4, %i1
  201. add %i0, 4, %i0
  202. srl %l2, 24, %l6
  203. andcc %g4, 0xff, %g4
  204. be 4b
  205. subcc %g4, %l6, %g4
  206. bne 4b
  207. srl %l2, 16, %l6
  208. andcc %i4, 0xff, %g4
  209. and %l6, 0xff, %l6
  210. be 4b
  211. subcc %g4, %l6, %g4
  212. be,a 1b
  213. ld [%i0], %i4
  214. jmpl %i7 + 8, %g0
  215. restore %g4, %g0, %o0
  216. 6: ld [%i1], %l2
  217. add %i1, 4, %i1
  218. add %i0, 4, %i0
  219. srl %l2, 24, %l6
  220. andcc %g4, 0xff, %g4
  221. be 4b
  222. subcc %g4, %l6, %g4
  223. bne 4b
  224. srl %l2, 16, %l6
  225. srl %i4, 8, %g4
  226. and %l6, 0xff, %l6
  227. andcc %g4, 0xff, %g4
  228. be 4b
  229. subcc %g4, %l6, %g4
  230. bne 4b
  231. srl %l2, 8, %l6
  232. andcc %i4, 0xff, %g4
  233. and %l6, 0xff, %l6
  234. be 4b
  235. subcc %g4, %l6, %g4
  236. be,a 1b
  237. ld [%i0], %i4
  238. jmpl %i7 + 8, %g0
  239. restore %g4, %g0, %o0
  240. END(strcmp)