strcat.S 6.7 KB

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