1 /* Copy SIZE bytes from SRC to DEST. For SUN4V Niagara.
2 Copyright (C) 2006, 2008 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
67 100: /* %o0=dst, %o1=src, %o2=len */
76 /* 2 blocks (128 bytes) is the minimum we can do the block
77 * copy with. We need to ensure that we'll iterate at least
78 * once in the block copy loop. At worst we'll need to align
79 * the destination to a 64-byte boundary which can chew up
80 * to (64 - 1) bytes from the length before we perform the
89 * %o2: len (known to be >= 128)
91 * The block copy loops will use %o4/%o5,%g2/%g3 as
92 * temporaries while copying the data.
95 LOAD(prefetch, %o1, #one_read)
96 wr %g0, ASI_BLK_INIT_QUAD_LDD_P, %asi
98 /* Align destination on 64-byte boundary. */
99 andcc %o0, (64 - 1), %o4
102 sub %g0, %o4, %o4 ! bytes to align dst
111 /* If the source is on a 16-byte boundary we can do
112 * the direct block copy loop. If it is 8-byte aligned
113 * we can do the 16-byte loads offset by -8 bytes and the
114 * init stores offset by one register.
116 * If the source is not even 8-byte aligned, we need to do
117 * shifting and masking (basically integer faligndata).
119 * The careful bit with init stores is that if we store
120 * to any part of the cache line we have to store the whole
121 * cacheline else we can end up with corrupt L2 cache line
122 * contents. Since the loop works on 64-bytes of 64-byte
123 * aligned store data at a time, this is easy to ensure.
126 andcc %o1, (16 - 1), %o4
127 andn %o2, (64 - 1), %g1 ! block copy loop iterator
128 sub %o2, %g1, %o2 ! final sub-block copy bytes
134 /* Neither 8-byte nor 16-byte aligned, shift and mask. */
144 #define SWIVEL_ONE_DWORD(SRC, TMP1, TMP2, PRE_VAL, PRE_SHIFT, POST_SHIFT, DST)\
145 LOAD(ldx, SRC, TMP1); \
146 srlx TMP1, PRE_SHIFT, TMP2; \
147 or TMP2, PRE_VAL, TMP2; \
148 STORE_INIT(TMP2, DST); \
149 sllx TMP1, POST_SHIFT, PRE_VAL;
152 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x00)
154 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x08)
156 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x10)
158 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x18)
160 LOAD(prefetch, %o1, #one_read)
162 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x20)
164 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x28)
166 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x30)
168 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x38)
173 #undef SWIVEL_ONE_DWORD
179 10: /* Destination is 64-byte aligned, source was only 8-byte
180 * aligned but it has been subtracted by 8 and we perform
181 * one twin load ahead, then add 8 back into source when
182 * we finish the loop.
184 LOAD_TWIN(%o1, %o4, %o5)
186 LOAD_TWIN(%o1, %g2, %g3)
187 add %o1, 16 + 32, %o1
188 LOAD(prefetch, %o1, #one_read)
190 STORE_INIT(%o5, %o0 + 0x00) ! initializes cache line
191 STORE_INIT(%g2, %o0 + 0x08)
192 LOAD_TWIN(%o1, %o4, %o5)
194 STORE_INIT(%g3, %o0 + 0x10)
195 STORE_INIT(%o4, %o0 + 0x18)
196 LOAD_TWIN(%o1, %g2, %g3)
198 STORE_INIT(%o5, %o0 + 0x20)
199 STORE_INIT(%g2, %o0 + 0x28)
200 LOAD_TWIN(%o1, %o4, %o5)
201 STORE_INIT(%g3, %o0 + 0x30)
202 STORE_INIT(%o4, %o0 + 0x38)
210 50: /* Destination is 64-byte aligned, and source is 16-byte
213 1: LOAD_TWIN(%o1, %o4, %o5)
215 LOAD_TWIN(%o1, %g2, %g3)
216 add %o1, 16 + 32, %o1
217 LOAD(prefetch, %o1, #one_read)
219 STORE_INIT(%o4, %o0 + 0x00) ! initializes cache line
220 STORE_INIT(%o5, %o0 + 0x08)
221 LOAD_TWIN(%o1, %o4, %o5)
223 STORE_INIT(%g2, %o0 + 0x10)
224 STORE_INIT(%g3, %o0 + 0x18)
225 LOAD_TWIN(%o1, %g2, %g3)
227 STORE_INIT(%o4, %o0 + 0x20)
228 STORE_INIT(%o5, %o0 + 0x28)
229 STORE_INIT(%g2, %o0 + 0x30)
230 STORE_INIT(%g3, %o0 + 0x38)
237 /* %o2 contains any final bytes still needed to be copied
238 * over. If anything is left, we copy it one byte at a time.
240 wr %g0, ASI_PNF, %asi
246 70: /* 16 < len <= 64 */
253 1: subcc %o4, 0x10, %o4
258 STORE(stx, %o5, %o1 + %o3)
260 STORE(stx, %g1, %o1 + %o3)
263 73: andcc %o2, 0x8, %g0
268 STORE(stx, %o5, %o1 + %o3)
270 1: andcc %o2, 0x4, %g0
275 STORE(stw, %o5, %o1 + %o3)
292 STORE(stb, %o5, %o1 + %o3)
330 80: /* 0 < len <= 16 */
338 STORE(stw, %g1, %o1 + %o3)
349 STORE(stb, %g1, %o1 + %o3)
357 #define RMOVE_BIGCHUNK(src, dst, offset, t0, t1, t2, t3) \
358 ldx [%src - offset - 0x20], %t0; \
359 ldx [%src - offset - 0x18], %t1; \
360 ldx [%src - offset - 0x10], %t2; \
361 ldx [%src - offset - 0x08], %t3; \
362 stw %t0, [%dst - offset - 0x1c]; \
364 stw %t0, [%dst - offset - 0x20]; \
365 stw %t1, [%dst - offset - 0x14]; \
367 stw %t1, [%dst - offset - 0x18]; \
368 stw %t2, [%dst - offset - 0x0c]; \
370 stw %t2, [%dst - offset - 0x10]; \
371 stw %t3, [%dst - offset - 0x04]; \
373 stw %t3, [%dst - offset - 0x08];
375 #define RMOVE_BIGALIGNCHUNK(src, dst, offset, t0, t1, t2, t3) \
376 ldx [%src - offset - 0x20], %t0; \
377 ldx [%src - offset - 0x18], %t1; \
378 ldx [%src - offset - 0x10], %t2; \
379 ldx [%src - offset - 0x08], %t3; \
380 stx %t0, [%dst - offset - 0x20]; \
381 stx %t1, [%dst - offset - 0x18]; \
382 stx %t2, [%dst - offset - 0x10]; \
383 stx %t3, [%dst - offset - 0x08]; \
384 ldx [%src - offset - 0x40], %t0; \
385 ldx [%src - offset - 0x38], %t1; \
386 ldx [%src - offset - 0x30], %t2; \
387 ldx [%src - offset - 0x28], %t3; \
388 stx %t0, [%dst - offset - 0x40]; \
389 stx %t1, [%dst - offset - 0x38]; \
390 stx %t2, [%dst - offset - 0x30]; \
391 stx %t3, [%dst - offset - 0x28];
393 #define RMOVE_LASTCHUNK(src, dst, offset, t0, t1, t2, t3) \
394 ldx [%src + offset + 0x00], %t0; \
395 ldx [%src + offset + 0x08], %t1; \
396 stw %t0, [%dst + offset + 0x04]; \
398 stw %t2, [%dst + offset + 0x00]; \
399 stw %t1, [%dst + offset + 0x0c]; \
401 stw %t3, [%dst + offset + 0x08];
403 #define RMOVE_LASTALIGNCHUNK(src, dst, offset, t0, t1) \
404 ldx [%src + offset + 0x00], %t0; \
405 ldx [%src + offset + 0x08], %t1; \
406 stx %t0, [%dst + offset + 0x00]; \
407 stx %t1, [%dst + offset + 0x08];
410 228: andcc %o2, 1, %g0
412 1: ldub [%o1 - 1], %o5
418 2: ldub [%o1 - 1], %o5
443 220: add %o1, %o2, %o1
462 4: lduh [%o1 - 2], %g2
468 236: be,a,pn %xcc, 2f
479 5: RMOVE_BIGCHUNK(o1, o0, 0x00, g1, g3, g5, o5)
480 RMOVE_BIGCHUNK(o1, o0, 0x20, g1, g3, g5, o5)
481 RMOVE_BIGCHUNK(o1, o0, 0x40, g1, g3, g5, o5)
482 RMOVE_BIGCHUNK(o1, o0, 0x60, g1, g3, g5, o5)
487 235: andcc %o2, 0x70, %g6
495 jmpl %o5 + %lo(280f - 279b), %g0
497 RMOVE_LASTCHUNK(o1, o0, 0x60, g2, g3, g5, o5)
498 RMOVE_LASTCHUNK(o1, o0, 0x50, g2, g3, g5, o5)
499 RMOVE_LASTCHUNK(o1, o0, 0x40, g2, g3, g5, o5)
500 RMOVE_LASTCHUNK(o1, o0, 0x30, g2, g3, g5, o5)
501 RMOVE_LASTCHUNK(o1, o0, 0x20, g2, g3, g5, o5)
502 RMOVE_LASTCHUNK(o1, o0, 0x10, g2, g3, g5, o5)
503 RMOVE_LASTCHUNK(o1, o0, 0x00, g2, g3, g5, o5)
504 280: be,pt %xcc, 281f
531 282: RMOVE_BIGALIGNCHUNK(o1, o0, 0x00, g1, g3, g5, o5)
532 RMOVE_BIGALIGNCHUNK(o1, o0, 0x40, g1, g3, g5, o5)
544 jmpl %o5 + %lo(284f - 283b), %g0
546 RMOVE_LASTALIGNCHUNK(o1, o0, 0x60, g2, g3)
547 RMOVE_LASTALIGNCHUNK(o1, o0, 0x50, g2, g3)
548 RMOVE_LASTALIGNCHUNK(o1, o0, 0x40, g2, g3)
549 RMOVE_LASTALIGNCHUNK(o1, o0, 0x30, g2, g3)
550 RMOVE_LASTALIGNCHUNK(o1, o0, 0x20, g2, g3)
551 RMOVE_LASTALIGNCHUNK(o1, o0, 0x10, g2, g3)
552 RMOVE_LASTALIGNCHUNK(o1, o0, 0x00, g2, g3)
553 284: be,pt %xcc, 285f
578 232: ldub [%o1 - 1], %g5
589 weak_alias (memcpy, __align_cpy_1)
590 weak_alias (memcpy, __align_cpy_2)
591 weak_alias (memcpy, __align_cpy_4)
592 weak_alias (memcpy, __align_cpy_8)
593 weak_alias (memcpy, __align_cpy_16)
595 libc_hidden_builtin_def (memcpy)
596 libc_hidden_builtin_def (memmove)