U3memcpy.S
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:12k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. /* $Id: U3memcpy.S,v 1.2 2000/11/01 09:29:19 davem Exp $
  2.  * U3memcpy.S: UltraSparc-III optimized memcpy.
  3.  *
  4.  * Copyright (C) 1999, 2000 David S. Miller (davem@redhat.com)
  5.  */
  6. #ifdef __KERNEL__
  7. #include <asm/visasm.h>
  8. #include <asm/asi.h>
  9. #undef SMALL_COPY_USES_FPU
  10. #else
  11. #define ASI_BLK_P 0xf0
  12. #define FPRS_FEF  0x04
  13. #define VISEntryHalf rd %fprs, %o5; wr %g0, FPRS_FEF, %fprs
  14. #define VISExitHalf and %o5, FPRS_FEF, %o5; wr %o5, 0x0, %fprs
  15. #define SMALL_COPY_USES_FPU
  16. #endif
  17. /* Special/non-trivial issues of this code:
  18.  *
  19.  * 1) %o5 is preserved from VISEntryHalf to VISExitHalf
  20.  * 2) Only low 32 FPU registers are used so that only the
  21.  *    lower half of the FPU register set is dirtied by this
  22.  *    code.  This is especially important in the kernel.
  23.  * 3) This code never prefetches cachelines past the end
  24.  *    of the source buffer.
  25.  */
  26. .text
  27. .align 32
  28. /* The cheetah's flexible spine, oversized liver, enlarged heart,
  29.  * slender muscular body, and claws make it the swiftest hunter
  30.  * in Africa and the fastest animal on land.  Can reach speeds
  31.  * of up to 2.4GB per second.
  32.  */
  33. .globl U3memcpy
  34. U3memcpy: /* %o0=dst, %o1=src, %o2=len */
  35. #ifndef __KERNEL__
  36. /* Save away original 'dst' for memcpy return value. */
  37. mov %o0, %g3 ! A0 Group
  38. #endif
  39. /* Anything to copy at all? */
  40. cmp %o2, 0 ! A1
  41. ble,pn %icc, U3memcpy_short_ret ! BR
  42. /* Extremely small copy? */
  43.  cmp %o2, 31 ! A0 Group
  44. ble,pn %icc, U3memcpy_short ! BR
  45. /* Large enough to use unrolled prefetch loops? */
  46.  cmp %o2, 0x100 ! A1
  47. bge,a,pt %icc, U3memcpy_enter ! BR Group
  48.  andcc %o0, 0x3f, %g2 ! A0
  49. ba,pt %xcc, U3memcpy_toosmall ! BR Group
  50.  andcc %o0, 0x7, %g2 ! A0
  51. .align 32
  52. U3memcpy_short:
  53. /* Copy %o2 bytes from src to dst, one byte at a time. */
  54. ldub [%o1 + 0x00], %o3 ! MS Group
  55. add %o1, 0x1, %o1 ! A0
  56. add %o0, 0x1, %o0 ! A1
  57. subcc %o2, 1, %o2 ! A0 Group
  58. bg,pt %icc, U3memcpy_short ! BR
  59.  stb %o3, [%o0 + -1] ! MS Group (1-cycle stall)
  60. U3memcpy_short_ret:
  61. #ifdef __KERNEL__
  62. retl ! BR Group (0-4 cycle stall)
  63.  clr %o0 ! A0
  64. #else
  65. retl ! BR Group (0-4 cycle stall)
  66.  mov %g3, %o0 ! A0
  67. #endif
  68. /* Here len >= (6 * 64) and condition codes reflect execution
  69.  * of "andcc %o0, 0x7, %g2", done by caller.
  70.  */
  71. .align 64
  72. U3memcpy_enter:
  73. /* Is 'dst' already aligned on an 64-byte boundary? */
  74. be,pt %xcc, 2f ! BR
  75. /* Compute abs((dst & 0x3f) - 0x40) into %g2.  This is the number
  76.  * of bytes to copy to make 'dst' 64-byte aligned.  We pre-
  77.  * subtract this from 'len'.
  78.  */
  79.  sub %g2, 0x40, %g2 ! A0 Group
  80. sub %g0, %g2, %g2 ! A0 Group
  81. sub %o2, %g2, %o2 ! A0 Group
  82. /* Copy %g2 bytes from src to dst, one byte at a time. */
  83. 1: ldub [%o1 + 0x00], %o3 ! MS (Group)
  84. add %o1, 0x1, %o1 ! A1
  85. add %o0, 0x1, %o0 ! A0 Group
  86. subcc %g2, 0x1, %g2 ! A1
  87. bg,pt %icc, 1b ! BR Group
  88.  stb %o3, [%o0 + -1] ! MS Group
  89. 2: VISEntryHalf ! MS+MS
  90. and %o1, 0x7, %g1 ! A1
  91. ba,pt %xcc, U3memcpy_begin ! BR
  92.  alignaddr %o1, %g0, %o1 ! MS       (Break-after)
  93. .align 64
  94. U3memcpy_begin:
  95. prefetch [%o1 + 0x000], #one_read ! MS Group1
  96. prefetch [%o1 + 0x040], #one_read ! MS Group2
  97. andn %o2, (0x40 - 1), %o4 ! A0
  98. prefetch [%o1 + 0x080], #one_read ! MS Group3
  99. cmp %o4, 0x140 ! A0
  100. prefetch [%o1 + 0x0c0], #one_read ! MS Group4
  101. ldd [%o1 + 0x000], %f0 ! MS Group5 (%f0 results at G8)
  102. bge,a,pt %icc, 1f ! BR
  103.  prefetch [%o1 + 0x100], #one_read ! MS Group6
  104. 1: ldd [%o1 + 0x008], %f2 ! AX        (%f2 results at G9)
  105. cmp %o4, 0x180 ! A1
  106. bge,a,pt %icc, 1f ! BR
  107.  prefetch [%o1 + 0x140], #one_read ! MS Group7
  108. 1: ldd [%o1 + 0x010], %f4 ! AX        (%f4 results at G10)
  109. cmp %o4, 0x1c0 ! A1
  110. bge,a,pt %icc, 1f ! BR
  111.  prefetch [%o1 + 0x180], #one_read ! MS Group8
  112. 1: faligndata %f0, %f2, %f16 ! FGA Group9 (%f16 at G12)
  113. ldd [%o1 + 0x018], %f6 ! AX        (%f6 results at G12)
  114. faligndata %f2, %f4, %f18 ! FGA Group10 (%f18 results at G13)
  115. ldd [%o1 + 0x020], %f8 ! MS         (%f8 results at G13)
  116. faligndata %f4, %f6, %f20 ! FGA Group12 (1-cycle stall,%f20 at G15)
  117. ldd [%o1 + 0x028], %f10 ! MS (%f10 results at G15)
  118. faligndata %f6, %f8, %f22 ! FGA Group13 (%f22 results at G16)
  119. ldd [%o1 + 0x030], %f12 ! MS (%f12 results at G16)
  120. faligndata %f8, %f10, %f24 ! FGA Group15 (1-cycle stall,%f24 at G18)
  121. ldd [%o1 + 0x038], %f14 ! MS (%f14 results at G18)
  122. faligndata %f10, %f12, %f26 ! FGA Group16 (%f26 results at G19)
  123. ldd [%o1 + 0x040], %f0 ! MS (%f0 results at G19)
  124. /* We only use the first loop if len > (7 * 64). */
  125. subcc %o4, 0x1c0, %o4 ! A0 Group17
  126. bg,pt %icc, U3memcpy_loop1 ! BR
  127.  add %o1, 0x40, %o1 ! A1
  128. add %o4, 0x140, %o4 ! A0 Group18
  129. ba,pt %xcc, U3memcpy_loop2 ! BR
  130.  srl %o4, 6, %o3 ! A0 Group19
  131. nop
  132. nop
  133. nop
  134. nop
  135. nop
  136. nop
  137. nop
  138. /* This loop performs the copy and queues new prefetches.
  139.  * We drop into the second loop when len <= (5 * 64).  Note
  140.  * that this (5 * 64) factor has been subtracted from len
  141.  * already.
  142.  */
  143. U3memcpy_loop1:
  144. ldd [%o1 + 0x008], %f2 ! MS Group2 (%f2 results at G5)
  145. faligndata %f12, %f14, %f28 ! FGA (%f28 results at G5)
  146. ldd [%o1 + 0x010], %f4 ! MS Group3 (%f4 results at G6)
  147. faligndata %f14, %f0, %f30 ! FGA Group4 (1-cycle stall, %f30 at G7)
  148. stda %f16, [%o0] ASI_BLK_P ! MS
  149. ldd [%o1 + 0x018], %f6 ! AX (%f6 results at G7)
  150. faligndata %f0, %f2, %f16 ! FGA Group12 (7-cycle stall)
  151. ldd [%o1 + 0x020], %f8 ! MS         (%f8 results at G15)
  152. faligndata %f2, %f4, %f18 ! FGA Group13 (%f18 results at G16)
  153. ldd [%o1 + 0x028], %f10 ! MS (%f10 results at G16)
  154. faligndata %f4, %f6, %f20 ! FGA Group14 (%f20 results at G17)
  155. ldd [%o1 + 0x030], %f12 ! MS (%f12 results at G17)
  156. faligndata %f6, %f8, %f22 ! FGA Group15 (%f22 results at G18)
  157. ldd [%o1 + 0x038], %f14 ! MS (%f14 results at G18)
  158. faligndata %f8, %f10, %f24 ! FGA Group16 (%f24 results at G19)
  159. ldd [%o1 + 0x040], %f0 ! AX (%f0 results at G19)
  160. prefetch [%o1 + 0x180], #one_read ! MS
  161. faligndata %f10, %f12, %f26 ! FGA Group17 (%f26 results at G20)
  162. subcc %o4, 0x40, %o4 ! A0
  163. add %o1, 0x40, %o1 ! A1
  164. bg,pt %xcc, U3memcpy_loop1 ! BR
  165.  add %o0, 0x40, %o0 ! A0 Group18
  166. U3memcpy_loop2_enter:
  167. mov 5, %o3 ! A1
  168. /* This loop performs on the copy, no new prefetches are
  169.  * queued.  We do things this way so that we do not perform
  170.  * any spurious prefetches past the end of the src buffer.
  171.  */
  172. U3memcpy_loop2:
  173. ldd [%o1 + 0x008], %f2 ! MS
  174. faligndata %f12, %f14, %f28 ! FGA Group2
  175. ldd [%o1 + 0x010], %f4 ! MS
  176. faligndata %f14, %f0, %f30 ! FGA Group4 (1-cycle stall)
  177. stda %f16, [%o0] ASI_BLK_P ! MS
  178. ldd [%o1 + 0x018], %f6 ! AX
  179. faligndata %f0, %f2, %f16 ! FGA Group12 (7-cycle stall)
  180. ldd [%o1 + 0x020], %f8 ! MS
  181. faligndata %f2, %f4, %f18 ! FGA Group13
  182. ldd [%o1 + 0x028], %f10 ! MS
  183. faligndata %f4, %f6, %f20 ! FGA Group14
  184. ldd [%o1 + 0x030], %f12 ! MS
  185. faligndata %f6, %f8, %f22 ! FGA Group15
  186. ldd [%o1 + 0x038], %f14 ! MS
  187. faligndata %f8, %f10, %f24 ! FGA Group16
  188. ldd [%o1 + 0x040], %f0 ! AX
  189. faligndata %f10, %f12, %f26 ! FGA Group17
  190. subcc %o3, 0x01, %o3 ! A0
  191. add %o1, 0x40, %o1 ! A1
  192. bg,pt %xcc, U3memcpy_loop2 ! BR
  193.  add %o0, 0x40, %o0 ! A0 Group18
  194. /* Finally we copy the last full 64-byte block. */
  195. U3memcpy_loopfini:
  196. ldd [%o1 + 0x008], %f2 ! MS
  197. faligndata %f12, %f14, %f28 ! FGA
  198. ldd [%o1 + 0x010], %f4 ! MS Group19
  199. faligndata %f14, %f0, %f30 ! FGA
  200. stda %f16, [%o0] ASI_BLK_P ! MS Group20
  201. ldd [%o1 + 0x018], %f6 ! AX
  202. faligndata %f0, %f2, %f16 ! FGA Group11 (7-cycle stall)
  203. ldd [%o1 + 0x020], %f8 ! MS
  204. faligndata %f2, %f4, %f18 ! FGA Group12
  205. ldd [%o1 + 0x028], %f10 ! MS
  206. faligndata %f4, %f6, %f20 ! FGA Group13
  207. ldd [%o1 + 0x030], %f12 ! MS
  208. faligndata %f6, %f8, %f22 ! FGA Group14
  209. ldd [%o1 + 0x038], %f14 ! MS
  210. faligndata %f8, %f10, %f24 ! FGA Group15
  211. cmp %g1, 0 ! A0
  212. be,pt %icc, 1f ! BR
  213.  add %o0, 0x40, %o0 ! A1
  214. ldd [%o1 + 0x040], %f0 ! MS
  215. 1: faligndata %f10, %f12, %f26 ! FGA Group16
  216. faligndata %f12, %f14, %f28 ! FGA Group17
  217. faligndata %f14, %f0, %f30 ! FGA Group18
  218. stda %f16, [%o0] ASI_BLK_P ! MS
  219. add %o0, 0x40, %o0 ! A0
  220. add %o1, 0x40, %o1 ! A1
  221. membar #Sync ! MS Group26 (7-cycle stall)
  222. /* Now we copy the (len modulo 64) bytes at the end.
  223.  * Note how we borrow the %f0 loaded above.
  224.  *
  225.  * Also notice how this code is careful not to perform a
  226.  * load past the end of the src buffer just like similar
  227.  * code found in U3memcpy_toosmall processing.
  228.  */
  229. U3memcpy_loopend:
  230. and %o2, 0x3f, %o2 ! A0 Group
  231. andcc %o2, 0x38, %g2 ! A0 Group
  232. be,pn %icc, U3memcpy_endcruft ! BR
  233.  subcc %g2, 0x8, %g2 ! A1
  234. be,pn %icc, U3memcpy_endcruft ! BR Group
  235.  cmp %g1, 0 ! A0
  236. be,a,pt %icc, 1f ! BR Group
  237.  ldd [%o1 + 0x00], %f0 ! MS
  238. 1: ldd [%o1 + 0x08], %f2 ! MS Group
  239. add %o1, 0x8, %o1 ! A0
  240. sub %o2, 0x8, %o2 ! A1
  241. subcc %g2, 0x8, %g2 ! A0 Group
  242. faligndata %f0, %f2, %f8 ! FGA Group
  243. std %f8, [%o0 + 0x00] ! MS (XXX does it stall here? XXX)
  244. be,pn %icc, U3memcpy_endcruft ! BR
  245.  add %o0, 0x8, %o0 ! A0
  246. ldd [%o1 + 0x08], %f0 ! MS Group
  247. add %o1, 0x8, %o1 ! A0
  248. sub %o2, 0x8, %o2 ! A1
  249. subcc %g2, 0x8, %g2 ! A0 Group
  250. faligndata %f2, %f0, %f8 ! FGA
  251. std %f8, [%o0 + 0x00] ! MS (XXX does it stall here? XXX)
  252. bne,pn %icc, 1b ! BR
  253.  add %o0, 0x8, %o0 ! A0 Group
  254. /* If anything is left, we copy it one byte at a time.
  255.  * Note that %g1 is (src & 0x3) saved above before the
  256.  * alignaddr was performed.
  257.  */
  258. U3memcpy_endcruft:
  259. cmp %o2, 0
  260. add %o1, %g1, %o1
  261. VISExitHalf
  262. be,pn %icc, U3memcpy_short_ret
  263.  nop
  264. ba,a,pt %xcc, U3memcpy_short
  265. /* If we get here, then 32 <= len < (6 * 64) */
  266. U3memcpy_toosmall:
  267. #ifdef SMALL_COPY_USES_FPU
  268. /* Is 'dst' already aligned on an 8-byte boundary? */
  269. be,pt %xcc, 2f ! BR Group
  270. /* Compute abs((dst & 7) - 8) into %g2.  This is the number
  271.  * of bytes to copy to make 'dst' 8-byte aligned.  We pre-
  272.  * subtract this from 'len'.
  273.  */
  274.  sub %g2, 0x8, %g2 ! A0
  275. sub %g0, %g2, %g2 ! A0 Group (reg-dep)
  276. sub %o2, %g2, %o2 ! A0 Group (reg-dep)
  277. /* Copy %g2 bytes from src to dst, one byte at a time. */
  278. 1: ldub [%o1 + 0x00], %o3 ! MS (Group) (%o3 in 3 cycles)
  279. add %o1, 0x1, %o1 ! A1
  280. add %o0, 0x1, %o0 ! A0 Group
  281. subcc %g2, 0x1, %g2 ! A1
  282. bg,pt %icc, 1b ! BR Group
  283.  stb %o3, [%o0 + -1] ! MS Group
  284. 2: VISEntryHalf ! MS+MS
  285. /* Compute (len - (len % 8)) into %g2.  This is guarenteed
  286.  * to be nonzero.
  287.  */
  288. andn %o2, 0x7, %g2 ! A0 Group
  289. /* You may read this and believe that it allows reading
  290.  * one 8-byte longword past the end of src.  It actually
  291.  * does not, as %g2 is subtracted as loads are done from
  292.  * src, so we always stop before running off the end.
  293.  * Also, we are guarenteed to have at least 0x10 bytes
  294.  * to move here.
  295.  */
  296. sub %g2, 0x8, %g2 ! A0 Group (reg-dep)
  297. alignaddr %o1, %g0, %g1 ! MS       (Break-after)
  298. ldd [%g1 + 0x00], %f0 ! MS Group (1-cycle stall)
  299. add %g1, 0x8, %g1 ! A0
  300. 1: ldd [%g1 + 0x00], %f2 ! MS Group
  301. add %g1, 0x8, %g1 ! A0
  302. sub %o2, 0x8, %o2 ! A1
  303. subcc %g2, 0x8, %g2 ! A0 Group
  304. faligndata %f0, %f2, %f8 ! FGA Group (1-cycle stall)
  305. std %f8, [%o0 + 0x00] ! MS Group (2-cycle stall)
  306. add %o1, 0x8, %o1 ! A0
  307. be,pn %icc, 2f ! BR
  308.  add %o0, 0x8, %o0 ! A1
  309. ldd [%g1 + 0x00], %f0 ! MS Group
  310. add %g1, 0x8, %g1 ! A0
  311. sub %o2, 0x8, %o2 ! A1
  312. subcc %g2, 0x8, %g2 ! A0 Group
  313. faligndata %f2, %f0, %f8 ! FGA Group (1-cycle stall)
  314. std %f8, [%o0 + 0x00] ! MS Group (2-cycle stall)
  315. add %o1, 0x8, %o1 ! A0
  316. bne,pn %icc, 1b ! BR
  317.  add %o0, 0x8, %o0 ! A1
  318. /* Nothing left to copy? */
  319. 2: cmp %o2, 0 ! A0 Group
  320. VISExitHalf ! A0+MS
  321. be,pn %icc, U3memcpy_short_ret ! BR Group
  322.  nop ! A0
  323. ba,a,pt %xcc, U3memcpy_short ! BR Group
  324. #else /* !(SMALL_COPY_USES_FPU) */
  325. xor %o1, %o0, %g2
  326. andcc %g2, 0x7, %g0
  327. bne,pn %icc, U3memcpy_short
  328.  andcc %o1, 0x7, %g2
  329. be,pt %xcc, 2f
  330.  sub %g2, 0x8, %g2
  331. sub %g0, %g2, %g2
  332. sub %o2, %g2, %o2
  333. 1: ldub [%o1 + 0x00], %o3
  334. add %o1, 0x1, %o1
  335. add %o0, 0x1, %o0
  336. subcc %g2, 0x1, %g2
  337. bg,pt %icc, 1b
  338.  stb %o3, [%o0 + -1]
  339. 2: andn %o2, 0x7, %g2
  340. sub %o2, %g2, %o2
  341. 3: ldx [%o1 + 0x00], %o3
  342. add %o1, 0x8, %o1
  343. add %o0, 0x8, %o0
  344. subcc %g2, 0x8, %g2
  345. bg,pt %icc, 3b
  346.  stx %o3, [%o0 + -8]
  347. cmp %o2, 0
  348. bne,pn %icc, U3memcpy_short
  349.  nop
  350. ba,a,pt %xcc, U3memcpy_short_ret
  351. #endif /* !(SMALL_COPY_USES_FPU) */