1 /* Copy SIZE bytes from SRC to DEST. For SUN4V Niagara.
2 Copyright (C) 2006-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
21 #define ASI_BLK_INIT_QUAD_LDD_P 0xe2
25 #define LOAD(type,addr,dest) type##a [addr] ASI_P, dest
26 #define LOAD_TWIN(addr_reg,dest0,dest1) \
27 ldda [addr_reg] ASI_BLK_INIT_QUAD_LDD_P, dest0
29 #define STORE(type,src,addr) type src, [addr]
30 #define STORE_INIT(src,addr) stxa src, [addr] %asi
39 .register %g2,#scratch
40 .register %g3,#scratch
41 .register %g6,#scratch
45 ENTRY(__mempcpy_niagara1)
48 END(__mempcpy_niagara1)
51 ENTRY(__memcpy_niagara1)
52 100: /* %o0=dst, %o1=src, %o2=len */
65 /* 2 blocks (128 bytes) is the minimum we can do the block
66 * copy with. We need to ensure that we'll iterate at least
67 * once in the block copy loop. At worst we'll need to align
68 * the destination to a 64-byte boundary which can chew up
69 * to (64 - 1) bytes from the length before we perform the
78 * %o2: len (known to be >= 128)
80 * The block copy loops will use %o4/%o5,%g2/%g3 as
81 * temporaries while copying the data.
84 LOAD(prefetch, %o1, #one_read)
85 wr %g0, ASI_BLK_INIT_QUAD_LDD_P, %asi
87 /* Align destination on 64-byte boundary. */
88 andcc %o0, (64 - 1), %o4
91 sub %g0, %o4, %o4 ! bytes to align dst
100 /* If the source is on a 16-byte boundary we can do
101 * the direct block copy loop. If it is 8-byte aligned
102 * we can do the 16-byte loads offset by -8 bytes and the
103 * init stores offset by one register.
105 * If the source is not even 8-byte aligned, we need to do
106 * shifting and masking (basically integer faligndata).
108 * The careful bit with init stores is that if we store
109 * to any part of the cache line we have to store the whole
110 * cacheline else we can end up with corrupt L2 cache line
111 * contents. Since the loop works on 64-bytes of 64-byte
112 * aligned store data at a time, this is easy to ensure.
115 andcc %o1, (16 - 1), %o4
116 andn %o2, (64 - 1), %g1 ! block copy loop iterator
117 sub %o2, %g1, %o2 ! final sub-block copy bytes
123 /* Neither 8-byte nor 16-byte aligned, shift and mask. */
133 #define SWIVEL_ONE_DWORD(SRC, TMP1, TMP2, PRE_VAL, PRE_SHIFT, POST_SHIFT, DST)\
134 LOAD(ldx, SRC, TMP1); \
135 srlx TMP1, PRE_SHIFT, TMP2; \
136 or TMP2, PRE_VAL, TMP2; \
137 STORE_INIT(TMP2, DST); \
138 sllx TMP1, POST_SHIFT, PRE_VAL;
141 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x00)
143 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x08)
145 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x10)
147 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x18)
149 LOAD(prefetch, %o1, #one_read)
151 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x20)
153 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x28)
155 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x30)
157 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x38)
162 #undef SWIVEL_ONE_DWORD
168 10: /* Destination is 64-byte aligned, source was only 8-byte
169 * aligned but it has been subtracted by 8 and we perform
170 * one twin load ahead, then add 8 back into source when
171 * we finish the loop.
173 LOAD_TWIN(%o1, %o4, %o5)
175 LOAD_TWIN(%o1, %g2, %g3)
176 add %o1, 16 + 32, %o1
177 LOAD(prefetch, %o1, #one_read)
179 STORE_INIT(%o5, %o0 + 0x00) ! initializes cache line
180 STORE_INIT(%g2, %o0 + 0x08)
181 LOAD_TWIN(%o1, %o4, %o5)
183 STORE_INIT(%g3, %o0 + 0x10)
184 STORE_INIT(%o4, %o0 + 0x18)
185 LOAD_TWIN(%o1, %g2, %g3)
187 STORE_INIT(%o5, %o0 + 0x20)
188 STORE_INIT(%g2, %o0 + 0x28)
189 LOAD_TWIN(%o1, %o4, %o5)
190 STORE_INIT(%g3, %o0 + 0x30)
191 STORE_INIT(%o4, %o0 + 0x38)
199 50: /* Destination is 64-byte aligned, and source is 16-byte
202 1: LOAD_TWIN(%o1, %o4, %o5)
204 LOAD_TWIN(%o1, %g2, %g3)
205 add %o1, 16 + 32, %o1
206 LOAD(prefetch, %o1, #one_read)
208 STORE_INIT(%o4, %o0 + 0x00) ! initializes cache line
209 STORE_INIT(%o5, %o0 + 0x08)
210 LOAD_TWIN(%o1, %o4, %o5)
212 STORE_INIT(%g2, %o0 + 0x10)
213 STORE_INIT(%g3, %o0 + 0x18)
214 LOAD_TWIN(%o1, %g2, %g3)
216 STORE_INIT(%o4, %o0 + 0x20)
217 STORE_INIT(%o5, %o0 + 0x28)
218 STORE_INIT(%g2, %o0 + 0x30)
219 STORE_INIT(%g3, %o0 + 0x38)
226 /* %o2 contains any final bytes still needed to be copied
227 * over. If anything is left, we copy it one byte at a time.
229 wr %g0, ASI_PNF, %asi
235 70: /* 16 < len <= 64 */
242 1: subcc %o4, 0x10, %o4
247 STORE(stx, %o5, %o1 + %o3)
249 STORE(stx, %g1, %o1 + %o3)
252 73: andcc %o2, 0x8, %g0
257 STORE(stx, %o5, %o1 + %o3)
259 1: andcc %o2, 0x4, %g0
264 STORE(stw, %o5, %o1 + %o3)
281 STORE(stb, %o5, %o1 + %o3)
319 80: /* 0 < len <= 16 */
327 STORE(stw, %g1, %o1 + %o3)
338 STORE(stb, %g1, %o1 + %o3)
344 END(__memcpy_niagara1)