1 /* NG2memcpy.S: Niagara-2 optimized memcpy.
3 * Copyright (C) 2007 David S. Miller (davem@davemloft.net)
7 #include <asm/visasm.h>
9 #define GLOBAL_SPARE %g7
12 #define ASI_BLK_P 0xf0
13 #define ASI_BLK_INIT_QUAD_LDD_P 0xe2
16 #define VISEntryHalf rd %fprs, %o5; wr %g0, FPRS_FEF, %fprs; \
17 clr %g1; clr %g2; clr %g3; clr %g5; subcc %g0, %g0, %g0;
18 #define VISExitHalf and %o5, FPRS_FEF, %o5; wr %o5, 0x0, %fprs
20 #define VISEntryHalf rd %fprs, %o5; wr %g0, FPRS_FEF, %fprs
21 #define VISExitHalf and %o5, FPRS_FEF, %o5; wr %o5, 0x0, %fprs
23 #define GLOBAL_SPARE %g5
27 #ifndef SIMULATE_NIAGARA_ON_NON_NIAGARA
28 #define STORE_ASI ASI_BLK_INIT_QUAD_LDD_P
30 #define STORE_ASI 0x80 /* ASI_P */
49 #define EX_RETVAL(x) x
53 #define LOAD(type,addr,dest) type [addr], dest
57 #define LOAD_BLK(addr,dest) ldda [addr] ASI_BLK_P, dest
62 #define STORE(type,src,addr) type src, [addr]
64 #define STORE(type,src,addr) type##a src, [addr] 0x80
69 #define STORE_BLK(src,addr) stda src, [addr] ASI_BLK_P
73 #define STORE_INIT(src,addr) stxa src, [addr] STORE_ASI
77 #define FUNC_NAME NG2memcpy
88 #define FREG_FROB(x0, x1, x2, x3, x4, x5, x6, x7, x8) \
89 faligndata %x0, %x1, %f0; \
90 faligndata %x1, %x2, %f2; \
91 faligndata %x2, %x3, %f4; \
92 faligndata %x3, %x4, %f6; \
93 faligndata %x4, %x5, %f8; \
94 faligndata %x5, %x6, %f10; \
95 faligndata %x6, %x7, %f12; \
96 faligndata %x7, %x8, %f14;
98 #define FREG_MOVE_1(x0) \
100 #define FREG_MOVE_2(x0, x1) \
103 #define FREG_MOVE_3(x0, x1, x2) \
107 #define FREG_MOVE_4(x0, x1, x2, x3) \
112 #define FREG_MOVE_5(x0, x1, x2, x3, x4) \
118 #define FREG_MOVE_6(x0, x1, x2, x3, x4, x5) \
125 #define FREG_MOVE_7(x0, x1, x2, x3, x4, x5, x6) \
133 #define FREG_MOVE_8(x0, x1, x2, x3, x4, x5, x6, x7) \
142 #define FREG_LOAD_1(base, x0) \
143 EX_LD_FP(LOAD(ldd, base + 0x00, %x0))
144 #define FREG_LOAD_2(base, x0, x1) \
145 EX_LD_FP(LOAD(ldd, base + 0x00, %x0)); \
146 EX_LD_FP(LOAD(ldd, base + 0x08, %x1));
147 #define FREG_LOAD_3(base, x0, x1, x2) \
148 EX_LD_FP(LOAD(ldd, base + 0x00, %x0)); \
149 EX_LD_FP(LOAD(ldd, base + 0x08, %x1)); \
150 EX_LD_FP(LOAD(ldd, base + 0x10, %x2));
151 #define FREG_LOAD_4(base, x0, x1, x2, x3) \
152 EX_LD_FP(LOAD(ldd, base + 0x00, %x0)); \
153 EX_LD_FP(LOAD(ldd, base + 0x08, %x1)); \
154 EX_LD_FP(LOAD(ldd, base + 0x10, %x2)); \
155 EX_LD_FP(LOAD(ldd, base + 0x18, %x3));
156 #define FREG_LOAD_5(base, x0, x1, x2, x3, x4) \
157 EX_LD_FP(LOAD(ldd, base + 0x00, %x0)); \
158 EX_LD_FP(LOAD(ldd, base + 0x08, %x1)); \
159 EX_LD_FP(LOAD(ldd, base + 0x10, %x2)); \
160 EX_LD_FP(LOAD(ldd, base + 0x18, %x3)); \
161 EX_LD_FP(LOAD(ldd, base + 0x20, %x4));
162 #define FREG_LOAD_6(base, x0, x1, x2, x3, x4, x5) \
163 EX_LD_FP(LOAD(ldd, base + 0x00, %x0)); \
164 EX_LD_FP(LOAD(ldd, base + 0x08, %x1)); \
165 EX_LD_FP(LOAD(ldd, base + 0x10, %x2)); \
166 EX_LD_FP(LOAD(ldd, base + 0x18, %x3)); \
167 EX_LD_FP(LOAD(ldd, base + 0x20, %x4)); \
168 EX_LD_FP(LOAD(ldd, base + 0x28, %x5));
169 #define FREG_LOAD_7(base, x0, x1, x2, x3, x4, x5, x6) \
170 EX_LD_FP(LOAD(ldd, base + 0x00, %x0)); \
171 EX_LD_FP(LOAD(ldd, base + 0x08, %x1)); \
172 EX_LD_FP(LOAD(ldd, base + 0x10, %x2)); \
173 EX_LD_FP(LOAD(ldd, base + 0x18, %x3)); \
174 EX_LD_FP(LOAD(ldd, base + 0x20, %x4)); \
175 EX_LD_FP(LOAD(ldd, base + 0x28, %x5)); \
176 EX_LD_FP(LOAD(ldd, base + 0x30, %x6));
178 .register %g2,#scratch
179 .register %g3,#scratch
185 .type FUNC_NAME,#function
186 FUNC_NAME: /* %o0=dst, %o1=src, %o2=len */
194 or %o0, %o1, GLOBAL_SPARE
197 or GLOBAL_SPARE, %o2, GLOBAL_SPARE
199 /* 2 blocks (128 bytes) is the minimum we can do the block
200 * copy with. We need to ensure that we'll iterate at least
201 * once in the block copy loop. At worst we'll need to align
202 * the destination to a 64-byte boundary which can chew up
203 * to (64 - 1) bytes from the length before we perform the
206 * However, the cut-off point, performance wise, is around
211 andcc GLOBAL_SPARE, 0x7, %g0
215 * %o2: len (known to be >= 128)
217 * The block copy loops can use %o4, %g2, %g3 as
218 * temporaries while copying the data. %o5 must
219 * be preserved between VISEntryHalf and VISExitHalf
222 LOAD(prefetch, %o1 + 0x000, #one_read)
223 LOAD(prefetch, %o1 + 0x040, #one_read)
224 LOAD(prefetch, %o1 + 0x080, #one_read)
226 /* Align destination on 64-byte boundary. */
227 andcc %o0, (64 - 1), %o4
230 sub %g0, %o4, %o4 ! bytes to align dst
233 EX_LD(LOAD(ldub, %o1, %g1))
234 EX_ST(STORE(stb, %g1, %o0))
240 /* Clobbers o5/g1/g2/g3/g7/icc/xcc. We must preserve
241 * o5 from here until we hit VISExitHalf.
246 alignaddr %o1, %g0, %g0
248 add %o1, (64 - 1), %o4
249 andn %o4, (64 - 1), %o4
250 andn %o2, (64 - 1), %g1
253 and %o1, (64 - 1), %g2
268 4: /* 32 <= low bits < 48 */
272 5: /* 0 < low bits < 32 */
279 6: /* 0 < low bits < 16 */
282 /* fall through for 0 < low bits < 8 */
283 110: sub %o4, 64, %g2
284 EX_LD_FP(LOAD_BLK(%g2, %f0))
285 1: EX_ST_FP(STORE_INIT(%g0, %o4 + %g3))
286 EX_LD_FP(LOAD_BLK(%o4, %f16))
287 FREG_FROB(f0, f2, f4, f6, f8, f10, f12, f14, f16)
288 EX_ST_FP(STORE_BLK(%f0, %o4 + %g3))
289 FREG_MOVE_8(f16, f18, f20, f22, f24, f26, f28, f30)
293 LOAD(prefetch, %o4 + 64, #one_read)
297 120: sub %o4, 56, %g2
298 FREG_LOAD_7(%g2, f0, f2, f4, f6, f8, f10, f12)
299 1: EX_ST_FP(STORE_INIT(%g0, %o4 + %g3))
300 EX_LD_FP(LOAD_BLK(%o4, %f16))
301 FREG_FROB(f0, f2, f4, f6, f8, f10, f12, f16, f18)
302 EX_ST_FP(STORE_BLK(%f0, %o4 + %g3))
303 FREG_MOVE_7(f18, f20, f22, f24, f26, f28, f30)
307 LOAD(prefetch, %o4 + 64, #one_read)
311 130: sub %o4, 48, %g2
312 FREG_LOAD_6(%g2, f0, f2, f4, f6, f8, f10)
313 1: EX_ST_FP(STORE_INIT(%g0, %o4 + %g3))
314 EX_LD_FP(LOAD_BLK(%o4, %f16))
315 FREG_FROB(f0, f2, f4, f6, f8, f10, f16, f18, f20)
316 EX_ST_FP(STORE_BLK(%f0, %o4 + %g3))
317 FREG_MOVE_6(f20, f22, f24, f26, f28, f30)
321 LOAD(prefetch, %o4 + 64, #one_read)
325 140: sub %o4, 40, %g2
326 FREG_LOAD_5(%g2, f0, f2, f4, f6, f8)
327 1: EX_ST_FP(STORE_INIT(%g0, %o4 + %g3))
328 EX_LD_FP(LOAD_BLK(%o4, %f16))
329 FREG_FROB(f0, f2, f4, f6, f8, f16, f18, f20, f22)
330 EX_ST_FP(STORE_BLK(%f0, %o4 + %g3))
331 FREG_MOVE_5(f22, f24, f26, f28, f30)
335 LOAD(prefetch, %o4 + 64, #one_read)
339 150: sub %o4, 32, %g2
340 FREG_LOAD_4(%g2, f0, f2, f4, f6)
341 1: EX_ST_FP(STORE_INIT(%g0, %o4 + %g3))
342 EX_LD_FP(LOAD_BLK(%o4, %f16))
343 FREG_FROB(f0, f2, f4, f6, f16, f18, f20, f22, f24)
344 EX_ST_FP(STORE_BLK(%f0, %o4 + %g3))
345 FREG_MOVE_4(f24, f26, f28, f30)
349 LOAD(prefetch, %o4 + 64, #one_read)
353 160: sub %o4, 24, %g2
354 FREG_LOAD_3(%g2, f0, f2, f4)
355 1: EX_ST_FP(STORE_INIT(%g0, %o4 + %g3))
356 EX_LD_FP(LOAD_BLK(%o4, %f16))
357 FREG_FROB(f0, f2, f4, f16, f18, f20, f22, f24, f26)
358 EX_ST_FP(STORE_BLK(%f0, %o4 + %g3))
359 FREG_MOVE_3(f26, f28, f30)
363 LOAD(prefetch, %o4 + 64, #one_read)
367 170: sub %o4, 16, %g2
368 FREG_LOAD_2(%g2, f0, f2)
369 1: EX_ST_FP(STORE_INIT(%g0, %o4 + %g3))
370 EX_LD_FP(LOAD_BLK(%o4, %f16))
371 FREG_FROB(f0, f2, f16, f18, f20, f22, f24, f26, f28)
372 EX_ST_FP(STORE_BLK(%f0, %o4 + %g3))
373 FREG_MOVE_2(f28, f30)
377 LOAD(prefetch, %o4 + 64, #one_read)
383 1: EX_ST_FP(STORE_INIT(%g0, %o4 + %g3))
384 EX_LD_FP(LOAD_BLK(%o4, %f16))
385 FREG_FROB(f0, f16, f18, f20, f22, f24, f26, f28, f30)
386 EX_ST_FP(STORE_BLK(%f0, %o4 + %g3))
391 LOAD(prefetch, %o4 + 64, #one_read)
396 1: EX_ST_FP(STORE_INIT(%g0, %o4 + %g3))
398 EX_LD_FP(LOAD_BLK(%o4, %f0))
399 EX_ST_FP(STORE_BLK(%f0, %o4 + %g3))
402 LOAD(prefetch, %o4 + 64, #one_read)
410 /* %o2 contains any final bytes still needed to be copied
411 * over. If anything is left, we copy it one byte at a time.
414 sub %o0, %o1, GLOBAL_SPARE
418 75: /* 16 < len <= 64 */
420 sub %o0, %o1, GLOBAL_SPARE
425 1: subcc %o4, 0x10, %o4
426 EX_LD(LOAD(ldx, %o1, %o5))
428 EX_LD(LOAD(ldx, %o1, %g1))
430 EX_ST(STORE(stx, %o5, %o1 + GLOBAL_SPARE))
432 EX_ST(STORE(stx, %g1, %o1 + GLOBAL_SPARE))
435 73: andcc %o2, 0x8, %g0
439 EX_LD(LOAD(ldx, %o1, %o5))
440 EX_ST(STORE(stx, %o5, %o1 + GLOBAL_SPARE))
442 1: andcc %o2, 0x4, %g0
446 EX_LD(LOAD(lduw, %o1, %o5))
447 EX_ST(STORE(stw, %o5, %o1 + GLOBAL_SPARE))
463 EX_LD(LOAD(ldub, %o1, %o5))
464 EX_ST(STORE(stb, %o5, %o1 + GLOBAL_SPARE))
468 2: add %o1, GLOBAL_SPARE, %o0
478 8: mov 64, GLOBAL_SPARE
480 EX_LD(LOAD(ldx, %o1, %g2))
481 sub GLOBAL_SPARE, %g1, GLOBAL_SPARE
485 EX_LD(LOAD(ldx, %o1, %g3))
487 srlx %g3, GLOBAL_SPARE, %o5
489 EX_ST(STORE(stx, %o5, %o0))
499 sub %o0, %o1, GLOBAL_SPARE
502 80: /* 0 < len <= 16 */
503 andcc GLOBAL_SPARE, 0x3, %g0
505 sub %o0, %o1, GLOBAL_SPARE
509 EX_LD(LOAD(lduw, %o1, %g1))
510 EX_ST(STORE(stw, %g1, %o1 + GLOBAL_SPARE))
515 mov EX_RETVAL(%o3), %o0
520 EX_LD(LOAD(ldub, %o1, %g1))
521 EX_ST(STORE(stb, %g1, %o1 + GLOBAL_SPARE))
525 mov EX_RETVAL(%o3), %o0
527 .size FUNC_NAME, .-FUNC_NAME