stpcpy.S 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /* Copy SRC to DEST returning the address of the terminating '\0' in DEST.
  2. For SPARC v9.
  3. Copyright (C) 1998, 1999, 2002, 2003, 2004 Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. Contributed by Jan Vondrak <jvon4518@ss1000.ms.mff.cuni.cz> and
  6. Jakub Jelinek <jj@ultra.linux.cz>.
  7. The GNU C Library is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU Lesser General Public
  9. License as published by the Free Software Foundation; either
  10. version 2.1 of the License, or (at your option) any later version.
  11. The GNU C Library is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. Lesser General Public License for more details.
  15. You should have received a copy of the GNU Lesser General Public
  16. License along with the GNU C Library; if not, write to the Free
  17. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  18. 02111-1307 USA. */
  19. #include <asm/asi.h>
  20. #ifndef XCC
  21. .register %g2, #scratch
  22. .register %g3, #scratch
  23. .register %g6, #scratch
  24. #endif
  25. /* Normally, this uses
  26. ((xword - 0x0101010101010101) & 0x8080808080808080) test
  27. to find out if any byte in xword could be zero. This is fast, but
  28. also gives false alarm for any byte in range 0x81-0xff. It does
  29. not matter for correctness, as if this test tells us there could
  30. be some zero byte, we check it byte by byte, but if bytes with
  31. high bits set are common in the strings, then this will give poor
  32. performance. You can #define EIGHTBIT_NOT_RARE and the algorithm
  33. will use one tick slower, but more precise test
  34. ((xword - 0x0101010101010101) & (~xword) & 0x8080808080808080),
  35. which does not give any false alarms (but if some bits are set,
  36. one cannot assume from it which bytes are zero and which are not).
  37. It is yet to be measured, what is the correct default for glibc
  38. in these days for an average user.
  39. */
  40. .text
  41. .align 32
  42. ENTRY(__stpcpy)
  43. sethi %hi(0x01010101), %g1 /* IEU0 Group */
  44. or %g1, %lo(0x01010101), %g1 /* IEU0 Group */
  45. andcc %o0, 7, %g0 /* IEU1 */
  46. sllx %g1, 32, %g2 /* IEU0 Group */
  47. bne,pn %icc, 12f /* CTI */
  48. andcc %o1, 7, %g3 /* IEU1 */
  49. or %g1, %g2, %g1 /* IEU0 Group */
  50. bne,pn %icc, 14f /* CTI */
  51. sllx %g1, 7, %g2 /* IEU0 Group */
  52. 1: ldx [%o1], %o3 /* Load */
  53. add %o1, 8, %o1 /* IEU1 */
  54. 2: mov %o3, %g3 /* IEU0 Group */
  55. sub %o3, %g1, %o2 /* IEU1 */
  56. 3: ldxa [%o1] ASI_PNF, %o3 /* Load */
  57. #ifdef EIGHTBIT_NOT_RARE
  58. andn %o2, %g3, %o2 /* IEU0 Group */
  59. #endif
  60. add %o0, 8, %o0 /* IEU0 Group */
  61. andcc %o2, %g2, %g0 /* IEU1 */
  62. add %o1, 8, %o1 /* IEU0 Group */
  63. be,a,pt %xcc, 2b /* CTI */
  64. stx %g3, [%o0 - 8] /* Store */
  65. srlx %g3, 56, %g5 /* IEU0 Group */
  66. andcc %g5, 0xff, %g0 /* IEU1 Group */
  67. be,pn %icc, 11f /* CTI */
  68. srlx %g3, 48, %g4 /* IEU0 */
  69. andcc %g4, 0xff, %g0 /* IEU1 Group */
  70. be,pn %icc, 10f /* CTI */
  71. srlx %g3, 40, %g5 /* IEU0 */
  72. andcc %g5, 0xff, %g0 /* IEU1 Group */
  73. be,pn %icc, 9f /* CTI */
  74. srlx %g3, 32, %g4 /* IEU0 */
  75. andcc %g4, 0xff, %g0 /* IEU1 Group */
  76. be,pn %icc, 8f /* CTI */
  77. srlx %g3, 24, %g5 /* IEU0 */
  78. andcc %g5, 0xff, %g0 /* IEU1 Group */
  79. be,pn %icc, 7f /* CTI */
  80. srlx %g3, 16, %g4 /* IEU0 */
  81. andcc %g4, 0xff, %g0 /* IEU1 Group */
  82. be,pn %icc, 6f /* CTI */
  83. srlx %g3, 8, %g5 /* IEU0 */
  84. andcc %g5, 0xff, %g0 /* IEU1 Group */
  85. be,pn %icc, 5f /* CTI */
  86. sub %o3, %g1, %o2 /* IEU0 */
  87. stx %g3, [%o0 - 8] /* Store Group */
  88. andcc %g3, 0xff, %g0 /* IEU1 */
  89. bne,pt %icc, 3b /* CTI */
  90. mov %o3, %g3 /* IEU0 Group */
  91. 4: retl /* CTI+IEU1 Group */
  92. sub %o0, 1, %o0 /* IEU0 */
  93. .align 16
  94. 6: ba,pt %xcc, 23f /* CTI Group */
  95. sub %o0, 3, %g6 /* IEU0 */
  96. 5: sub %o0, 2, %g6 /* IEU0 Group */
  97. stb %g5, [%o0 - 2] /* Store */
  98. srlx %g3, 16, %g4 /* IEU0 Group */
  99. 23: sth %g4, [%o0 - 4] /* Store */
  100. srlx %g3, 32, %g4 /* IEU0 Group */
  101. stw %g4, [%o0 - 8] /* Store */
  102. retl /* CTI+IEU1 Group */
  103. mov %g6, %o0 /* IEU0 */
  104. 8: ba,pt %xcc, 24f /* CTI Group */
  105. sub %o0, 5, %g6 /* IEU0 */
  106. 7: sub %o0, 4, %g6 /* IEU0 Group */
  107. stb %g5, [%o0 - 4] /* Store */
  108. srlx %g3, 32, %g4 /* IEU0 Group */
  109. 24: stw %g4, [%o0 - 8] /* Store */
  110. retl /* CTI+IEU1 Group */
  111. mov %g6, %o0 /* IEU0 */
  112. 10: ba,pt %xcc, 25f /* CTI Group */
  113. sub %o0, 7, %g6 /* IEU0 */
  114. 9: sub %o0, 6, %g6 /* IEU0 Group */
  115. stb %g5, [%o0 - 6] /* Store */
  116. srlx %g3, 48, %g4 /* IEU0 */
  117. 25: sth %g4, [%o0 - 8] /* Store Group */
  118. retl /* CTI+IEU1 Group */
  119. mov %g6, %o0 /* IEU0 */
  120. 11: stb %g5, [%o0 - 8] /* Store Group */
  121. retl /* CTI+IEU1 Group */
  122. sub %o0, 8, %o0 /* IEU0 */
  123. .align 16
  124. 12: or %g1, %g2, %g1 /* IEU0 Group */
  125. ldub [%o1], %o3 /* Load */
  126. sllx %g1, 7, %g2 /* IEU0 Group */
  127. stb %o3, [%o0] /* Store Group */
  128. 13: add %o0, 1, %o0 /* IEU0 */
  129. add %o1, 1, %o1 /* IEU1 */
  130. andcc %o3, 0xff, %g0 /* IEU1 Group */
  131. be,pn %icc, 4b /* CTI */
  132. lduba [%o1] ASI_PNF, %o3 /* Load */
  133. andcc %o0, 7, %g0 /* IEU1 Group */
  134. bne,a,pt %icc, 13b /* CTI */
  135. stb %o3, [%o0] /* Store */
  136. andcc %o1, 7, %g3 /* IEU1 Group */
  137. be,a,pt %icc, 1b /* CTI */
  138. ldx [%o1], %o3 /* Load */
  139. 14: orcc %g0, 64, %g4 /* IEU1 Group */
  140. sllx %g3, 3, %g5 /* IEU0 */
  141. sub %o1, %g3, %o1 /* IEU0 Group */
  142. sub %g4, %g5, %g4 /* IEU1 */
  143. /* %g1 = 0101010101010101 *
  144. * %g2 = 8080808080808080 *
  145. * %g3 = source alignment *
  146. * %g5 = number of bits to shift left *
  147. * %g4 = number of bits to shift right */
  148. ldxa [%o1] ASI_PNF, %o5 /* Load Group */
  149. addcc %o1, 8, %o1 /* IEU1 */
  150. 15: sllx %o5, %g5, %o3 /* IEU0 Group */
  151. ldxa [%o1] ASI_PNF, %o5 /* Load */
  152. srlx %o5, %g4, %o4 /* IEU0 Group */
  153. add %o0, 8, %o0 /* IEU1 */
  154. or %o3, %o4, %o3 /* IEU0 Group */
  155. add %o1, 8, %o1 /* IEU1 */
  156. sub %o3, %g1, %o4 /* IEU0 Group */
  157. #ifdef EIGHTBIT_NOT_RARE
  158. andn %o4, %o3, %o4 /* IEU0 Group */
  159. #endif
  160. andcc %o4, %g2, %g0 /* IEU1 Group */
  161. be,a,pt %xcc, 15b /* CTI */
  162. stx %o3, [%o0 - 8] /* Store */
  163. srlx %o3, 56, %o4 /* IEU0 Group */
  164. andcc %o4, 0xff, %g0 /* IEU1 Group */
  165. be,pn %icc, 22f /* CTI */
  166. srlx %o3, 48, %o4 /* IEU0 */
  167. andcc %o4, 0xff, %g0 /* IEU1 Group */
  168. be,pn %icc, 21f /* CTI */
  169. srlx %o3, 40, %o4 /* IEU0 */
  170. andcc %o4, 0xff, %g0 /* IEU1 Group */
  171. be,pn %icc, 20f /* CTI */
  172. srlx %o3, 32, %o4 /* IEU0 */
  173. andcc %o4, 0xff, %g0 /* IEU1 Group */
  174. be,pn %icc, 19f /* CTI */
  175. srlx %o3, 24, %o4 /* IEU0 */
  176. andcc %o4, 0xff, %g0 /* IEU1 Group */
  177. be,pn %icc, 18f /* CTI */
  178. srlx %o3, 16, %o4 /* IEU0 */
  179. andcc %o4, 0xff, %g0 /* IEU1 Group */
  180. be,pn %icc, 17f /* CTI */
  181. srlx %o3, 8, %o4 /* IEU0 */
  182. andcc %o4, 0xff, %g0 /* IEU1 Group */
  183. be,pn %icc, 16f /* CTI */
  184. andcc %o3, 0xff, %g0 /* IEU1 Group */
  185. bne,pn %icc, 15b /* CTI */
  186. stx %o3, [%o0 - 8] /* Store */
  187. retl /* CTI+IEU1 Group */
  188. sub %o0, 1, %o0 /* IEU0 */
  189. .align 16
  190. 17: ba,pt %xcc, 26f /* CTI Group */
  191. subcc %o0, 3, %g6 /* IEU1 */
  192. 18: ba,pt %xcc, 27f /* CTI Group */
  193. subcc %o0, 4, %g6 /* IEU1 */
  194. 19: ba,pt %xcc, 28f /* CTI Group */
  195. subcc %o0, 5, %g6 /* IEU1 */
  196. 16: subcc %o0, 2, %g6 /* IEU1 Group */
  197. srlx %o3, 8, %o4 /* IEU0 */
  198. stb %o4, [%o0 - 2] /* Store */
  199. 26: srlx %o3, 16, %o4 /* IEU0 Group */
  200. stb %o4, [%o0 - 3] /* Store */
  201. 27: srlx %o3, 24, %o4 /* IEU0 Group */
  202. stb %o4, [%o0 - 4] /* Store */
  203. 28: srlx %o3, 32, %o4 /* IEU0 Group */
  204. stw %o4, [%o0 - 8] /* Store */
  205. retl /* CTI+IEU1 Group */
  206. mov %g6, %o0 /* IEU0 */
  207. .align 16
  208. 21: ba,pt %xcc, 29f /* CTI Group */
  209. subcc %o0, 7, %g6 /* IEU1 */
  210. 22: ba,pt %xcc, 30f /* CTI Group */
  211. subcc %o0, 8, %g6 /* IEU1 */
  212. 20: subcc %o0, 6, %g6 /* IEU1 Group */
  213. srlx %o3, 40, %o4 /* IEU0 */
  214. stb %o4, [%o0 - 6] /* Store */
  215. 29: srlx %o3, 48, %o4 /* IEU0 Group */
  216. stb %o4, [%o0 - 7] /* Store */
  217. 30: srlx %o3, 56, %o4 /* IEU0 Group */
  218. stb %o4, [%o0 - 8] /* Store */
  219. retl /* CTI+IEU1 Group */
  220. mov %g6, %o0 /* IEU0 */
  221. END(__stpcpy)
  222. strong_alias(__stpcpy,stpcpy)