strcat.S 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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. .globl strcat
  88. .set strcat,__strcat
  89. .hidden __strcat
  90. ENTRY(__strcat)
  91. mov %o0, %g2
  92. andcc %o0, 3, %g0
  93. bne 11b
  94. sethi %hi(0x80808080), %o4
  95. or %o4, %lo(0x80808080), %o3
  96. 7: sethi %hi(0x01010101), %o4
  97. 8: or %o4, %lo(0x01010101), %o2
  98. 9: ld [%o0], %o5
  99. 7: sub %o5, %o2, %o4
  100. #ifdef EIGHTBIT_NOT_RARE
  101. andn %o4, %o5, %o4
  102. #endif
  103. andcc %o4, %o3, %g0
  104. be 9b
  105. add %o0, 4, %o0
  106. srl %o5, 24, %g5
  107. andcc %g5, 0xff, %g0
  108. be 3f
  109. add %o0, -4, %o0
  110. srl %o5, 16, %g5
  111. andcc %g5, 0xff, %g0
  112. be 3f
  113. add %o0, 1, %o0
  114. srl %o5, 8, %g5
  115. andcc %g5, 0xff, %g0
  116. be 3f
  117. add %o0, 1, %o0
  118. andcc %o5, 0xff, %g0
  119. add %o0, 2, %o0
  120. bne,a 7b
  121. ld [%o0], %o5
  122. sub %o0, 1, %o0
  123. 3: andcc %o1, 3, %o4
  124. bne 10b
  125. 4: andcc %o0, 3, %g3
  126. bne 12f
  127. 1: ld [%o1], %o5
  128. add %o1, 4, %o1
  129. sub %o5, %o2, %o4
  130. #ifdef EIGHTBIT_NOT_RARE
  131. andn %o4, %o5, %o4
  132. #endif
  133. add %o0, 4, %o0
  134. andcc %o4, %o3, %g0
  135. be,a 1b
  136. st %o5, [%o0 - 4]
  137. srl %o5, 24, %g5
  138. andcc %g5, 0xff, %g0
  139. be 1f
  140. srl %o5, 16, %g5
  141. andcc %g5, 0xff, %g0
  142. be 2f
  143. srl %o5, 8, %g5
  144. andcc %g5, 0xff, %g0
  145. be 3f
  146. andcc %o5, 0xff, %g0
  147. bne 1b
  148. st %o5, [%o0 - 4]
  149. retl
  150. mov %g2, %o0
  151. 3: srl %o5, 16, %o5
  152. sth %o5, [%o0 - 4]
  153. stb %g0, [%o0 - 2]
  154. retl
  155. mov %g2, %o0
  156. 2: srl %o5, 16, %o5
  157. sth %o5, [%o0 - 4]
  158. retl
  159. mov %g2, %o0
  160. 1: stb %g0, [%o0 - 4]
  161. retl
  162. mov %g2, %o0
  163. 12: add %o1, 4, %o1
  164. sub %o5, %o2, %o4
  165. cmp %g3, 2
  166. be 2f
  167. cmp %g3, 3
  168. be 3f
  169. andcc %o4, %o3, %g0
  170. bne 5f
  171. srl %o5, 24, %g5
  172. stb %g5, [%o0]
  173. sub %o0, 1, %o0
  174. srl %o5, 8, %g5
  175. sth %g5, [%o0 + 2]
  176. 1: add %o0, 4, %o0
  177. 4: sll %o5, 24, %g6
  178. ld [%o1], %o5
  179. add %o1, 4, %o1
  180. srl %o5, 8, %g5
  181. sub %o5, %o2, %o4
  182. #ifdef EIGHTBIT_NOT_RARE
  183. andn %o4, %o5, %o4
  184. #endif
  185. or %g5, %g6, %g5
  186. andcc %o4, %o3, %g0
  187. be,a 1b
  188. st %g5, [%o0]
  189. srl %o5, 24, %o4
  190. andcc %o4, 0xff, %g0
  191. be 6f
  192. srl %o5, 16, %o4
  193. andcc %o4, 0xff, %g0
  194. be 7f
  195. srl %o5, 8, %o4
  196. st %g5, [%o0]
  197. andcc %o4, 0xff, %g0
  198. be 0f
  199. andcc %o5, 0xff, %g0
  200. 1: bne 4b
  201. add %o0, 4, %o0
  202. 9: stb %g0, [%o0]
  203. 0: retl
  204. mov %g2, %o0
  205. 6: srl %g5, 16, %g5
  206. sth %g5, [%o0]
  207. retl
  208. mov %g2, %o0
  209. 7: srl %g5, 16, %g5
  210. sth %g5, [%o0]
  211. stb %g0, [%o0 + 2]
  212. retl
  213. mov %g2, %o0
  214. 5: andcc %g5, 0xff, %g4
  215. be 9b
  216. srl %o5, 16, %g5
  217. andcc %g5, 0xff, %g0
  218. be 7f
  219. srl %o5, 8, %g5
  220. andcc %g5, 0xff, %g0
  221. stb %g4, [%o0]
  222. sth %g5, [%o0 + 1]
  223. sub %o0, 1, %o0
  224. bne 1b
  225. andcc %o5, 0xff, %g0
  226. retl
  227. mov %g2, %o0
  228. 7: stb %g4, [%o0]
  229. stb %g0, [%o0 + 1]
  230. retl
  231. mov %g2, %o0
  232. 2: andcc %o4, %o3, %g0
  233. bne 5f
  234. srl %o5, 16, %g5
  235. sth %g5, [%o0]
  236. sub %o0, 2, %o0
  237. 1: add %o0, 4, %o0
  238. 4: sll %o5, 16, %g6
  239. ld [%o1], %o5
  240. add %o1, 4, %o1
  241. srl %o5, 16, %g5
  242. sub %o5, %o2, %o4
  243. #ifdef EIGHTBIT_NOT_RARE
  244. andn %o4, %o5, %o4
  245. #endif
  246. or %g5, %g6, %g5
  247. andcc %o4, %o3, %g0
  248. be,a 1b
  249. st %g5, [%o0]
  250. srl %o5, 24, %o4
  251. andcc %o4, 0xff, %g0
  252. be 7f
  253. srl %o5, 16, %o4
  254. st %g5, [%o0]
  255. andcc %o4, 0xff, %g0
  256. be 0b
  257. srl %o5, 8, %o4
  258. 1: andcc %o4, 0xff, %g0
  259. be 8f
  260. andcc %o5, 0xff, %g0
  261. bne 4b
  262. add %o0, 4, %o0
  263. sth %o5, [%o0]
  264. retl
  265. mov %g2, %o0
  266. 7: srl %g5, 16, %g5
  267. sth %g5, [%o0]
  268. stb %g0, [%o0 + 2]
  269. retl
  270. mov %g2, %o0
  271. 8: stb %g0, [%o0 + 4]
  272. retl
  273. mov %g2, %o0
  274. 5: srl %o5, 24, %g5
  275. andcc %g5, 0xff, %g0
  276. be 9b
  277. srl %o5, 16, %g5
  278. andcc %g5, 0xff, %g0
  279. sth %g5, [%o0]
  280. sub %o0, 2, %o0
  281. bne 1b
  282. srl %o5, 8, %o4
  283. retl
  284. mov %g2, %o0
  285. 3: bne 5f
  286. srl %o5, 24, %g5
  287. stb %g5, [%o0]
  288. sub %o0, 3, %o0
  289. 1: add %o0, 4, %o0
  290. 4: sll %o5, 8, %g6
  291. ld [%o1], %o5
  292. add %o1, 4, %o1
  293. srl %o5, 24, %g5
  294. sub %o5, %o2, %o4
  295. #ifdef EIGHTBIT_NOT_RARE
  296. andn %o4, %o5, %o4
  297. #endif
  298. or %g5, %g6, %g5
  299. andcc %o4, %o3, %g0
  300. be 1b
  301. st %g5, [%o0]
  302. srl %o5, 24, %o4
  303. andcc %o4, 0xff, %g0
  304. be 0b
  305. srl %o5, 16, %o4
  306. 1: andcc %o4, 0xff, %g0
  307. be 8b
  308. srl %o5, 8, %o4
  309. andcc %o4, 0xff, %g0
  310. be 9f
  311. andcc %o5, 0xff, %g0
  312. bne 4b
  313. add %o0, 4, %o0
  314. srl %o5, 8, %o5
  315. sth %o5, [%o0]
  316. stb %g0, [%o0 + 2]
  317. retl
  318. mov %g2, %o0
  319. 9: srl %o5, 8, %o5
  320. sth %o5, [%o0 + 4]
  321. retl
  322. mov %g2, %o0
  323. 5: andcc %g5, 0xff, %g0
  324. stb %g5, [%o0]
  325. sub %o0, 3, %o0
  326. bne 1b
  327. srl %o5, 16, %o4
  328. retl
  329. mov %g2, %o0
  330. END(__strcat)