1 /* NGmemcpy.S: Niagara optimized memcpy.
3 * Copyright (C) 2006, 2007 David S. Miller (davem@davemloft.net)
7 #include <linux/linkage.h>
9 #include <asm/thread_info.h>
10 #define GLOBAL_SPARE %g7
11 #define RESTORE_ASI(TMP) \
12 ldub [%g6 + TI_CURRENT_DS], TMP; \
15 #define GLOBAL_SPARE %g5
16 #define RESTORE_ASI(TMP) \
21 #define SAVE_AMOUNT 128
23 #define SAVE_AMOUNT 64
27 #define STORE_ASI ASI_BLK_INIT_QUAD_LDD_P
40 #define LOAD(type,addr,dest) type [addr], dest
42 #define LOAD(type,addr,dest) type##a [addr] 0x80, dest
47 #define LOAD_TWIN(addr_reg,dest0,dest1) \
48 ldda [addr_reg] ASI_BLK_INIT_QUAD_LDD_P, dest0
52 #define STORE(type,src,addr) type src, [addr]
56 #ifndef SIMULATE_NIAGARA_ON_NON_NIAGARA
57 #define STORE_INIT(src,addr) stxa src, [addr] %asi
59 #define STORE_INIT(src,addr) stx src, [addr + 0x00]
64 #define FUNC_NAME NGmemcpy
75 .register %g2,#scratch
76 .register %g3,#scratch
80 #define EX_RETVAL(x) x
83 wr %g0, ASI_AIUS, %asi
85 ENTRY(NG_ret_i2_plus_i4_plus_1)
86 ba,pt %xcc, __restore_asi
88 ENDPROC(NG_ret_i2_plus_i4_plus_1)
89 ENTRY(NG_ret_i2_plus_g1)
90 ba,pt %xcc, __restore_asi
92 ENDPROC(NG_ret_i2_plus_g1)
93 ENTRY(NG_ret_i2_plus_g1_minus_8)
95 ba,pt %xcc, __restore_asi
97 ENDPROC(NG_ret_i2_plus_g1_minus_8)
98 ENTRY(NG_ret_i2_plus_g1_minus_16)
100 ba,pt %xcc, __restore_asi
102 ENDPROC(NG_ret_i2_plus_g1_minus_16)
103 ENTRY(NG_ret_i2_plus_g1_minus_24)
105 ba,pt %xcc, __restore_asi
107 ENDPROC(NG_ret_i2_plus_g1_minus_24)
108 ENTRY(NG_ret_i2_plus_g1_minus_32)
110 ba,pt %xcc, __restore_asi
112 ENDPROC(NG_ret_i2_plus_g1_minus_32)
113 ENTRY(NG_ret_i2_plus_g1_minus_40)
115 ba,pt %xcc, __restore_asi
117 ENDPROC(NG_ret_i2_plus_g1_minus_40)
118 ENTRY(NG_ret_i2_plus_g1_minus_48)
120 ba,pt %xcc, __restore_asi
122 ENDPROC(NG_ret_i2_plus_g1_minus_48)
123 ENTRY(NG_ret_i2_plus_g1_minus_56)
125 ba,pt %xcc, __restore_asi
127 ENDPROC(NG_ret_i2_plus_g1_minus_56)
128 ENTRY(NG_ret_i2_plus_i4)
129 ba,pt %xcc, __restore_asi
131 ENDPROC(NG_ret_i2_plus_i4)
132 ENTRY(NG_ret_i2_plus_i4_minus_8)
134 ba,pt %xcc, __restore_asi
136 ENDPROC(NG_ret_i2_plus_i4_minus_8)
137 ENTRY(NG_ret_i2_plus_8)
138 ba,pt %xcc, __restore_asi
140 ENDPROC(NG_ret_i2_plus_8)
141 ENTRY(NG_ret_i2_plus_4)
142 ba,pt %xcc, __restore_asi
144 ENDPROC(NG_ret_i2_plus_4)
145 ENTRY(NG_ret_i2_plus_1)
146 ba,pt %xcc, __restore_asi
148 ENDPROC(NG_ret_i2_plus_1)
149 ENTRY(NG_ret_i2_plus_g1_plus_1)
151 ba,pt %xcc, __restore_asi
153 ENDPROC(NG_ret_i2_plus_g1_plus_1)
155 ba,pt %xcc, __restore_asi
158 ENTRY(NG_ret_i2_and_7_plus_i4)
160 ba,pt %xcc, __restore_asi
162 ENDPROC(NG_ret_i2_and_7_plus_i4)
168 .type FUNC_NAME,#function
169 FUNC_NAME: /* %i0=dst, %i1=src, %i2=len */
171 save %sp, -SAVE_AMOUNT, %sp
183 /* 2 blocks (128 bytes) is the minimum we can do the block
184 * copy with. We need to ensure that we'll iterate at least
185 * once in the block copy loop. At worst we'll need to align
186 * the destination to a 64-byte boundary which can chew up
187 * to (64 - 1) bytes from the length before we perform the
196 * %i2: len (known to be >= 128)
198 * The block copy loops will use %i4/%i5,%g2/%g3 as
199 * temporaries while copying the data.
202 LOAD(prefetch, %i1, #one_read)
203 wr %g0, STORE_ASI, %asi
205 /* Align destination on 64-byte boundary. */
206 andcc %o0, (64 - 1), %i4
209 sub %g0, %i4, %i4 ! bytes to align dst
212 EX_LD(LOAD(ldub, %i1, %g1), NG_ret_i2_plus_i4_plus_1)
213 EX_ST(STORE(stb, %g1, %o0), NG_ret_i2_plus_i4_plus_1)
218 /* If the source is on a 16-byte boundary we can do
219 * the direct block copy loop. If it is 8-byte aligned
220 * we can do the 16-byte loads offset by -8 bytes and the
221 * init stores offset by one register.
223 * If the source is not even 8-byte aligned, we need to do
224 * shifting and masking (basically integer faligndata).
226 * The careful bit with init stores is that if we store
227 * to any part of the cache line we have to store the whole
228 * cacheline else we can end up with corrupt L2 cache line
229 * contents. Since the loop works on 64-bytes of 64-byte
230 * aligned store data at a time, this is easy to ensure.
233 andcc %i1, (16 - 1), %i4
234 andn %i2, (64 - 1), %g1 ! block copy loop iterator
236 sub %i2, %g1, %i2 ! final sub-block copy bytes
242 /* Neither 8-byte nor 16-byte aligned, shift and mask. */
243 and %i4, 0x7, GLOBAL_SPARE
244 sll GLOBAL_SPARE, 3, GLOBAL_SPARE
246 EX_LD(LOAD_TWIN(%i1, %g2, %g3), NG_ret_i2_plus_g1)
247 sub %i5, GLOBAL_SPARE, %i5
256 #define MIX_THREE_WORDS(WORD1, WORD2, WORD3, PRE_SHIFT, POST_SHIFT, TMP) \
257 sllx WORD1, POST_SHIFT, WORD1; \
258 srlx WORD2, PRE_SHIFT, TMP; \
259 sllx WORD2, POST_SHIFT, WORD2; \
260 or WORD1, TMP, WORD1; \
261 srlx WORD3, PRE_SHIFT, TMP; \
262 or WORD2, TMP, WORD2;
264 8: EX_LD(LOAD_TWIN(%i1 + %o4, %o2, %o3), NG_ret_i2_plus_g1)
265 MIX_THREE_WORDS(%g2, %g3, %o2, %i5, GLOBAL_SPARE, %o1)
266 LOAD(prefetch, %i1 + %i3, #one_read)
268 EX_ST(STORE_INIT(%g2, %o0 + 0x00), NG_ret_i2_plus_g1)
269 EX_ST(STORE_INIT(%g3, %o0 + 0x08), NG_ret_i2_plus_g1_minus_8)
271 EX_LD(LOAD_TWIN(%i1 + %o5, %g2, %g3), NG_ret_i2_plus_g1_minus_16)
272 MIX_THREE_WORDS(%o2, %o3, %g2, %i5, GLOBAL_SPARE, %o1)
274 EX_ST(STORE_INIT(%o2, %o0 + 0x10), NG_ret_i2_plus_g1_minus_16)
275 EX_ST(STORE_INIT(%o3, %o0 + 0x18), NG_ret_i2_plus_g1_minus_24)
277 EX_LD(LOAD_TWIN(%i1 + %o7, %o2, %o3), NG_ret_i2_plus_g1_minus_32)
278 MIX_THREE_WORDS(%g2, %g3, %o2, %i5, GLOBAL_SPARE, %o1)
280 EX_ST(STORE_INIT(%g2, %o0 + 0x20), NG_ret_i2_plus_g1_minus_32)
281 EX_ST(STORE_INIT(%g3, %o0 + 0x28), NG_ret_i2_plus_g1_minus_40)
283 EX_LD(LOAD_TWIN(%i1 + %i3, %g2, %g3), NG_ret_i2_plus_g1_minus_48)
285 MIX_THREE_WORDS(%o2, %o3, %g2, %i5, GLOBAL_SPARE, %o1)
287 EX_ST(STORE_INIT(%o2, %o0 + 0x30), NG_ret_i2_plus_g1_minus_48)
288 EX_ST(STORE_INIT(%o3, %o0 + 0x38), NG_ret_i2_plus_g1_minus_56)
297 9: EX_LD(LOAD_TWIN(%i1 + %o4, %o2, %o3), NG_ret_i2_plus_g1)
298 MIX_THREE_WORDS(%g3, %o2, %o3, %i5, GLOBAL_SPARE, %o1)
299 LOAD(prefetch, %i1 + %i3, #one_read)
301 EX_ST(STORE_INIT(%g3, %o0 + 0x00), NG_ret_i2_plus_g1)
302 EX_ST(STORE_INIT(%o2, %o0 + 0x08), NG_ret_i2_plus_g1_minus_8)
304 EX_LD(LOAD_TWIN(%i1 + %o5, %g2, %g3), NG_ret_i2_plus_g1_minus_16)
305 MIX_THREE_WORDS(%o3, %g2, %g3, %i5, GLOBAL_SPARE, %o1)
307 EX_ST(STORE_INIT(%o3, %o0 + 0x10), NG_ret_i2_plus_g1_minus_16)
308 EX_ST(STORE_INIT(%g2, %o0 + 0x18), NG_ret_i2_plus_g1_minus_24)
310 EX_LD(LOAD_TWIN(%i1 + %o7, %o2, %o3), NG_ret_i2_plus_g1_minus_32)
311 MIX_THREE_WORDS(%g3, %o2, %o3, %i5, GLOBAL_SPARE, %o1)
313 EX_ST(STORE_INIT(%g3, %o0 + 0x20), NG_ret_i2_plus_g1_minus_32)
314 EX_ST(STORE_INIT(%o2, %o0 + 0x28), NG_ret_i2_plus_g1_minus_40)
316 EX_LD(LOAD_TWIN(%i1 + %i3, %g2, %g3), NG_ret_i2_plus_g1_minus_48)
318 MIX_THREE_WORDS(%o3, %g2, %g3, %i5, GLOBAL_SPARE, %o1)
320 EX_ST(STORE_INIT(%o3, %o0 + 0x30), NG_ret_i2_plus_g1_minus_48)
321 EX_ST(STORE_INIT(%g2, %o0 + 0x38), NG_ret_i2_plus_g1_minus_56)
330 10: /* Destination is 64-byte aligned, source was only 8-byte
331 * aligned but it has been subtracted by 8 and we perform
332 * one twin load ahead, then add 8 back into source when
333 * we finish the loop.
335 EX_LD(LOAD_TWIN(%i1, %o4, %o5), NG_ret_i2_plus_g1)
340 1: EX_LD(LOAD_TWIN(%i1 + %o7, %o2, %o3), NG_ret_i2_plus_g1)
341 LOAD(prefetch, %i1 + %o1, #one_read)
342 EX_ST(STORE_INIT(%o5, %o0 + 0x00), NG_ret_i2_plus_g1) ! initializes cache line
343 EX_ST(STORE_INIT(%o2, %o0 + 0x08), NG_ret_i2_plus_g1_minus_8)
344 EX_LD(LOAD_TWIN(%i1 + %g2, %o4, %o5), NG_ret_i2_plus_g1_minus_16)
345 EX_ST(STORE_INIT(%o3, %o0 + 0x10), NG_ret_i2_plus_g1_minus_16)
346 EX_ST(STORE_INIT(%o4, %o0 + 0x18), NG_ret_i2_plus_g1_minus_24)
347 EX_LD(LOAD_TWIN(%i1 + %g3, %o2, %o3), NG_ret_i2_plus_g1_minus_32)
348 EX_ST(STORE_INIT(%o5, %o0 + 0x20), NG_ret_i2_plus_g1_minus_32)
349 EX_ST(STORE_INIT(%o2, %o0 + 0x28), NG_ret_i2_plus_g1_minus_40)
350 EX_LD(LOAD_TWIN(%i1 + %o1, %o4, %o5), NG_ret_i2_plus_g1_minus_48)
352 EX_ST(STORE_INIT(%o3, %o0 + 0x30), NG_ret_i2_plus_g1_minus_48)
353 EX_ST(STORE_INIT(%o4, %o0 + 0x38), NG_ret_i2_plus_g1_minus_56)
361 50: /* Destination is 64-byte aligned, and source is 16-byte
368 1: EX_LD(LOAD_TWIN(%i1 + %g0, %o4, %o5), NG_ret_i2_plus_g1)
369 EX_LD(LOAD_TWIN(%i1 + %o7, %o2, %o3), NG_ret_i2_plus_g1)
370 LOAD(prefetch, %i1 + %o1, #one_read)
371 EX_ST(STORE_INIT(%o4, %o0 + 0x00), NG_ret_i2_plus_g1) ! initializes cache line
372 EX_ST(STORE_INIT(%o5, %o0 + 0x08), NG_ret_i2_plus_g1_minus_8)
373 EX_LD(LOAD_TWIN(%i1 + %g2, %o4, %o5), NG_ret_i2_plus_g1_minus_16)
374 EX_ST(STORE_INIT(%o2, %o0 + 0x10), NG_ret_i2_plus_g1_minus_16)
375 EX_ST(STORE_INIT(%o3, %o0 + 0x18), NG_ret_i2_plus_g1_minus_24)
376 EX_LD(LOAD_TWIN(%i1 + %g3, %o2, %o3), NG_ret_i2_plus_g1_minus_32)
378 EX_ST(STORE_INIT(%o4, %o0 + 0x20), NG_ret_i2_plus_g1_minus_32)
379 EX_ST(STORE_INIT(%o5, %o0 + 0x28), NG_ret_i2_plus_g1_minus_40)
380 EX_ST(STORE_INIT(%o2, %o0 + 0x30), NG_ret_i2_plus_g1_minus_48)
381 EX_ST(STORE_INIT(%o3, %o0 + 0x38), NG_ret_i2_plus_g1_minus_56)
390 /* %i2 contains any final bytes still needed to be copied
391 * over. If anything is left, we copy it one byte at a time.
400 70: /* 16 < len <= 64 */
407 1: subcc %i4, 0x10, %i4
408 EX_LD(LOAD(ldx, %i1, %o4), NG_ret_i2_plus_i4)
410 EX_LD(LOAD(ldx, %i1, %g1), NG_ret_i2_plus_i4)
412 EX_ST(STORE(stx, %o4, %i1 + %i3), NG_ret_i2_plus_i4)
414 EX_ST(STORE(stx, %g1, %i1 + %i3), NG_ret_i2_plus_i4_minus_8)
417 73: andcc %i2, 0x8, %g0
421 EX_LD(LOAD(ldx, %i1, %o4), NG_ret_i2_plus_8)
422 EX_ST(STORE(stx, %o4, %i1 + %i3), NG_ret_i2_plus_8)
424 1: andcc %i2, 0x4, %g0
428 EX_LD(LOAD(lduw, %i1, %i5), NG_ret_i2_plus_4)
429 EX_ST(STORE(stw, %i5, %i1 + %i3), NG_ret_i2_plus_4)
445 EX_LD(LOAD(ldub, %i1, %i5), NG_ret_i2_plus_g1_plus_1)
446 EX_ST(STORE(stb, %i5, %i1 + %i3), NG_ret_i2_plus_g1_plus_1)
462 EX_LD(LOAD(ldx, %i1, %g2), NG_ret_i2)
467 EX_LD(LOAD(ldx, %i1, %g3), NG_ret_i2_and_7_plus_i4)
471 EX_ST(STORE(stx, %i5, %o0), NG_ret_i2_and_7_plus_i4)
484 80: /* 0 < len <= 16 */
491 EX_LD(LOAD(lduw, %i1, %g1), NG_ret_i2_plus_4)
492 EX_ST(STORE(stw, %g1, %i1 + %i3), NG_ret_i2_plus_4)
497 restore EX_RETVAL(%i0), %g0, %o0
502 EX_LD(LOAD(ldub, %i1, %g1), NG_ret_i2_plus_1)
503 EX_ST(STORE(stb, %g1, %i1 + %i3), NG_ret_i2_plus_1)
507 restore EX_RETVAL(%i0), %g0, %o0
509 .size FUNC_NAME, .-FUNC_NAME