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