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 <asm/export.h>
18 /* Both these macros have to start with exactly the same insn */
19 #define MOVE_BIGCHUNK(src, dst, offset, t0, t1, t2, t3, t4, t5, t6, t7) \
20 ldd [%src + (offset) + 0x00], %t0; \
21 ldd [%src + (offset) + 0x08], %t2; \
22 ldd [%src + (offset) + 0x10], %t4; \
23 ldd [%src + (offset) + 0x18], %t6; \
24 st %t0, [%dst + (offset) + 0x00]; \
25 st %t1, [%dst + (offset) + 0x04]; \
26 st %t2, [%dst + (offset) + 0x08]; \
27 st %t3, [%dst + (offset) + 0x0c]; \
28 st %t4, [%dst + (offset) + 0x10]; \
29 st %t5, [%dst + (offset) + 0x14]; \
30 st %t6, [%dst + (offset) + 0x18]; \
31 st %t7, [%dst + (offset) + 0x1c];
33 #define MOVE_BIGALIGNCHUNK(src, dst, offset, t0, t1, t2, t3, t4, t5, t6, t7) \
34 ldd [%src + (offset) + 0x00], %t0; \
35 ldd [%src + (offset) + 0x08], %t2; \
36 ldd [%src + (offset) + 0x10], %t4; \
37 ldd [%src + (offset) + 0x18], %t6; \
38 std %t0, [%dst + (offset) + 0x00]; \
39 std %t2, [%dst + (offset) + 0x08]; \
40 std %t4, [%dst + (offset) + 0x10]; \
41 std %t6, [%dst + (offset) + 0x18];
43 #define MOVE_LASTCHUNK(src, dst, offset, t0, t1, t2, t3) \
44 ldd [%src - (offset) - 0x10], %t0; \
45 ldd [%src - (offset) - 0x08], %t2; \
46 st %t0, [%dst - (offset) - 0x10]; \
47 st %t1, [%dst - (offset) - 0x0c]; \
48 st %t2, [%dst - (offset) - 0x08]; \
49 st %t3, [%dst - (offset) - 0x04];
51 #define MOVE_LASTALIGNCHUNK(src, dst, offset, t0, t1, t2, t3) \
52 ldd [%src - (offset) - 0x10], %t0; \
53 ldd [%src - (offset) - 0x08], %t2; \
54 std %t0, [%dst - (offset) - 0x10]; \
55 std %t2, [%dst - (offset) - 0x08];
57 #define MOVE_SHORTCHUNK(src, dst, offset, t0, t1) \
58 ldub [%src - (offset) - 0x02], %t0; \
59 ldub [%src - (offset) - 0x01], %t1; \
60 stb %t0, [%dst - (offset) - 0x02]; \
61 stb %t1, [%dst - (offset) - 0x01];
67 EXPORT_SYMBOL(memmove)
83 1: /* reverse_bytes */
95 /* NOTE: This code is executed just for the cases,
96 where %src (=%o1) & 3 is != 0.
97 We need to align it to 4. So, for (%src & 3)
98 1 we need to do ldub,lduh
101 so even if it looks weird, the branches
102 are correct here. -jj
104 78: /* dword_align */
124 FUNC(memcpy) /* %o0=dst %o1=src %o2=len */
125 EXPORT_SYMBOL(memcpy)
151 andcc %g1, 0xffffff80, %g0
157 MOVE_BIGCHUNK(o1, o0, 0x00, o2, o3, o4, o5, g2, g3, g4, g5)
158 MOVE_BIGCHUNK(o1, o0, 0x20, o2, o3, o4, o5, g2, g3, g4, g5)
159 MOVE_BIGCHUNK(o1, o0, 0x40, o2, o3, o4, o5, g2, g3, g4, g5)
160 MOVE_BIGCHUNK(o1, o0, 0x60, o2, o3, o4, o5, g2, g3, g4, g5)
176 jmpl %o5 + %lo(80f), %g0
179 79: /* memcpy_table */
181 MOVE_LASTCHUNK(o1, o0, 0x60, g2, g3, g4, g5)
182 MOVE_LASTCHUNK(o1, o0, 0x50, g2, g3, g4, g5)
183 MOVE_LASTCHUNK(o1, o0, 0x40, g2, g3, g4, g5)
184 MOVE_LASTCHUNK(o1, o0, 0x30, g2, g3, g4, g5)
185 MOVE_LASTCHUNK(o1, o0, 0x20, g2, g3, g4, g5)
186 MOVE_LASTCHUNK(o1, o0, 0x10, g2, g3, g4, g5)
187 MOVE_LASTCHUNK(o1, o0, 0x00, g2, g3, g4, g5)
189 80: /* memcpy_table_end */
199 81: /* memcpy_last7 */
227 MOVE_BIGALIGNCHUNK(o1, o0, 0x00, o2, o3, o4, o5, g2, g3, g4, g5)
228 MOVE_BIGALIGNCHUNK(o1, o0, 0x20, o2, o3, o4, o5, g2, g3, g4, g5)
229 MOVE_BIGALIGNCHUNK(o1, o0, 0x40, o2, o3, o4, o5, g2, g3, g4, g5)
230 MOVE_BIGALIGNCHUNK(o1, o0, 0x60, o2, o3, o4, o5, g2, g3, g4, g5)
244 jmpl %o5 + %lo(84f), %g0
247 83: /* amemcpy_table */
249 MOVE_LASTALIGNCHUNK(o1, o0, 0x60, g2, g3, g4, g5)
250 MOVE_LASTALIGNCHUNK(o1, o0, 0x50, g2, g3, g4, g5)
251 MOVE_LASTALIGNCHUNK(o1, o0, 0x40, g2, g3, g4, g5)
252 MOVE_LASTALIGNCHUNK(o1, o0, 0x30, g2, g3, g4, g5)
253 MOVE_LASTALIGNCHUNK(o1, o0, 0x20, g2, g3, g4, g5)
254 MOVE_LASTALIGNCHUNK(o1, o0, 0x10, g2, g3, g4, g5)
255 MOVE_LASTALIGNCHUNK(o1, o0, 0x00, g2, g3, g4, g5)
257 84: /* amemcpy_table_end */
263 std %g2, [%o0 - 0x08]
265 85: /* amemcpy_last7 */
291 86: /* non_aligned */
414 restore %g7, %g0, %o0
425 jmpl %o5 + %lo(89f), %g0
428 MOVE_SHORTCHUNK(o1, o0, 0x0c, g2, g3)
429 MOVE_SHORTCHUNK(o1, o0, 0x0a, g2, g3)
430 MOVE_SHORTCHUNK(o1, o0, 0x08, g2, g3)
431 MOVE_SHORTCHUNK(o1, o0, 0x06, g2, g3)
432 MOVE_SHORTCHUNK(o1, o0, 0x04, g2, g3)
433 MOVE_SHORTCHUNK(o1, o0, 0x02, g2, g3)
434 MOVE_SHORTCHUNK(o1, o0, 0x00, g2, g3)
436 89: /* short_table_end */
447 90: /* short_aligned_end */