U3memcpy.S 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. /* U3memcpy.S: UltraSparc-III optimized memcpy.
  2. *
  3. * Copyright (C) 1999, 2000, 2004 David S. Miller (davem@redhat.com)
  4. */
  5. #ifdef __KERNEL__
  6. #include <asm/visasm.h>
  7. #include <asm/asi.h>
  8. #define GLOBAL_SPARE %g7
  9. #else
  10. #define ASI_BLK_P 0xf0
  11. #define FPRS_FEF 0x04
  12. #ifdef MEMCPY_DEBUG
  13. #define VISEntryHalf rd %fprs, %o5; wr %g0, FPRS_FEF, %fprs; \
  14. clr %g1; clr %g2; clr %g3; subcc %g0, %g0, %g0;
  15. #define VISExitHalf and %o5, FPRS_FEF, %o5; wr %o5, 0x0, %fprs
  16. #else
  17. #define VISEntryHalf rd %fprs, %o5; wr %g0, FPRS_FEF, %fprs
  18. #define VISExitHalf and %o5, FPRS_FEF, %o5; wr %o5, 0x0, %fprs
  19. #endif
  20. #define GLOBAL_SPARE %g5
  21. #endif
  22. #ifndef EX_LD
  23. #define EX_LD(x) x
  24. #endif
  25. #ifndef EX_ST
  26. #define EX_ST(x) x
  27. #endif
  28. #ifndef EX_RETVAL
  29. #define EX_RETVAL(x) x
  30. #endif
  31. #ifndef LOAD
  32. #define LOAD(type,addr,dest) type [addr], dest
  33. #endif
  34. #ifndef STORE
  35. #define STORE(type,src,addr) type src, [addr]
  36. #endif
  37. #ifndef STORE_BLK
  38. #define STORE_BLK(src,addr) stda src, [addr] ASI_BLK_P
  39. #endif
  40. #ifndef FUNC_NAME
  41. #define FUNC_NAME U3memcpy
  42. #endif
  43. #ifndef PREAMBLE
  44. #define PREAMBLE
  45. #endif
  46. #ifndef XCC
  47. #define XCC xcc
  48. #endif
  49. .register %g2,#scratch
  50. .register %g3,#scratch
  51. /* Special/non-trivial issues of this code:
  52. *
  53. * 1) %o5 is preserved from VISEntryHalf to VISExitHalf
  54. * 2) Only low 32 FPU registers are used so that only the
  55. * lower half of the FPU register set is dirtied by this
  56. * code. This is especially important in the kernel.
  57. * 3) This code never prefetches cachelines past the end
  58. * of the source buffer.
  59. */
  60. .text
  61. .align 64
  62. /* The cheetah's flexible spine, oversized liver, enlarged heart,
  63. * slender muscular body, and claws make it the swiftest hunter
  64. * in Africa and the fastest animal on land. Can reach speeds
  65. * of up to 2.4GB per second.
  66. */
  67. .globl FUNC_NAME
  68. .type FUNC_NAME,#function
  69. FUNC_NAME: /* %o0=dst, %o1=src, %o2=len */
  70. srlx %o2, 31, %g2
  71. cmp %g2, 0
  72. tne %xcc, 5
  73. PREAMBLE
  74. mov %o0, %o4
  75. cmp %o2, 0
  76. be,pn %XCC, 85f
  77. or %o0, %o1, %o3
  78. cmp %o2, 16
  79. blu,a,pn %XCC, 80f
  80. or %o3, %o2, %o3
  81. cmp %o2, (3 * 64)
  82. blu,pt %XCC, 70f
  83. andcc %o3, 0x7, %g0
  84. /* Clobbers o5/g1/g2/g3/g7/icc/xcc. We must preserve
  85. * o5 from here until we hit VISExitHalf.
  86. */
  87. VISEntryHalf
  88. /* Is 'dst' already aligned on an 64-byte boundary? */
  89. andcc %o0, 0x3f, %g2
  90. be,pt %XCC, 2f
  91. /* Compute abs((dst & 0x3f) - 0x40) into %g2. This is the number
  92. * of bytes to copy to make 'dst' 64-byte aligned. We pre-
  93. * subtract this from 'len'.
  94. */
  95. sub %o0, %o1, GLOBAL_SPARE
  96. sub %g2, 0x40, %g2
  97. sub %g0, %g2, %g2
  98. sub %o2, %g2, %o2
  99. andcc %g2, 0x7, %g1
  100. be,pt %icc, 2f
  101. and %g2, 0x38, %g2
  102. 1: subcc %g1, 0x1, %g1
  103. EX_LD(LOAD(ldub, %o1 + 0x00, %o3))
  104. EX_ST(STORE(stb, %o3, %o1 + GLOBAL_SPARE))
  105. bgu,pt %XCC, 1b
  106. add %o1, 0x1, %o1
  107. add %o1, GLOBAL_SPARE, %o0
  108. 2: cmp %g2, 0x0
  109. and %o1, 0x7, %g1
  110. be,pt %icc, 3f
  111. alignaddr %o1, %g0, %o1
  112. EX_LD(LOAD(ldd, %o1, %f4))
  113. 1: EX_LD(LOAD(ldd, %o1 + 0x8, %f6))
  114. add %o1, 0x8, %o1
  115. subcc %g2, 0x8, %g2
  116. faligndata %f4, %f6, %f0
  117. EX_ST(STORE(std, %f0, %o0))
  118. be,pn %icc, 3f
  119. add %o0, 0x8, %o0
  120. EX_LD(LOAD(ldd, %o1 + 0x8, %f4))
  121. add %o1, 0x8, %o1
  122. subcc %g2, 0x8, %g2
  123. faligndata %f6, %f4, %f2
  124. EX_ST(STORE(std, %f2, %o0))
  125. bne,pt %icc, 1b
  126. add %o0, 0x8, %o0
  127. 3: LOAD(prefetch, %o1 + 0x000, #one_read)
  128. LOAD(prefetch, %o1 + 0x040, #one_read)
  129. andn %o2, (0x40 - 1), GLOBAL_SPARE
  130. LOAD(prefetch, %o1 + 0x080, #one_read)
  131. LOAD(prefetch, %o1 + 0x0c0, #one_read)
  132. LOAD(prefetch, %o1 + 0x100, #one_read)
  133. EX_LD(LOAD(ldd, %o1 + 0x000, %f0))
  134. LOAD(prefetch, %o1 + 0x140, #one_read)
  135. EX_LD(LOAD(ldd, %o1 + 0x008, %f2))
  136. LOAD(prefetch, %o1 + 0x180, #one_read)
  137. EX_LD(LOAD(ldd, %o1 + 0x010, %f4))
  138. LOAD(prefetch, %o1 + 0x1c0, #one_read)
  139. faligndata %f0, %f2, %f16
  140. EX_LD(LOAD(ldd, %o1 + 0x018, %f6))
  141. faligndata %f2, %f4, %f18
  142. EX_LD(LOAD(ldd, %o1 + 0x020, %f8))
  143. faligndata %f4, %f6, %f20
  144. EX_LD(LOAD(ldd, %o1 + 0x028, %f10))
  145. faligndata %f6, %f8, %f22
  146. EX_LD(LOAD(ldd, %o1 + 0x030, %f12))
  147. faligndata %f8, %f10, %f24
  148. EX_LD(LOAD(ldd, %o1 + 0x038, %f14))
  149. faligndata %f10, %f12, %f26
  150. EX_LD(LOAD(ldd, %o1 + 0x040, %f0))
  151. subcc GLOBAL_SPARE, 0x80, GLOBAL_SPARE
  152. add %o1, 0x40, %o1
  153. bgu,pt %XCC, 1f
  154. srl GLOBAL_SPARE, 6, %o3
  155. ba,pt %xcc, 2f
  156. nop
  157. .align 64
  158. 1:
  159. EX_LD(LOAD(ldd, %o1 + 0x008, %f2))
  160. faligndata %f12, %f14, %f28
  161. EX_LD(LOAD(ldd, %o1 + 0x010, %f4))
  162. faligndata %f14, %f0, %f30
  163. EX_ST(STORE_BLK(%f16, %o0))
  164. EX_LD(LOAD(ldd, %o1 + 0x018, %f6))
  165. faligndata %f0, %f2, %f16
  166. add %o0, 0x40, %o0
  167. EX_LD(LOAD(ldd, %o1 + 0x020, %f8))
  168. faligndata %f2, %f4, %f18
  169. EX_LD(LOAD(ldd, %o1 + 0x028, %f10))
  170. faligndata %f4, %f6, %f20
  171. EX_LD(LOAD(ldd, %o1 + 0x030, %f12))
  172. subcc %o3, 0x01, %o3
  173. faligndata %f6, %f8, %f22
  174. EX_LD(LOAD(ldd, %o1 + 0x038, %f14))
  175. faligndata %f8, %f10, %f24
  176. EX_LD(LOAD(ldd, %o1 + 0x040, %f0))
  177. LOAD(prefetch, %o1 + 0x1c0, #one_read)
  178. faligndata %f10, %f12, %f26
  179. bg,pt %XCC, 1b
  180. add %o1, 0x40, %o1
  181. /* Finally we copy the last full 64-byte block. */
  182. 2:
  183. EX_LD(LOAD(ldd, %o1 + 0x008, %f2))
  184. faligndata %f12, %f14, %f28
  185. EX_LD(LOAD(ldd, %o1 + 0x010, %f4))
  186. faligndata %f14, %f0, %f30
  187. EX_ST(STORE_BLK(%f16, %o0))
  188. EX_LD(LOAD(ldd, %o1 + 0x018, %f6))
  189. faligndata %f0, %f2, %f16
  190. EX_LD(LOAD(ldd, %o1 + 0x020, %f8))
  191. faligndata %f2, %f4, %f18
  192. EX_LD(LOAD(ldd, %o1 + 0x028, %f10))
  193. faligndata %f4, %f6, %f20
  194. EX_LD(LOAD(ldd, %o1 + 0x030, %f12))
  195. faligndata %f6, %f8, %f22
  196. EX_LD(LOAD(ldd, %o1 + 0x038, %f14))
  197. faligndata %f8, %f10, %f24
  198. cmp %g1, 0
  199. be,pt %XCC, 1f
  200. add %o0, 0x40, %o0
  201. EX_LD(LOAD(ldd, %o1 + 0x040, %f0))
  202. 1: faligndata %f10, %f12, %f26
  203. faligndata %f12, %f14, %f28
  204. faligndata %f14, %f0, %f30
  205. EX_ST(STORE_BLK(%f16, %o0))
  206. add %o0, 0x40, %o0
  207. add %o1, 0x40, %o1
  208. membar #Sync
  209. /* Now we copy the (len modulo 64) bytes at the end.
  210. * Note how we borrow the %f0 loaded above.
  211. *
  212. * Also notice how this code is careful not to perform a
  213. * load past the end of the src buffer.
  214. */
  215. and %o2, 0x3f, %o2
  216. andcc %o2, 0x38, %g2
  217. be,pn %XCC, 2f
  218. subcc %g2, 0x8, %g2
  219. be,pn %XCC, 2f
  220. cmp %g1, 0
  221. sub %o2, %g2, %o2
  222. be,a,pt %XCC, 1f
  223. EX_LD(LOAD(ldd, %o1 + 0x00, %f0))
  224. 1: EX_LD(LOAD(ldd, %o1 + 0x08, %f2))
  225. add %o1, 0x8, %o1
  226. subcc %g2, 0x8, %g2
  227. faligndata %f0, %f2, %f8
  228. EX_ST(STORE(std, %f8, %o0))
  229. be,pn %XCC, 2f
  230. add %o0, 0x8, %o0
  231. EX_LD(LOAD(ldd, %o1 + 0x08, %f0))
  232. add %o1, 0x8, %o1
  233. subcc %g2, 0x8, %g2
  234. faligndata %f2, %f0, %f8
  235. EX_ST(STORE(std, %f8, %o0))
  236. bne,pn %XCC, 1b
  237. add %o0, 0x8, %o0
  238. /* If anything is left, we copy it one byte at a time.
  239. * Note that %g1 is (src & 0x3) saved above before the
  240. * alignaddr was performed.
  241. */
  242. 2:
  243. cmp %o2, 0
  244. add %o1, %g1, %o1
  245. VISExitHalf
  246. be,pn %XCC, 85f
  247. sub %o0, %o1, %o3
  248. andcc %g1, 0x7, %g0
  249. bne,pn %icc, 90f
  250. andcc %o2, 0x8, %g0
  251. be,pt %icc, 1f
  252. nop
  253. EX_LD(LOAD(ldx, %o1, %o5))
  254. EX_ST(STORE(stx, %o5, %o1 + %o3))
  255. add %o1, 0x8, %o1
  256. 1: andcc %o2, 0x4, %g0
  257. be,pt %icc, 1f
  258. nop
  259. EX_LD(LOAD(lduw, %o1, %o5))
  260. EX_ST(STORE(stw, %o5, %o1 + %o3))
  261. add %o1, 0x4, %o1
  262. 1: andcc %o2, 0x2, %g0
  263. be,pt %icc, 1f
  264. nop
  265. EX_LD(LOAD(lduh, %o1, %o5))
  266. EX_ST(STORE(sth, %o5, %o1 + %o3))
  267. add %o1, 0x2, %o1
  268. 1: andcc %o2, 0x1, %g0
  269. be,pt %icc, 85f
  270. nop
  271. EX_LD(LOAD(ldub, %o1, %o5))
  272. ba,pt %xcc, 85f
  273. EX_ST(STORE(stb, %o5, %o1 + %o3))
  274. .align 64
  275. 70: /* 16 < len <= 64 */
  276. bne,pn %XCC, 75f
  277. sub %o0, %o1, %o3
  278. 72:
  279. andn %o2, 0xf, GLOBAL_SPARE
  280. and %o2, 0xf, %o2
  281. 1: subcc GLOBAL_SPARE, 0x10, GLOBAL_SPARE
  282. EX_LD(LOAD(ldx, %o1 + 0x00, %o5))
  283. EX_LD(LOAD(ldx, %o1 + 0x08, %g1))
  284. EX_ST(STORE(stx, %o5, %o1 + %o3))
  285. add %o1, 0x8, %o1
  286. EX_ST(STORE(stx, %g1, %o1 + %o3))
  287. bgu,pt %XCC, 1b
  288. add %o1, 0x8, %o1
  289. 73: andcc %o2, 0x8, %g0
  290. be,pt %XCC, 1f
  291. nop
  292. sub %o2, 0x8, %o2
  293. EX_LD(LOAD(ldx, %o1, %o5))
  294. EX_ST(STORE(stx, %o5, %o1 + %o3))
  295. add %o1, 0x8, %o1
  296. 1: andcc %o2, 0x4, %g0
  297. be,pt %XCC, 1f
  298. nop
  299. sub %o2, 0x4, %o2
  300. EX_LD(LOAD(lduw, %o1, %o5))
  301. EX_ST(STORE(stw, %o5, %o1 + %o3))
  302. add %o1, 0x4, %o1
  303. 1: cmp %o2, 0
  304. be,pt %XCC, 85f
  305. nop
  306. ba,pt %xcc, 90f
  307. nop
  308. 75:
  309. andcc %o0, 0x7, %g1
  310. sub %g1, 0x8, %g1
  311. be,pn %icc, 2f
  312. sub %g0, %g1, %g1
  313. sub %o2, %g1, %o2
  314. 1: subcc %g1, 1, %g1
  315. EX_LD(LOAD(ldub, %o1, %o5))
  316. EX_ST(STORE(stb, %o5, %o1 + %o3))
  317. bgu,pt %icc, 1b
  318. add %o1, 1, %o1
  319. 2: add %o1, %o3, %o0
  320. andcc %o1, 0x7, %g1
  321. bne,pt %icc, 8f
  322. sll %g1, 3, %g1
  323. cmp %o2, 16
  324. bgeu,pt %icc, 72b
  325. nop
  326. ba,a,pt %xcc, 73b
  327. 8: mov 64, %o3
  328. andn %o1, 0x7, %o1
  329. EX_LD(LOAD(ldx, %o1, %g2))
  330. sub %o3, %g1, %o3
  331. andn %o2, 0x7, GLOBAL_SPARE
  332. sllx %g2, %g1, %g2
  333. 1: EX_LD(LOAD(ldx, %o1 + 0x8, %g3))
  334. subcc GLOBAL_SPARE, 0x8, GLOBAL_SPARE
  335. add %o1, 0x8, %o1
  336. srlx %g3, %o3, %o5
  337. or %o5, %g2, %o5
  338. EX_ST(STORE(stx, %o5, %o0))
  339. add %o0, 0x8, %o0
  340. bgu,pt %icc, 1b
  341. sllx %g3, %g1, %g2
  342. srl %g1, 3, %g1
  343. andcc %o2, 0x7, %o2
  344. be,pn %icc, 85f
  345. add %o1, %g1, %o1
  346. ba,pt %xcc, 90f
  347. sub %o0, %o1, %o3
  348. .align 64
  349. 80: /* 0 < len <= 16 */
  350. andcc %o3, 0x3, %g0
  351. bne,pn %XCC, 90f
  352. sub %o0, %o1, %o3
  353. 1:
  354. subcc %o2, 4, %o2
  355. EX_LD(LOAD(lduw, %o1, %g1))
  356. EX_ST(STORE(stw, %g1, %o1 + %o3))
  357. bgu,pt %XCC, 1b
  358. add %o1, 4, %o1
  359. 85: retl
  360. mov EX_RETVAL(%o4), %o0
  361. .align 32
  362. 90:
  363. subcc %o2, 1, %o2
  364. EX_LD(LOAD(ldub, %o1, %g1))
  365. EX_ST(STORE(stb, %g1, %o1 + %o3))
  366. bgu,pt %XCC, 90b
  367. add %o1, 1, %o1
  368. retl
  369. mov EX_RETVAL(%o4), %o0
  370. .size FUNC_NAME, .-FUNC_NAME