1 /* NGmemcpy.S: Niagara optimized memcpy.
3 * Copyright (C) 2006 David S. Miller (davem@davemloft.net)
8 #include <asm/thread_info.h>
9 #define GLOBAL_SPARE %g7
10 #define RESTORE_ASI(TMP) \
11 ldub [%g6 + TI_CURRENT_DS], TMP; \
14 #define GLOBAL_SPARE %g5
15 #define RESTORE_ASI(TMP) \
20 #define STORE_ASI ASI_BLK_INIT_QUAD_LDD_P
32 #define EX_RETVAL(x) x
37 #define LOAD(type,addr,dest) type [addr], dest
39 #define LOAD(type,addr,dest) type##a [addr] 0x80, dest
44 #define LOAD_TWIN(addr_reg,dest0,dest1) \
45 ldda [addr_reg] ASI_BLK_INIT_QUAD_LDD_P, dest0
49 #define STORE(type,src,addr) type src, [addr]
53 #define STORE_INIT(src,addr) stxa src, [addr] %asi
57 #define FUNC_NAME NGmemcpy
68 .register %g2,#scratch
69 .register %g3,#scratch
75 .type FUNC_NAME,#function
76 FUNC_NAME: /* %o0=dst, %o1=src, %o2=len */
89 /* 2 blocks (128 bytes) is the minimum we can do the block
90 * copy with. We need to ensure that we'll iterate at least
91 * once in the block copy loop. At worst we'll need to align
92 * the destination to a 64-byte boundary which can chew up
93 * to (64 - 1) bytes from the length before we perform the
102 * %o2: len (known to be >= 128)
104 * The block copy loops will use %o4/%o5,%g2/%g3 as
105 * temporaries while copying the data.
108 LOAD(prefetch, %o1, #one_read)
109 wr %g0, STORE_ASI, %asi
111 /* Align destination on 64-byte boundary. */
112 andcc %o0, (64 - 1), %o4
115 sub %g0, %o4, %o4 ! bytes to align dst
118 EX_LD(LOAD(ldub, %o1, %g1))
119 EX_ST(STORE(stb, %g1, %o0))
124 /* If the source is on a 16-byte boundary we can do
125 * the direct block copy loop. If it is 8-byte aligned
126 * we can do the 16-byte loads offset by -8 bytes and the
127 * init stores offset by one register.
129 * If the source is not even 8-byte aligned, we need to do
130 * shifting and masking (basically integer faligndata).
132 * The careful bit with init stores is that if we store
133 * to any part of the cache line we have to store the whole
134 * cacheline else we can end up with corrupt L2 cache line
135 * contents. Since the loop works on 64-bytes of 64-byte
136 * aligned store data at a time, this is easy to ensure.
139 andcc %o1, (16 - 1), %o4
140 andn %o2, (64 - 1), %g1 ! block copy loop iterator
141 sub %o2, %g1, %o2 ! final sub-block copy bytes
147 /* Neither 8-byte nor 16-byte aligned, shift and mask. */
153 EX_LD(LOAD(ldx, %o1, %g2))
157 #define SWIVEL_ONE_DWORD(SRC, TMP1, TMP2, PRE_VAL, PRE_SHIFT, POST_SHIFT, DST)\
158 EX_LD(LOAD(ldx, SRC, TMP1)); \
159 srlx TMP1, PRE_SHIFT, TMP2; \
160 or TMP2, PRE_VAL, TMP2; \
161 EX_ST(STORE_INIT(TMP2, DST)); \
162 sllx TMP1, POST_SHIFT, PRE_VAL;
165 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x00)
167 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x08)
169 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x10)
171 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x18)
173 LOAD(prefetch, %o1, #one_read)
175 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x20)
177 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x28)
179 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x30)
181 SWIVEL_ONE_DWORD(%o1, %g3, %o5, %g2, %o3, %g1, %o0 + 0x38)
186 #undef SWIVEL_ONE_DWORD
192 10: /* Destination is 64-byte aligned, source was only 8-byte
193 * aligned but it has been subtracted by 8 and we perform
194 * one twin load ahead, then add 8 back into source when
195 * we finish the loop.
197 EX_LD(LOAD_TWIN(%o1, %o4, %o5))
199 EX_LD(LOAD_TWIN(%o1, %g2, %g3))
200 add %o1, 16 + 32, %o1
201 LOAD(prefetch, %o1, #one_read)
203 EX_ST(STORE_INIT(%o5, %o0 + 0x00)) ! initializes cache line
204 EX_ST(STORE_INIT(%g2, %o0 + 0x08))
205 EX_LD(LOAD_TWIN(%o1, %o4, %o5))
207 EX_ST(STORE_INIT(%g3, %o0 + 0x10))
208 EX_ST(STORE_INIT(%o4, %o0 + 0x18))
209 EX_LD(LOAD_TWIN(%o1, %g2, %g3))
211 EX_ST(STORE_INIT(%o5, %o0 + 0x20))
212 EX_ST(STORE_INIT(%g2, %o0 + 0x28))
213 EX_LD(LOAD_TWIN(%o1, %o4, %o5))
214 EX_ST(STORE_INIT(%g3, %o0 + 0x30))
215 EX_ST(STORE_INIT(%o4, %o0 + 0x38))
223 50: /* Destination is 64-byte aligned, and source is 16-byte
226 1: EX_LD(LOAD_TWIN(%o1, %o4, %o5))
228 EX_LD(LOAD_TWIN(%o1, %g2, %g3))
229 add %o1, 16 + 32, %o1
230 LOAD(prefetch, %o1, #one_read)
232 EX_ST(STORE_INIT(%o4, %o0 + 0x00)) ! initializes cache line
233 EX_ST(STORE_INIT(%o5, %o0 + 0x08))
234 EX_LD(LOAD_TWIN(%o1, %o4, %o5))
236 EX_ST(STORE_INIT(%g2, %o0 + 0x10))
237 EX_ST(STORE_INIT(%g3, %o0 + 0x18))
238 EX_LD(LOAD_TWIN(%o1, %g2, %g3))
240 EX_ST(STORE_INIT(%o4, %o0 + 0x20))
241 EX_ST(STORE_INIT(%o5, %o0 + 0x28))
242 EX_ST(STORE_INIT(%g2, %o0 + 0x30))
243 EX_ST(STORE_INIT(%g3, %o0 + 0x38))
250 /* %o2 contains any final bytes still needed to be copied
251 * over. If anything is left, we copy it one byte at a time.
259 70: /* 16 < len <= 64 */
266 1: subcc %o4, 0x10, %o4
267 EX_LD(LOAD(ldx, %o1, %o5))
269 EX_LD(LOAD(ldx, %o1, %g1))
271 EX_ST(STORE(stx, %o5, %o1 + %o3))
273 EX_ST(STORE(stx, %g1, %o1 + %o3))
276 73: andcc %o2, 0x8, %g0
280 EX_LD(LOAD(ldx, %o1, %o5))
281 EX_ST(STORE(stx, %o5, %o1 + %o3))
283 1: andcc %o2, 0x4, %g0
287 EX_LD(LOAD(lduw, %o1, %o5))
288 EX_ST(STORE(stw, %o5, %o1 + %o3))
304 EX_LD(LOAD(ldub, %o1, %o5))
305 EX_ST(STORE(stb, %o5, %o1 + %o3))
321 EX_LD(LOAD(ldx, %o1, %g2))
326 EX_LD(LOAD(ldx, %o1, %g3))
330 EX_ST(STORE(stx, %o5, %o0))
343 80: /* 0 < len <= 16 */
350 EX_LD(LOAD(lduw, %o1, %g1))
351 EX_ST(STORE(stw, %g1, %o1 + %o3))
356 mov EX_RETVAL(GLOBAL_SPARE), %o0
361 EX_LD(LOAD(ldub, %o1, %g1))
362 EX_ST(STORE(stb, %g1, %o1 + %o3))
366 mov EX_RETVAL(GLOBAL_SPARE), %o0
368 .size FUNC_NAME, .-FUNC_NAME