1 /* U3memcpy.S: UltraSparc-III optimized memcpy.
3 * Copyright (C) 1999, 2000, 2004 David S. Miller (davem@redhat.com)
7 #include <linux/linkage.h>
8 #include <asm/visasm.h>
10 #define GLOBAL_SPARE %g7
12 #define ASI_BLK_P 0xf0
15 #define VISEntryHalf rd %fprs, %o5; wr %g0, FPRS_FEF, %fprs; \
16 clr %g1; clr %g2; clr %g3; subcc %g0, %g0, %g0;
17 #define VISExitHalf and %o5, FPRS_FEF, %o5; wr %o5, 0x0, %fprs
19 #define VISEntryHalf rd %fprs, %o5; wr %g0, FPRS_FEF, %fprs
20 #define VISExitHalf and %o5, FPRS_FEF, %o5; wr %o5, 0x0, %fprs
22 #define GLOBAL_SPARE %g5
29 #define EX_LD_FP(x,y) x
36 #define EX_ST_FP(x,y) x
40 #define LOAD(type,addr,dest) type [addr], dest
44 #define STORE(type,src,addr) type src, [addr]
48 #define STORE_BLK(src,addr) stda src, [addr] ASI_BLK_P
52 #define FUNC_NAME U3memcpy
63 .register %g2,#scratch
64 .register %g3,#scratch
66 /* Special/non-trivial issues of this code:
68 * 1) %o5 is preserved from VISEntryHalf to VISExitHalf
69 * 2) Only low 32 FPU registers are used so that only the
70 * lower half of the FPU register set is dirtied by this
71 * code. This is especially important in the kernel.
72 * 3) This code never prefetches cachelines past the end
73 * of the source buffer.
78 #define EX_RETVAL(x) x
83 ENTRY(U3_retl_o2_plus_g2_plus_g1_plus_1_fp)
86 ba,pt %xcc, __restore_fp
88 ENDPROC(U3_retl_o2_plus_g2_plus_g1_plus_1_fp)
89 ENTRY(U3_retl_o2_plus_g2_fp)
90 ba,pt %xcc, __restore_fp
92 ENDPROC(U3_retl_o2_plus_g2_fp)
93 ENTRY(U3_retl_o2_plus_g2_plus_8_fp)
95 ba,pt %xcc, __restore_fp
97 ENDPROC(U3_retl_o2_plus_g2_plus_8_fp)
102 ENTRY(U3_retl_o2_plus_1)
105 ENDPROC(U3_retl_o2_plus_1)
106 ENTRY(U3_retl_o2_plus_4)
109 ENDPROC(U3_retl_o2_plus_4)
110 ENTRY(U3_retl_o2_plus_8)
113 ENDPROC(U3_retl_o2_plus_8)
114 ENTRY(U3_retl_o2_plus_g1_plus_1)
118 ENDPROC(U3_retl_o2_plus_g1_plus_1)
120 ba,pt %xcc, __restore_fp
122 ENDPROC(U3_retl_o2_fp)
123 ENTRY(U3_retl_o2_plus_o3_sll_6_plus_0x80_fp)
126 ba,pt %xcc, __restore_fp
128 ENDPROC(U3_retl_o2_plus_o3_sll_6_plus_0x80_fp)
129 ENTRY(U3_retl_o2_plus_o3_sll_6_plus_0x40_fp)
132 ba,pt %xcc, __restore_fp
134 ENDPROC(U3_retl_o2_plus_o3_sll_6_plus_0x40_fp)
135 ENTRY(U3_retl_o2_plus_GS_plus_0x10)
136 add GLOBAL_SPARE, 0x10, GLOBAL_SPARE
138 add %o2, GLOBAL_SPARE, %o0
139 ENDPROC(U3_retl_o2_plus_GS_plus_0x10)
140 ENTRY(U3_retl_o2_plus_GS_plus_0x08)
141 add GLOBAL_SPARE, 0x08, GLOBAL_SPARE
143 add %o2, GLOBAL_SPARE, %o0
144 ENDPROC(U3_retl_o2_plus_GS_plus_0x08)
145 ENTRY(U3_retl_o2_and_7_plus_GS)
148 add %o2, GLOBAL_SPARE, %o0
149 ENDPROC(U3_retl_o2_and_7_plus_GS)
150 ENTRY(U3_retl_o2_and_7_plus_GS_plus_8)
151 add GLOBAL_SPARE, 8, GLOBAL_SPARE
154 add %o2, GLOBAL_SPARE, %o0
155 ENDPROC(U3_retl_o2_and_7_plus_GS_plus_8)
160 /* The cheetah's flexible spine, oversized liver, enlarged heart,
161 * slender muscular body, and claws make it the swiftest hunter
162 * in Africa and the fastest animal on land. Can reach speeds
163 * of up to 2.4GB per second.
167 .type FUNC_NAME,#function
168 FUNC_NAME: /* %o0=dst, %o1=src, %o2=len */
185 /* Clobbers o5/g1/g2/g3/g7/icc/xcc. We must preserve
186 * o5 from here until we hit VISExitHalf.
190 /* Is 'dst' already aligned on an 64-byte boundary? */
194 /* Compute abs((dst & 0x3f) - 0x40) into %g2. This is the number
195 * of bytes to copy to make 'dst' 64-byte aligned. We pre-
196 * subtract this from 'len'.
198 sub %o0, %o1, GLOBAL_SPARE
206 1: subcc %g1, 0x1, %g1
207 EX_LD_FP(LOAD(ldub, %o1 + 0x00, %o3), U3_retl_o2_plus_g2_plus_g1_plus_1)
208 EX_ST_FP(STORE(stb, %o3, %o1 + GLOBAL_SPARE), U3_retl_o2_plus_g2_plus_g1_plus_1)
212 add %o1, GLOBAL_SPARE, %o0
217 alignaddr %o1, %g0, %o1
219 EX_LD_FP(LOAD(ldd, %o1, %f4), U3_retl_o2_plus_g2)
220 1: EX_LD_FP(LOAD(ldd, %o1 + 0x8, %f6), U3_retl_o2_plus_g2)
223 faligndata %f4, %f6, %f0
224 EX_ST_FP(STORE(std, %f0, %o0), U3_retl_o2_plus_g2_plus_8)
228 EX_LD_FP(LOAD(ldd, %o1 + 0x8, %f4), U3_retl_o2_plus_g2)
231 faligndata %f6, %f4, %f2
232 EX_ST_FP(STORE(std, %f2, %o0), U3_retl_o2_plus_g2_plus_8)
236 3: LOAD(prefetch, %o1 + 0x000, #one_read)
237 LOAD(prefetch, %o1 + 0x040, #one_read)
238 andn %o2, (0x40 - 1), GLOBAL_SPARE
239 LOAD(prefetch, %o1 + 0x080, #one_read)
240 LOAD(prefetch, %o1 + 0x0c0, #one_read)
241 LOAD(prefetch, %o1 + 0x100, #one_read)
242 EX_LD_FP(LOAD(ldd, %o1 + 0x000, %f0), U3_retl_o2)
243 LOAD(prefetch, %o1 + 0x140, #one_read)
244 EX_LD_FP(LOAD(ldd, %o1 + 0x008, %f2), U3_retl_o2)
245 LOAD(prefetch, %o1 + 0x180, #one_read)
246 EX_LD_FP(LOAD(ldd, %o1 + 0x010, %f4), U3_retl_o2)
247 LOAD(prefetch, %o1 + 0x1c0, #one_read)
248 faligndata %f0, %f2, %f16
249 EX_LD_FP(LOAD(ldd, %o1 + 0x018, %f6), U3_retl_o2)
250 faligndata %f2, %f4, %f18
251 EX_LD_FP(LOAD(ldd, %o1 + 0x020, %f8), U3_retl_o2)
252 faligndata %f4, %f6, %f20
253 EX_LD_FP(LOAD(ldd, %o1 + 0x028, %f10), U3_retl_o2)
254 faligndata %f6, %f8, %f22
256 EX_LD_FP(LOAD(ldd, %o1 + 0x030, %f12), U3_retl_o2)
257 faligndata %f8, %f10, %f24
258 EX_LD_FP(LOAD(ldd, %o1 + 0x038, %f14), U3_retl_o2)
259 faligndata %f10, %f12, %f26
260 EX_LD_FP(LOAD(ldd, %o1 + 0x040, %f0), U3_retl_o2)
262 subcc GLOBAL_SPARE, 0x80, GLOBAL_SPARE
265 srl GLOBAL_SPARE, 6, %o3
271 EX_LD_FP(LOAD(ldd, %o1 + 0x008, %f2), U3_retl_o2_plus_o3_sll_6_plus_0x80)
272 faligndata %f12, %f14, %f28
273 EX_LD_FP(LOAD(ldd, %o1 + 0x010, %f4), U3_retl_o2_plus_o3_sll_6_plus_0x80)
274 faligndata %f14, %f0, %f30
275 EX_ST_FP(STORE_BLK(%f16, %o0), U3_retl_o2_plus_o3_sll_6_plus_0x80)
276 EX_LD_FP(LOAD(ldd, %o1 + 0x018, %f6), U3_retl_o2_plus_o3_sll_6_plus_0x40)
277 faligndata %f0, %f2, %f16
280 EX_LD_FP(LOAD(ldd, %o1 + 0x020, %f8), U3_retl_o2_plus_o3_sll_6_plus_0x40)
281 faligndata %f2, %f4, %f18
282 EX_LD_FP(LOAD(ldd, %o1 + 0x028, %f10), U3_retl_o2_plus_o3_sll_6_plus_0x40)
283 faligndata %f4, %f6, %f20
284 EX_LD_FP(LOAD(ldd, %o1 + 0x030, %f12), U3_retl_o2_plus_o3_sll_6_plus_0x40)
286 faligndata %f6, %f8, %f22
287 EX_LD_FP(LOAD(ldd, %o1 + 0x038, %f14), U3_retl_o2_plus_o3_sll_6_plus_0x80)
289 faligndata %f8, %f10, %f24
290 EX_LD_FP(LOAD(ldd, %o1 + 0x040, %f0), U3_retl_o2_plus_o3_sll_6_plus_0x80)
291 LOAD(prefetch, %o1 + 0x1c0, #one_read)
292 faligndata %f10, %f12, %f26
296 /* Finally we copy the last full 64-byte block. */
298 EX_LD_FP(LOAD(ldd, %o1 + 0x008, %f2), U3_retl_o2_plus_o3_sll_6_plus_0x80)
299 faligndata %f12, %f14, %f28
300 EX_LD_FP(LOAD(ldd, %o1 + 0x010, %f4), U3_retl_o2_plus_o3_sll_6_plus_0x80)
301 faligndata %f14, %f0, %f30
302 EX_ST_FP(STORE_BLK(%f16, %o0), U3_retl_o2_plus_o3_sll_6_plus_0x80)
303 EX_LD_FP(LOAD(ldd, %o1 + 0x018, %f6), U3_retl_o2_plus_o3_sll_6_plus_0x40)
304 faligndata %f0, %f2, %f16
305 EX_LD_FP(LOAD(ldd, %o1 + 0x020, %f8), U3_retl_o2_plus_o3_sll_6_plus_0x40)
306 faligndata %f2, %f4, %f18
307 EX_LD_FP(LOAD(ldd, %o1 + 0x028, %f10), U3_retl_o2_plus_o3_sll_6_plus_0x40)
308 faligndata %f4, %f6, %f20
309 EX_LD_FP(LOAD(ldd, %o1 + 0x030, %f12), U3_retl_o2_plus_o3_sll_6_plus_0x40)
310 faligndata %f6, %f8, %f22
311 EX_LD_FP(LOAD(ldd, %o1 + 0x038, %f14), U3_retl_o2_plus_o3_sll_6_plus_0x40)
312 faligndata %f8, %f10, %f24
316 EX_LD_FP(LOAD(ldd, %o1 + 0x040, %f0), U3_retl_o2_plus_o3_sll_6_plus_0x40)
317 1: faligndata %f10, %f12, %f26
318 faligndata %f12, %f14, %f28
319 faligndata %f14, %f0, %f30
320 EX_ST_FP(STORE_BLK(%f16, %o0), U3_retl_o2_plus_o3_sll_6_plus_0x40)
325 /* Now we copy the (len modulo 64) bytes at the end.
326 * Note how we borrow the %f0 loaded above.
328 * Also notice how this code is careful not to perform a
329 * load past the end of the src buffer.
340 EX_LD_FP(LOAD(ldd, %o1 + 0x00, %f0), U3_retl_o2_plus_g2)
342 1: EX_LD_FP(LOAD(ldd, %o1 + 0x08, %f2), U3_retl_o2_plus_g2)
345 faligndata %f0, %f2, %f8
346 EX_ST_FP(STORE(std, %f8, %o0), U3_retl_o2_plus_g2_plus_8)
349 EX_LD_FP(LOAD(ldd, %o1 + 0x08, %f0), U3_retl_o2_plus_g2)
352 faligndata %f2, %f0, %f8
353 EX_ST_FP(STORE(std, %f8, %o0), U3_retl_o2_plus_g2_plus_8)
357 /* If anything is left, we copy it one byte at a time.
358 * Note that %g1 is (src & 0x3) saved above before the
359 * alignaddr was performed.
373 EX_LD(LOAD(ldx, %o1, %o5), U3_retl_o2)
374 EX_ST(STORE(stx, %o5, %o1 + %o3), U3_retl_o2)
378 1: andcc %o2, 0x4, %g0
381 EX_LD(LOAD(lduw, %o1, %o5), U3_retl_o2)
382 EX_ST(STORE(stw, %o5, %o1 + %o3), U3_retl_o2)
386 1: andcc %o2, 0x2, %g0
389 EX_LD(LOAD(lduh, %o1, %o5), U3_retl_o2)
390 EX_ST(STORE(sth, %o5, %o1 + %o3), U3_retl_o2)
394 1: andcc %o2, 0x1, %g0
397 EX_LD(LOAD(ldub, %o1, %o5), U3_retl_o2)
399 EX_ST(STORE(stb, %o5, %o1 + %o3), U3_retl_o2)
402 70: /* 16 < len <= 64 */
407 andn %o2, 0xf, GLOBAL_SPARE
409 1: subcc GLOBAL_SPARE, 0x10, GLOBAL_SPARE
410 EX_LD(LOAD(ldx, %o1 + 0x00, %o5), U3_retl_o2_plus_GS_plus_0x10)
411 EX_LD(LOAD(ldx, %o1 + 0x08, %g1), U3_retl_o2_plus_GS_plus_0x10)
412 EX_ST(STORE(stx, %o5, %o1 + %o3), U3_retl_o2_plus_GS_plus_0x10)
414 EX_ST(STORE(stx, %g1, %o1 + %o3), U3_retl_o2_plus_GS_plus_0x08)
417 73: andcc %o2, 0x8, %g0
421 EX_LD(LOAD(ldx, %o1, %o5), U3_retl_o2_plus_8)
422 EX_ST(STORE(stx, %o5, %o1 + %o3), U3_retl_o2_plus_8)
424 1: andcc %o2, 0x4, %g0
428 EX_LD(LOAD(lduw, %o1, %o5), U3_retl_o2_plus_4)
429 EX_ST(STORE(stw, %o5, %o1 + %o3), U3_retl_o2_plus_4)
445 EX_LD(LOAD(ldub, %o1, %o5), U3_retl_o2_plus_g1_plus_1)
446 EX_ST(STORE(stb, %o5, %o1 + %o3), U3_retl_o2_plus_g1_plus_1)
462 EX_LD(LOAD(ldx, %o1, %g2), U3_retl_o2)
464 andn %o2, 0x7, GLOBAL_SPARE
466 1: EX_LD(LOAD(ldx, %o1 + 0x8, %g3), U3_retl_o2_and_7_plus_GS)
467 subcc GLOBAL_SPARE, 0x8, GLOBAL_SPARE
471 EX_ST(STORE(stx, %o5, %o0), U3_retl_o2_and_7_plus_GS_plus_8)
484 80: /* 0 < len <= 16 */
491 EX_LD(LOAD(lduw, %o1, %g1), U3_retl_o2_plus_4)
492 EX_ST(STORE(stw, %g1, %o1 + %o3), U3_retl_o2_plus_4)
497 mov EX_RETVAL(%o4), %o0
502 EX_LD(LOAD(ldub, %o1, %g1), U3_retl_o2_plus_1)
503 EX_ST(STORE(stb, %g1, %o1 + %o3), U3_retl_o2_plus_1)
507 mov EX_RETVAL(%o4), %o0
509 .size FUNC_NAME, .-FUNC_NAME