strcpy.S 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /* Copy SRC to DEST returning 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. 1: ldub [%o1], %o5
  34. stb %o5, [%o0]
  35. cmp %o5, 0
  36. add %o0, 1, %o0
  37. be 0f
  38. add %o1, 1, %o1
  39. andcc %o1, 3, %g0
  40. be 4f
  41. or %o4, %lo(0x80808080), %o3
  42. ldub [%o1], %o5
  43. stb %o5, [%o0]
  44. cmp %o5, 0
  45. add %o0, 1, %o0
  46. be 0f
  47. add %o1, 1, %o1
  48. andcc %o1, 3, %g0
  49. be 5f
  50. sethi %hi(0x01010101), %o4
  51. ldub [%o1], %o5
  52. stb %o5, [%o0]
  53. cmp %o5, 0
  54. add %o0, 1, %o0
  55. be 0f
  56. add %o1, 1, %o1
  57. b 6f
  58. andcc %o0, 3, %g3
  59. ENTRY(strcpy)
  60. mov %o0, %g2
  61. andcc %o1, 3, %g0
  62. bne 1b
  63. sethi %hi(0x80808080), %o4
  64. or %o4, %lo(0x80808080), %o3
  65. 4: sethi %hi(0x01010101), %o4
  66. 5: andcc %o0, 3, %g3
  67. 6: bne 10f
  68. or %o4, %lo(0x01010101), %o2
  69. 1: ld [%o1], %o5
  70. add %o1, 4, %o1
  71. sub %o5, %o2, %o4
  72. add %o0, 4, %o0
  73. andcc %o4, %o3, %g0
  74. be,a 1b
  75. st %o5, [%o0 - 4]
  76. srl %o5, 24, %g5
  77. andcc %g5, 0xff, %g0
  78. be 1f
  79. srl %o5, 16, %g5
  80. andcc %g5, 0xff, %g0
  81. be 2f
  82. srl %o5, 8, %g5
  83. andcc %g5, 0xff, %g0
  84. be 3f
  85. andcc %o5, 0xff, %g0
  86. bne 1b
  87. st %o5, [%o0 - 4]
  88. retl
  89. mov %g2, %o0
  90. 3: srl %o5, 16, %o5
  91. sth %o5, [%o0 - 4]
  92. stb %g0, [%o0 - 2]
  93. retl
  94. mov %g2, %o0
  95. 2: srl %o5, 16, %o5
  96. sth %o5, [%o0 - 4]
  97. retl
  98. mov %g2, %o0
  99. 1: stb %g0, [%o0 - 4]
  100. retl
  101. mov %g2, %o0
  102. 10: ld [%o1], %o5
  103. add %o1, 4, %o1
  104. sub %o5, %o2, %o4
  105. cmp %g3, 2
  106. be 2f
  107. cmp %g3, 3
  108. be 3f
  109. andcc %o4, %o3, %g0
  110. bne 5f
  111. srl %o5, 24, %g5
  112. stb %g5, [%o0]
  113. sub %o0, 1, %o0
  114. srl %o5, 8, %g5
  115. sth %g5, [%o0 + 2]
  116. 1: add %o0, 4, %o0
  117. 4: sll %o5, 24, %g6
  118. ld [%o1], %o5
  119. add %o1, 4, %o1
  120. srl %o5, 8, %g5
  121. sub %o5, %o2, %o4
  122. or %g5, %g6, %g5
  123. andcc %o4, %o3, %g0
  124. be,a 1b
  125. st %g5, [%o0]
  126. srl %o5, 24, %o4
  127. andcc %o4, 0xff, %g0
  128. be 6f
  129. srl %o5, 16, %o4
  130. andcc %o4, 0xff, %g0
  131. be 7f
  132. srl %o5, 8, %o4
  133. st %g5, [%o0]
  134. andcc %o4, 0xff, %g0
  135. be 0f
  136. andcc %o5, 0xff, %g0
  137. 1: bne 4b
  138. add %o0, 4, %o0
  139. 9: stb %g0, [%o0]
  140. 0: retl
  141. mov %g2, %o0
  142. 6: srl %g5, 16, %g5
  143. sth %g5, [%o0]
  144. retl
  145. mov %g2, %o0
  146. 7: srl %g5, 16, %g5
  147. sth %g5, [%o0]
  148. stb %g0, [%o0 + 2]
  149. retl
  150. mov %g2, %o0
  151. 5: andcc %g5, 0xff, %g4
  152. be 9b
  153. srl %o5, 16, %g5
  154. andcc %g5, 0xff, %g0
  155. be 7f
  156. srl %o5, 8, %g5
  157. andcc %g5, 0xff, %g0
  158. stb %g4, [%o0]
  159. sth %g5, [%o0 + 1]
  160. sub %o0, 1, %o0
  161. bne 1b
  162. andcc %o5, 0xff, %g0
  163. retl
  164. mov %g2, %o0
  165. 7: stb %g4, [%o0]
  166. stb %g0, [%o0 + 1]
  167. retl
  168. mov %g2, %o0
  169. 2: andcc %o4, %o3, %g0
  170. bne 5f
  171. srl %o5, 16, %g5
  172. sth %g5, [%o0]
  173. sub %o0, 2, %o0
  174. 1: add %o0, 4, %o0
  175. 4: sll %o5, 16, %g6
  176. ld [%o1], %o5
  177. add %o1, 4, %o1
  178. srl %o5, 16, %g5
  179. sub %o5, %o2, %o4
  180. or %g5, %g6, %g5
  181. andcc %o4, %o3, %g0
  182. be,a 1b
  183. st %g5, [%o0]
  184. srl %o5, 24, %o4
  185. andcc %o4, 0xff, %g0
  186. be 7f
  187. srl %o5, 16, %o4
  188. st %g5, [%o0]
  189. andcc %o4, 0xff, %g0
  190. be 0b
  191. srl %o5, 8, %o4
  192. 1: andcc %o4, 0xff, %g0
  193. be 8f
  194. andcc %o5, 0xff, %g0
  195. bne 4b
  196. add %o0, 4, %o0
  197. sth %o5, [%o0]
  198. retl
  199. mov %g2, %o0
  200. 7: srl %g5, 16, %g5
  201. sth %g5, [%o0]
  202. stb %g0, [%o0 + 2]
  203. retl
  204. mov %g2, %o0
  205. 8: stb %g0, [%o0 + 4]
  206. retl
  207. mov %g2, %o0
  208. 5: srl %o5, 24, %g5
  209. andcc %g5, 0xff, %g0
  210. be 9b
  211. srl %o5, 16, %g5
  212. andcc %g5, 0xff, %g0
  213. sth %g5, [%o0]
  214. sub %o0, 2, %o0
  215. bne 1b
  216. srl %o5, 8, %o4
  217. retl
  218. mov %g2, %o0
  219. 3: bne 5f
  220. srl %o5, 24, %g5
  221. stb %g5, [%o0]
  222. sub %o0, 3, %o0
  223. 1: add %o0, 4, %o0
  224. 4: sll %o5, 8, %g6
  225. ld [%o1], %o5
  226. add %o1, 4, %o1
  227. srl %o5, 24, %g5
  228. sub %o5, %o2, %o4
  229. or %g5, %g6, %g5
  230. andcc %o4, %o3, %g0
  231. be 1b
  232. st %g5, [%o0]
  233. srl %o5, 24, %o4
  234. andcc %o4, 0xff, %g0
  235. be 0b
  236. srl %o5, 16, %o4
  237. 1: andcc %o4, 0xff, %g0
  238. be 8b
  239. srl %o5, 8, %o4
  240. andcc %o4, 0xff, %g0
  241. be 9f
  242. andcc %o5, 0xff, %g0
  243. bne 4b
  244. add %o0, 4, %o0
  245. srl %o5, 8, %o5
  246. sth %o5, [%o0]
  247. stb %g0, [%o0 + 2]
  248. retl
  249. mov %g2, %o0
  250. 9: srl %o5, 8, %o5
  251. sth %o5, [%o0 + 4]
  252. retl
  253. mov %g2, %o0
  254. 5: andcc %g5, 0xff, %g0
  255. stb %g5, [%o0]
  256. sub %o0, 3, %o0
  257. bne 1b
  258. srl %o5, 16, %o4
  259. retl
  260. mov %g2, %o0
  261. END(strcpy)
  262. libc_hidden_def(strcpy)