strcat.S 11 KB

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