strcat.S 11 KB

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