1 /* U1memcpy.S: UltraSPARC-I/II/IIi/IIe optimized memcpy.
3 * Copyright (C) 1997, 2004 David S. Miller (davem@redhat.com)
4 * Copyright (C) 1996, 1997, 1998, 1999 Jakub Jelinek (jj@ultra.linux.cz)
8 #include <asm/visasm.h>
10 #define GLOBAL_SPARE g7
12 #define GLOBAL_SPARE g5
13 #define ASI_BLK_P 0xf0
16 #define VISEntry rd %fprs, %o5; wr %g0, FPRS_FEF, %fprs; \
17 clr %g1; clr %g2; clr %g3; subcc %g0, %g0, %g0;
18 #define VISExit and %o5, FPRS_FEF, %o5; wr %o5, 0x0, %fprs
20 #define VISEntry rd %fprs, %o5; wr %g0, FPRS_FEF, %fprs
21 #define VISExit and %o5, FPRS_FEF, %o5; wr %o5, 0x0, %fprs
40 #define EX_RETVAL(x) x
44 #define LOAD(type,addr,dest) type [addr], dest
48 #define LOAD_BLK(addr,dest) ldda [addr] ASI_BLK_P, dest
52 #define STORE(type,src,addr) type src, [addr]
56 #define STORE_BLK(src,addr) stda src, [addr] ASI_BLK_P
60 #define FUNC_NAME memcpy
71 #define FREG_FROB(f1, f2, f3, f4, f5, f6, f7, f8, f9) \
72 faligndata %f1, %f2, %f48; \
73 faligndata %f2, %f3, %f50; \
74 faligndata %f3, %f4, %f52; \
75 faligndata %f4, %f5, %f54; \
76 faligndata %f5, %f6, %f56; \
77 faligndata %f6, %f7, %f58; \
78 faligndata %f7, %f8, %f60; \
79 faligndata %f8, %f9, %f62;
81 #define MAIN_LOOP_CHUNK(src, dest, fdest, fsrc, len, jmptgt) \
82 EX_LD_FP(LOAD_BLK(%src, %fdest)); \
83 EX_ST_FP(STORE_BLK(%fsrc, %dest)); \
84 add %src, 0x40, %src; \
85 subcc %len, 0x40, %len; \
87 add %dest, 0x40, %dest; \
89 #define LOOP_CHUNK1(src, dest, len, branch_dest) \
90 MAIN_LOOP_CHUNK(src, dest, f0, f48, len, branch_dest)
91 #define LOOP_CHUNK2(src, dest, len, branch_dest) \
92 MAIN_LOOP_CHUNK(src, dest, f16, f48, len, branch_dest)
93 #define LOOP_CHUNK3(src, dest, len, branch_dest) \
94 MAIN_LOOP_CHUNK(src, dest, f32, f48, len, branch_dest)
96 #define DO_SYNC membar #Sync;
97 #define STORE_SYNC(dest, fsrc) \
98 EX_ST_FP(STORE_BLK(%fsrc, %dest)); \
99 add %dest, 0x40, %dest; \
102 #define STORE_JUMP(dest, fsrc, target) \
103 EX_ST_FP(STORE_BLK(%fsrc, %dest)); \
104 add %dest, 0x40, %dest; \
105 ba,pt %xcc, target; \
108 #define FINISH_VISCHUNK(dest, f0, f1, left) \
109 subcc %left, 8, %left;\
111 faligndata %f0, %f1, %f48; \
112 EX_ST_FP(STORE(std, %f48, %dest)); \
115 #define UNEVEN_VISCHUNK_LAST(dest, f0, f1, left) \
116 subcc %left, 8, %left; \
120 #define UNEVEN_VISCHUNK(dest, f0, f1, left) \
121 UNEVEN_VISCHUNK_LAST(dest, f0, f1, left) \
124 .register %g2,#scratch
125 .register %g3,#scratch
131 .type FUNC_NAME,#function
132 FUNC_NAME: /* %o0=dst, %o1=src, %o2=len */
149 /* Clobbers o5/g1/g2/g3/g7/icc/xcc. */
152 /* Is 'dst' already aligned on an 64-byte boundary? */
156 /* Compute abs((dst & 0x3f) - 0x40) into %g2. This is the number
157 * of bytes to copy to make 'dst' 64-byte aligned. We pre-
158 * subtract this from 'len'.
160 sub %o0, %o1, %GLOBAL_SPARE
168 1: subcc %g1, 0x1, %g1
169 EX_LD_FP(LOAD(ldub, %o1 + 0x00, %o3))
170 EX_ST_FP(STORE(stb, %o3, %o1 + %GLOBAL_SPARE))
174 add %o1, %GLOBAL_SPARE, %o0
179 alignaddr %o1, %g0, %o1
181 EX_LD_FP(LOAD(ldd, %o1, %f4))
182 1: EX_LD_FP(LOAD(ldd, %o1 + 0x8, %f6))
185 faligndata %f4, %f6, %f0
186 EX_ST_FP(STORE(std, %f0, %o0))
190 EX_LD_FP(LOAD(ldd, %o1 + 0x8, %f4))
193 faligndata %f6, %f4, %f0
194 EX_ST_FP(STORE(std, %f0, %o0))
198 /* Destination is 64-byte aligned. */
200 membar #LoadStore | #StoreStore | #StoreLoad
202 subcc %o2, 0x40, %GLOBAL_SPARE
204 andncc %GLOBAL_SPARE, (0x40 - 1), %GLOBAL_SPARE
206 sub %o2, %GLOBAL_SPARE, %g3
207 andn %o1, (0x40 - 1), %o1
212 sub %o2, %GLOBAL_SPARE, %o2
214 add %g1, %GLOBAL_SPARE, %g1
217 EX_LD_FP(LOAD_BLK(%o1, %f0))
220 EX_LD_FP(LOAD_BLK(%o1, %f16))
222 sub %GLOBAL_SPARE, 0x80, %GLOBAL_SPARE
223 EX_LD_FP(LOAD_BLK(%o1, %f32))
226 /* There are 8 instances of the unrolled loop,
227 * one for each possible alignment of the
228 * source buffer. Each loop instance is 452
237 add %o3, %lo(1f - 1b), %o3
242 1: FREG_FROB(f0, f2, f4, f6, f8, f10,f12,f14,f16)
243 LOOP_CHUNK1(o1, o0, GLOBAL_SPARE, 1f)
244 FREG_FROB(f16,f18,f20,f22,f24,f26,f28,f30,f32)
245 LOOP_CHUNK2(o1, o0, GLOBAL_SPARE, 2f)
246 FREG_FROB(f32,f34,f36,f38,f40,f42,f44,f46,f0)
247 LOOP_CHUNK3(o1, o0, GLOBAL_SPARE, 3f)
249 faligndata %f0, %f2, %f48
250 1: FREG_FROB(f16,f18,f20,f22,f24,f26,f28,f30,f32)
252 FREG_FROB(f32,f34,f36,f38,f40,f42,f44,f46,f0)
253 STORE_JUMP(o0, f48, 40f)
254 2: FREG_FROB(f32,f34,f36,f38,f40,f42,f44,f46,f0)
256 FREG_FROB(f0, f2, f4, f6, f8, f10,f12,f14,f16)
257 STORE_JUMP(o0, f48, 48f)
258 3: FREG_FROB(f0, f2, f4, f6, f8, f10,f12,f14,f16)
260 FREG_FROB(f16,f18,f20,f22,f24,f26,f28,f30,f32)
261 STORE_JUMP(o0, f48, 56f)
263 1: FREG_FROB(f2, f4, f6, f8, f10,f12,f14,f16,f18)
264 LOOP_CHUNK1(o1, o0, GLOBAL_SPARE, 1f)
265 FREG_FROB(f18,f20,f22,f24,f26,f28,f30,f32,f34)
266 LOOP_CHUNK2(o1, o0, GLOBAL_SPARE, 2f)
267 FREG_FROB(f34,f36,f38,f40,f42,f44,f46,f0, f2)
268 LOOP_CHUNK3(o1, o0, GLOBAL_SPARE, 3f)
270 faligndata %f2, %f4, %f48
271 1: FREG_FROB(f18,f20,f22,f24,f26,f28,f30,f32,f34)
273 FREG_FROB(f34,f36,f38,f40,f42,f44,f46,f0, f2)
274 STORE_JUMP(o0, f48, 41f)
275 2: FREG_FROB(f34,f36,f38,f40,f42,f44,f46,f0, f2)
277 FREG_FROB(f2, f4, f6, f8, f10,f12,f14,f16,f18)
278 STORE_JUMP(o0, f48, 49f)
279 3: FREG_FROB(f2, f4, f6, f8, f10,f12,f14,f16,f18)
281 FREG_FROB(f18,f20,f22,f24,f26,f28,f30,f32,f34)
282 STORE_JUMP(o0, f48, 57f)
284 1: FREG_FROB(f4, f6, f8, f10,f12,f14,f16,f18,f20)
285 LOOP_CHUNK1(o1, o0, GLOBAL_SPARE, 1f)
286 FREG_FROB(f20,f22,f24,f26,f28,f30,f32,f34,f36)
287 LOOP_CHUNK2(o1, o0, GLOBAL_SPARE, 2f)
288 FREG_FROB(f36,f38,f40,f42,f44,f46,f0, f2, f4)
289 LOOP_CHUNK3(o1, o0, GLOBAL_SPARE, 3f)
291 faligndata %f4, %f6, %f48
292 1: FREG_FROB(f20,f22,f24,f26,f28,f30,f32,f34,f36)
294 FREG_FROB(f36,f38,f40,f42,f44,f46,f0, f2, f4)
295 STORE_JUMP(o0, f48, 42f)
296 2: FREG_FROB(f36,f38,f40,f42,f44,f46,f0, f2, f4)
298 FREG_FROB(f4, f6, f8, f10,f12,f14,f16,f18,f20)
299 STORE_JUMP(o0, f48, 50f)
300 3: FREG_FROB(f4, f6, f8, f10,f12,f14,f16,f18,f20)
302 FREG_FROB(f20,f22,f24,f26,f28,f30,f32,f34,f36)
303 STORE_JUMP(o0, f48, 58f)
305 1: FREG_FROB(f6, f8, f10,f12,f14,f16,f18,f20,f22)
306 LOOP_CHUNK1(o1, o0, GLOBAL_SPARE, 1f)
307 FREG_FROB(f22,f24,f26,f28,f30,f32,f34,f36,f38)
308 LOOP_CHUNK2(o1, o0, GLOBAL_SPARE, 2f)
309 FREG_FROB(f38,f40,f42,f44,f46,f0, f2, f4, f6)
310 LOOP_CHUNK3(o1, o0, GLOBAL_SPARE, 3f)
312 faligndata %f6, %f8, %f48
313 1: FREG_FROB(f22,f24,f26,f28,f30,f32,f34,f36,f38)
315 FREG_FROB(f38,f40,f42,f44,f46,f0, f2, f4, f6)
316 STORE_JUMP(o0, f48, 43f)
317 2: FREG_FROB(f38,f40,f42,f44,f46,f0, f2, f4, f6)
319 FREG_FROB(f6, f8, f10,f12,f14,f16,f18,f20,f22)
320 STORE_JUMP(o0, f48, 51f)
321 3: FREG_FROB(f6, f8, f10,f12,f14,f16,f18,f20,f22)
323 FREG_FROB(f22,f24,f26,f28,f30,f32,f34,f36,f38)
324 STORE_JUMP(o0, f48, 59f)
326 1: FREG_FROB(f8, f10,f12,f14,f16,f18,f20,f22,f24)
327 LOOP_CHUNK1(o1, o0, GLOBAL_SPARE, 1f)
328 FREG_FROB(f24,f26,f28,f30,f32,f34,f36,f38,f40)
329 LOOP_CHUNK2(o1, o0, GLOBAL_SPARE, 2f)
330 FREG_FROB(f40,f42,f44,f46,f0, f2, f4, f6, f8)
331 LOOP_CHUNK3(o1, o0, GLOBAL_SPARE, 3f)
333 faligndata %f8, %f10, %f48
334 1: FREG_FROB(f24,f26,f28,f30,f32,f34,f36,f38,f40)
336 FREG_FROB(f40,f42,f44,f46,f0, f2, f4, f6, f8)
337 STORE_JUMP(o0, f48, 44f)
338 2: FREG_FROB(f40,f42,f44,f46,f0, f2, f4, f6, f8)
340 FREG_FROB(f8, f10,f12,f14,f16,f18,f20,f22,f24)
341 STORE_JUMP(o0, f48, 52f)
342 3: FREG_FROB(f8, f10,f12,f14,f16,f18,f20,f22,f24)
344 FREG_FROB(f24,f26,f28,f30,f32,f34,f36,f38,f40)
345 STORE_JUMP(o0, f48, 60f)
347 1: FREG_FROB(f10,f12,f14,f16,f18,f20,f22,f24,f26)
348 LOOP_CHUNK1(o1, o0, GLOBAL_SPARE, 1f)
349 FREG_FROB(f26,f28,f30,f32,f34,f36,f38,f40,f42)
350 LOOP_CHUNK2(o1, o0, GLOBAL_SPARE, 2f)
351 FREG_FROB(f42,f44,f46,f0, f2, f4, f6, f8, f10)
352 LOOP_CHUNK3(o1, o0, GLOBAL_SPARE, 3f)
354 faligndata %f10, %f12, %f48
355 1: FREG_FROB(f26,f28,f30,f32,f34,f36,f38,f40,f42)
357 FREG_FROB(f42,f44,f46,f0, f2, f4, f6, f8, f10)
358 STORE_JUMP(o0, f48, 45f)
359 2: FREG_FROB(f42,f44,f46,f0, f2, f4, f6, f8, f10)
361 FREG_FROB(f10,f12,f14,f16,f18,f20,f22,f24,f26)
362 STORE_JUMP(o0, f48, 53f)
363 3: FREG_FROB(f10,f12,f14,f16,f18,f20,f22,f24,f26)
365 FREG_FROB(f26,f28,f30,f32,f34,f36,f38,f40,f42)
366 STORE_JUMP(o0, f48, 61f)
368 1: FREG_FROB(f12,f14,f16,f18,f20,f22,f24,f26,f28)
369 LOOP_CHUNK1(o1, o0, GLOBAL_SPARE, 1f)
370 FREG_FROB(f28,f30,f32,f34,f36,f38,f40,f42,f44)
371 LOOP_CHUNK2(o1, o0, GLOBAL_SPARE, 2f)
372 FREG_FROB(f44,f46,f0, f2, f4, f6, f8, f10,f12)
373 LOOP_CHUNK3(o1, o0, GLOBAL_SPARE, 3f)
375 faligndata %f12, %f14, %f48
376 1: FREG_FROB(f28,f30,f32,f34,f36,f38,f40,f42,f44)
378 FREG_FROB(f44,f46,f0, f2, f4, f6, f8, f10,f12)
379 STORE_JUMP(o0, f48, 46f)
380 2: FREG_FROB(f44,f46,f0, f2, f4, f6, f8, f10,f12)
382 FREG_FROB(f12,f14,f16,f18,f20,f22,f24,f26,f28)
383 STORE_JUMP(o0, f48, 54f)
384 3: FREG_FROB(f12,f14,f16,f18,f20,f22,f24,f26,f28)
386 FREG_FROB(f28,f30,f32,f34,f36,f38,f40,f42,f44)
387 STORE_JUMP(o0, f48, 62f)
389 1: FREG_FROB(f14,f16,f18,f20,f22,f24,f26,f28,f30)
390 LOOP_CHUNK1(o1, o0, GLOBAL_SPARE, 1f)
391 FREG_FROB(f30,f32,f34,f36,f38,f40,f42,f44,f46)
392 LOOP_CHUNK2(o1, o0, GLOBAL_SPARE, 2f)
393 FREG_FROB(f46,f0, f2, f4, f6, f8, f10,f12,f14)
394 LOOP_CHUNK3(o1, o0, GLOBAL_SPARE, 3f)
396 faligndata %f14, %f16, %f48
397 1: FREG_FROB(f30,f32,f34,f36,f38,f40,f42,f44,f46)
399 FREG_FROB(f46,f0, f2, f4, f6, f8, f10,f12,f14)
400 STORE_JUMP(o0, f48, 47f)
401 2: FREG_FROB(f46,f0, f2, f4, f6, f8, f10,f12,f14)
403 FREG_FROB(f14,f16,f18,f20,f22,f24,f26,f28,f30)
404 STORE_JUMP(o0, f48, 55f)
405 3: FREG_FROB(f14,f16,f18,f20,f22,f24,f26,f28,f30)
407 FREG_FROB(f30,f32,f34,f36,f38,f40,f42,f44,f46)
408 STORE_JUMP(o0, f48, 63f)
410 40: FINISH_VISCHUNK(o0, f0, f2, g3)
411 41: FINISH_VISCHUNK(o0, f2, f4, g3)
412 42: FINISH_VISCHUNK(o0, f4, f6, g3)
413 43: FINISH_VISCHUNK(o0, f6, f8, g3)
414 44: FINISH_VISCHUNK(o0, f8, f10, g3)
415 45: FINISH_VISCHUNK(o0, f10, f12, g3)
416 46: FINISH_VISCHUNK(o0, f12, f14, g3)
417 47: UNEVEN_VISCHUNK(o0, f14, f0, g3)
418 48: FINISH_VISCHUNK(o0, f16, f18, g3)
419 49: FINISH_VISCHUNK(o0, f18, f20, g3)
420 50: FINISH_VISCHUNK(o0, f20, f22, g3)
421 51: FINISH_VISCHUNK(o0, f22, f24, g3)
422 52: FINISH_VISCHUNK(o0, f24, f26, g3)
423 53: FINISH_VISCHUNK(o0, f26, f28, g3)
424 54: FINISH_VISCHUNK(o0, f28, f30, g3)
425 55: UNEVEN_VISCHUNK(o0, f30, f0, g3)
426 56: FINISH_VISCHUNK(o0, f32, f34, g3)
427 57: FINISH_VISCHUNK(o0, f34, f36, g3)
428 58: FINISH_VISCHUNK(o0, f36, f38, g3)
429 59: FINISH_VISCHUNK(o0, f38, f40, g3)
430 60: FINISH_VISCHUNK(o0, f40, f42, g3)
431 61: FINISH_VISCHUNK(o0, f42, f44, g3)
432 62: FINISH_VISCHUNK(o0, f44, f46, g3)
433 63: UNEVEN_VISCHUNK_LAST(o0, f46, f0, g3)
435 93: EX_LD_FP(LOAD(ldd, %o1, %f2))
438 faligndata %f0, %f2, %f8
439 EX_ST_FP(STORE(std, %f8, %o0))
442 EX_LD_FP(LOAD(ldd, %o1, %f0))
445 faligndata %f2, %f0, %f8
446 EX_ST_FP(STORE(std, %f8, %o0))
453 1: EX_LD_FP(LOAD(ldub, %o1, %o3))
456 EX_ST_FP(STORE(stb, %o3, %o0))
460 2: membar #StoreLoad | #StoreStore
463 mov EX_RETVAL(%o4), %o0
466 70: /* 16 < len <= (5 * 64) */
470 72: andn %o2, 0xf, %GLOBAL_SPARE
472 1: EX_LD(LOAD(ldx, %o1 + 0x00, %o5))
473 EX_LD(LOAD(ldx, %o1 + 0x08, %g1))
474 subcc %GLOBAL_SPARE, 0x10, %GLOBAL_SPARE
475 EX_ST(STORE(stx, %o5, %o1 + %o3))
477 EX_ST(STORE(stx, %g1, %o1 + %o3))
480 73: andcc %o2, 0x8, %g0
483 EX_LD(LOAD(ldx, %o1, %o5))
485 EX_ST(STORE(stx, %o5, %o1 + %o3))
487 1: andcc %o2, 0x4, %g0
490 EX_LD(LOAD(lduw, %o1, %o5))
492 EX_ST(STORE(stw, %o5, %o1 + %o3))
500 75: andcc %o0, 0x7, %g1
506 1: EX_LD(LOAD(ldub, %o1, %o5))
508 EX_ST(STORE(stb, %o5, %o1 + %o3))
524 EX_LD(LOAD(ldx, %o1, %g2))
526 andn %o2, 0x7, %GLOBAL_SPARE
528 1: EX_LD(LOAD(ldx, %o1 + 0x8, %g3))
529 subcc %GLOBAL_SPARE, 0x8, %GLOBAL_SPARE
533 EX_ST(STORE(stx, %o5, %o0))
546 80: /* 0 < len <= 16 */
551 1: EX_LD(LOAD(lduw, %o1, %g1))
553 EX_ST(STORE(stw, %g1, %o1 + %o3))
558 mov EX_RETVAL(%o4), %o0
561 90: EX_LD(LOAD(ldub, %o1, %g1))
563 EX_ST(STORE(stb, %g1, %o1 + %o3))
567 mov EX_RETVAL(%o4), %o0
569 .size FUNC_NAME, .-FUNC_NAME