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 #if !defined NOT_IN_libc
41 .register %g2,#scratch
42 .register %g3,#scratch
43 .register %g6,#scratch
48 ENTRY(__memcpy_niagara1)
52 100: /* %o0=dst, %o1=src, %o2=len */
61 /* 2 blocks (128 bytes) is the minimum we can do the block
62 * copy with. We need to ensure that we'll iterate at least
63 * once in the block copy loop. At worst we'll need to align
64 * the destination to a 64-byte boundary which can chew up
65 * to (64 - 1) bytes from the length before we perform the
74 * %o2: len (known to be >= 128)
76 * The block copy loops will use %o4/%o5,%g2/%g3 as
77 * temporaries while copying the data.
80 LOAD(prefetch, %o1, #one_read)
81 wr %g0, ASI_BLK_INIT_QUAD_LDD_P, %asi
83 /* Align destination on 64-byte boundary. */
84 andcc %o0, (64 - 1), %o4
87 sub %g0, %o4, %o4 ! bytes to align dst
96 /* If the source is on a 16-byte boundary we can do
97 * the direct block copy loop. If it is 8-byte aligned
98 * we can do the 16-byte loads offset by -8 bytes and the
99 * init stores offset by one register.
101 * If the source is not even 8-byte aligned, we need to do
102 * shifting and masking (basically integer faligndata).
104 * The careful bit with init stores is that if we store
105 * to any part of the cache line we have to store the whole
106 * cacheline else we can end up with corrupt L2 cache line
107 * contents. Since the loop works on 64-bytes of 64-byte
108 * aligned store data at a time, this is easy to ensure.
111 andcc %o1, (16 - 1), %o4
112 andn %o2, (64 - 1), %g1 ! block copy loop iterator
113 sub %o2, %g1, %o2 ! final sub-block copy bytes
119 /* Neither 8-byte nor 16-byte aligned, shift and mask. */
129 #define SWIVEL_ONE_DWORD(SRC, TMP1, TMP2, PRE_VAL, PRE_SHIFT, POST_SHIFT, DST)\
130 LOAD(ldx, SRC, TMP1); \
131 srlx TMP1, PRE_SHIFT, TMP2; \
132 or TMP2, PRE_VAL, TMP2; \
133 STORE_INIT(TMP2, DST); \
134 sllx TMP1, POST_SHIFT, PRE_VAL;
137 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x00)
139 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x08)
141 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x10)
143 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x18)
145 LOAD(prefetch, %o1, #one_read)
147 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x20)
149 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x28)
151 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x30)
153 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x38)
158 #undef SWIVEL_ONE_DWORD
164 10: /* Destination is 64-byte aligned, source was only 8-byte
165 * aligned but it has been subtracted by 8 and we perform
166 * one twin load ahead, then add 8 back into source when
167 * we finish the loop.
169 LOAD_TWIN(%o1, %o4, %o5)
171 LOAD_TWIN(%o1, %g2, %g3)
172 add %o1, 16 + 32, %o1
173 LOAD(prefetch, %o1, #one_read)
175 STORE_INIT(%o5, %o0 + 0x00) ! initializes cache line
176 STORE_INIT(%g2, %o0 + 0x08)
177 LOAD_TWIN(%o1, %o4, %o5)
179 STORE_INIT(%g3, %o0 + 0x10)
180 STORE_INIT(%o4, %o0 + 0x18)
181 LOAD_TWIN(%o1, %g2, %g3)
183 STORE_INIT(%o5, %o0 + 0x20)
184 STORE_INIT(%g2, %o0 + 0x28)
185 LOAD_TWIN(%o1, %o4, %o5)
186 STORE_INIT(%g3, %o0 + 0x30)
187 STORE_INIT(%o4, %o0 + 0x38)
195 50: /* Destination is 64-byte aligned, and source is 16-byte
198 1: LOAD_TWIN(%o1, %o4, %o5)
200 LOAD_TWIN(%o1, %g2, %g3)
201 add %o1, 16 + 32, %o1
202 LOAD(prefetch, %o1, #one_read)
204 STORE_INIT(%o4, %o0 + 0x00) ! initializes cache line
205 STORE_INIT(%o5, %o0 + 0x08)
206 LOAD_TWIN(%o1, %o4, %o5)
208 STORE_INIT(%g2, %o0 + 0x10)
209 STORE_INIT(%g3, %o0 + 0x18)
210 LOAD_TWIN(%o1, %g2, %g3)
212 STORE_INIT(%o4, %o0 + 0x20)
213 STORE_INIT(%o5, %o0 + 0x28)
214 STORE_INIT(%g2, %o0 + 0x30)
215 STORE_INIT(%g3, %o0 + 0x38)
222 /* %o2 contains any final bytes still needed to be copied
223 * over. If anything is left, we copy it one byte at a time.
225 wr %g0, ASI_PNF, %asi
231 70: /* 16 < len <= 64 */
238 1: subcc %o4, 0x10, %o4
243 STORE(stx, %o5, %o1 + %o3)
245 STORE(stx, %g1, %o1 + %o3)
248 73: andcc %o2, 0x8, %g0
253 STORE(stx, %o5, %o1 + %o3)
255 1: andcc %o2, 0x4, %g0
260 STORE(stw, %o5, %o1 + %o3)
277 STORE(stb, %o5, %o1 + %o3)
315 80: /* 0 < len <= 16 */
323 STORE(stw, %g1, %o1 + %o3)
334 STORE(stb, %g1, %o1 + %o3)
340 END(__memcpy_niagara1)