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