1 /* Copy SIZE bytes from SRC to DEST. For SUN4V Niagara.
2 Copyright (C) 2006 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by David S. Miller (davem@davemloft.net)
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23 #define ASI_BLK_INIT_QUAD_LDD_P 0xe2
27 #define LOAD(type,addr,dest) type##a [addr] ASI_P, dest
28 #define LOAD_TWIN(addr_reg,dest0,dest1) \
29 ldda [addr_reg] ASI_BLK_INIT_QUAD_LDD_P, dest0
31 #define STORE(type,src,addr) type src, [addr]
32 #define STORE_INIT(src,addr) stxa src, [addr] %asi
39 .register %g2,#scratch
40 .register %g3,#scratch
41 .register %g6,#scratch
64 100: /* %o0=dst, %o1=src, %o2=len */
73 /* 2 blocks (128 bytes) is the minimum we can do the block
74 * copy with. We need to ensure that we'll iterate at least
75 * once in the block copy loop. At worst we'll need to align
76 * the destination to a 64-byte boundary which can chew up
77 * to (64 - 1) bytes from the length before we perform the
86 * %o2: len (known to be >= 128)
88 * The block copy loops will use %o4/%o5,%g2/%g3 as
89 * temporaries while copying the data.
92 LOAD(prefetch, %o1, #one_read)
93 wr %g0, ASI_BLK_INIT_QUAD_LDD_P, %asi
95 /* Align destination on 64-byte boundary. */
96 andcc %o0, (64 - 1), %o4
99 sub %g0, %o4, %o4 ! bytes to align dst
108 /* If the source is on a 16-byte boundary we can do
109 * the direct block copy loop. If it is 8-byte aligned
110 * we can do the 16-byte loads offset by -8 bytes and the
111 * init stores offset by one register.
113 * If the source is not even 8-byte aligned, we need to do
114 * shifting and masking (basically integer faligndata).
116 * The careful bit with init stores is that if we store
117 * to any part of the cache line we have to store the whole
118 * cacheline else we can end up with corrupt L2 cache line
119 * contents. Since the loop works on 64-bytes of 64-byte
120 * aligned store data at a time, this is easy to ensure.
123 andcc %o1, (16 - 1), %o4
124 andn %o2, (64 - 1), %g1 ! block copy loop iterator
125 sub %o2, %g1, %o2 ! final sub-block copy bytes
131 /* Neither 8-byte nor 16-byte aligned, shift and mask. */
141 #define SWIVEL_ONE_DWORD(SRC, TMP1, TMP2, PRE_VAL, PRE_SHIFT, POST_SHIFT, DST)\
142 LOAD(ldx, SRC, TMP1); \
143 srlx TMP1, PRE_SHIFT, TMP2; \
144 or TMP2, PRE_VAL, TMP2; \
145 STORE_INIT(TMP2, DST); \
146 sllx TMP1, POST_SHIFT, PRE_VAL;
149 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x00)
151 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x08)
153 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x10)
155 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x18)
157 LOAD(prefetch, %o1, #one_read)
159 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x20)
161 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x28)
163 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x30)
165 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x38)
170 #undef SWIVEL_ONE_DWORD
176 10: /* Destination is 64-byte aligned, source was only 8-byte
177 * aligned but it has been subtracted by 8 and we perform
178 * one twin load ahead, then add 8 back into source when
179 * we finish the loop.
181 LOAD_TWIN(%o1, %o4, %o5)
183 LOAD_TWIN(%o1, %g2, %g3)
184 add %o1, 16 + 32, %o1
185 LOAD(prefetch, %o1, #one_read)
187 STORE_INIT(%o5, %o0 + 0x00) ! initializes cache line
188 STORE_INIT(%g2, %o0 + 0x08)
189 LOAD_TWIN(%o1, %o4, %o5)
191 STORE_INIT(%g3, %o0 + 0x10)
192 STORE_INIT(%o4, %o0 + 0x18)
193 LOAD_TWIN(%o1, %g2, %g3)
195 STORE_INIT(%o5, %o0 + 0x20)
196 STORE_INIT(%g2, %o0 + 0x28)
197 LOAD_TWIN(%o1, %o4, %o5)
198 STORE_INIT(%g3, %o0 + 0x30)
199 STORE_INIT(%o4, %o0 + 0x38)
207 50: /* Destination is 64-byte aligned, and source is 16-byte
210 1: LOAD_TWIN(%o1, %o4, %o5)
212 LOAD_TWIN(%o1, %g2, %g3)
213 add %o1, 16 + 32, %o1
214 LOAD(prefetch, %o1, #one_read)
216 STORE_INIT(%o4, %o0 + 0x00) ! initializes cache line
217 STORE_INIT(%o5, %o0 + 0x08)
218 LOAD_TWIN(%o1, %o4, %o5)
220 STORE_INIT(%g2, %o0 + 0x10)
221 STORE_INIT(%g3, %o0 + 0x18)
222 LOAD_TWIN(%o1, %g2, %g3)
224 STORE_INIT(%o4, %o0 + 0x20)
225 STORE_INIT(%o5, %o0 + 0x28)
226 STORE_INIT(%g2, %o0 + 0x30)
227 STORE_INIT(%g3, %o0 + 0x38)
234 /* %o2 contains any final bytes still needed to be copied
235 * over. If anything is left, we copy it one byte at a time.
237 wr %g0, ASI_PNF, %asi
243 70: /* 16 < len <= 64 */
250 1: subcc %o4, 0x10, %o4
255 STORE(stx, %o5, %o1 + %o3)
257 STORE(stx, %g1, %o1 + %o3)
260 73: andcc %o2, 0x8, %g0
265 STORE(stx, %o5, %o1 + %o3)
267 1: andcc %o2, 0x4, %g0
272 STORE(stw, %o5, %o1 + %o3)
289 STORE(stb, %o5, %o1 + %o3)
327 80: /* 0 < len <= 16 */
335 STORE(stw, %g1, %o1 + %o3)
346 STORE(stb, %g1, %o1 + %o3)
354 #define RMOVE_BIGCHUNK(src, dst, offset, t0, t1, t2, t3) \
355 ldx [%src - offset - 0x20], %t0; \
356 ldx [%src - offset - 0x18], %t1; \
357 ldx [%src - offset - 0x10], %t2; \
358 ldx [%src - offset - 0x08], %t3; \
359 stw %t0, [%dst - offset - 0x1c]; \
361 stw %t0, [%dst - offset - 0x20]; \
362 stw %t1, [%dst - offset - 0x14]; \
364 stw %t1, [%dst - offset - 0x18]; \
365 stw %t2, [%dst - offset - 0x0c]; \
367 stw %t2, [%dst - offset - 0x10]; \
368 stw %t3, [%dst - offset - 0x04]; \
370 stw %t3, [%dst - offset - 0x08];
372 #define RMOVE_BIGALIGNCHUNK(src, dst, offset, t0, t1, t2, t3) \
373 ldx [%src - offset - 0x20], %t0; \
374 ldx [%src - offset - 0x18], %t1; \
375 ldx [%src - offset - 0x10], %t2; \
376 ldx [%src - offset - 0x08], %t3; \
377 stx %t0, [%dst - offset - 0x20]; \
378 stx %t1, [%dst - offset - 0x18]; \
379 stx %t2, [%dst - offset - 0x10]; \
380 stx %t3, [%dst - offset - 0x08]; \
381 ldx [%src - offset - 0x40], %t0; \
382 ldx [%src - offset - 0x38], %t1; \
383 ldx [%src - offset - 0x30], %t2; \
384 ldx [%src - offset - 0x28], %t3; \
385 stx %t0, [%dst - offset - 0x40]; \
386 stx %t1, [%dst - offset - 0x38]; \
387 stx %t2, [%dst - offset - 0x30]; \
388 stx %t3, [%dst - offset - 0x28];
390 #define RMOVE_LASTCHUNK(src, dst, offset, t0, t1, t2, t3) \
391 ldx [%src + offset + 0x00], %t0; \
392 ldx [%src + offset + 0x08], %t1; \
393 stw %t0, [%dst + offset + 0x04]; \
395 stw %t2, [%dst + offset + 0x00]; \
396 stw %t1, [%dst + offset + 0x0c]; \
398 stw %t3, [%dst + offset + 0x08];
400 #define RMOVE_LASTALIGNCHUNK(src, dst, offset, t0, t1) \
401 ldx [%src + offset + 0x00], %t0; \
402 ldx [%src + offset + 0x08], %t1; \
403 stx %t0, [%dst + offset + 0x00]; \
404 stx %t1, [%dst + offset + 0x08];
407 228: andcc %o2, 1, %g0
409 1: ldub [%o1 - 1], %o5
415 2: ldub [%o1 - 1], %o5
440 220: add %o1, %o2, %o1
459 4: lduh [%o1 - 2], %g2
465 236: be,a,pn %xcc, 2f
476 5: RMOVE_BIGCHUNK(o1, o0, 0x00, g1, g3, g5, o5)
477 RMOVE_BIGCHUNK(o1, o0, 0x20, g1, g3, g5, o5)
478 RMOVE_BIGCHUNK(o1, o0, 0x40, g1, g3, g5, o5)
479 RMOVE_BIGCHUNK(o1, o0, 0x60, g1, g3, g5, o5)
484 235: andcc %o2, 0x70, %g6
492 jmpl %o5 + %lo(280f - 279b), %g0
494 RMOVE_LASTCHUNK(o1, o0, 0x60, g2, g3, g5, o5)
495 RMOVE_LASTCHUNK(o1, o0, 0x50, g2, g3, g5, o5)
496 RMOVE_LASTCHUNK(o1, o0, 0x40, g2, g3, g5, o5)
497 RMOVE_LASTCHUNK(o1, o0, 0x30, g2, g3, g5, o5)
498 RMOVE_LASTCHUNK(o1, o0, 0x20, g2, g3, g5, o5)
499 RMOVE_LASTCHUNK(o1, o0, 0x10, g2, g3, g5, o5)
500 RMOVE_LASTCHUNK(o1, o0, 0x00, g2, g3, g5, o5)
501 280: be,pt %xcc, 281f
528 282: RMOVE_BIGALIGNCHUNK(o1, o0, 0x00, g1, g3, g5, o5)
529 RMOVE_BIGALIGNCHUNK(o1, o0, 0x40, g1, g3, g5, o5)
541 jmpl %o5 + %lo(284f - 283b), %g0
543 RMOVE_LASTALIGNCHUNK(o1, o0, 0x60, g2, g3)
544 RMOVE_LASTALIGNCHUNK(o1, o0, 0x50, g2, g3)
545 RMOVE_LASTALIGNCHUNK(o1, o0, 0x40, g2, g3)
546 RMOVE_LASTALIGNCHUNK(o1, o0, 0x30, g2, g3)
547 RMOVE_LASTALIGNCHUNK(o1, o0, 0x20, g2, g3)
548 RMOVE_LASTALIGNCHUNK(o1, o0, 0x10, g2, g3)
549 RMOVE_LASTALIGNCHUNK(o1, o0, 0x00, g2, g3)
550 284: be,pt %xcc, 285f
575 232: ldub [%o1 - 1], %g5
586 weak_alias (memcpy, __align_cpy_1)
587 weak_alias (memcpy, __align_cpy_2)
588 weak_alias (memcpy, __align_cpy_4)
589 weak_alias (memcpy, __align_cpy_8)
590 weak_alias (memcpy, __align_cpy_16)
592 libc_hidden_builtin_def (memcpy)
593 libc_hidden_builtin_def (memmove)