1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* U1memcpy.S: UltraSPARC-I/II/IIi/IIe optimized memcpy.
4 * Copyright (C) 1997, 2004 David S. Miller (davem@redhat.com)
5 * Copyright (C) 1996, 1997, 1998, 1999 Jakub Jelinek (jj@ultra.linux.cz)
9 #include <linux/linkage.h>
10 #include <asm/visasm.h>
12 #include <asm/export.h>
13 #define GLOBAL_SPARE g7
15 #define GLOBAL_SPARE g5
16 #define ASI_BLK_P 0xf0
19 #define VISEntry rd %fprs, %o5; wr %g0, FPRS_FEF, %fprs; \
20 clr %g1; clr %g2; clr %g3; subcc %g0, %g0, %g0;
21 #define VISExit and %o5, FPRS_FEF, %o5; wr %o5, 0x0, %fprs
23 #define VISEntry rd %fprs, %o5; wr %g0, FPRS_FEF, %fprs
24 #define VISExit and %o5, FPRS_FEF, %o5; wr %o5, 0x0, %fprs
32 #define EX_LD_FP(x,y) x
39 #define EX_ST_FP(x,y) x
43 #define LOAD(type,addr,dest) type [addr], dest
47 #define LOAD_BLK(addr,dest) ldda [addr] ASI_BLK_P, dest
51 #define STORE(type,src,addr) type src, [addr]
55 #define STORE_BLK(src,addr) stda src, [addr] ASI_BLK_P
59 #define FUNC_NAME memcpy
70 #define FREG_FROB(f1, f2, f3, f4, f5, f6, f7, f8, f9) \
71 faligndata %f1, %f2, %f48; \
72 faligndata %f2, %f3, %f50; \
73 faligndata %f3, %f4, %f52; \
74 faligndata %f4, %f5, %f54; \
75 faligndata %f5, %f6, %f56; \
76 faligndata %f6, %f7, %f58; \
77 faligndata %f7, %f8, %f60; \
78 faligndata %f8, %f9, %f62;
80 #define MAIN_LOOP_CHUNK(src, dest, fdest, fsrc, jmptgt) \
81 EX_LD_FP(LOAD_BLK(%src, %fdest), U1_gs_80_fp); \
82 EX_ST_FP(STORE_BLK(%fsrc, %dest), U1_gs_80_fp); \
83 add %src, 0x40, %src; \
84 subcc %GLOBAL_SPARE, 0x40, %GLOBAL_SPARE; \
86 add %dest, 0x40, %dest; \
88 #define LOOP_CHUNK1(src, dest, branch_dest) \
89 MAIN_LOOP_CHUNK(src, dest, f0, f48, branch_dest)
90 #define LOOP_CHUNK2(src, dest, branch_dest) \
91 MAIN_LOOP_CHUNK(src, dest, f16, f48, branch_dest)
92 #define LOOP_CHUNK3(src, dest, branch_dest) \
93 MAIN_LOOP_CHUNK(src, dest, f32, f48, branch_dest)
95 #define DO_SYNC membar #Sync;
96 #define STORE_SYNC(dest, fsrc) \
97 EX_ST_FP(STORE_BLK(%fsrc, %dest), U1_gs_80_fp); \
98 add %dest, 0x40, %dest; \
101 #define STORE_JUMP(dest, fsrc, target) \
102 EX_ST_FP(STORE_BLK(%fsrc, %dest), U1_gs_40_fp); \
103 add %dest, 0x40, %dest; \
104 ba,pt %xcc, target; \
107 #define FINISH_VISCHUNK(dest, f0, f1) \
110 faligndata %f0, %f1, %f48; \
111 EX_ST_FP(STORE(std, %f48, %dest), U1_g3_8_fp); \
114 #define UNEVEN_VISCHUNK_LAST(dest, f0, f1) \
119 #define UNEVEN_VISCHUNK(dest, f0, f1) \
120 UNEVEN_VISCHUNK_LAST(dest, f0, f1) \
123 .register %g2,#scratch
124 .register %g3,#scratch
128 #define EX_RETVAL(x) x
149 add %GLOBAL_SPARE, %g3, %o0
155 add %GLOBAL_SPARE, 0x80, %GLOBAL_SPARE
156 add %GLOBAL_SPARE, %g3, %o0
162 add %GLOBAL_SPARE, 0x40, %GLOBAL_SPARE
163 add %GLOBAL_SPARE, %g3, %o0
191 add %GLOBAL_SPARE, %o2, %o0
195 add %GLOBAL_SPARE, %o2, %GLOBAL_SPARE
197 add %GLOBAL_SPARE, 0x8, %o0
201 add %GLOBAL_SPARE, %o2, %GLOBAL_SPARE
203 add %GLOBAL_SPARE, 0x10, %o0
230 ENTRY(U1_gs_0_o2_adj)
233 add %GLOBAL_SPARE, %o2, %o0
234 ENDPROC(U1_gs_0_o2_adj)
235 ENTRY(U1_gs_8_o2_adj)
237 add %GLOBAL_SPARE, 8, %GLOBAL_SPARE
239 add %GLOBAL_SPARE, %o2, %o0
240 ENDPROC(U1_gs_8_o2_adj)
246 .type FUNC_NAME,#function
247 FUNC_NAME: /* %o0=dst, %o1=src, %o2=len */
264 /* Clobbers o5/g1/g2/g3/g7/icc/xcc. */
267 /* Is 'dst' already aligned on an 64-byte boundary? */
271 /* Compute abs((dst & 0x3f) - 0x40) into %g2. This is the number
272 * of bytes to copy to make 'dst' 64-byte aligned. We pre-
273 * subtract this from 'len'.
275 sub %o0, %o1, %GLOBAL_SPARE
283 1: subcc %g1, 0x1, %g1
284 EX_LD_FP(LOAD(ldub, %o1 + 0x00, %o3), U1_g1_1_fp)
285 EX_ST_FP(STORE(stb, %o3, %o1 + %GLOBAL_SPARE), U1_g1_1_fp)
289 add %o1, %GLOBAL_SPARE, %o0
294 alignaddr %o1, %g0, %o1
296 EX_LD_FP(LOAD(ldd, %o1, %f4), U1_g2_0_fp)
297 1: EX_LD_FP(LOAD(ldd, %o1 + 0x8, %f6), U1_g2_0_fp)
300 faligndata %f4, %f6, %f0
301 EX_ST_FP(STORE(std, %f0, %o0), U1_g2_8_fp)
305 EX_LD_FP(LOAD(ldd, %o1 + 0x8, %f4), U1_g2_0_fp)
308 faligndata %f6, %f4, %f0
309 EX_ST_FP(STORE(std, %f0, %o0), U1_g2_8_fp)
313 /* Destination is 64-byte aligned. */
315 membar #LoadStore | #StoreStore | #StoreLoad
317 subcc %o2, 0x40, %GLOBAL_SPARE
319 andncc %GLOBAL_SPARE, (0x40 - 1), %GLOBAL_SPARE
321 sub %o2, %GLOBAL_SPARE, %g3
322 andn %o1, (0x40 - 1), %o1
327 sub %o2, %GLOBAL_SPARE, %o2
329 add %g1, %GLOBAL_SPARE, %g1
332 EX_LD_FP(LOAD_BLK(%o1, %f0), U1_gs_0_fp)
335 EX_LD_FP(LOAD_BLK(%o1, %f16), U1_gs_0_fp)
337 sub %GLOBAL_SPARE, 0x80, %GLOBAL_SPARE
338 EX_LD_FP(LOAD_BLK(%o1, %f32), U1_gs_80_fp)
341 /* There are 8 instances of the unrolled loop,
342 * one for each possible alignment of the
343 * source buffer. Each loop instance is 452
352 add %o3, %lo(1f - 1b), %o3
357 1: FREG_FROB(f0, f2, f4, f6, f8, f10,f12,f14,f16)
358 LOOP_CHUNK1(o1, o0, 1f)
359 FREG_FROB(f16,f18,f20,f22,f24,f26,f28,f30,f32)
360 LOOP_CHUNK2(o1, o0, 2f)
361 FREG_FROB(f32,f34,f36,f38,f40,f42,f44,f46,f0)
362 LOOP_CHUNK3(o1, o0, 3f)
364 faligndata %f0, %f2, %f48
365 1: FREG_FROB(f16,f18,f20,f22,f24,f26,f28,f30,f32)
367 FREG_FROB(f32,f34,f36,f38,f40,f42,f44,f46,f0)
368 STORE_JUMP(o0, f48, 40f)
369 2: FREG_FROB(f32,f34,f36,f38,f40,f42,f44,f46,f0)
371 FREG_FROB(f0, f2, f4, f6, f8, f10,f12,f14,f16)
372 STORE_JUMP(o0, f48, 48f)
373 3: FREG_FROB(f0, f2, f4, f6, f8, f10,f12,f14,f16)
375 FREG_FROB(f16,f18,f20,f22,f24,f26,f28,f30,f32)
376 STORE_JUMP(o0, f48, 56f)
378 1: FREG_FROB(f2, f4, f6, f8, f10,f12,f14,f16,f18)
379 LOOP_CHUNK1(o1, o0, 1f)
380 FREG_FROB(f18,f20,f22,f24,f26,f28,f30,f32,f34)
381 LOOP_CHUNK2(o1, o0, 2f)
382 FREG_FROB(f34,f36,f38,f40,f42,f44,f46,f0, f2)
383 LOOP_CHUNK3(o1, o0, 3f)
385 faligndata %f2, %f4, %f48
386 1: FREG_FROB(f18,f20,f22,f24,f26,f28,f30,f32,f34)
388 FREG_FROB(f34,f36,f38,f40,f42,f44,f46,f0, f2)
389 STORE_JUMP(o0, f48, 41f)
390 2: FREG_FROB(f34,f36,f38,f40,f42,f44,f46,f0, f2)
392 FREG_FROB(f2, f4, f6, f8, f10,f12,f14,f16,f18)
393 STORE_JUMP(o0, f48, 49f)
394 3: FREG_FROB(f2, f4, f6, f8, f10,f12,f14,f16,f18)
396 FREG_FROB(f18,f20,f22,f24,f26,f28,f30,f32,f34)
397 STORE_JUMP(o0, f48, 57f)
399 1: FREG_FROB(f4, f6, f8, f10,f12,f14,f16,f18,f20)
400 LOOP_CHUNK1(o1, o0, 1f)
401 FREG_FROB(f20,f22,f24,f26,f28,f30,f32,f34,f36)
402 LOOP_CHUNK2(o1, o0, 2f)
403 FREG_FROB(f36,f38,f40,f42,f44,f46,f0, f2, f4)
404 LOOP_CHUNK3(o1, o0, 3f)
406 faligndata %f4, %f6, %f48
407 1: FREG_FROB(f20,f22,f24,f26,f28,f30,f32,f34,f36)
409 FREG_FROB(f36,f38,f40,f42,f44,f46,f0, f2, f4)
410 STORE_JUMP(o0, f48, 42f)
411 2: FREG_FROB(f36,f38,f40,f42,f44,f46,f0, f2, f4)
413 FREG_FROB(f4, f6, f8, f10,f12,f14,f16,f18,f20)
414 STORE_JUMP(o0, f48, 50f)
415 3: FREG_FROB(f4, f6, f8, f10,f12,f14,f16,f18,f20)
417 FREG_FROB(f20,f22,f24,f26,f28,f30,f32,f34,f36)
418 STORE_JUMP(o0, f48, 58f)
420 1: FREG_FROB(f6, f8, f10,f12,f14,f16,f18,f20,f22)
421 LOOP_CHUNK1(o1, o0, 1f)
422 FREG_FROB(f22,f24,f26,f28,f30,f32,f34,f36,f38)
423 LOOP_CHUNK2(o1, o0, 2f)
424 FREG_FROB(f38,f40,f42,f44,f46,f0, f2, f4, f6)
425 LOOP_CHUNK3(o1, o0, 3f)
427 faligndata %f6, %f8, %f48
428 1: FREG_FROB(f22,f24,f26,f28,f30,f32,f34,f36,f38)
430 FREG_FROB(f38,f40,f42,f44,f46,f0, f2, f4, f6)
431 STORE_JUMP(o0, f48, 43f)
432 2: FREG_FROB(f38,f40,f42,f44,f46,f0, f2, f4, f6)
434 FREG_FROB(f6, f8, f10,f12,f14,f16,f18,f20,f22)
435 STORE_JUMP(o0, f48, 51f)
436 3: FREG_FROB(f6, f8, f10,f12,f14,f16,f18,f20,f22)
438 FREG_FROB(f22,f24,f26,f28,f30,f32,f34,f36,f38)
439 STORE_JUMP(o0, f48, 59f)
441 1: FREG_FROB(f8, f10,f12,f14,f16,f18,f20,f22,f24)
442 LOOP_CHUNK1(o1, o0, 1f)
443 FREG_FROB(f24,f26,f28,f30,f32,f34,f36,f38,f40)
444 LOOP_CHUNK2(o1, o0, 2f)
445 FREG_FROB(f40,f42,f44,f46,f0, f2, f4, f6, f8)
446 LOOP_CHUNK3(o1, o0, 3f)
448 faligndata %f8, %f10, %f48
449 1: FREG_FROB(f24,f26,f28,f30,f32,f34,f36,f38,f40)
451 FREG_FROB(f40,f42,f44,f46,f0, f2, f4, f6, f8)
452 STORE_JUMP(o0, f48, 44f)
453 2: FREG_FROB(f40,f42,f44,f46,f0, f2, f4, f6, f8)
455 FREG_FROB(f8, f10,f12,f14,f16,f18,f20,f22,f24)
456 STORE_JUMP(o0, f48, 52f)
457 3: FREG_FROB(f8, f10,f12,f14,f16,f18,f20,f22,f24)
459 FREG_FROB(f24,f26,f28,f30,f32,f34,f36,f38,f40)
460 STORE_JUMP(o0, f48, 60f)
462 1: FREG_FROB(f10,f12,f14,f16,f18,f20,f22,f24,f26)
463 LOOP_CHUNK1(o1, o0, 1f)
464 FREG_FROB(f26,f28,f30,f32,f34,f36,f38,f40,f42)
465 LOOP_CHUNK2(o1, o0, 2f)
466 FREG_FROB(f42,f44,f46,f0, f2, f4, f6, f8, f10)
467 LOOP_CHUNK3(o1, o0, 3f)
469 faligndata %f10, %f12, %f48
470 1: FREG_FROB(f26,f28,f30,f32,f34,f36,f38,f40,f42)
472 FREG_FROB(f42,f44,f46,f0, f2, f4, f6, f8, f10)
473 STORE_JUMP(o0, f48, 45f)
474 2: FREG_FROB(f42,f44,f46,f0, f2, f4, f6, f8, f10)
476 FREG_FROB(f10,f12,f14,f16,f18,f20,f22,f24,f26)
477 STORE_JUMP(o0, f48, 53f)
478 3: FREG_FROB(f10,f12,f14,f16,f18,f20,f22,f24,f26)
480 FREG_FROB(f26,f28,f30,f32,f34,f36,f38,f40,f42)
481 STORE_JUMP(o0, f48, 61f)
483 1: FREG_FROB(f12,f14,f16,f18,f20,f22,f24,f26,f28)
484 LOOP_CHUNK1(o1, o0, 1f)
485 FREG_FROB(f28,f30,f32,f34,f36,f38,f40,f42,f44)
486 LOOP_CHUNK2(o1, o0, 2f)
487 FREG_FROB(f44,f46,f0, f2, f4, f6, f8, f10,f12)
488 LOOP_CHUNK3(o1, o0, 3f)
490 faligndata %f12, %f14, %f48
491 1: FREG_FROB(f28,f30,f32,f34,f36,f38,f40,f42,f44)
493 FREG_FROB(f44,f46,f0, f2, f4, f6, f8, f10,f12)
494 STORE_JUMP(o0, f48, 46f)
495 2: FREG_FROB(f44,f46,f0, f2, f4, f6, f8, f10,f12)
497 FREG_FROB(f12,f14,f16,f18,f20,f22,f24,f26,f28)
498 STORE_JUMP(o0, f48, 54f)
499 3: FREG_FROB(f12,f14,f16,f18,f20,f22,f24,f26,f28)
501 FREG_FROB(f28,f30,f32,f34,f36,f38,f40,f42,f44)
502 STORE_JUMP(o0, f48, 62f)
504 1: FREG_FROB(f14,f16,f18,f20,f22,f24,f26,f28,f30)
505 LOOP_CHUNK1(o1, o0, 1f)
506 FREG_FROB(f30,f32,f34,f36,f38,f40,f42,f44,f46)
507 LOOP_CHUNK2(o1, o0, 2f)
508 FREG_FROB(f46,f0, f2, f4, f6, f8, f10,f12,f14)
509 LOOP_CHUNK3(o1, o0, 3f)
511 faligndata %f14, %f16, %f48
512 1: FREG_FROB(f30,f32,f34,f36,f38,f40,f42,f44,f46)
514 FREG_FROB(f46,f0, f2, f4, f6, f8, f10,f12,f14)
515 STORE_JUMP(o0, f48, 47f)
516 2: FREG_FROB(f46,f0, f2, f4, f6, f8, f10,f12,f14)
518 FREG_FROB(f14,f16,f18,f20,f22,f24,f26,f28,f30)
519 STORE_JUMP(o0, f48, 55f)
520 3: FREG_FROB(f14,f16,f18,f20,f22,f24,f26,f28,f30)
522 FREG_FROB(f30,f32,f34,f36,f38,f40,f42,f44,f46)
523 STORE_JUMP(o0, f48, 63f)
525 40: FINISH_VISCHUNK(o0, f0, f2)
526 41: FINISH_VISCHUNK(o0, f2, f4)
527 42: FINISH_VISCHUNK(o0, f4, f6)
528 43: FINISH_VISCHUNK(o0, f6, f8)
529 44: FINISH_VISCHUNK(o0, f8, f10)
530 45: FINISH_VISCHUNK(o0, f10, f12)
531 46: FINISH_VISCHUNK(o0, f12, f14)
532 47: UNEVEN_VISCHUNK(o0, f14, f0)
533 48: FINISH_VISCHUNK(o0, f16, f18)
534 49: FINISH_VISCHUNK(o0, f18, f20)
535 50: FINISH_VISCHUNK(o0, f20, f22)
536 51: FINISH_VISCHUNK(o0, f22, f24)
537 52: FINISH_VISCHUNK(o0, f24, f26)
538 53: FINISH_VISCHUNK(o0, f26, f28)
539 54: FINISH_VISCHUNK(o0, f28, f30)
540 55: UNEVEN_VISCHUNK(o0, f30, f0)
541 56: FINISH_VISCHUNK(o0, f32, f34)
542 57: FINISH_VISCHUNK(o0, f34, f36)
543 58: FINISH_VISCHUNK(o0, f36, f38)
544 59: FINISH_VISCHUNK(o0, f38, f40)
545 60: FINISH_VISCHUNK(o0, f40, f42)
546 61: FINISH_VISCHUNK(o0, f42, f44)
547 62: FINISH_VISCHUNK(o0, f44, f46)
548 63: UNEVEN_VISCHUNK_LAST(o0, f46, f0)
550 93: EX_LD_FP(LOAD(ldd, %o1, %f2), U1_g3_0_fp)
553 faligndata %f0, %f2, %f8
554 EX_ST_FP(STORE(std, %f8, %o0), U1_g3_8_fp)
557 EX_LD_FP(LOAD(ldd, %o1, %f0), U1_g3_0_fp)
560 faligndata %f2, %f0, %f8
561 EX_ST_FP(STORE(std, %f8, %o0), U1_g3_8_fp)
568 1: EX_LD_FP(LOAD(ldub, %o1, %o3), U1_o2_0_fp)
571 EX_ST_FP(STORE(stb, %o3, %o0), U1_o2_1_fp)
575 2: membar #StoreLoad | #StoreStore
578 mov EX_RETVAL(%o4), %o0
581 70: /* 16 < len <= (5 * 64) */
585 72: andn %o2, 0xf, %GLOBAL_SPARE
587 1: EX_LD(LOAD(ldx, %o1 + 0x00, %o5), U1_gs_0)
588 EX_LD(LOAD(ldx, %o1 + 0x08, %g1), U1_gs_0)
589 subcc %GLOBAL_SPARE, 0x10, %GLOBAL_SPARE
590 EX_ST(STORE(stx, %o5, %o1 + %o3), U1_gs_10)
592 EX_ST(STORE(stx, %g1, %o1 + %o3), U1_gs_8)
595 73: andcc %o2, 0x8, %g0
598 EX_LD(LOAD(ldx, %o1, %o5), U1_o2_0)
600 EX_ST(STORE(stx, %o5, %o1 + %o3), U1_o2_8)
602 1: andcc %o2, 0x4, %g0
605 EX_LD(LOAD(lduw, %o1, %o5), U1_o2_0)
607 EX_ST(STORE(stw, %o5, %o1 + %o3), U1_o2_4)
615 75: andcc %o0, 0x7, %g1
621 1: EX_LD(LOAD(ldub, %o1, %o5), U1_g1_0)
623 EX_ST(STORE(stb, %o5, %o1 + %o3), U1_g1_1)
639 EX_LD(LOAD(ldx, %o1, %g2), U1_o2_0)
641 andn %o2, 0x7, %GLOBAL_SPARE
643 1: EX_LD(LOAD(ldx, %o1 + 0x8, %g3), U1_gs_0_o2_adj)
644 subcc %GLOBAL_SPARE, 0x8, %GLOBAL_SPARE
648 EX_ST(STORE(stx, %o5, %o0), U1_gs_8_o2_adj)
661 80: /* 0 < len <= 16 */
666 1: EX_LD(LOAD(lduw, %o1, %g1), U1_o2_0)
668 EX_ST(STORE(stw, %g1, %o1 + %o3), U1_o2_4)
673 mov EX_RETVAL(%o4), %o0
676 90: EX_LD(LOAD(ldub, %o1, %g1), U1_o2_0)
678 EX_ST(STORE(stb, %g1, %o1 + %o3), U1_o2_1)
682 mov EX_RETVAL(%o4), %o0
684 .size FUNC_NAME, .-FUNC_NAME
685 EXPORT_SYMBOL(FUNC_NAME)