U3memcpy.S
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:13k
源码类别:

Linux/Unix编程

开发平台:

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