strcpy.S 5.6 KB

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