strcmp.S 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. .globl strcmp
  43. .set strcmp,__strcmp
  44. .hidden __strcmp
  45. ENTRY(__strcmp)
  46. sethi %hi(0x01010101), %g1 /* IEU0 Group */
  47. andcc %o0, 7, %g0 /* IEU1 */
  48. bne,pn %icc, 7f /* CTI */
  49. or %g1, %lo(0x01010101), %g1 /* IEU0 Group */
  50. andcc %o1, 7, %g3 /* IEU1 */
  51. bne,pn %icc, 9f /* CTI */
  52. sllx %g1, 32, %g2 /* IEU0 Group */
  53. ldx [%o0], %o2 /* Load */
  54. or %g1, %g2, %g1 /* IEU0 Group */
  55. 1: ldx [%o1], %o3 /* Load */
  56. sub %o1, %o0, %o1 /* IEU1 */
  57. sllx %g1, 7, %g2 /* IEU0 Group */
  58. 2: add %o0, 8, %o0 /* IEU1 */
  59. sub %o2, %g1, %g3 /* IEU0 Group */
  60. subcc %o2, %o3, %g0 /* IEU1 */
  61. bne,pn %xcc, 13f /* CTI */
  62. #ifdef EIGHTBIT_NOT_RARE
  63. andn %g3, %o2, %g4 /* IEU0 Group */
  64. ldxa [%o0] ASI_PNF, %o2 /* Load */
  65. andcc %g4, %g2, %g0 /* IEU1 Group */
  66. #else
  67. ldxa [%o0] ASI_PNF, %o2 /* Load Group */
  68. andcc %g3, %g2, %g0 /* IEU1 */
  69. #endif
  70. be,a,pt %xcc, 2b /* CTI */
  71. ldxa [%o1 + %o0] ASI_PNF, %o3 /* Load Group */
  72. addcc %g3, %g1, %o4 /* IEU1 */
  73. srlx %g3, 32, %g3 /* IEU0 */
  74. andcc %g3, %g2, %g0 /* IEU1 Group */
  75. be,pt %xcc, 3f /* CTI */
  76. srlx %o4, 56, %o5 /* IEU0 */
  77. andcc %o5, 0xff, %g0 /* IEU1 Group */
  78. be,pn %icc, 4f /* CTI */
  79. srlx %o4, 48, %o5 /* IEU0 */
  80. andcc %o5, 0xff, %g0 /* IEU1 Group */
  81. be,pn %icc, 4f /* CTI */
  82. srlx %o4, 40, %o5 /* IEU0 */
  83. andcc %o5, 0xff, %g0 /* IEU1 Group */
  84. be,pn %icc, 4f /* CTI */
  85. srlx %o4, 32, %o5 /* IEU0 */
  86. andcc %o5, 0xff, %g0 /* IEU1 Group */
  87. be,pn %icc, 4f /* CTI */
  88. 3: srlx %o4, 24, %o5 /* IEU0 */
  89. andcc %o5, 0xff, %g0 /* IEU1 Group */
  90. be,pn %icc, 4f /* CTI */
  91. srlx %o4, 16, %o5 /* IEU0 */
  92. andcc %o5, 0xff, %g0 /* IEU1 Group */
  93. be,pn %icc, 4f /* CTI */
  94. srlx %o4, 8, %o5 /* IEU0 */
  95. andcc %o5, 0xff, %g0 /* IEU1 Group */
  96. be,pn %icc, 4f /* CTI */
  97. andcc %o4, 0xff, %g0 /* IEU1 Group */
  98. bne,a,pn %icc, 2b /* CTI */
  99. ldxa [%o1 + %o0] ASI_PNF, %o3 /* Load */
  100. 4: retl /* CTI+IEU1 Group */
  101. clr %o0 /* IEU0 */
  102. .align 32
  103. 13: mov 0xff, %g6 /* IEU0 Group */
  104. #ifdef EIGHTBIT_NOT_RARE
  105. andcc %g4, %g2, %g0 /* IEU1 */
  106. #else
  107. andcc %g3, %g2, %g0 /* IEU1 */
  108. #endif
  109. be,pt %xcc, 25f /* CTI */
  110. addcc %g3, %g1, %o4 /* IEU1 Group */
  111. srlx %g3, 32, %g3 /* IEU0 */
  112. andcc %g3, %g2, %g0 /* IEU1 Group */
  113. be,pt %xcc, 23f /* CTI */
  114. sllx %g6, 56, %o5 /* IEU0 */
  115. andcc %o4, %o5, %g0 /* IEU1 Group */
  116. be,pn %xcc, 24f /* CTI */
  117. sllx %g6, 48, %o5 /* IEU0 */
  118. andcc %o4, %o5, %g0 /* IEU1 Group */
  119. be,pn %xcc, 24f /* CTI */
  120. sllx %g6, 40, %o5 /* IEU0 */
  121. andcc %o4, %o5, %g0 /* IEU1 Group */
  122. be,pn %xcc, 24f /* CTI */
  123. sllx %g6, 32, %o5 /* IEU0 */
  124. andcc %o4, %o5, %g0 /* IEU1 Group */
  125. be,pn %xcc, 24f /* CTI */
  126. 23: sllx %g6, 24, %o5 /* IEU0 */
  127. andcc %o4, %o5, %g0 /* IEU1 Group */
  128. be,pn %icc, 24f /* CTI */
  129. sllx %g6, 16, %o5 /* IEU0 */
  130. andcc %o4, %o5, %g0 /* IEU1 Group */
  131. be,pn %icc, 24f /* CTI */
  132. sllx %g6, 8, %o5 /* IEU0 */
  133. andcc %o4, %o5, %g0 /* IEU1 Group */
  134. be,pn %icc, 24f /* CTI */
  135. mov %g6, %o5 /* IEU0 */
  136. 25: cmp %o4, %o3 /* IEU1 Group */
  137. 5: mov -1, %o0 /* IEU0 */
  138. retl /* CTI+IEU1 Group */
  139. movgu %xcc, 1, %o0 /* Single Group */
  140. .align 16
  141. 24: sub %o5, 1, %g6 /* IEU0 Group */
  142. clr %o0 /* IEU1 */
  143. or %o5, %g6, %o5 /* IEU0 Group */
  144. andn %o4, %o5, %o4 /* IEU0 Group */
  145. andn %o3, %o5, %o3 /* IEU1 */
  146. cmp %o4, %o3 /* IEU1 Group */
  147. movgu %xcc, 1, %o0 /* Single Group */
  148. retl /* CTI+IEU1 Group */
  149. movlu %xcc, -1, %o0 /* Single Group */
  150. 6: retl /* CTI+IEU1 Group */
  151. mov %o4, %o0 /* IEU0 */
  152. .align 16
  153. 7: ldub [%o0], %o2 /* Load */
  154. add %o0, 1, %o0 /* IEU1 */
  155. ldub [%o1], %o3 /* Load Group */
  156. sllx %g1, 32, %g2 /* IEU0 */
  157. 8: add %o1, 1, %o1 /* IEU1 */
  158. subcc %o2, %o3, %o4 /* IEU1 Group */
  159. bne,pn %xcc, 6b /* CTI */
  160. lduba [%o0] ASI_PNF, %o2 /* Load */
  161. brz,pn %o3, 4b /* CTI+IEU1 Group */
  162. lduba [%o1] ASI_PNF, %o3 /* Load */
  163. andcc %o0, 7, %g0 /* IEU1 Group */
  164. bne,a,pn %icc, 8b /* CTI */
  165. add %o0, 1, %o0 /* IEU0 */
  166. or %g1, %g2, %g1 /* IEU0 Group */
  167. andcc %o1, 7, %g3 /* IEU1 */
  168. be,a,pn %icc, 1b /* CTI */
  169. ldxa [%o0] ASI_PNF, %o2 /* Load Group */
  170. 9: sllx %g3, 3, %g5 /* IEU0 */
  171. mov 64, %o5 /* IEU1 */
  172. sub %o1, %g3, %o1 /* IEU0 Group */
  173. sub %o5, %g5, %o5 /* IEU1 */
  174. ldxa [%o1] ASI_PNF, %g6 /* Load Group */
  175. or %g1, %g2, %g1 /* IEU0 */
  176. sub %o1, %o0, %o1 /* IEU1 */
  177. sllx %g1, 7, %g2 /* IEU0 Group */
  178. add %o1, 8, %o1 /* IEU1 */
  179. /* %g1 = 0101010101010101
  180. * %g2 = 8080808080800880
  181. * %g5 = number of bits to shift left
  182. * %o5 = number of bits to shift right */
  183. 10: sllx %g6, %g5, %o3 /* IEU0 Group */
  184. ldxa [%o1 + %o0] ASI_PNF, %g6 /* Load */
  185. 11: srlx %g6, %o5, %o4 /* IEU0 Group */
  186. ldxa [%o0] ASI_PNF, %o2 /* Load */
  187. or %o3, %o4, %o3 /* IEU1 */
  188. add %o0, 8, %o0 /* IEU0 Group */
  189. subcc %o2, %o3, %g0 /* IEU1 */
  190. #ifdef EIGHTBIT_NOT_RARE
  191. sub %o2, %g1, %g3 /* IEU0 Group */
  192. bne,pn %xcc, 13b /* CTI */
  193. andn %g3, %o2, %g4 /* IEU0 Group */
  194. andcc %g4, %g2, %g0 /* IEU1 Group */
  195. be,pt %xcc, 10b /* CTI */
  196. srlx %g4, 32, %g4 /* IEU0 */
  197. andcc %g4, %g2, %g0 /* IEU1 Group */
  198. #else
  199. bne,pn %xcc, 13b /* CTI */
  200. sub %o2, %g1, %g3 /* IEU0 Group */
  201. andcc %g3, %g2, %g0 /* IEU1 Group */
  202. be,pt %xcc, 10b /* CTI */
  203. srlx %g3, 32, %g3 /* IEU0 */
  204. andcc %g3, %g2, %g0 /* IEU1 Group */
  205. #endif
  206. be,pt %xcc, 12f /* CTI */
  207. srlx %o2, 56, %g3 /* IEU0 */
  208. andcc %g3, 0xff, %g0 /* IEU1 Group */
  209. be,pn %icc, 4b /* CTI */
  210. srlx %o2, 48, %g3 /* IEU0 */
  211. andcc %g3, 0xff, %g0 /* IEU1 Group */
  212. be,pn %icc, 4b /* CTI */
  213. srlx %o2, 40, %g3 /* IEU0 */
  214. andcc %g3, 0xff, %g0 /* IEU1 Group */
  215. be,pn %icc, 4b /* CTI */
  216. srlx %o2, 32, %g3 /* IEU0 */
  217. andcc %g3, 0xff, %g0 /* IEU1 Group */
  218. be,pn %icc, 4b /* CTI */
  219. 12: srlx %o2, 24, %g3 /* IEU0 */
  220. andcc %g3, 0xff, %g0 /* IEU1 Group */
  221. be,pn %icc, 4b /* CTI */
  222. srlx %o2, 16, %g3 /* IEU0 */
  223. andcc %g3, 0xff, %g0 /* IEU1 Group */
  224. be,pn %icc, 4b /* CTI */
  225. srlx %o2, 8, %g3 /* IEU0 */
  226. andcc %g3, 0xff, %g0 /* IEU1 Group */
  227. be,pn %icc, 4b /* CTI */
  228. andcc %o2, 0xff, %g0 /* IEU1 Group */
  229. be,pn %icc, 4b /* CTI */
  230. sllx %g6, %g5, %o3 /* IEU0 */
  231. ba,pt %xcc, 11b /* CTI Group */
  232. ldxa [%o1 + %o0] ASI_PNF, %g6 /* Load */
  233. END(__strcmp)