1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* NG2memcpy.S: Niagara-2 optimized memcpy.
4 * Copyright (C) 2007 David S. Miller (davem@davemloft.net)
8 #include <linux/linkage.h>
9 #include <asm/visasm.h>
11 #define GLOBAL_SPARE %g7
14 #define ASI_BLK_P 0xf0
15 #define ASI_BLK_INIT_QUAD_LDD_P 0xe2
18 #define VISEntryHalf rd %fprs, %o5; wr %g0, FPRS_FEF, %fprs; \
19 clr %g1; clr %g2; clr %g3; clr %g5; subcc %g0, %g0, %g0;
20 #define VISExitHalf and %o5, FPRS_FEF, %o5; wr %o5, 0x0, %fprs
22 #define VISEntryHalf rd %fprs, %o5; wr %g0, FPRS_FEF, %fprs
23 #define VISExitHalf and %o5, FPRS_FEF, %o5; wr %o5, 0x0, %fprs
25 #define GLOBAL_SPARE %g5
29 #ifndef SIMULATE_NIAGARA_ON_NON_NIAGARA
30 #define STORE_ASI ASI_BLK_INIT_QUAD_LDD_P
32 #define STORE_ASI 0x80 /* ASI_P */
40 #define EX_LD_FP(x,y) x
47 #define EX_ST_FP(x,y) x
51 #define LOAD(type,addr,dest) type [addr], dest
55 #define LOAD_BLK(addr,dest) ldda [addr] ASI_BLK_P, dest
60 #define STORE(type,src,addr) type src, [addr]
62 #define STORE(type,src,addr) type##a src, [addr] 0x80
67 #define STORE_BLK(src,addr) stda src, [addr] ASI_BLK_P
71 #define STORE_INIT(src,addr) stxa src, [addr] STORE_ASI
75 #define FUNC_NAME NG2memcpy
86 #define FREG_FROB(x0, x1, x2, x3, x4, x5, x6, x7, x8) \
87 faligndata %x0, %x1, %f0; \
88 faligndata %x1, %x2, %f2; \
89 faligndata %x2, %x3, %f4; \
90 faligndata %x3, %x4, %f6; \
91 faligndata %x4, %x5, %f8; \
92 faligndata %x5, %x6, %f10; \
93 faligndata %x6, %x7, %f12; \
94 faligndata %x7, %x8, %f14;
96 #define FREG_MOVE_1(x0) \
98 #define FREG_MOVE_2(x0, x1) \
101 #define FREG_MOVE_3(x0, x1, x2) \
105 #define FREG_MOVE_4(x0, x1, x2, x3) \
110 #define FREG_MOVE_5(x0, x1, x2, x3, x4) \
116 #define FREG_MOVE_6(x0, x1, x2, x3, x4, x5) \
123 #define FREG_MOVE_7(x0, x1, x2, x3, x4, x5, x6) \
131 #define FREG_MOVE_8(x0, x1, x2, x3, x4, x5, x6, x7) \
140 #define FREG_LOAD_1(base, x0) \
141 EX_LD_FP(LOAD(ldd, base + 0x00, %x0), NG2_retl_o2_plus_g1)
142 #define FREG_LOAD_2(base, x0, x1) \
143 EX_LD_FP(LOAD(ldd, base + 0x00, %x0), NG2_retl_o2_plus_g1); \
144 EX_LD_FP(LOAD(ldd, base + 0x08, %x1), NG2_retl_o2_plus_g1);
145 #define FREG_LOAD_3(base, x0, x1, x2) \
146 EX_LD_FP(LOAD(ldd, base + 0x00, %x0), NG2_retl_o2_plus_g1); \
147 EX_LD_FP(LOAD(ldd, base + 0x08, %x1), NG2_retl_o2_plus_g1); \
148 EX_LD_FP(LOAD(ldd, base + 0x10, %x2), NG2_retl_o2_plus_g1);
149 #define FREG_LOAD_4(base, x0, x1, x2, x3) \
150 EX_LD_FP(LOAD(ldd, base + 0x00, %x0), NG2_retl_o2_plus_g1); \
151 EX_LD_FP(LOAD(ldd, base + 0x08, %x1), NG2_retl_o2_plus_g1); \
152 EX_LD_FP(LOAD(ldd, base + 0x10, %x2), NG2_retl_o2_plus_g1); \
153 EX_LD_FP(LOAD(ldd, base + 0x18, %x3), NG2_retl_o2_plus_g1);
154 #define FREG_LOAD_5(base, x0, x1, x2, x3, x4) \
155 EX_LD_FP(LOAD(ldd, base + 0x00, %x0), NG2_retl_o2_plus_g1); \
156 EX_LD_FP(LOAD(ldd, base + 0x08, %x1), NG2_retl_o2_plus_g1); \
157 EX_LD_FP(LOAD(ldd, base + 0x10, %x2), NG2_retl_o2_plus_g1); \
158 EX_LD_FP(LOAD(ldd, base + 0x18, %x3), NG2_retl_o2_plus_g1); \
159 EX_LD_FP(LOAD(ldd, base + 0x20, %x4), NG2_retl_o2_plus_g1);
160 #define FREG_LOAD_6(base, x0, x1, x2, x3, x4, x5) \
161 EX_LD_FP(LOAD(ldd, base + 0x00, %x0), NG2_retl_o2_plus_g1); \
162 EX_LD_FP(LOAD(ldd, base + 0x08, %x1), NG2_retl_o2_plus_g1); \
163 EX_LD_FP(LOAD(ldd, base + 0x10, %x2), NG2_retl_o2_plus_g1); \
164 EX_LD_FP(LOAD(ldd, base + 0x18, %x3), NG2_retl_o2_plus_g1); \
165 EX_LD_FP(LOAD(ldd, base + 0x20, %x4), NG2_retl_o2_plus_g1); \
166 EX_LD_FP(LOAD(ldd, base + 0x28, %x5), NG2_retl_o2_plus_g1);
167 #define FREG_LOAD_7(base, x0, x1, x2, x3, x4, x5, x6) \
168 EX_LD_FP(LOAD(ldd, base + 0x00, %x0), NG2_retl_o2_plus_g1); \
169 EX_LD_FP(LOAD(ldd, base + 0x08, %x1), NG2_retl_o2_plus_g1); \
170 EX_LD_FP(LOAD(ldd, base + 0x10, %x2), NG2_retl_o2_plus_g1); \
171 EX_LD_FP(LOAD(ldd, base + 0x18, %x3), NG2_retl_o2_plus_g1); \
172 EX_LD_FP(LOAD(ldd, base + 0x20, %x4), NG2_retl_o2_plus_g1); \
173 EX_LD_FP(LOAD(ldd, base + 0x28, %x5), NG2_retl_o2_plus_g1); \
174 EX_LD_FP(LOAD(ldd, base + 0x30, %x6), NG2_retl_o2_plus_g1);
176 .register %g2,#scratch
177 .register %g3,#scratch
181 #define EX_RETVAL(x) x
186 wr %g0, ASI_AIUS, %asi
188 ba,pt %xcc, __restore_asi
191 ENTRY(NG2_retl_o2_plus_1)
192 ba,pt %xcc, __restore_asi
194 ENDPROC(NG2_retl_o2_plus_1)
195 ENTRY(NG2_retl_o2_plus_4)
196 ba,pt %xcc, __restore_asi
198 ENDPROC(NG2_retl_o2_plus_4)
199 ENTRY(NG2_retl_o2_plus_8)
200 ba,pt %xcc, __restore_asi
202 ENDPROC(NG2_retl_o2_plus_8)
203 ENTRY(NG2_retl_o2_plus_o4_plus_1)
205 ba,pt %xcc, __restore_asi
207 ENDPROC(NG2_retl_o2_plus_o4_plus_1)
208 ENTRY(NG2_retl_o2_plus_o4_plus_8)
210 ba,pt %xcc, __restore_asi
212 ENDPROC(NG2_retl_o2_plus_o4_plus_8)
213 ENTRY(NG2_retl_o2_plus_o4_plus_16)
215 ba,pt %xcc, __restore_asi
217 ENDPROC(NG2_retl_o2_plus_o4_plus_16)
218 ENTRY(NG2_retl_o2_plus_g1_fp)
219 ba,pt %xcc, __restore_fp
221 ENDPROC(NG2_retl_o2_plus_g1_fp)
222 ENTRY(NG2_retl_o2_plus_g1_plus_64_fp)
224 ba,pt %xcc, __restore_fp
226 ENDPROC(NG2_retl_o2_plus_g1_plus_64_fp)
227 ENTRY(NG2_retl_o2_plus_g1_plus_1)
229 ba,pt %xcc, __restore_asi
231 ENDPROC(NG2_retl_o2_plus_g1_plus_1)
232 ENTRY(NG2_retl_o2_and_7_plus_o4)
234 ba,pt %xcc, __restore_asi
236 ENDPROC(NG2_retl_o2_and_7_plus_o4)
237 ENTRY(NG2_retl_o2_and_7_plus_o4_plus_8)
240 ba,pt %xcc, __restore_asi
242 ENDPROC(NG2_retl_o2_and_7_plus_o4_plus_8)
248 .type FUNC_NAME,#function
249 FUNC_NAME: /* %o0=dst, %o1=src, %o2=len */
257 or %o0, %o1, GLOBAL_SPARE
260 or GLOBAL_SPARE, %o2, GLOBAL_SPARE
262 /* 2 blocks (128 bytes) is the minimum we can do the block
263 * copy with. We need to ensure that we'll iterate at least
264 * once in the block copy loop. At worst we'll need to align
265 * the destination to a 64-byte boundary which can chew up
266 * to (64 - 1) bytes from the length before we perform the
269 * However, the cut-off point, performance wise, is around
274 andcc GLOBAL_SPARE, 0x7, %g0
278 * %o2: len (known to be >= 128)
280 * The block copy loops can use %o4, %g2, %g3 as
281 * temporaries while copying the data. %o5 must
282 * be preserved between VISEntryHalf and VISExitHalf
285 LOAD(prefetch, %o1 + 0x000, #one_read)
286 LOAD(prefetch, %o1 + 0x040, #one_read)
287 LOAD(prefetch, %o1 + 0x080, #one_read)
289 /* Align destination on 64-byte boundary. */
290 andcc %o0, (64 - 1), %o4
293 sub %g0, %o4, %o4 ! bytes to align dst
296 EX_LD(LOAD(ldub, %o1, %g1), NG2_retl_o2_plus_o4_plus_1)
297 EX_ST(STORE(stb, %g1, %o0), NG2_retl_o2_plus_o4_plus_1)
303 /* Clobbers o5/g1/g2/g3/g7/icc/xcc. We must preserve
304 * o5 from here until we hit VISExitHalf.
309 alignaddr %o1, %g0, %g0
311 add %o1, (64 - 1), %o4
312 andn %o4, (64 - 1), %o4
313 andn %o2, (64 - 1), %g1
316 and %o1, (64 - 1), %g2
332 4: /* 32 <= low bits < 48 */
337 5: /* 0 < low bits < 32 */
345 6: /* 0 < low bits < 16 */
348 /* fall through for 0 < low bits < 8 */
349 110: sub %o4, 64, %g2
350 EX_LD_FP(LOAD_BLK(%g2, %f0), NG2_retl_o2_plus_g1)
351 1: EX_ST_FP(STORE_INIT(%g0, %o4 + %g3), NG2_retl_o2_plus_g1)
352 EX_LD_FP(LOAD_BLK(%o4, %f16), NG2_retl_o2_plus_g1)
353 FREG_FROB(f0, f2, f4, f6, f8, f10, f12, f14, f16)
354 EX_ST_FP(STORE_BLK(%f0, %o4 + %g3), NG2_retl_o2_plus_g1)
355 FREG_MOVE_8(f16, f18, f20, f22, f24, f26, f28, f30)
359 LOAD(prefetch, %o4 + 64, #one_read)
363 120: sub %o4, 56, %g2
364 FREG_LOAD_7(%g2, f0, f2, f4, f6, f8, f10, f12)
365 1: EX_ST_FP(STORE_INIT(%g0, %o4 + %g3), NG2_retl_o2_plus_g1)
366 EX_LD_FP(LOAD_BLK(%o4, %f16), NG2_retl_o2_plus_g1)
367 FREG_FROB(f0, f2, f4, f6, f8, f10, f12, f16, f18)
368 EX_ST_FP(STORE_BLK(%f0, %o4 + %g3), NG2_retl_o2_plus_g1)
369 FREG_MOVE_7(f18, f20, f22, f24, f26, f28, f30)
373 LOAD(prefetch, %o4 + 64, #one_read)
377 130: sub %o4, 48, %g2
378 FREG_LOAD_6(%g2, f0, f2, f4, f6, f8, f10)
379 1: EX_ST_FP(STORE_INIT(%g0, %o4 + %g3), NG2_retl_o2_plus_g1)
380 EX_LD_FP(LOAD_BLK(%o4, %f16), NG2_retl_o2_plus_g1)
381 FREG_FROB(f0, f2, f4, f6, f8, f10, f16, f18, f20)
382 EX_ST_FP(STORE_BLK(%f0, %o4 + %g3), NG2_retl_o2_plus_g1)
383 FREG_MOVE_6(f20, f22, f24, f26, f28, f30)
387 LOAD(prefetch, %o4 + 64, #one_read)
391 140: sub %o4, 40, %g2
392 FREG_LOAD_5(%g2, f0, f2, f4, f6, f8)
393 1: EX_ST_FP(STORE_INIT(%g0, %o4 + %g3), NG2_retl_o2_plus_g1)
394 EX_LD_FP(LOAD_BLK(%o4, %f16), NG2_retl_o2_plus_g1)
395 FREG_FROB(f0, f2, f4, f6, f8, f16, f18, f20, f22)
396 EX_ST_FP(STORE_BLK(%f0, %o4 + %g3), NG2_retl_o2_plus_g1)
397 FREG_MOVE_5(f22, f24, f26, f28, f30)
401 LOAD(prefetch, %o4 + 64, #one_read)
405 150: sub %o4, 32, %g2
406 FREG_LOAD_4(%g2, f0, f2, f4, f6)
407 1: EX_ST_FP(STORE_INIT(%g0, %o4 + %g3), NG2_retl_o2_plus_g1)
408 EX_LD_FP(LOAD_BLK(%o4, %f16), NG2_retl_o2_plus_g1)
409 FREG_FROB(f0, f2, f4, f6, f16, f18, f20, f22, f24)
410 EX_ST_FP(STORE_BLK(%f0, %o4 + %g3), NG2_retl_o2_plus_g1)
411 FREG_MOVE_4(f24, f26, f28, f30)
415 LOAD(prefetch, %o4 + 64, #one_read)
419 160: sub %o4, 24, %g2
420 FREG_LOAD_3(%g2, f0, f2, f4)
421 1: EX_ST_FP(STORE_INIT(%g0, %o4 + %g3), NG2_retl_o2_plus_g1)
422 EX_LD_FP(LOAD_BLK(%o4, %f16), NG2_retl_o2_plus_g1)
423 FREG_FROB(f0, f2, f4, f16, f18, f20, f22, f24, f26)
424 EX_ST_FP(STORE_BLK(%f0, %o4 + %g3), NG2_retl_o2_plus_g1)
425 FREG_MOVE_3(f26, f28, f30)
429 LOAD(prefetch, %o4 + 64, #one_read)
433 170: sub %o4, 16, %g2
434 FREG_LOAD_2(%g2, f0, f2)
435 1: EX_ST_FP(STORE_INIT(%g0, %o4 + %g3), NG2_retl_o2_plus_g1)
436 EX_LD_FP(LOAD_BLK(%o4, %f16), NG2_retl_o2_plus_g1)
437 FREG_FROB(f0, f2, f16, f18, f20, f22, f24, f26, f28)
438 EX_ST_FP(STORE_BLK(%f0, %o4 + %g3), NG2_retl_o2_plus_g1)
439 FREG_MOVE_2(f28, f30)
443 LOAD(prefetch, %o4 + 64, #one_read)
449 1: EX_ST_FP(STORE_INIT(%g0, %o4 + %g3), NG2_retl_o2_plus_g1)
450 EX_LD_FP(LOAD_BLK(%o4, %f16), NG2_retl_o2_plus_g1)
451 FREG_FROB(f0, f16, f18, f20, f22, f24, f26, f28, f30)
452 EX_ST_FP(STORE_BLK(%f0, %o4 + %g3), NG2_retl_o2_plus_g1)
457 LOAD(prefetch, %o4 + 64, #one_read)
462 1: EX_ST_FP(STORE_INIT(%g0, %o4 + %g3), NG2_retl_o2_plus_g1)
464 EX_LD_FP(LOAD_BLK(%o4, %f0), NG2_retl_o2_plus_g1_plus_64)
465 EX_ST_FP(STORE_BLK(%f0, %o4 + %g3), NG2_retl_o2_plus_g1_plus_64)
468 LOAD(prefetch, %o4 + 64, #one_read)
476 /* %o2 contains any final bytes still needed to be copied
477 * over. If anything is left, we copy it one byte at a time.
480 sub %o0, %o1, GLOBAL_SPARE
485 75: /* 16 < len <= 64 */
487 sub %o0, %o1, GLOBAL_SPARE
492 1: subcc %o4, 0x10, %o4
493 EX_LD(LOAD(ldx, %o1, %o5), NG2_retl_o2_plus_o4_plus_16)
495 EX_LD(LOAD(ldx, %o1, %g1), NG2_retl_o2_plus_o4_plus_16)
497 EX_ST(STORE(stx, %o5, %o1 + GLOBAL_SPARE), NG2_retl_o2_plus_o4_plus_16)
499 EX_ST(STORE(stx, %g1, %o1 + GLOBAL_SPARE), NG2_retl_o2_plus_o4_plus_8)
502 73: andcc %o2, 0x8, %g0
506 EX_LD(LOAD(ldx, %o1, %o5), NG2_retl_o2_plus_8)
507 EX_ST(STORE(stx, %o5, %o1 + GLOBAL_SPARE), NG2_retl_o2_plus_8)
509 1: andcc %o2, 0x4, %g0
513 EX_LD(LOAD(lduw, %o1, %o5), NG2_retl_o2_plus_4)
514 EX_ST(STORE(stw, %o5, %o1 + GLOBAL_SPARE), NG2_retl_o2_plus_4)
530 EX_LD(LOAD(ldub, %o1, %o5), NG2_retl_o2_plus_g1_plus_1)
531 EX_ST(STORE(stb, %o5, %o1 + GLOBAL_SPARE), NG2_retl_o2_plus_g1_plus_1)
535 2: add %o1, GLOBAL_SPARE, %o0
545 8: mov 64, GLOBAL_SPARE
547 EX_LD(LOAD(ldx, %o1, %g2), NG2_retl_o2)
548 sub GLOBAL_SPARE, %g1, GLOBAL_SPARE
552 EX_LD(LOAD(ldx, %o1, %g3), NG2_retl_o2_and_7_plus_o4)
554 srlx %g3, GLOBAL_SPARE, %o5
556 EX_ST(STORE(stx, %o5, %o0), NG2_retl_o2_and_7_plus_o4_plus_8)
566 sub %o0, %o1, GLOBAL_SPARE
569 80: /* 0 < len <= 16 */
570 andcc GLOBAL_SPARE, 0x3, %g0
572 sub %o0, %o1, GLOBAL_SPARE
576 EX_LD(LOAD(lduw, %o1, %g1), NG2_retl_o2_plus_4)
577 EX_ST(STORE(stw, %g1, %o1 + GLOBAL_SPARE), NG2_retl_o2_plus_4)
582 mov EX_RETVAL(%o3), %o0
587 EX_LD(LOAD(ldub, %o1, %g1), NG2_retl_o2_plus_1)
588 EX_ST(STORE(stb, %g1, %o1 + GLOBAL_SPARE), NG2_retl_o2_plus_1)
592 mov EX_RETVAL(%o3), %o0
594 .size FUNC_NAME, .-FUNC_NAME