1 /* Copy SIZE bytes from SRC to DEST. For SUN4V Niagara.
2 Copyright (C) 2006-2015 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, see
18 <http://www.gnu.org/licenses/>. */
22 #define ASI_BLK_INIT_QUAD_LDD_P 0xe2
26 #define LOAD(type,addr,dest) type##a [addr] ASI_P, dest
27 #define LOAD_TWIN(addr_reg,dest0,dest1) \
28 ldda [addr_reg] ASI_BLK_INIT_QUAD_LDD_P, dest0
30 #define STORE(type,src,addr) type src, [addr]
31 #define STORE_INIT(src,addr) stxa src, [addr] %asi
40 .register %g2,#scratch
41 .register %g3,#scratch
42 .register %g6,#scratch
46 ENTRY(__mempcpy_niagara1)
49 END(__mempcpy_niagara1)
52 ENTRY(__memcpy_niagara1)
53 100: /* %o0=dst, %o1=src, %o2=len */
66 /* 2 blocks (128 bytes) is the minimum we can do the block
67 * copy with. We need to ensure that we'll iterate at least
68 * once in the block copy loop. At worst we'll need to align
69 * the destination to a 64-byte boundary which can chew up
70 * to (64 - 1) bytes from the length before we perform the
79 * %o2: len (known to be >= 128)
81 * The block copy loops will use %o4/%o5,%g2/%g3 as
82 * temporaries while copying the data.
85 LOAD(prefetch, %o1, #one_read)
86 wr %g0, ASI_BLK_INIT_QUAD_LDD_P, %asi
88 /* Align destination on 64-byte boundary. */
89 andcc %o0, (64 - 1), %o4
92 sub %g0, %o4, %o4 ! bytes to align dst
101 /* If the source is on a 16-byte boundary we can do
102 * the direct block copy loop. If it is 8-byte aligned
103 * we can do the 16-byte loads offset by -8 bytes and the
104 * init stores offset by one register.
106 * If the source is not even 8-byte aligned, we need to do
107 * shifting and masking (basically integer faligndata).
109 * The careful bit with init stores is that if we store
110 * to any part of the cache line we have to store the whole
111 * cacheline else we can end up with corrupt L2 cache line
112 * contents. Since the loop works on 64-bytes of 64-byte
113 * aligned store data at a time, this is easy to ensure.
116 andcc %o1, (16 - 1), %o4
117 andn %o2, (64 - 1), %g1 ! block copy loop iterator
118 sub %o2, %g1, %o2 ! final sub-block copy bytes
124 /* Neither 8-byte nor 16-byte aligned, shift and mask. */
134 #define SWIVEL_ONE_DWORD(SRC, TMP1, TMP2, PRE_VAL, PRE_SHIFT, POST_SHIFT, DST)\
135 LOAD(ldx, SRC, TMP1); \
136 srlx TMP1, PRE_SHIFT, TMP2; \
137 or TMP2, PRE_VAL, TMP2; \
138 STORE_INIT(TMP2, DST); \
139 sllx TMP1, POST_SHIFT, PRE_VAL;
142 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x00)
144 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x08)
146 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x10)
148 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x18)
150 LOAD(prefetch, %o1, #one_read)
152 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x20)
154 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x28)
156 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x30)
158 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x38)
163 #undef SWIVEL_ONE_DWORD
169 10: /* Destination is 64-byte aligned, source was only 8-byte
170 * aligned but it has been subtracted by 8 and we perform
171 * one twin load ahead, then add 8 back into source when
172 * we finish the loop.
174 LOAD_TWIN(%o1, %o4, %o5)
176 LOAD_TWIN(%o1, %g2, %g3)
177 add %o1, 16 + 32, %o1
178 LOAD(prefetch, %o1, #one_read)
180 STORE_INIT(%o5, %o0 + 0x00) ! initializes cache line
181 STORE_INIT(%g2, %o0 + 0x08)
182 LOAD_TWIN(%o1, %o4, %o5)
184 STORE_INIT(%g3, %o0 + 0x10)
185 STORE_INIT(%o4, %o0 + 0x18)
186 LOAD_TWIN(%o1, %g2, %g3)
188 STORE_INIT(%o5, %o0 + 0x20)
189 STORE_INIT(%g2, %o0 + 0x28)
190 LOAD_TWIN(%o1, %o4, %o5)
191 STORE_INIT(%g3, %o0 + 0x30)
192 STORE_INIT(%o4, %o0 + 0x38)
200 50: /* Destination is 64-byte aligned, and source is 16-byte
203 1: LOAD_TWIN(%o1, %o4, %o5)
205 LOAD_TWIN(%o1, %g2, %g3)
206 add %o1, 16 + 32, %o1
207 LOAD(prefetch, %o1, #one_read)
209 STORE_INIT(%o4, %o0 + 0x00) ! initializes cache line
210 STORE_INIT(%o5, %o0 + 0x08)
211 LOAD_TWIN(%o1, %o4, %o5)
213 STORE_INIT(%g2, %o0 + 0x10)
214 STORE_INIT(%g3, %o0 + 0x18)
215 LOAD_TWIN(%o1, %g2, %g3)
217 STORE_INIT(%o4, %o0 + 0x20)
218 STORE_INIT(%o5, %o0 + 0x28)
219 STORE_INIT(%g2, %o0 + 0x30)
220 STORE_INIT(%g3, %o0 + 0x38)
227 /* %o2 contains any final bytes still needed to be copied
228 * over. If anything is left, we copy it one byte at a time.
230 wr %g0, ASI_PNF, %asi
236 70: /* 16 < len <= 64 */
243 1: subcc %o4, 0x10, %o4
248 STORE(stx, %o5, %o1 + %o3)
250 STORE(stx, %g1, %o1 + %o3)
253 73: andcc %o2, 0x8, %g0
258 STORE(stx, %o5, %o1 + %o3)
260 1: andcc %o2, 0x4, %g0
265 STORE(stw, %o5, %o1 + %o3)
282 STORE(stb, %o5, %o1 + %o3)
320 80: /* 0 < len <= 16 */
328 STORE(stw, %g1, %o1 + %o3)
339 STORE(stb, %g1, %o1 + %o3)
345 END(__memcpy_niagara1)