strcat.S 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. /* strcat (dest, src) -- Append SRC on the end of DEST.
  2. For SPARC v7.
  3. Copyright (C) 1996, 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>.
  6. The GNU C Library is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU Lesser General Public
  8. License as published by the Free Software Foundation; either
  9. version 2.1 of the License, or (at your option) any later version.
  10. The GNU C Library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public
  15. License along with the GNU C Library; if not, see
  16. <http://www.gnu.org/licenses/>. */
  17. /* Normally, this uses ((xword - 0x01010101) & 0x80808080) test
  18. to find out if any byte in xword could be zero. This is fast, but
  19. also gives false alarm for any byte in range 0x81-0xff. It does
  20. not matter for correctness, as if this test tells us there could
  21. be some zero byte, we check it byte by byte, but if bytes with
  22. high bits set are common in the strings, then this will give poor
  23. performance. You can #define EIGHTBIT_NOT_RARE and the algorithm
  24. will use one tick slower, but more precise test
  25. ((xword - 0x01010101) & (~xword) & 0x80808080),
  26. which does not give any false alarms (but if some bits are set,
  27. one cannot assume from it which bytes are zero and which are not).
  28. It is yet to be measured, what is the correct default for glibc
  29. in these days for an average user.
  30. */
  31. .text
  32. .align 4
  33. 10: cmp %o4, 2
  34. be 1f
  35. cmp %o4, 3
  36. ldub [%o1], %o5
  37. add %o1, 1, %o1
  38. stb %o5, [%o0]
  39. be 3f
  40. cmp %o5, 0
  41. be 0f
  42. add %o0, 1, %o0
  43. 1: lduh [%o1], %o5
  44. add %o1, 2, %o1
  45. srl %o5, 8, %o4
  46. cmp %o4, 0
  47. stb %o4, [%o0]
  48. bne,a 2f
  49. stb %o5, [%o0 + 1]
  50. retl
  51. mov %g2, %o0
  52. 2: andcc %o5, 0xff, %o5
  53. bne 4f
  54. add %o0, 2, %o0
  55. retl
  56. mov %g2, %o0
  57. 3: bne 4f
  58. add %o0, 1, %o0
  59. retl
  60. mov %g2, %o0
  61. 11: ldub [%o0], %o5
  62. cmp %o5, 0
  63. be 1f
  64. add %o0, 1, %o0
  65. andcc %o0, 3, %g0
  66. be 7f
  67. or %o4, %lo(0x80808080), %o3
  68. ldub [%o0], %o5
  69. cmp %o5, 0
  70. be 2f
  71. add %o0, 1, %o0
  72. andcc %o0, 3, %g0
  73. be 8f
  74. sethi %hi(0x01010101), %o4
  75. ldub [%o0], %o5
  76. cmp %o5, 0
  77. be 3f
  78. add %o0, 1, %o0
  79. b 9f
  80. or %o4, %lo(0x01010101), %o2
  81. 1: or %o4, %lo(0x80808080), %o3
  82. 2: sethi %hi(0x01010101), %o4
  83. 3: or %o4, %lo(0x01010101), %o2
  84. b 3f
  85. sub %o0, 1, %o0
  86. ENTRY(strcat)
  87. mov %o0, %g2
  88. andcc %o0, 3, %g0
  89. bne 11b
  90. sethi %hi(0x80808080), %o4
  91. or %o4, %lo(0x80808080), %o3
  92. 7: sethi %hi(0x01010101), %o4
  93. 8: or %o4, %lo(0x01010101), %o2
  94. 9: ld [%o0], %o5
  95. 7: sub %o5, %o2, %o4
  96. #ifdef EIGHTBIT_NOT_RARE
  97. andn %o4, %o5, %o4
  98. #endif
  99. andcc %o4, %o3, %g0
  100. be 9b
  101. add %o0, 4, %o0
  102. srl %o5, 24, %g5
  103. andcc %g5, 0xff, %g0
  104. be 3f
  105. add %o0, -4, %o0
  106. srl %o5, 16, %g5
  107. andcc %g5, 0xff, %g0
  108. be 3f
  109. add %o0, 1, %o0
  110. srl %o5, 8, %g5
  111. andcc %g5, 0xff, %g0
  112. be 3f
  113. add %o0, 1, %o0
  114. andcc %o5, 0xff, %g0
  115. add %o0, 2, %o0
  116. bne,a 7b
  117. ld [%o0], %o5
  118. sub %o0, 1, %o0
  119. 3: andcc %o1, 3, %o4
  120. bne 10b
  121. 4: andcc %o0, 3, %g3
  122. bne 12f
  123. 1: ld [%o1], %o5
  124. add %o1, 4, %o1
  125. sub %o5, %o2, %o4
  126. #ifdef EIGHTBIT_NOT_RARE
  127. andn %o4, %o5, %o4
  128. #endif
  129. add %o0, 4, %o0
  130. andcc %o4, %o3, %g0
  131. be,a 1b
  132. st %o5, [%o0 - 4]
  133. srl %o5, 24, %g5
  134. andcc %g5, 0xff, %g0
  135. be 1f
  136. srl %o5, 16, %g5
  137. andcc %g5, 0xff, %g0
  138. be 2f
  139. srl %o5, 8, %g5
  140. andcc %g5, 0xff, %g0
  141. be 3f
  142. andcc %o5, 0xff, %g0
  143. bne 1b
  144. st %o5, [%o0 - 4]
  145. retl
  146. mov %g2, %o0
  147. 3: srl %o5, 16, %o5
  148. sth %o5, [%o0 - 4]
  149. stb %g0, [%o0 - 2]
  150. retl
  151. mov %g2, %o0
  152. 2: srl %o5, 16, %o5
  153. sth %o5, [%o0 - 4]
  154. retl
  155. mov %g2, %o0
  156. 1: stb %g0, [%o0 - 4]
  157. retl
  158. mov %g2, %o0
  159. 12: add %o1, 4, %o1
  160. sub %o5, %o2, %o4
  161. cmp %g3, 2
  162. be 2f
  163. cmp %g3, 3
  164. be 3f
  165. andcc %o4, %o3, %g0
  166. bne 5f
  167. srl %o5, 24, %g5
  168. stb %g5, [%o0]
  169. sub %o0, 1, %o0
  170. srl %o5, 8, %g5
  171. sth %g5, [%o0 + 2]
  172. 1: add %o0, 4, %o0
  173. 4: sll %o5, 24, %g6
  174. ld [%o1], %o5
  175. add %o1, 4, %o1
  176. srl %o5, 8, %g5
  177. sub %o5, %o2, %o4
  178. #ifdef EIGHTBIT_NOT_RARE
  179. andn %o4, %o5, %o4
  180. #endif
  181. or %g5, %g6, %g5
  182. andcc %o4, %o3, %g0
  183. be,a 1b
  184. st %g5, [%o0]
  185. srl %o5, 24, %o4
  186. andcc %o4, 0xff, %g0
  187. be 6f
  188. srl %o5, 16, %o4
  189. andcc %o4, 0xff, %g0
  190. be 7f
  191. srl %o5, 8, %o4
  192. st %g5, [%o0]
  193. andcc %o4, 0xff, %g0
  194. be 0f
  195. andcc %o5, 0xff, %g0
  196. 1: bne 4b
  197. add %o0, 4, %o0
  198. 9: stb %g0, [%o0]
  199. 0: retl
  200. mov %g2, %o0
  201. 6: srl %g5, 16, %g5
  202. sth %g5, [%o0]
  203. retl
  204. mov %g2, %o0
  205. 7: srl %g5, 16, %g5
  206. sth %g5, [%o0]
  207. stb %g0, [%o0 + 2]
  208. retl
  209. mov %g2, %o0
  210. 5: andcc %g5, 0xff, %g4
  211. be 9b
  212. srl %o5, 16, %g5
  213. andcc %g5, 0xff, %g0
  214. be 7f
  215. srl %o5, 8, %g5
  216. andcc %g5, 0xff, %g0
  217. stb %g4, [%o0]
  218. sth %g5, [%o0 + 1]
  219. sub %o0, 1, %o0
  220. bne 1b
  221. andcc %o5, 0xff, %g0
  222. retl
  223. mov %g2, %o0
  224. 7: stb %g4, [%o0]
  225. stb %g0, [%o0 + 1]
  226. retl
  227. mov %g2, %o0
  228. 2: andcc %o4, %o3, %g0
  229. bne 5f
  230. srl %o5, 16, %g5
  231. sth %g5, [%o0]
  232. sub %o0, 2, %o0
  233. 1: add %o0, 4, %o0
  234. 4: sll %o5, 16, %g6
  235. ld [%o1], %o5
  236. add %o1, 4, %o1
  237. srl %o5, 16, %g5
  238. sub %o5, %o2, %o4
  239. #ifdef EIGHTBIT_NOT_RARE
  240. andn %o4, %o5, %o4
  241. #endif
  242. or %g5, %g6, %g5
  243. andcc %o4, %o3, %g0
  244. be,a 1b
  245. st %g5, [%o0]
  246. srl %o5, 24, %o4
  247. andcc %o4, 0xff, %g0
  248. be 7f
  249. srl %o5, 16, %o4
  250. st %g5, [%o0]
  251. andcc %o4, 0xff, %g0
  252. be 0b
  253. srl %o5, 8, %o4
  254. 1: andcc %o4, 0xff, %g0
  255. be 8f
  256. andcc %o5, 0xff, %g0
  257. bne 4b
  258. add %o0, 4, %o0
  259. sth %o5, [%o0]
  260. retl
  261. mov %g2, %o0
  262. 7: srl %g5, 16, %g5
  263. sth %g5, [%o0]
  264. stb %g0, [%o0 + 2]
  265. retl
  266. mov %g2, %o0
  267. 8: stb %g0, [%o0 + 4]
  268. retl
  269. mov %g2, %o0
  270. 5: srl %o5, 24, %g5
  271. andcc %g5, 0xff, %g0
  272. be 9b
  273. srl %o5, 16, %g5
  274. andcc %g5, 0xff, %g0
  275. sth %g5, [%o0]
  276. sub %o0, 2, %o0
  277. bne 1b
  278. srl %o5, 8, %o4
  279. retl
  280. mov %g2, %o0
  281. 3: bne 5f
  282. srl %o5, 24, %g5
  283. stb %g5, [%o0]
  284. sub %o0, 3, %o0
  285. 1: add %o0, 4, %o0
  286. 4: sll %o5, 8, %g6
  287. ld [%o1], %o5
  288. add %o1, 4, %o1
  289. srl %o5, 24, %g5
  290. sub %o5, %o2, %o4
  291. #ifdef EIGHTBIT_NOT_RARE
  292. andn %o4, %o5, %o4
  293. #endif
  294. or %g5, %g6, %g5
  295. andcc %o4, %o3, %g0
  296. be 1b
  297. st %g5, [%o0]
  298. srl %o5, 24, %o4
  299. andcc %o4, 0xff, %g0
  300. be 0b
  301. srl %o5, 16, %o4
  302. 1: andcc %o4, 0xff, %g0
  303. be 8b
  304. srl %o5, 8, %o4
  305. andcc %o4, 0xff, %g0
  306. be 9f
  307. andcc %o5, 0xff, %g0
  308. bne 4b
  309. add %o0, 4, %o0
  310. srl %o5, 8, %o5
  311. sth %o5, [%o0]
  312. stb %g0, [%o0 + 2]
  313. retl
  314. mov %g2, %o0
  315. 9: srl %o5, 8, %o5
  316. sth %o5, [%o0 + 4]
  317. retl
  318. mov %g2, %o0
  319. 5: andcc %g5, 0xff, %g0
  320. stb %g5, [%o0]
  321. sub %o0, 3, %o0
  322. bne 1b
  323. srl %o5, 16, %o4
  324. retl
  325. mov %g2, %o0
  326. END(strcat)
  327. libc_hidden_def(strcat)