1 /* memcpy.S: Sparc optimized memcpy and memmove code
2 * Hand optimized from GNU libc's memcpy and memmove
3 * Copyright (C) 1991,1996 Free Software Foundation
4 * Copyright (C) 1995 Linus Torvalds (Linus.Torvalds@helsinki.fi)
5 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
6 * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be)
7 * Copyright (C) 1996 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
16 /* Both these macros have to start with exactly the same insn */
17 #define MOVE_BIGCHUNK(src, dst, offset, t0, t1, t2, t3, t4, t5, t6, t7) \
18 ldd [%src + (offset) + 0x00], %t0; \
19 ldd [%src + (offset) + 0x08], %t2; \
20 ldd [%src + (offset) + 0x10], %t4; \
21 ldd [%src + (offset) + 0x18], %t6; \
22 st %t0, [%dst + (offset) + 0x00]; \
23 st %t1, [%dst + (offset) + 0x04]; \
24 st %t2, [%dst + (offset) + 0x08]; \
25 st %t3, [%dst + (offset) + 0x0c]; \
26 st %t4, [%dst + (offset) + 0x10]; \
27 st %t5, [%dst + (offset) + 0x14]; \
28 st %t6, [%dst + (offset) + 0x18]; \
29 st %t7, [%dst + (offset) + 0x1c];
31 #define MOVE_BIGALIGNCHUNK(src, dst, offset, t0, t1, t2, t3, t4, t5, t6, t7) \
32 ldd [%src + (offset) + 0x00], %t0; \
33 ldd [%src + (offset) + 0x08], %t2; \
34 ldd [%src + (offset) + 0x10], %t4; \
35 ldd [%src + (offset) + 0x18], %t6; \
36 std %t0, [%dst + (offset) + 0x00]; \
37 std %t2, [%dst + (offset) + 0x08]; \
38 std %t4, [%dst + (offset) + 0x10]; \
39 std %t6, [%dst + (offset) + 0x18];
41 #define MOVE_LASTCHUNK(src, dst, offset, t0, t1, t2, t3) \
42 ldd [%src - (offset) - 0x10], %t0; \
43 ldd [%src - (offset) - 0x08], %t2; \
44 st %t0, [%dst - (offset) - 0x10]; \
45 st %t1, [%dst - (offset) - 0x0c]; \
46 st %t2, [%dst - (offset) - 0x08]; \
47 st %t3, [%dst - (offset) - 0x04];
49 #define MOVE_LASTALIGNCHUNK(src, dst, offset, t0, t1, t2, t3) \
50 ldd [%src - (offset) - 0x10], %t0; \
51 ldd [%src - (offset) - 0x08], %t2; \
52 std %t0, [%dst - (offset) - 0x10]; \
53 std %t2, [%dst - (offset) - 0x08];
55 #define MOVE_SHORTCHUNK(src, dst, offset, t0, t1) \
56 ldub [%src - (offset) - 0x02], %t0; \
57 ldub [%src - (offset) - 0x01], %t1; \
58 stb %t0, [%dst - (offset) - 0x02]; \
59 stb %t1, [%dst - (offset) - 0x01];
61 /* Both these macros have to start with exactly the same insn */
62 #define RMOVE_BIGCHUNK(src, dst, offset, t0, t1, t2, t3, t4, t5, t6, t7) \
63 ldd [%src - (offset) - 0x20], %t0; \
64 ldd [%src - (offset) - 0x18], %t2; \
65 ldd [%src - (offset) - 0x10], %t4; \
66 ldd [%src - (offset) - 0x08], %t6; \
67 st %t0, [%dst - (offset) - 0x20]; \
68 st %t1, [%dst - (offset) - 0x1c]; \
69 st %t2, [%dst - (offset) - 0x18]; \
70 st %t3, [%dst - (offset) - 0x14]; \
71 st %t4, [%dst - (offset) - 0x10]; \
72 st %t5, [%dst - (offset) - 0x0c]; \
73 st %t6, [%dst - (offset) - 0x08]; \
74 st %t7, [%dst - (offset) - 0x04];
76 #define RMOVE_BIGALIGNCHUNK(src, dst, offset, t0, t1, t2, t3, t4, t5, t6, t7) \
77 ldd [%src - (offset) - 0x20], %t0; \
78 ldd [%src - (offset) - 0x18], %t2; \
79 ldd [%src - (offset) - 0x10], %t4; \
80 ldd [%src - (offset) - 0x08], %t6; \
81 std %t0, [%dst - (offset) - 0x20]; \
82 std %t2, [%dst - (offset) - 0x18]; \
83 std %t4, [%dst - (offset) - 0x10]; \
84 std %t6, [%dst - (offset) - 0x08];
86 #define RMOVE_LASTCHUNK(src, dst, offset, t0, t1, t2, t3) \
87 ldd [%src + (offset) + 0x00], %t0; \
88 ldd [%src + (offset) + 0x08], %t2; \
89 st %t0, [%dst + (offset) + 0x00]; \
90 st %t1, [%dst + (offset) + 0x04]; \
91 st %t2, [%dst + (offset) + 0x08]; \
92 st %t3, [%dst + (offset) + 0x0c];
94 #define RMOVE_SHORTCHUNK(src, dst, offset, t0, t1) \
95 ldub [%src + (offset) + 0x00], %t0; \
96 ldub [%src + (offset) + 0x01], %t1; \
97 stb %t0, [%dst + (offset) + 0x00]; \
98 stb %t1, [%dst + (offset) + 0x01];
100 #define SMOVE_CHUNK(src, dst, offset, t0, t1, t2, t3, t4, t5, t6, prev, shil, shir, offset2) \
101 ldd [%src + (offset) + 0x00], %t0; \
102 ldd [%src + (offset) + 0x08], %t2; \
103 srl %t0, shir, %t5; \
104 srl %t1, shir, %t6; \
105 sll %t0, shil, %t0; \
106 or %t5, %prev, %t5; \
107 sll %t1, shil, %prev; \
109 srl %t2, shir, %t1; \
110 srl %t3, shir, %t6; \
111 sll %t2, shil, %t2; \
112 or %t1, %prev, %t1; \
113 std %t4, [%dst + (offset) + (offset2) - 0x04]; \
114 std %t0, [%dst + (offset) + (offset2) + 0x04]; \
115 sll %t3, shil, %prev; \
118 #define SMOVE_ALIGNCHUNK(src, dst, offset, t0, t1, t2, t3, t4, t5, t6, prev, shil, shir, offset2) \
119 ldd [%src + (offset) + 0x00], %t0; \
120 ldd [%src + (offset) + 0x08], %t2; \
121 srl %t0, shir, %t4; \
122 srl %t1, shir, %t5; \
123 sll %t0, shil, %t6; \
124 or %t4, %prev, %t0; \
125 sll %t1, shil, %prev; \
127 srl %t2, shir, %t4; \
128 srl %t3, shir, %t5; \
129 sll %t2, shil, %t6; \
130 or %t4, %prev, %t2; \
131 sll %t3, shil, %prev; \
133 std %t0, [%dst + (offset) + (offset2) + 0x00]; \
134 std %t2, [%dst + (offset) + (offset2) + 0x08];
141 nop ! Only bcopy returns here and it retuns void...
163 1: /* reverse_bytes */
175 /* NOTE: This code is executed just for the cases,
176 where %src (=%o1) & 3 is != 0.
177 We need to align it to 4. So, for (%src & 3)
178 1 we need to do ldub,lduh
181 so even if it looks weird, the branches
182 are correct here. -jj
184 78: /* dword_align */
204 FUNC(memcpy) /* %o0=dst %o1=src %o2=len */
230 andcc %g1, 0xffffff80, %g0
236 MOVE_BIGCHUNK(o1, o0, 0x00, o2, o3, o4, o5, g2, g3, g4, g5)
237 MOVE_BIGCHUNK(o1, o0, 0x20, o2, o3, o4, o5, g2, g3, g4, g5)
238 MOVE_BIGCHUNK(o1, o0, 0x40, o2, o3, o4, o5, g2, g3, g4, g5)
239 MOVE_BIGCHUNK(o1, o0, 0x60, o2, o3, o4, o5, g2, g3, g4, g5)
255 jmpl %o5 + %lo(80f), %g0
258 79: /* memcpy_table */
260 MOVE_LASTCHUNK(o1, o0, 0x60, g2, g3, g4, g5)
261 MOVE_LASTCHUNK(o1, o0, 0x50, g2, g3, g4, g5)
262 MOVE_LASTCHUNK(o1, o0, 0x40, g2, g3, g4, g5)
263 MOVE_LASTCHUNK(o1, o0, 0x30, g2, g3, g4, g5)
264 MOVE_LASTCHUNK(o1, o0, 0x20, g2, g3, g4, g5)
265 MOVE_LASTCHUNK(o1, o0, 0x10, g2, g3, g4, g5)
266 MOVE_LASTCHUNK(o1, o0, 0x00, g2, g3, g4, g5)
268 80: /* memcpy_table_end */
278 81: /* memcpy_last7 */
306 MOVE_BIGALIGNCHUNK(o1, o0, 0x00, o2, o3, o4, o5, g2, g3, g4, g5)
307 MOVE_BIGALIGNCHUNK(o1, o0, 0x20, o2, o3, o4, o5, g2, g3, g4, g5)
308 MOVE_BIGALIGNCHUNK(o1, o0, 0x40, o2, o3, o4, o5, g2, g3, g4, g5)
309 MOVE_BIGALIGNCHUNK(o1, o0, 0x60, o2, o3, o4, o5, g2, g3, g4, g5)
323 jmpl %o5 + %lo(84f), %g0
326 83: /* amemcpy_table */
328 MOVE_LASTALIGNCHUNK(o1, o0, 0x60, g2, g3, g4, g5)
329 MOVE_LASTALIGNCHUNK(o1, o0, 0x50, g2, g3, g4, g5)
330 MOVE_LASTALIGNCHUNK(o1, o0, 0x40, g2, g3, g4, g5)
331 MOVE_LASTALIGNCHUNK(o1, o0, 0x30, g2, g3, g4, g5)
332 MOVE_LASTALIGNCHUNK(o1, o0, 0x20, g2, g3, g4, g5)
333 MOVE_LASTALIGNCHUNK(o1, o0, 0x10, g2, g3, g4, g5)
334 MOVE_LASTALIGNCHUNK(o1, o0, 0x00, g2, g3, g4, g5)
336 84: /* amemcpy_table_end */
342 std %g2, [%o0 - 0x08]
344 85: /* amemcpy_last7 */
370 86: /* non_aligned */
493 restore %g7, %g0, %o0
504 jmpl %o5 + %lo(89f), %g0
507 MOVE_SHORTCHUNK(o1, o0, 0x0c, g2, g3)
508 MOVE_SHORTCHUNK(o1, o0, 0x0a, g2, g3)
509 MOVE_SHORTCHUNK(o1, o0, 0x08, g2, g3)
510 MOVE_SHORTCHUNK(o1, o0, 0x06, g2, g3)
511 MOVE_SHORTCHUNK(o1, o0, 0x04, g2, g3)
512 MOVE_SHORTCHUNK(o1, o0, 0x02, g2, g3)
513 MOVE_SHORTCHUNK(o1, o0, 0x00, g2, g3)
515 89: /* short_table_end */
526 90: /* short_aligned_end */