strcmp.S 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /* Compare two strings for differences.
  2. For SPARC v9.
  3. Copyright (C) 1997, 1999, 2003 Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. Contributed by Jan Vondrak <jvon4518@ss1000.ms.mff.cuni.cz> and
  6. Jakub Jelinek <jj@ultra.linux.cz>.
  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. #include <asm/asi.h>
  20. #ifndef XCC
  21. .register %g2, #scratch
  22. .register %g3, #scratch
  23. .register %g6, #scratch
  24. #endif
  25. /* Normally, this uses
  26. ((xword - 0x0101010101010101) & 0x8080808080808080) test
  27. to find out if any byte in xword could be zero. This is fast, but
  28. also gives false alarm for any byte in range 0x81-0xff. It does
  29. not matter for correctness, as if this test tells us there could
  30. be some zero byte, we check it byte by byte, but if bytes with
  31. high bits set are common in the strings, then this will give poor
  32. performance. You can #define EIGHTBIT_NOT_RARE and the algorithm
  33. will use one tick slower, but more precise test
  34. ((xword - 0x0101010101010101) & (~xword) & 0x8080808080808080),
  35. which does not give any false alarms (but if some bits are set,
  36. one cannot assume from it which bytes are zero and which are not).
  37. It is yet to be measured, what is the correct default for glibc
  38. in these days for an average user.
  39. */
  40. .text
  41. .align 32
  42. ENTRY(strcmp)
  43. sethi %hi(0x01010101), %g1 /* IEU0 Group */
  44. andcc %o0, 7, %g0 /* IEU1 */
  45. bne,pn %icc, 7f /* CTI */
  46. or %g1, %lo(0x01010101), %g1 /* IEU0 Group */
  47. andcc %o1, 7, %g3 /* IEU1 */
  48. bne,pn %icc, 9f /* CTI */
  49. sllx %g1, 32, %g2 /* IEU0 Group */
  50. ldx [%o0], %o2 /* Load */
  51. or %g1, %g2, %g1 /* IEU0 Group */
  52. 1: ldx [%o1], %o3 /* Load */
  53. sub %o1, %o0, %o1 /* IEU1 */
  54. sllx %g1, 7, %g2 /* IEU0 Group */
  55. 2: add %o0, 8, %o0 /* IEU1 */
  56. sub %o2, %g1, %g3 /* IEU0 Group */
  57. subcc %o2, %o3, %g0 /* IEU1 */
  58. bne,pn %xcc, 13f /* CTI */
  59. #ifdef EIGHTBIT_NOT_RARE
  60. andn %g3, %o2, %g4 /* IEU0 Group */
  61. ldxa [%o0] ASI_PNF, %o2 /* Load */
  62. andcc %g4, %g2, %g0 /* IEU1 Group */
  63. #else
  64. ldxa [%o0] ASI_PNF, %o2 /* Load Group */
  65. andcc %g3, %g2, %g0 /* IEU1 */
  66. #endif
  67. be,a,pt %xcc, 2b /* CTI */
  68. ldxa [%o1 + %o0] ASI_PNF, %o3 /* Load Group */
  69. addcc %g3, %g1, %o4 /* IEU1 */
  70. srlx %g3, 32, %g3 /* IEU0 */
  71. andcc %g3, %g2, %g0 /* IEU1 Group */
  72. be,pt %xcc, 3f /* CTI */
  73. srlx %o4, 56, %o5 /* IEU0 */
  74. andcc %o5, 0xff, %g0 /* IEU1 Group */
  75. be,pn %icc, 4f /* CTI */
  76. srlx %o4, 48, %o5 /* IEU0 */
  77. andcc %o5, 0xff, %g0 /* IEU1 Group */
  78. be,pn %icc, 4f /* CTI */
  79. srlx %o4, 40, %o5 /* IEU0 */
  80. andcc %o5, 0xff, %g0 /* IEU1 Group */
  81. be,pn %icc, 4f /* CTI */
  82. srlx %o4, 32, %o5 /* IEU0 */
  83. andcc %o5, 0xff, %g0 /* IEU1 Group */
  84. be,pn %icc, 4f /* CTI */
  85. 3: srlx %o4, 24, %o5 /* IEU0 */
  86. andcc %o5, 0xff, %g0 /* IEU1 Group */
  87. be,pn %icc, 4f /* CTI */
  88. srlx %o4, 16, %o5 /* IEU0 */
  89. andcc %o5, 0xff, %g0 /* IEU1 Group */
  90. be,pn %icc, 4f /* CTI */
  91. srlx %o4, 8, %o5 /* IEU0 */
  92. andcc %o5, 0xff, %g0 /* IEU1 Group */
  93. be,pn %icc, 4f /* CTI */
  94. andcc %o4, 0xff, %g0 /* IEU1 Group */
  95. bne,a,pn %icc, 2b /* CTI */
  96. ldxa [%o1 + %o0] ASI_PNF, %o3 /* Load */
  97. 4: retl /* CTI+IEU1 Group */
  98. clr %o0 /* IEU0 */
  99. .align 32
  100. 13: mov 0xff, %g6 /* IEU0 Group */
  101. #ifdef EIGHTBIT_NOT_RARE
  102. andcc %g4, %g2, %g0 /* IEU1 */
  103. #else
  104. andcc %g3, %g2, %g0 /* IEU1 */
  105. #endif
  106. be,pt %xcc, 25f /* CTI */
  107. addcc %g3, %g1, %o4 /* IEU1 Group */
  108. srlx %g3, 32, %g3 /* IEU0 */
  109. andcc %g3, %g2, %g0 /* IEU1 Group */
  110. be,pt %xcc, 23f /* CTI */
  111. sllx %g6, 56, %o5 /* IEU0 */
  112. andcc %o4, %o5, %g0 /* IEU1 Group */
  113. be,pn %xcc, 24f /* CTI */
  114. sllx %g6, 48, %o5 /* IEU0 */
  115. andcc %o4, %o5, %g0 /* IEU1 Group */
  116. be,pn %xcc, 24f /* CTI */
  117. sllx %g6, 40, %o5 /* IEU0 */
  118. andcc %o4, %o5, %g0 /* IEU1 Group */
  119. be,pn %xcc, 24f /* CTI */
  120. sllx %g6, 32, %o5 /* IEU0 */
  121. andcc %o4, %o5, %g0 /* IEU1 Group */
  122. be,pn %xcc, 24f /* CTI */
  123. 23: sllx %g6, 24, %o5 /* IEU0 */
  124. andcc %o4, %o5, %g0 /* IEU1 Group */
  125. be,pn %icc, 24f /* CTI */
  126. sllx %g6, 16, %o5 /* IEU0 */
  127. andcc %o4, %o5, %g0 /* IEU1 Group */
  128. be,pn %icc, 24f /* CTI */
  129. sllx %g6, 8, %o5 /* IEU0 */
  130. andcc %o4, %o5, %g0 /* IEU1 Group */
  131. be,pn %icc, 24f /* CTI */
  132. mov %g6, %o5 /* IEU0 */
  133. 25: cmp %o4, %o3 /* IEU1 Group */
  134. 5: mov -1, %o0 /* IEU0 */
  135. retl /* CTI+IEU1 Group */
  136. movgu %xcc, 1, %o0 /* Single Group */
  137. .align 16
  138. 24: sub %o5, 1, %g6 /* IEU0 Group */
  139. clr %o0 /* IEU1 */
  140. or %o5, %g6, %o5 /* IEU0 Group */
  141. andn %o4, %o5, %o4 /* IEU0 Group */
  142. andn %o3, %o5, %o3 /* IEU1 */
  143. cmp %o4, %o3 /* IEU1 Group */
  144. movgu %xcc, 1, %o0 /* Single Group */
  145. retl /* CTI+IEU1 Group */
  146. movlu %xcc, -1, %o0 /* Single Group */
  147. 6: retl /* CTI+IEU1 Group */
  148. mov %o4, %o0 /* IEU0 */
  149. .align 16
  150. 7: ldub [%o0], %o2 /* Load */
  151. add %o0, 1, %o0 /* IEU1 */
  152. ldub [%o1], %o3 /* Load Group */
  153. sllx %g1, 32, %g2 /* IEU0 */
  154. 8: add %o1, 1, %o1 /* IEU1 */
  155. subcc %o2, %o3, %o4 /* IEU1 Group */
  156. bne,pn %xcc, 6b /* CTI */
  157. lduba [%o0] ASI_PNF, %o2 /* Load */
  158. brz,pn %o3, 4b /* CTI+IEU1 Group */
  159. lduba [%o1] ASI_PNF, %o3 /* Load */
  160. andcc %o0, 7, %g0 /* IEU1 Group */
  161. bne,a,pn %icc, 8b /* CTI */
  162. add %o0, 1, %o0 /* IEU0 */
  163. or %g1, %g2, %g1 /* IEU0 Group */
  164. andcc %o1, 7, %g3 /* IEU1 */
  165. be,a,pn %icc, 1b /* CTI */
  166. ldxa [%o0] ASI_PNF, %o2 /* Load Group */
  167. 9: sllx %g3, 3, %g5 /* IEU0 */
  168. mov 64, %o5 /* IEU1 */
  169. sub %o1, %g3, %o1 /* IEU0 Group */
  170. sub %o5, %g5, %o5 /* IEU1 */
  171. ldxa [%o1] ASI_PNF, %g6 /* Load Group */
  172. or %g1, %g2, %g1 /* IEU0 */
  173. sub %o1, %o0, %o1 /* IEU1 */
  174. sllx %g1, 7, %g2 /* IEU0 Group */
  175. add %o1, 8, %o1 /* IEU1 */
  176. /* %g1 = 0101010101010101
  177. * %g2 = 8080808080800880
  178. * %g5 = number of bits to shift left
  179. * %o5 = number of bits to shift right */
  180. 10: sllx %g6, %g5, %o3 /* IEU0 Group */
  181. ldxa [%o1 + %o0] ASI_PNF, %g6 /* Load */
  182. 11: srlx %g6, %o5, %o4 /* IEU0 Group */
  183. ldxa [%o0] ASI_PNF, %o2 /* Load */
  184. or %o3, %o4, %o3 /* IEU1 */
  185. add %o0, 8, %o0 /* IEU0 Group */
  186. subcc %o2, %o3, %g0 /* IEU1 */
  187. #ifdef EIGHTBIT_NOT_RARE
  188. sub %o2, %g1, %g3 /* IEU0 Group */
  189. bne,pn %xcc, 13b /* CTI */
  190. andn %g3, %o2, %g4 /* IEU0 Group */
  191. andcc %g4, %g2, %g0 /* IEU1 Group */
  192. be,pt %xcc, 10b /* CTI */
  193. srlx %g4, 32, %g4 /* IEU0 */
  194. andcc %g4, %g2, %g0 /* IEU1 Group */
  195. #else
  196. bne,pn %xcc, 13b /* CTI */
  197. sub %o2, %g1, %g3 /* IEU0 Group */
  198. andcc %g3, %g2, %g0 /* IEU1 Group */
  199. be,pt %xcc, 10b /* CTI */
  200. srlx %g3, 32, %g3 /* IEU0 */
  201. andcc %g3, %g2, %g0 /* IEU1 Group */
  202. #endif
  203. be,pt %xcc, 12f /* CTI */
  204. srlx %o2, 56, %g3 /* IEU0 */
  205. andcc %g3, 0xff, %g0 /* IEU1 Group */
  206. be,pn %icc, 4b /* CTI */
  207. srlx %o2, 48, %g3 /* IEU0 */
  208. andcc %g3, 0xff, %g0 /* IEU1 Group */
  209. be,pn %icc, 4b /* CTI */
  210. srlx %o2, 40, %g3 /* IEU0 */
  211. andcc %g3, 0xff, %g0 /* IEU1 Group */
  212. be,pn %icc, 4b /* CTI */
  213. srlx %o2, 32, %g3 /* IEU0 */
  214. andcc %g3, 0xff, %g0 /* IEU1 Group */
  215. be,pn %icc, 4b /* CTI */
  216. 12: srlx %o2, 24, %g3 /* IEU0 */
  217. andcc %g3, 0xff, %g0 /* IEU1 Group */
  218. be,pn %icc, 4b /* CTI */
  219. srlx %o2, 16, %g3 /* IEU0 */
  220. andcc %g3, 0xff, %g0 /* IEU1 Group */
  221. be,pn %icc, 4b /* CTI */
  222. srlx %o2, 8, %g3 /* IEU0 */
  223. andcc %g3, 0xff, %g0 /* IEU1 Group */
  224. be,pn %icc, 4b /* CTI */
  225. andcc %o2, 0xff, %g0 /* IEU1 Group */
  226. be,pn %icc, 4b /* CTI */
  227. sllx %g6, %g5, %o3 /* IEU0 */
  228. ba,pt %xcc, 11b /* CTI Group */
  229. ldxa [%o1 + %o0] ASI_PNF, %g6 /* Load */
  230. END(strcmp)