2 * M7memcpy: Optimized SPARC M7 memcpy
4 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
12 * Copy s2 to s1, always copy n bytes.
13 * Note: this C code does not work for overlapped copies.
15 * Fast assembler language version of the following C-program for memcpy
16 * which represents the `standard' for the C-library.
19 * memcpy(void *s, const void *s0, size_t n)
23 * const char *s2 = s0;
34 * if (count < SMALL_MAX) {
35 * if count < SHORTCOPY (SHORTCOPY=3)
36 * copy bytes; exit with dst addr
37 * if src & dst aligned on word boundary but not long word boundary,
38 * copy with ldw/stw; branch to finish_up
39 * if src & dst aligned on long word boundary
40 * copy with ldx/stx; branch to finish_up
41 * if src & dst not aligned and length <= SHORTCHECK (SHORTCHECK=14)
42 * copy bytes; exit with dst addr
43 * move enough bytes to get src to word boundary
44 * if dst now on word boundary
46 * copy words; branch to finish_up
47 * if dst now on half word boundary
48 * load words, shift half words, store words; branch to finish_up
50 * load words, shift 3 bytes, store words; branch to finish_up
52 * load words, shift 1 byte, store words; branch to finish_up
54 * copy bytes; exit with dst addr
55 * } else { More than SMALL_MAX bytes
56 * move bytes until dst is on long word boundary
57 * if( src is on long word boundary ) {
58 * if (count < MED_MAX) {
59 * finish_long: src/dst aligned on 8 bytes
60 * copy with ldx/stx in 8-way unrolled loop;
61 * copy final 0-63 bytes; exit with dst addr
62 * } else { src/dst aligned; count > MED_MAX
63 * align dst on 64 byte boundary; for main data movement:
64 * prefetch src data to L2 cache; let HW prefetch move data to L1 cache
65 * Use BIS (block initializing store) to avoid copying store cache
66 * lines from memory. But pre-store first element of each cache line
67 * ST_CHUNK lines in advance of the rest of that cache line. That
68 * gives time for replacement cache lines to be written back without
69 * excess STQ and Miss Buffer filling. Repeat until near the end,
70 * then finish up storing before going to finish_long.
72 * } else { src/dst not aligned on 8 bytes
73 * if src is word aligned and count < MED_WMAX
74 * move words in 8-way unrolled loop
75 * move final 0-31 bytes; exit with dst addr
77 * use alignaddr/faligndata combined with ldd/std in 8-way
78 * unrolled loop to move data.
81 * setup alignaddr for faligndata instructions
82 * align dst on 64 byte boundary; prefetch src data to L1 cache
83 * loadx8, falign, block-store, prefetch loop
84 * (only use block-init-store when src/dst on 8 byte boundaries.)
86 * move remaining bytes for unaligned cases. exit with dst addr.
91 #include <asm/visasm.h>
94 #if !defined(EX_LD) && !defined(EX_ST)
102 #define EX_LD_FP(x,y) x
109 #define EX_ST_FP(x,y) x
113 #define EX_RETVAL(x) x
117 #define LOAD(type,addr,dest) type [addr], dest
121 #define STORE(type,src,addr) type src, [addr]
125 * ASI_BLK_INIT_QUAD_LDD_P/ASI_BLK_INIT_QUAD_LDD_S marks the cache
126 * line as "least recently used" which means if many threads are
127 * active, it has a high probability of being pushed out of the cache
128 * between the first initializing store and the final stores.
129 * Thus, we use ASI_ST_BLKINIT_MRU_P/ASI_ST_BLKINIT_MRU_S which
130 * marks the cache line as "most recently used" for all
131 * but the last cache line
134 #ifndef SIMULATE_NIAGARA_ON_NON_NIAGARA
135 #define STORE_ASI ASI_BLK_INIT_QUAD_LDD_P
137 #define STORE_ASI 0x80 /* ASI_P */
141 #ifndef STORE_MRU_ASI
142 #ifndef SIMULATE_NIAGARA_ON_NON_NIAGARA
143 #define STORE_MRU_ASI ASI_ST_BLKINIT_MRU_P
145 #define STORE_MRU_ASI 0x80 /* ASI_P */
150 #define STORE_INIT(src,addr) stxa src, [addr] STORE_ASI
153 #ifndef STORE_INIT_MRU
154 #define STORE_INIT_MRU(src,addr) stxa src, [addr] STORE_MRU_ASI
158 #define FUNC_NAME M7memcpy
165 #define BLOCK_SIZE 64
167 #define SHORTCHECK 14
168 #define SHORT_LONG 64 /* max copy for short longword-aligned case */
169 /* must be at least 64 */
170 #define SMALL_MAX 128
171 #define MED_UMAX 1024 /* max copy for medium un-aligned case */
172 #define MED_WMAX 1024 /* max copy for medium word-aligned case */
173 #define MED_MAX 1024 /* max copy for medium longword-aligned case */
174 #define ST_CHUNK 24 /* ST_CHUNK - block of values for BIS Store */
175 #define ALIGN_PRE 24 /* distance for aligned prefetch loop */
177 .register %g2,#scratch
181 .type FUNC_NAME, #function
188 mov %o0, %g1 ! save %o0
191 ble,pn %icc, .Ltiny_cp
193 ble,pn %icc, .Lsmall_cp
196 bl,pn %icc, .Lmedium_cp
201 andcc %o5, 7, %o5 ! bytes till DST 8 byte aligned
202 brz,pt %o5, .Ldst_aligned_on_8
204 ! %o5 has the bytes to be written in partial store.
206 sub %o1, %o0, %o1 ! %o1 gets the difference
207 7: ! dst aligning loop
209 EX_LD(LOAD(ldub, %o4, %o4), memcpy_retl_o2_plus_o5) ! load one byte
211 EX_ST(STORE(stb, %o4, %o0), memcpy_retl_o2_plus_o5_plus_1)
213 add %o0, 1, %o0 ! advance dst
214 add %o1, %o0, %o1 ! restore %o1
217 brnz,pt %o5, .Lsrc_dst_unaligned_on_8
220 .Lsrc_dst_aligned_on_8:
221 ! check if we are copying MED_MAX or more bytes
223 cmp %o2, %o3 ! limit to store buffer size
224 bgu,pn %xcc, .Llarge_align8_copy
228 * Special case for handling when src and dest are both long word aligned
229 * and total data to move is less than MED_MAX bytes
232 subcc %o2, 63, %o2 ! adjust length to allow cc test
233 ble,pn %xcc, .Lmedl63 ! skip big loop if less than 64 bytes
236 EX_LD(LOAD(ldx, %o1, %o4), memcpy_retl_o2_plus_63) ! load
237 subcc %o2, 64, %o2 ! decrement length count
238 EX_ST(STORE(stx, %o4, %o0), memcpy_retl_o2_plus_63_64) ! and store
239 EX_LD(LOAD(ldx, %o1+8, %o3), memcpy_retl_o2_plus_63_56) ! a block of 64
240 EX_ST(STORE(stx, %o3, %o0+8), memcpy_retl_o2_plus_63_56)
241 EX_LD(LOAD(ldx, %o1+16, %o4), memcpy_retl_o2_plus_63_48)
242 EX_ST(STORE(stx, %o4, %o0+16), memcpy_retl_o2_plus_63_48)
243 EX_LD(LOAD(ldx, %o1+24, %o3), memcpy_retl_o2_plus_63_40)
244 EX_ST(STORE(stx, %o3, %o0+24), memcpy_retl_o2_plus_63_40)
245 EX_LD(LOAD(ldx, %o1+32, %o4), memcpy_retl_o2_plus_63_32)! load and store
246 EX_ST(STORE(stx, %o4, %o0+32), memcpy_retl_o2_plus_63_32)
247 EX_LD(LOAD(ldx, %o1+40, %o3), memcpy_retl_o2_plus_63_24)! a block of 64
248 add %o1, 64, %o1 ! increase src ptr by 64
249 EX_ST(STORE(stx, %o3, %o0+40), memcpy_retl_o2_plus_63_24)
250 EX_LD(LOAD(ldx, %o1-16, %o4), memcpy_retl_o2_plus_63_16)
251 add %o0, 64, %o0 ! increase dst ptr by 64
252 EX_ST(STORE(stx, %o4, %o0-16), memcpy_retl_o2_plus_63_16)
253 EX_LD(LOAD(ldx, %o1-8, %o3), memcpy_retl_o2_plus_63_8)
254 bgu,pt %xcc, .Lmedl64 ! repeat if at least 64 bytes left
255 EX_ST(STORE(stx, %o3, %o0-8), memcpy_retl_o2_plus_63_8)
257 addcc %o2, 32, %o2 ! adjust remaining count
258 ble,pt %xcc, .Lmedl31 ! to skip if 31 or fewer bytes left
260 EX_LD(LOAD(ldx, %o1, %o4), memcpy_retl_o2_plus_31) ! load
261 sub %o2, 32, %o2 ! decrement length count
262 EX_ST(STORE(stx, %o4, %o0), memcpy_retl_o2_plus_31_32) ! and store
263 EX_LD(LOAD(ldx, %o1+8, %o3), memcpy_retl_o2_plus_31_24) ! a block of 32
264 add %o1, 32, %o1 ! increase src ptr by 32
265 EX_ST(STORE(stx, %o3, %o0+8), memcpy_retl_o2_plus_31_24)
266 EX_LD(LOAD(ldx, %o1-16, %o4), memcpy_retl_o2_plus_31_16)
267 add %o0, 32, %o0 ! increase dst ptr by 32
268 EX_ST(STORE(stx, %o4, %o0-16), memcpy_retl_o2_plus_31_16)
269 EX_LD(LOAD(ldx, %o1-8, %o3), memcpy_retl_o2_plus_31_8)
270 EX_ST(STORE(stx, %o3, %o0-8), memcpy_retl_o2_plus_31_8)
272 addcc %o2, 16, %o2 ! adjust remaining count
273 ble,pt %xcc, .Lmedl15 ! skip if 15 or fewer bytes left
275 EX_LD(LOAD(ldx, %o1, %o4), memcpy_retl_o2_plus_15)
276 add %o1, 16, %o1 ! increase src ptr by 16
277 EX_ST(STORE(stx, %o4, %o0), memcpy_retl_o2_plus_15)
278 sub %o2, 16, %o2 ! decrease count by 16
279 EX_LD(LOAD(ldx, %o1-8, %o3), memcpy_retl_o2_plus_15_8)
280 add %o0, 16, %o0 ! increase dst ptr by 16
281 EX_ST(STORE(stx, %o3, %o0-8), memcpy_retl_o2_plus_15_8)
283 addcc %o2, 15, %o2 ! restore count
284 bz,pt %xcc, .Lsmallx ! exit if finished
286 blt,pt %xcc, .Lmedw7 ! skip if 7 or fewer bytes left
288 EX_LD(LOAD(ldx, %o1, %o4), memcpy_retl_o2) ! load 8 bytes
289 add %o1, 8, %o1 ! increase src ptr by 8
290 add %o0, 8, %o0 ! increase dst ptr by 8
291 subcc %o2, 8, %o2 ! decrease count by 8
293 EX_ST(STORE(stx, %o4, %o0-8), memcpy_retl_o2_plus_8) ! and store 8
295 mov EX_RETVAL(%g1), %o0 ! restore %o0
298 .Lsrc_dst_unaligned_on_8:
299 ! DST is 8-byte aligned, src is not
301 andcc %o1, 0x3, %o5 ! test word alignment
302 bnz,pt %xcc, .Lunalignsetup ! branch to skip if not word aligned
306 * Handle all cases where src and dest are aligned on word
307 * boundaries. Use unrolled loops for better performance.
308 * This option wins over standard large data move when
309 * source and destination is in cache for.Lmedium
310 * to short data moves.
313 cmp %o2, %o3 ! limit to store buffer size
314 bge,pt %xcc, .Lunalignrejoin ! otherwise rejoin main loop
317 subcc %o2, 31, %o2 ! adjust length to allow cc test
319 ble,pt %xcc, .Lmedw31 ! skip big loop if less than 16
321 EX_LD(LOAD(ld, %o1, %o4), memcpy_retl_o2_plus_31)! move a block of 32
323 EX_LD(LOAD(ld, %o1+4, %o4), memcpy_retl_o2_plus_31)
325 EX_ST(STORE(stx, %o5, %o0), memcpy_retl_o2_plus_31)
326 subcc %o2, 32, %o2 ! decrement length count
327 EX_LD(LOAD(ld, %o1+8, %o4), memcpy_retl_o2_plus_31_24)
329 EX_LD(LOAD(ld, %o1+12, %o4), memcpy_retl_o2_plus_31_24)
331 EX_ST(STORE(stx, %o5, %o0+8), memcpy_retl_o2_plus_31_24)
332 add %o1, 32, %o1 ! increase src ptr by 32
333 EX_LD(LOAD(ld, %o1-16, %o4), memcpy_retl_o2_plus_31_16)
335 EX_LD(LOAD(ld, %o1-12, %o4), memcpy_retl_o2_plus_31_16)
337 EX_ST(STORE(stx, %o5, %o0+16), memcpy_retl_o2_plus_31_16)
338 add %o0, 32, %o0 ! increase dst ptr by 32
339 EX_LD(LOAD(ld, %o1-8, %o4), memcpy_retl_o2_plus_31_8)
341 EX_LD(LOAD(ld, %o1-4, %o4), memcpy_retl_o2_plus_31_8)
343 bgu,pt %xcc, .Lmedw32 ! repeat if at least 32 bytes left
344 EX_ST(STORE(stx, %o5, %o0-8), memcpy_retl_o2_plus_31_8)
346 addcc %o2, 31, %o2 ! restore count
348 bz,pt %xcc, .Lsmallx ! exit if finished
351 blt,pt %xcc, .Lmedw15
353 EX_LD(LOAD(ld, %o1, %o4), memcpy_retl_o2)! move a block of 16 bytes
355 subcc %o2, 16, %o2 ! decrement length count
356 EX_LD(LOAD(ld, %o1+4, %o4), memcpy_retl_o2_plus_16)
358 EX_ST(STORE(stx, %o5, %o0), memcpy_retl_o2_plus_16)
359 add %o1, 16, %o1 ! increase src ptr by 16
360 EX_LD(LOAD(ld, %o1-8, %o4), memcpy_retl_o2_plus_8)
361 add %o0, 16, %o0 ! increase dst ptr by 16
363 EX_LD(LOAD(ld, %o1-4, %o4), memcpy_retl_o2_plus_8)
365 EX_ST(STORE(stx, %o5, %o0-8), memcpy_retl_o2_plus_8)
367 bz,pt %xcc, .Lsmallx ! exit if finished
369 blt,pn %xcc, .Lmedw7 ! skip if 7 or fewer bytes left
371 EX_LD(LOAD(ld, %o1, %o4), memcpy_retl_o2) ! load 4 bytes
372 subcc %o2, 8, %o2 ! decrease count by 8
373 EX_ST(STORE(stw, %o4, %o0), memcpy_retl_o2_plus_8)! and store 4 bytes
374 add %o1, 8, %o1 ! increase src ptr by 8
375 EX_LD(LOAD(ld, %o1-4, %o3), memcpy_retl_o2_plus_4) ! load 4 bytes
376 add %o0, 8, %o0 ! increase dst ptr by 8
377 EX_ST(STORE(stw, %o3, %o0-4), memcpy_retl_o2_plus_4)! and store 4 bytes
378 bz,pt %xcc, .Lsmallx ! exit if finished
379 .Lmedw7: ! count is ge 1, less than 8
380 cmp %o2, 4 ! check for 4 bytes left
381 blt,pn %xcc, .Lsmallleft3 ! skip if 3 or fewer bytes left
383 EX_LD(LOAD(ld, %o1, %o4), memcpy_retl_o2) ! load 4 bytes
384 add %o1, 4, %o1 ! increase src ptr by 4
385 add %o0, 4, %o0 ! increase dst ptr by 4
386 subcc %o2, 4, %o2 ! decrease count by 4
388 EX_ST(STORE(stw, %o4, %o0-4), memcpy_retl_o2_plus_4)! and store 4 bytes
390 mov EX_RETVAL(%g1), %o0
393 .Llarge_align8_copy: ! Src and dst share 8 byte alignment
394 ! align dst to 64 byte boundary
395 andcc %o0, 0x3f, %o3 ! %o3 == 0 means dst is 64 byte aligned
396 brz,pn %o3, .Laligned_to_64
397 andcc %o0, 8, %o3 ! odd long words to move?
398 brz,pt %o3, .Laligned_to_16
400 EX_LD(LOAD(ldx, %o1, %o4), memcpy_retl_o2)
402 add %o1, 8, %o1 ! increment src ptr
403 add %o0, 8, %o0 ! increment dst ptr
404 EX_ST(STORE(stx, %o4, %o0-8), memcpy_retl_o2_plus_8)
406 andcc %o0, 16, %o3 ! pair of long words to move?
407 brz,pt %o3, .Laligned_to_32
409 EX_LD(LOAD(ldx, %o1, %o4), memcpy_retl_o2)
411 EX_ST(STORE(stx, %o4, %o0), memcpy_retl_o2_plus_16)
412 add %o1, 16, %o1 ! increment src ptr
413 EX_LD(LOAD(ldx, %o1-8, %o4), memcpy_retl_o2_plus_8)
414 add %o0, 16, %o0 ! increment dst ptr
415 EX_ST(STORE(stx, %o4, %o0-8), memcpy_retl_o2_plus_8)
417 andcc %o0, 32, %o3 ! four long words to move?
418 brz,pt %o3, .Laligned_to_64
420 EX_LD(LOAD(ldx, %o1, %o4), memcpy_retl_o2)
422 EX_ST(STORE(stx, %o4, %o0), memcpy_retl_o2_plus_32)
423 EX_LD(LOAD(ldx, %o1+8, %o4), memcpy_retl_o2_plus_24)
424 EX_ST(STORE(stx, %o4, %o0+8), memcpy_retl_o2_plus_24)
425 EX_LD(LOAD(ldx, %o1+16, %o4), memcpy_retl_o2_plus_16)
426 EX_ST(STORE(stx, %o4, %o0+16), memcpy_retl_o2_plus_16)
427 add %o1, 32, %o1 ! increment src ptr
428 EX_LD(LOAD(ldx, %o1-8, %o4), memcpy_retl_o2_plus_8)
429 add %o0, 32, %o0 ! increment dst ptr
430 EX_ST(STORE(stx, %o4, %o0-8), memcpy_retl_o2_plus_8)
433 ! Using block init store (BIS) instructions to avoid fetching cache
434 ! lines from memory. Use ST_CHUNK stores to first element of each cache
435 ! line (similar to prefetching) to avoid overfilling STQ or miss buffers.
436 ! Gives existing cache lines time to be moved out of L1/L2/L3 cache.
437 ! Initial stores using MRU version of BIS to keep cache line in
438 ! cache until we are ready to store final element of cache line.
439 ! Then store last element using the LRU version of BIS.
441 andn %o2, 0x3f, %o5 ! %o5 is multiple of block size
442 and %o2, 0x3f, %o2 ! residue bytes in %o2
444 ! We use STORE_MRU_ASI for the first seven stores to each cache line
445 ! followed by STORE_ASI (mark as LRU) for the last store. That
446 ! mixed approach reduces the probability that the cache line is removed
447 ! before we finish setting it, while minimizing the effects on
448 ! other cached values during a large memcpy
450 ! ST_CHUNK batches up initial BIS operations for several cache lines
451 ! to allow multiple requests to not be blocked by overflowing the
452 ! the store miss buffer. Then the matching stores for all those
453 ! BIS operations are executed.
456 sub %o0, 8, %o0 ! adjust %o0 for ASI alignment
459 blu,pt %xcc, .Lalign_loop_fin
462 prefetch [%o1 + (ALIGN_PRE * BLOCK_SIZE)], 21
464 EX_LD(LOAD(ldx, %o1, %o4), memcpy_retl_o2_plus_o5)
467 EX_ST(STORE_INIT_MRU(%o4, %o0), memcpy_retl_o2_plus_o5)
468 bgu %xcc,.Lalign_loop_start
472 sllx %o3, 6, %o4 ! ST_CHUNK*64
473 sub %o1, %o4, %o1 ! reset %o1
474 sub %o0, %o4, %o0 ! reset %o0
477 EX_LD(LOAD(ldx, %o1+8, %o4), memcpy_retl_o2_plus_o5)
479 EX_ST(STORE_INIT_MRU(%o4, %o0), memcpy_retl_o2_plus_o5)
480 EX_LD(LOAD(ldx, %o1+16, %o4), memcpy_retl_o2_plus_o5)
482 EX_ST(STORE_INIT_MRU(%o4, %o0), memcpy_retl_o2_plus_o5)
484 EX_LD(LOAD(ldx, %o1+24, %o4), memcpy_retl_o2_plus_o5)
486 EX_ST(STORE_INIT_MRU(%o4, %o0), memcpy_retl_o2_plus_o5)
487 EX_LD(LOAD(ldx, %o1+32, %o4), memcpy_retl_o2_plus_o5)
489 EX_ST(STORE_INIT_MRU(%o4, %o0), memcpy_retl_o2_plus_o5)
490 EX_LD(LOAD(ldx, %o1+40, %o4), memcpy_retl_o2_plus_o5)
492 EX_ST(STORE_INIT_MRU(%o4, %o0), memcpy_retl_o2_plus_o5)
493 EX_LD(LOAD(ldx, %o1+48, %o4), memcpy_retl_o2_plus_o5)
496 EX_ST(STORE_INIT_MRU(%o4, %o0), memcpy_retl_o2_plus_o5)
498 EX_LD(LOAD(ldx, %o1-8, %o4), memcpy_retl_o2_plus_o5)
500 bgu %xcc,.Lalign_loop_rest
501 ! mark cache line as LRU
502 EX_ST(STORE_INIT(%o4, %o0), memcpy_retl_o2_plus_o5_plus_64)
505 bgu,pt %xcc, .Lalign_loop_start
512 EX_LD(LOAD(ldx, %o1, %o4), memcpy_retl_o2_plus_o5)
513 EX_ST(STORE(stx, %o4, %o0+8), memcpy_retl_o2_plus_o5)
514 EX_LD(LOAD(ldx, %o1+8, %o4), memcpy_retl_o2_plus_o5)
515 EX_ST(STORE(stx, %o4, %o0+8+8), memcpy_retl_o2_plus_o5)
516 EX_LD(LOAD(ldx, %o1+16, %o4), memcpy_retl_o2_plus_o5)
517 EX_ST(STORE(stx, %o4, %o0+8+16), memcpy_retl_o2_plus_o5)
519 EX_LD(LOAD(ldx, %o1+24, %o4), memcpy_retl_o2_plus_o5_64)
520 EX_ST(STORE(stx, %o4, %o0+8+24), memcpy_retl_o2_plus_o5_64)
521 EX_LD(LOAD(ldx, %o1+32, %o4), memcpy_retl_o2_plus_o5_64)
522 EX_ST(STORE(stx, %o4, %o0+8+32), memcpy_retl_o2_plus_o5_64)
523 EX_LD(LOAD(ldx, %o1+40, %o4), memcpy_retl_o2_plus_o5_64)
524 EX_ST(STORE(stx, %o4, %o0+8+40), memcpy_retl_o2_plus_o5_64)
525 EX_LD(LOAD(ldx, %o1+48, %o4), memcpy_retl_o2_plus_o5_64)
527 EX_ST(STORE(stx, %o4, %o0+8+48), memcpy_retl_o2_plus_o5_64)
529 EX_LD(LOAD(ldx, %o1-8, %o4), memcpy_retl_o2_plus_o5_64)
530 bgu %xcc,.Lalign_loop_fin
531 EX_ST(STORE(stx, %o4, %o0), memcpy_retl_o2_plus_o5_64)
534 add %o0, 8, %o0 ! restore %o0 from ASI alignment
536 sub %o2, 63, %o2 ! adjust length to allow cc test
537 ba .Lmedl63 ! in .Lmedl63
541 ! Dst is on 8 byte boundary; src is not; remaining count > SMALL_MAX
544 mov %g1, %o3 ! save %g1 as VISEntryHalf clobbers it
546 VISEntryHalfFast(.Lmedium_vis_entry_fail_cp)
550 mov %o3, %g1 ! restore %g1
553 cmp %o2, %o3 ! check for.Lmedium unaligned limit
554 bge,pt %xcc,.Lunalign_large
555 prefetch [%o1 + (4 * BLOCK_SIZE)], 20
556 andn %o2, 0x3f, %o5 ! %o5 is multiple of block size
557 and %o2, 0x3f, %o2 ! residue bytes in %o2
558 cmp %o2, 8 ! Insure we do not load beyond
559 bgt .Lunalign_adjust ! end of source buffer
560 andn %o1, 0x7, %o4 ! %o4 has long word aligned src address
561 add %o2, 64, %o2 ! adjust to leave loop
562 sub %o5, 64, %o5 ! early if necessary
564 alignaddr %o1, %g0, %g0 ! generate %gsr
565 add %o1, %o5, %o1 ! advance %o1 to after blocks
566 EX_LD_FP(LOAD(ldd, %o4, %f0), memcpy_retl_o2_plus_o5)
568 EX_LD_FP(LOAD(ldd, %o4+8, %f2), memcpy_retl_o2_plus_o5)
569 faligndata %f0, %f2, %f16
570 EX_LD_FP(LOAD(ldd, %o4+16, %f4), memcpy_retl_o2_plus_o5)
571 subcc %o5, BLOCK_SIZE, %o5
572 EX_ST_FP(STORE(std, %f16, %o0), memcpy_retl_o2_plus_o5_plus_64)
573 faligndata %f2, %f4, %f18
574 EX_LD_FP(LOAD(ldd, %o4+24, %f6), memcpy_retl_o2_plus_o5_plus_56)
575 EX_ST_FP(STORE(std, %f18, %o0+8), memcpy_retl_o2_plus_o5_plus_56)
576 faligndata %f4, %f6, %f20
577 EX_LD_FP(LOAD(ldd, %o4+32, %f8), memcpy_retl_o2_plus_o5_plus_48)
578 EX_ST_FP(STORE(std, %f20, %o0+16), memcpy_retl_o2_plus_o5_plus_48)
579 faligndata %f6, %f8, %f22
580 EX_LD_FP(LOAD(ldd, %o4+40, %f10), memcpy_retl_o2_plus_o5_plus_40)
581 EX_ST_FP(STORE(std, %f22, %o0+24), memcpy_retl_o2_plus_o5_plus_40)
582 faligndata %f8, %f10, %f24
583 EX_LD_FP(LOAD(ldd, %o4+48, %f12), memcpy_retl_o2_plus_o5_plus_32)
584 EX_ST_FP(STORE(std, %f24, %o0+32), memcpy_retl_o2_plus_o5_plus_32)
585 faligndata %f10, %f12, %f26
586 EX_LD_FP(LOAD(ldd, %o4+56, %f14), memcpy_retl_o2_plus_o5_plus_24)
587 add %o4, BLOCK_SIZE, %o4
588 EX_ST_FP(STORE(std, %f26, %o0+40), memcpy_retl_o2_plus_o5_plus_24)
589 faligndata %f12, %f14, %f28
590 EX_LD_FP(LOAD(ldd, %o4, %f0), memcpy_retl_o2_plus_o5_plus_16)
591 EX_ST_FP(STORE(std, %f28, %o0+48), memcpy_retl_o2_plus_o5_plus_16)
592 faligndata %f14, %f0, %f30
593 EX_ST_FP(STORE(std, %f30, %o0+56), memcpy_retl_o2_plus_o5_plus_8)
594 add %o0, BLOCK_SIZE, %o0
595 bgu,pt %xcc, .Lunalign_loop
596 prefetch [%o4 + (5 * BLOCK_SIZE)], 20
601 andcc %o0, 0x3f, %o3 ! is dst 64-byte block aligned?
602 bz %xcc, .Lunalignsrc
603 sub %o3, 64, %o3 ! %o3 will be multiple of 8
604 neg %o3 ! bytes until dest is 64 byte aligned
605 sub %o2, %o3, %o2 ! update cnt with bytes to be moved
606 ! Move bytes according to source alignment
608 bnz %xcc, .Lunalignbyte ! check for byte alignment
610 andcc %o1, 2, %o5 ! check for half word alignment
611 bnz %xcc, .Lunalignhalf
613 ! Src is word aligned
615 EX_LD_FP(LOAD(ld, %o1, %o4), memcpy_retl_o2_plus_o3) ! load 4 bytes
616 add %o1, 8, %o1 ! increase src ptr by 8
617 EX_ST_FP(STORE(stw, %o4, %o0), memcpy_retl_o2_plus_o3) ! and store 4
618 subcc %o3, 8, %o3 ! decrease count by 8
619 EX_LD_FP(LOAD(ld, %o1-4, %o4), memcpy_retl_o2_plus_o3_plus_4)! load 4
620 add %o0, 8, %o0 ! increase dst ptr by 8
621 bnz %xcc, .Lunalignword
622 EX_ST_FP(STORE(stw, %o4, %o0-4), memcpy_retl_o2_plus_o3_plus_4)
626 ! Src is half-word aligned
628 EX_LD_FP(LOAD(lduh, %o1, %o4), memcpy_retl_o2_plus_o3) ! load 2 bytes
629 sllx %o4, 32, %o5 ! shift left
630 EX_LD_FP(LOAD(lduw, %o1+2, %o4), memcpy_retl_o2_plus_o3)
633 EX_LD_FP(LOAD(lduh, %o1+6, %o4), memcpy_retl_o2_plus_o3)
635 EX_ST_FP(STORE(stx, %o5, %o0), memcpy_retl_o2_plus_o3)
638 bnz %xcc, .Lunalignhalf
643 ! Src is Byte aligned
645 sub %o0, %o1, %o0 ! share pointer advance
647 EX_LD_FP(LOAD(ldub, %o1, %o4), memcpy_retl_o2_plus_o3)
649 EX_LD_FP(LOAD(lduh, %o1+1, %o4), memcpy_retl_o2_plus_o3)
652 EX_LD_FP(LOAD(lduh, %o1+3, %o4), memcpy_retl_o2_plus_o3)
655 EX_LD_FP(LOAD(lduh, %o1+5, %o4), memcpy_retl_o2_plus_o3)
658 EX_LD_FP(LOAD(ldub, %o1+7, %o4), memcpy_retl_o2_plus_o3)
661 EX_ST_FP(STORE(stx, %o5, %o0), memcpy_retl_o2_plus_o3)
664 bnz %xcc, .Lunalignbyte_loop
666 add %o0,%o1, %o0 ! restore pointer
668 ! Destination is now block (64 byte aligned)
670 andn %o2, 0x3f, %o5 ! %o5 is multiple of block size
671 and %o2, 0x3f, %o2 ! residue bytes in %o2
672 add %o2, 64, %o2 ! Insure we do not load beyond
673 sub %o5, 64, %o5 ! end of source buffer
675 andn %o1, 0x7, %o4 ! %o4 has long word aligned src address
676 alignaddr %o1, %g0, %g0 ! generate %gsr
677 add %o1, %o5, %o1 ! advance %o1 to after blocks
679 EX_LD_FP(LOAD(ldd, %o4, %f14), memcpy_retl_o2_plus_o5)
682 EX_LD_FP(LOAD(ldd, %o4, %f16), memcpy_retl_o2_plus_o5)
683 faligndata %f14, %f16, %f0
684 EX_LD_FP(LOAD(ldd, %o4+8, %f18), memcpy_retl_o2_plus_o5)
685 faligndata %f16, %f18, %f2
686 EX_LD_FP(LOAD(ldd, %o4+16, %f20), memcpy_retl_o2_plus_o5)
687 faligndata %f18, %f20, %f4
688 EX_ST_FP(STORE(std, %f0, %o0), memcpy_retl_o2_plus_o5)
690 EX_LD_FP(LOAD(ldd, %o4+24, %f22), memcpy_retl_o2_plus_o5_plus_56)
691 faligndata %f20, %f22, %f6
692 EX_ST_FP(STORE(std, %f2, %o0+8), memcpy_retl_o2_plus_o5_plus_56)
693 EX_LD_FP(LOAD(ldd, %o4+32, %f24), memcpy_retl_o2_plus_o5_plus_48)
694 faligndata %f22, %f24, %f8
695 EX_ST_FP(STORE(std, %f4, %o0+16), memcpy_retl_o2_plus_o5_plus_48)
696 EX_LD_FP(LOAD(ldd, %o4+40, %f26), memcpy_retl_o2_plus_o5_plus_40)
697 faligndata %f24, %f26, %f10
698 EX_ST_FP(STORE(std, %f6, %o0+24), memcpy_retl_o2_plus_o5_plus_40)
699 EX_LD_FP(LOAD(ldd, %o4+48, %f28), memcpy_retl_o2_plus_o5_plus_40)
700 faligndata %f26, %f28, %f12
701 EX_ST_FP(STORE(std, %f8, %o0+32), memcpy_retl_o2_plus_o5_plus_40)
703 EX_LD_FP(LOAD(ldd, %o4-8, %f30), memcpy_retl_o2_plus_o5_plus_40)
704 faligndata %f28, %f30, %f14
705 EX_ST_FP(STORE(std, %f10, %o0+40), memcpy_retl_o2_plus_o5_plus_40)
706 EX_ST_FP(STORE(std, %f12, %o0+48), memcpy_retl_o2_plus_o5_plus_40)
708 EX_ST_FP(STORE(std, %f14, %o0-8), memcpy_retl_o2_plus_o5_plus_40)
710 bgu,pt %xcc, .Lunalign_sloop
711 prefetch [%o4 + (8 * BLOCK_SIZE)], 20
714 ! Handle trailing bytes, 64 to 127
715 ! Dest long word aligned, Src not long word aligned
717 bleu %xcc, .Lunalign_short
719 andn %o2, 0x7, %o5 ! %o5 is multiple of 8
720 and %o2, 0x7, %o2 ! residue bytes in %o2
722 sub %o5, 8, %o5 ! insure we do not load past end of src
723 andn %o1, 0x7, %o4 ! %o4 has long word aligned src address
724 add %o1, %o5, %o1 ! advance %o1 to after multiple of 8
725 EX_LD_FP(LOAD(ldd, %o4, %f0), memcpy_retl_o2_plus_o5)! fetch partialword
727 EX_LD_FP(LOAD(ldd, %o4+8, %f2), memcpy_retl_o2_plus_o5)
729 faligndata %f0, %f2, %f16
731 EX_ST_FP(STORE(std, %f16, %o0), memcpy_retl_o2_plus_o5)
733 bgu,pt %xcc, .Lunalign_by8
746 * This is a special case of nested memcpy. This can happen when kernel
747 * calls unaligned memcpy back to back without saving FP registers. We need
748 * traps(context switch) to save/restore FP registers. If the kernel calls
749 * memcpy without this trap sequence we will hit FP corruption. Let's use
750 * the normal integer load/store method in this case.
754 .Lmedium_vis_entry_fail_cp:
758 LOAD(prefetch, %o1 + 0x40, #n_reads_strong)
760 bne,pn %xcc, .Lmedium_unaligned_cp
763 .Lmedium_noprefetch_cp:
764 andncc %o2, 0x20 - 1, %o5
767 1: EX_LD(LOAD(ldx, %o1 + 0x00, %o3), memcpy_retl_o2_plus_o5)
768 EX_LD(LOAD(ldx, %o1 + 0x08, %g2), memcpy_retl_o2_plus_o5)
769 EX_LD(LOAD(ldx, %o1 + 0x10, %g7), memcpy_retl_o2_plus_o5)
770 EX_LD(LOAD(ldx, %o1 + 0x18, %o4), memcpy_retl_o2_plus_o5)
773 EX_ST(STORE(stx, %o3, %o0 + 0x00), memcpy_retl_o2_plus_o5_plus_32)
774 EX_ST(STORE(stx, %g2, %o0 + 0x08), memcpy_retl_o2_plus_o5_plus_24)
775 EX_ST(STORE(stx, %g7, %o0 + 0x10), memcpy_retl_o2_plus_o5_plus_24)
776 EX_ST(STORE(stx, %o4, %o0 + 0x18), memcpy_retl_o2_plus_o5_plus_8)
779 2: andcc %o2, 0x18, %o5
782 1: EX_LD(LOAD(ldx, %o1 + 0x00, %o3), memcpy_retl_o2_plus_o5)
787 EX_ST(STORE(stx, %o3, %o0 - 0x08), memcpy_retl_o2_plus_o5_plus_8)
788 3: brz,pt %o2, .Lexit_cp
790 bl,pn %xcc, .Ltiny_cp
792 EX_LD(LOAD(lduw, %o1 + 0x00, %o3), memcpy_retl_o2)
796 bne,pn %xcc, .Ltiny_cp
797 EX_ST(STORE(stw, %o3, %o0 - 0x04), memcpy_retl_o2_plus_4)
798 ba,a,pt %xcc, .Lexit_cp
800 .Lmedium_unaligned_cp:
801 /* First get dest 8 byte aligned. */
807 1: EX_LD(LOAD(ldub, %o1 + 0x00, %g2), memcpy_retl_o2_plus_g1)
812 EX_ST(STORE(stb, %g2, %o0 - 0x01), memcpy_retl_o2_plus_g1_plus_1)
815 brz,pn %o3, .Lmedium_noprefetch_cp
820 EX_LD(LOAD(ldx, %o1 + 0x00, %o4), memcpy_retl_o2)
822 andn %o2, 0x08 - 1, %o5
825 1: EX_LD(LOAD(ldx, %o1 + 0x08, %g3), memcpy_retl_o2_plus_o5)
830 EX_ST(STORE(stx, %g7, %o0 + 0x00), memcpy_retl_o2_plus_o5_plus_8)
836 brz,pn %o2, .Lexit_cp
838 ba,pt %xcc, .Lsmall_unaligned_cp
841 EX_LD(LOAD(ldub, %o1 + 0x00, %o3), memcpy_retl_o2)
843 be,pn %xcc, .Lexit_cp
844 EX_ST(STORE(stb, %o3, %o0 + 0x00), memcpy_retl_o2_plus_1)
845 EX_LD(LOAD(ldub, %o1 + 0x01, %o3), memcpy_retl_o2)
847 be,pn %xcc, .Lexit_cp
848 EX_ST(STORE(stb, %o3, %o0 + 0x01), memcpy_retl_o2_plus_1)
849 EX_LD(LOAD(ldub, %o1 + 0x02, %o3), memcpy_retl_o2)
850 ba,pt %xcc, .Lexit_cp
851 EX_ST(STORE(stb, %o3, %o0 + 0x02), memcpy_retl_o2)
855 bne,pn %xcc, .Lsmall_unaligned_cp
856 andn %o2, 0x4 - 1, %o5
859 EX_LD(LOAD(lduw, %o1 + 0x00, %o3), memcpy_retl_o2_plus_o5)
864 EX_ST(STORE(stw, %o3, %o0 - 0x04), memcpy_retl_o2_plus_o5_plus_4)
865 brz,pt %o2, .Lexit_cp
867 ba,a,pt %xcc, .Ltiny_cp
869 .Lsmall_unaligned_cp:
870 1: EX_LD(LOAD(ldub, %o1 + 0x00, %o3), memcpy_retl_o2)
875 EX_ST(STORE(stb, %o3, %o0 - 0x01), memcpy_retl_o2_plus_1)
876 ba,a,pt %xcc, .Lexit_cp
882 blt,pn %xcc, .Lsmallleft3
886 EX_LD(LOAD(ldub, %o1, %o3), memcpy_retl_o2_plus_3)! read byte
887 subcc %o2, 4, %o2 ! reduce count by 4
888 EX_ST(STORE(stb, %o3, %o0), memcpy_retl_o2_plus_7)! write byte & repeat
889 EX_LD(LOAD(ldub, %o1+1, %o3), memcpy_retl_o2_plus_6)! for total of 4
890 add %o1, 4, %o1 ! advance SRC by 4
891 EX_ST(STORE(stb, %o3, %o0+1), memcpy_retl_o2_plus_6)
892 EX_LD(LOAD(ldub, %o1-2, %o3), memcpy_retl_o2_plus_5)
893 add %o0, 4, %o0 ! advance DST by 4
894 EX_ST(STORE(stb, %o3, %o0-2), memcpy_retl_o2_plus_5)
895 EX_LD(LOAD(ldub, %o1-1, %o3), memcpy_retl_o2_plus_4)
896 bgu,pt %xcc, .Lsmallnotalign4 ! loop til 3 or fewer bytes remain
897 EX_ST(STORE(stb, %o3, %o0-1), memcpy_retl_o2_plus_4)
898 addcc %o2, 3, %o2 ! restore count
900 .Lsmallleft3: ! 1, 2, or 3 bytes remain
902 EX_LD(LOAD(ldub, %o1, %o3), memcpy_retl_o2_plus_1) ! load one byte
904 EX_ST(STORE(stb, %o3, %o0), memcpy_retl_o2_plus_1) ! store one byte
905 EX_LD(LOAD(ldub, %o1+1, %o3), memcpy_retl_o2) ! load second byte
908 EX_ST(STORE(stb, %o3, %o0+1), memcpy_retl_o2_plus_1)! store second byte
909 EX_LD(LOAD(ldub, %o1+2, %o3), memcpy_retl_o2) ! load third byte
910 EX_ST(STORE(stb, %o3, %o0+2), memcpy_retl_o2) ! store third byte
913 mov EX_RETVAL(%g1), %o0
916 bnz,pn %xcc, .Lsmallleft3
919 mov EX_RETVAL(%g1), %o0 ! restore %o0
922 mov EX_RETVAL(%g1), %o0
923 .size FUNC_NAME, .-FUNC_NAME