1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* memcpy.S: Sparc optimized memcpy and memmove code
3 * Hand optimized from GNU libc's memcpy and memmove
4 * Copyright (C) 1991,1996 Free Software Foundation
5 * Copyright (C) 1995 Linus Torvalds (Linus.Torvalds@helsinki.fi)
6 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
7 * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be)
8 * Copyright (C) 1996 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
11 #include <linux/export.h>
19 /* Both these macros have to start with exactly the same insn */
20 #define MOVE_BIGCHUNK(src, dst, offset, t0, t1, t2, t3, t4, t5, t6, t7) \
21 ldd [%src + (offset) + 0x00], %t0; \
22 ldd [%src + (offset) + 0x08], %t2; \
23 ldd [%src + (offset) + 0x10], %t4; \
24 ldd [%src + (offset) + 0x18], %t6; \
25 st %t0, [%dst + (offset) + 0x00]; \
26 st %t1, [%dst + (offset) + 0x04]; \
27 st %t2, [%dst + (offset) + 0x08]; \
28 st %t3, [%dst + (offset) + 0x0c]; \
29 st %t4, [%dst + (offset) + 0x10]; \
30 st %t5, [%dst + (offset) + 0x14]; \
31 st %t6, [%dst + (offset) + 0x18]; \
32 st %t7, [%dst + (offset) + 0x1c];
34 #define MOVE_BIGALIGNCHUNK(src, dst, offset, t0, t1, t2, t3, t4, t5, t6, t7) \
35 ldd [%src + (offset) + 0x00], %t0; \
36 ldd [%src + (offset) + 0x08], %t2; \
37 ldd [%src + (offset) + 0x10], %t4; \
38 ldd [%src + (offset) + 0x18], %t6; \
39 std %t0, [%dst + (offset) + 0x00]; \
40 std %t2, [%dst + (offset) + 0x08]; \
41 std %t4, [%dst + (offset) + 0x10]; \
42 std %t6, [%dst + (offset) + 0x18];
44 #define MOVE_LASTCHUNK(src, dst, offset, t0, t1, t2, t3) \
45 ldd [%src - (offset) - 0x10], %t0; \
46 ldd [%src - (offset) - 0x08], %t2; \
47 st %t0, [%dst - (offset) - 0x10]; \
48 st %t1, [%dst - (offset) - 0x0c]; \
49 st %t2, [%dst - (offset) - 0x08]; \
50 st %t3, [%dst - (offset) - 0x04];
52 #define MOVE_LASTALIGNCHUNK(src, dst, offset, t0, t1, t2, t3) \
53 ldd [%src - (offset) - 0x10], %t0; \
54 ldd [%src - (offset) - 0x08], %t2; \
55 std %t0, [%dst - (offset) - 0x10]; \
56 std %t2, [%dst - (offset) - 0x08];
58 #define MOVE_SHORTCHUNK(src, dst, offset, t0, t1) \
59 ldub [%src - (offset) - 0x02], %t0; \
60 ldub [%src - (offset) - 0x01], %t1; \
61 stb %t0, [%dst - (offset) - 0x02]; \
62 stb %t1, [%dst - (offset) - 0x01];
68 EXPORT_SYMBOL(memmove)
84 1: /* reverse_bytes */
96 /* NOTE: This code is executed just for the cases,
97 where %src (=%o1) & 3 is != 0.
98 We need to align it to 4. So, for (%src & 3)
99 1 we need to do ldub,lduh
102 so even if it looks weird, the branches
103 are correct here. -jj
105 78: /* dword_align */
125 FUNC(memcpy) /* %o0=dst %o1=src %o2=len */
126 EXPORT_SYMBOL(memcpy)
152 andcc %g1, 0xffffff80, %g0
158 MOVE_BIGCHUNK(o1, o0, 0x00, o2, o3, o4, o5, g2, g3, g4, g5)
159 MOVE_BIGCHUNK(o1, o0, 0x20, o2, o3, o4, o5, g2, g3, g4, g5)
160 MOVE_BIGCHUNK(o1, o0, 0x40, o2, o3, o4, o5, g2, g3, g4, g5)
161 MOVE_BIGCHUNK(o1, o0, 0x60, o2, o3, o4, o5, g2, g3, g4, g5)
177 jmpl %o5 + %lo(80f), %g0
180 79: /* memcpy_table */
182 MOVE_LASTCHUNK(o1, o0, 0x60, g2, g3, g4, g5)
183 MOVE_LASTCHUNK(o1, o0, 0x50, g2, g3, g4, g5)
184 MOVE_LASTCHUNK(o1, o0, 0x40, g2, g3, g4, g5)
185 MOVE_LASTCHUNK(o1, o0, 0x30, g2, g3, g4, g5)
186 MOVE_LASTCHUNK(o1, o0, 0x20, g2, g3, g4, g5)
187 MOVE_LASTCHUNK(o1, o0, 0x10, g2, g3, g4, g5)
188 MOVE_LASTCHUNK(o1, o0, 0x00, g2, g3, g4, g5)
190 80: /* memcpy_table_end */
200 81: /* memcpy_last7 */
228 MOVE_BIGALIGNCHUNK(o1, o0, 0x00, o2, o3, o4, o5, g2, g3, g4, g5)
229 MOVE_BIGALIGNCHUNK(o1, o0, 0x20, o2, o3, o4, o5, g2, g3, g4, g5)
230 MOVE_BIGALIGNCHUNK(o1, o0, 0x40, o2, o3, o4, o5, g2, g3, g4, g5)
231 MOVE_BIGALIGNCHUNK(o1, o0, 0x60, o2, o3, o4, o5, g2, g3, g4, g5)
245 jmpl %o5 + %lo(84f), %g0
248 83: /* amemcpy_table */
250 MOVE_LASTALIGNCHUNK(o1, o0, 0x60, g2, g3, g4, g5)
251 MOVE_LASTALIGNCHUNK(o1, o0, 0x50, g2, g3, g4, g5)
252 MOVE_LASTALIGNCHUNK(o1, o0, 0x40, g2, g3, g4, g5)
253 MOVE_LASTALIGNCHUNK(o1, o0, 0x30, g2, g3, g4, g5)
254 MOVE_LASTALIGNCHUNK(o1, o0, 0x20, g2, g3, g4, g5)
255 MOVE_LASTALIGNCHUNK(o1, o0, 0x10, g2, g3, g4, g5)
256 MOVE_LASTALIGNCHUNK(o1, o0, 0x00, g2, g3, g4, g5)
258 84: /* amemcpy_table_end */
264 std %g2, [%o0 - 0x08]
266 85: /* amemcpy_last7 */
292 86: /* non_aligned */
415 restore %g7, %g0, %o0
426 jmpl %o5 + %lo(89f), %g0
429 MOVE_SHORTCHUNK(o1, o0, 0x0c, g2, g3)
430 MOVE_SHORTCHUNK(o1, o0, 0x0a, g2, g3)
431 MOVE_SHORTCHUNK(o1, o0, 0x08, g2, g3)
432 MOVE_SHORTCHUNK(o1, o0, 0x06, g2, g3)
433 MOVE_SHORTCHUNK(o1, o0, 0x04, g2, g3)
434 MOVE_SHORTCHUNK(o1, o0, 0x02, g2, g3)
435 MOVE_SHORTCHUNK(o1, o0, 0x00, g2, g3)
437 89: /* short_table_end */
448 90: /* short_aligned_end */