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 */
43 #define EX_RETVAL(x) x
47 #define LOAD(type,addr,dest) type [addr], dest
51 #define LOAD_BLK(addr,dest) ldda [addr] ASI_BLK_P, dest
56 #define STORE(type,src,addr) type src, [addr]
58 #define STORE(type,src,addr) type##a src, [addr] 0x80
63 #define STORE_BLK(src,addr) stda src, [addr] ASI_BLK_P
67 #define STORE_INIT(src,addr) stxa src, [addr] STORE_ASI
71 #define FUNC_NAME NG2memcpy
82 #define FREG_FROB(x0, x1, x2, x3, x4, x5, x6, x7, x8) \
83 faligndata %x0, %x1, %f0; \
84 faligndata %x1, %x2, %f2; \
85 faligndata %x2, %x3, %f4; \
86 faligndata %x3, %x4, %f6; \
87 faligndata %x4, %x5, %f8; \
88 faligndata %x5, %x6, %f10; \
89 faligndata %x6, %x7, %f12; \
90 faligndata %x7, %x8, %f14;
92 #define FREG_MOVE_1(x0) \
94 #define FREG_MOVE_2(x0, x1) \
97 #define FREG_MOVE_3(x0, x1, x2) \
101 #define FREG_MOVE_4(x0, x1, x2, x3) \
106 #define FREG_MOVE_5(x0, x1, x2, x3, x4) \
112 #define FREG_MOVE_6(x0, x1, x2, x3, x4, x5) \
119 #define FREG_MOVE_7(x0, x1, x2, x3, x4, x5, x6) \
127 #define FREG_MOVE_8(x0, x1, x2, x3, x4, x5, x6, x7) \
136 #define FREG_LOAD_1(base, x0) \
137 EX_LD(LOAD(ldd, base + 0x00, %x0))
138 #define FREG_LOAD_2(base, x0, x1) \
139 EX_LD(LOAD(ldd, base + 0x00, %x0)); \
140 EX_LD(LOAD(ldd, base + 0x08, %x1));
141 #define FREG_LOAD_3(base, x0, x1, x2) \
142 EX_LD(LOAD(ldd, base + 0x00, %x0)); \
143 EX_LD(LOAD(ldd, base + 0x08, %x1)); \
144 EX_LD(LOAD(ldd, base + 0x10, %x2));
145 #define FREG_LOAD_4(base, x0, x1, x2, x3) \
146 EX_LD(LOAD(ldd, base + 0x00, %x0)); \
147 EX_LD(LOAD(ldd, base + 0x08, %x1)); \
148 EX_LD(LOAD(ldd, base + 0x10, %x2)); \
149 EX_LD(LOAD(ldd, base + 0x18, %x3));
150 #define FREG_LOAD_5(base, x0, x1, x2, x3, x4) \
151 EX_LD(LOAD(ldd, base + 0x00, %x0)); \
152 EX_LD(LOAD(ldd, base + 0x08, %x1)); \
153 EX_LD(LOAD(ldd, base + 0x10, %x2)); \
154 EX_LD(LOAD(ldd, base + 0x18, %x3)); \
155 EX_LD(LOAD(ldd, base + 0x20, %x4));
156 #define FREG_LOAD_6(base, x0, x1, x2, x3, x4, x5) \
157 EX_LD(LOAD(ldd, base + 0x00, %x0)); \
158 EX_LD(LOAD(ldd, base + 0x08, %x1)); \
159 EX_LD(LOAD(ldd, base + 0x10, %x2)); \
160 EX_LD(LOAD(ldd, base + 0x18, %x3)); \
161 EX_LD(LOAD(ldd, base + 0x20, %x4)); \
162 EX_LD(LOAD(ldd, base + 0x28, %x5));
163 #define FREG_LOAD_7(base, x0, x1, x2, x3, x4, x5, x6) \
164 EX_LD(LOAD(ldd, base + 0x00, %x0)); \
165 EX_LD(LOAD(ldd, base + 0x08, %x1)); \
166 EX_LD(LOAD(ldd, base + 0x10, %x2)); \
167 EX_LD(LOAD(ldd, base + 0x18, %x3)); \
168 EX_LD(LOAD(ldd, base + 0x20, %x4)); \
169 EX_LD(LOAD(ldd, base + 0x28, %x5)); \
170 EX_LD(LOAD(ldd, base + 0x30, %x6));
172 .register %g2,#scratch
173 .register %g3,#scratch
179 .type FUNC_NAME,#function
180 FUNC_NAME: /* %o0=dst, %o1=src, %o2=len */
188 or %o0, %o1, GLOBAL_SPARE
191 or GLOBAL_SPARE, %o2, GLOBAL_SPARE
193 /* 2 blocks (128 bytes) is the minimum we can do the block
194 * copy with. We need to ensure that we'll iterate at least
195 * once in the block copy loop. At worst we'll need to align
196 * the destination to a 64-byte boundary which can chew up
197 * to (64 - 1) bytes from the length before we perform the
200 * However, the cut-off point, performance wise, is around
205 andcc GLOBAL_SPARE, 0x7, %g0
209 * %o2: len (known to be >= 128)
211 * The block copy loops can use %o4, %g2, %g3 as
212 * temporaries while copying the data. %o5 must
213 * be preserved between VISEntryHalf and VISExitHalf
216 LOAD(prefetch, %o1 + 0x000, #one_read)
217 LOAD(prefetch, %o1 + 0x040, #one_read)
218 LOAD(prefetch, %o1 + 0x080, #one_read)
220 /* Align destination on 64-byte boundary. */
221 andcc %o0, (64 - 1), %o4
224 sub %g0, %o4, %o4 ! bytes to align dst
227 EX_LD(LOAD(ldub, %o1, %g1))
228 EX_ST(STORE(stb, %g1, %o0))
234 /* Clobbers o5/g1/g2/g3/g7/icc/xcc. We must preserve
235 * o5 from here until we hit VISExitHalf.
240 alignaddr %o1, %g0, %g0
242 add %o1, (64 - 1), %o4
243 andn %o4, (64 - 1), %o4
244 andn %o2, (64 - 1), %g1
247 and %o1, (64 - 1), %g2
262 4: /* 32 <= low bits < 48 */
266 5: /* 0 < low bits < 32 */
273 6: /* 0 < low bits < 16 */
276 /* fall through for 0 < low bits < 8 */
277 110: sub %o4, 64, %g2
278 EX_LD(LOAD_BLK(%g2, %f0))
279 1: EX_ST(STORE_INIT(%g0, %o4 + %g3))
280 EX_LD(LOAD_BLK(%o4, %f16))
281 FREG_FROB(f0, f2, f4, f6, f8, f10, f12, f14, f16)
282 EX_ST(STORE_BLK(%f0, %o4 + %g3))
283 FREG_MOVE_8(f16, f18, f20, f22, f24, f26, f28, f30)
287 LOAD(prefetch, %o4 + 64, #one_read)
291 120: sub %o4, 56, %g2
292 FREG_LOAD_7(%g2, f0, f2, f4, f6, f8, f10, f12)
293 1: EX_ST(STORE_INIT(%g0, %o4 + %g3))
294 EX_LD(LOAD_BLK(%o4, %f16))
295 FREG_FROB(f0, f2, f4, f6, f8, f10, f12, f16, f18)
296 EX_ST(STORE_BLK(%f0, %o4 + %g3))
297 FREG_MOVE_7(f18, f20, f22, f24, f26, f28, f30)
301 LOAD(prefetch, %o4 + 64, #one_read)
305 130: sub %o4, 48, %g2
306 FREG_LOAD_6(%g2, f0, f2, f4, f6, f8, f10)
307 1: EX_ST(STORE_INIT(%g0, %o4 + %g3))
308 EX_LD(LOAD_BLK(%o4, %f16))
309 FREG_FROB(f0, f2, f4, f6, f8, f10, f16, f18, f20)
310 EX_ST(STORE_BLK(%f0, %o4 + %g3))
311 FREG_MOVE_6(f20, f22, f24, f26, f28, f30)
315 LOAD(prefetch, %o4 + 64, #one_read)
319 140: sub %o4, 40, %g2
320 FREG_LOAD_5(%g2, f0, f2, f4, f6, f8)
321 1: EX_ST(STORE_INIT(%g0, %o4 + %g3))
322 EX_LD(LOAD_BLK(%o4, %f16))
323 FREG_FROB(f0, f2, f4, f6, f8, f16, f18, f20, f22)
324 EX_ST(STORE_BLK(%f0, %o4 + %g3))
325 FREG_MOVE_5(f22, f24, f26, f28, f30)
329 LOAD(prefetch, %o4 + 64, #one_read)
333 150: sub %o4, 32, %g2
334 FREG_LOAD_4(%g2, f0, f2, f4, f6)
335 1: EX_ST(STORE_INIT(%g0, %o4 + %g3))
336 EX_LD(LOAD_BLK(%o4, %f16))
337 FREG_FROB(f0, f2, f4, f6, f16, f18, f20, f22, f24)
338 EX_ST(STORE_BLK(%f0, %o4 + %g3))
339 FREG_MOVE_4(f24, f26, f28, f30)
343 LOAD(prefetch, %o4 + 64, #one_read)
347 160: sub %o4, 24, %g2
348 FREG_LOAD_3(%g2, f0, f2, f4)
349 1: EX_ST(STORE_INIT(%g0, %o4 + %g3))
350 EX_LD(LOAD_BLK(%o4, %f16))
351 FREG_FROB(f0, f2, f4, f16, f18, f20, f22, f24, f26)
352 EX_ST(STORE_BLK(%f0, %o4 + %g3))
353 FREG_MOVE_3(f26, f28, f30)
357 LOAD(prefetch, %o4 + 64, #one_read)
361 170: sub %o4, 16, %g2
362 FREG_LOAD_2(%g2, f0, f2)
363 1: EX_ST(STORE_INIT(%g0, %o4 + %g3))
364 EX_LD(LOAD_BLK(%o4, %f16))
365 FREG_FROB(f0, f2, f16, f18, f20, f22, f24, f26, f28)
366 EX_ST(STORE_BLK(%f0, %o4 + %g3))
367 FREG_MOVE_2(f28, f30)
371 LOAD(prefetch, %o4 + 64, #one_read)
377 1: EX_ST(STORE_INIT(%g0, %o4 + %g3))
378 EX_LD(LOAD_BLK(%o4, %f16))
379 FREG_FROB(f0, f16, f18, f20, f22, f24, f26, f28, f30)
380 EX_ST(STORE_BLK(%f0, %o4 + %g3))
385 LOAD(prefetch, %o4 + 64, #one_read)
390 1: EX_ST(STORE_INIT(%g0, %o4 + %g3))
392 EX_LD(LOAD_BLK(%o4, %f0))
393 EX_ST(STORE_BLK(%f0, %o4 + %g3))
396 LOAD(prefetch, %o4 + 64, #one_read)
404 /* %o2 contains any final bytes still needed to be copied
405 * over. If anything is left, we copy it one byte at a time.
408 sub %o0, %o1, GLOBAL_SPARE
412 75: /* 16 < len <= 64 */
414 sub %o0, %o1, GLOBAL_SPARE
419 1: subcc %o4, 0x10, %o4
420 EX_LD(LOAD(ldx, %o1, %o5))
422 EX_LD(LOAD(ldx, %o1, %g1))
424 EX_ST(STORE(stx, %o5, %o1 + GLOBAL_SPARE))
426 EX_ST(STORE(stx, %g1, %o1 + GLOBAL_SPARE))
429 73: andcc %o2, 0x8, %g0
433 EX_LD(LOAD(ldx, %o1, %o5))
434 EX_ST(STORE(stx, %o5, %o1 + GLOBAL_SPARE))
436 1: andcc %o2, 0x4, %g0
440 EX_LD(LOAD(lduw, %o1, %o5))
441 EX_ST(STORE(stw, %o5, %o1 + GLOBAL_SPARE))
457 EX_LD(LOAD(ldub, %o1, %o5))
458 EX_ST(STORE(stb, %o5, %o1 + GLOBAL_SPARE))
462 2: add %o1, GLOBAL_SPARE, %o0
472 8: mov 64, GLOBAL_SPARE
474 EX_LD(LOAD(ldx, %o1, %g2))
475 sub GLOBAL_SPARE, %g1, GLOBAL_SPARE
479 EX_LD(LOAD(ldx, %o1, %g3))
481 srlx %g3, GLOBAL_SPARE, %o5
483 EX_ST(STORE(stx, %o5, %o0))
493 sub %o0, %o1, GLOBAL_SPARE
496 80: /* 0 < len <= 16 */
497 andcc GLOBAL_SPARE, 0x3, %g0
499 sub %o0, %o1, GLOBAL_SPARE
503 EX_LD(LOAD(lduw, %o1, %g1))
504 EX_ST(STORE(stw, %g1, %o1 + GLOBAL_SPARE))
509 mov EX_RETVAL(%o3), %o0
514 EX_LD(LOAD(ldub, %o1, %g1))
515 EX_ST(STORE(stb, %g1, %o1 + GLOBAL_SPARE))
519 mov EX_RETVAL(%o3), %o0
521 .size FUNC_NAME, .-FUNC_NAME