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
34 #define EX_RETVAL(x) x
38 #define LOAD(type,addr,dest) type [addr], dest
42 #define LOAD_BLK(addr,dest) ldda [addr] ASI_BLK_P, dest
46 #define STORE(type,src,addr) type src, [addr]
50 #define STORE_BLK(src,addr) stda src, [addr] ASI_BLK_P
54 #define FUNC_NAME memcpy
65 #define FREG_FROB(f1, f2, f3, f4, f5, f6, f7, f8, f9) \
66 faligndata %f1, %f2, %f48; \
67 faligndata %f2, %f3, %f50; \
68 faligndata %f3, %f4, %f52; \
69 faligndata %f4, %f5, %f54; \
70 faligndata %f5, %f6, %f56; \
71 faligndata %f6, %f7, %f58; \
72 faligndata %f7, %f8, %f60; \
73 faligndata %f8, %f9, %f62;
75 #define MAIN_LOOP_CHUNK(src, dest, fdest, fsrc, len, jmptgt) \
76 EX_LD(LOAD_BLK(%src, %fdest)); \
77 EX_ST(STORE_BLK(%fsrc, %dest)); \
78 add %src, 0x40, %src; \
79 subcc %len, 0x40, %len; \
81 add %dest, 0x40, %dest; \
83 #define LOOP_CHUNK1(src, dest, len, branch_dest) \
84 MAIN_LOOP_CHUNK(src, dest, f0, f48, len, branch_dest)
85 #define LOOP_CHUNK2(src, dest, len, branch_dest) \
86 MAIN_LOOP_CHUNK(src, dest, f16, f48, len, branch_dest)
87 #define LOOP_CHUNK3(src, dest, len, branch_dest) \
88 MAIN_LOOP_CHUNK(src, dest, f32, f48, len, branch_dest)
90 #define STORE_SYNC(dest, fsrc) \
91 EX_ST(STORE_BLK(%fsrc, %dest)); \
92 add %dest, 0x40, %dest;
94 #define STORE_JUMP(dest, fsrc, target) \
95 EX_ST(STORE_BLK(%fsrc, %dest)); \
96 add %dest, 0x40, %dest; \
99 #define FINISH_VISCHUNK(dest, f0, f1, left) \
100 subcc %left, 8, %left;\
102 faligndata %f0, %f1, %f48; \
103 EX_ST(STORE(std, %f48, %dest)); \
106 #define UNEVEN_VISCHUNK_LAST(dest, f0, f1, left) \
107 subcc %left, 8, %left; \
111 #define UNEVEN_VISCHUNK(dest, f0, f1, left) \
112 UNEVEN_VISCHUNK_LAST(dest, f0, f1, left) \
115 .register %g2,#scratch
116 .register %g3,#scratch
122 .type FUNC_NAME,#function
123 FUNC_NAME: /* %o0=dst, %o1=src, %o2=len */
140 /* Clobbers o5/g1/g2/g3/g7/icc/xcc. */
143 /* Is 'dst' already aligned on an 64-byte boundary? */
147 /* Compute abs((dst & 0x3f) - 0x40) into %g2. This is the number
148 * of bytes to copy to make 'dst' 64-byte aligned. We pre-
149 * subtract this from 'len'.
151 sub %o0, %o1, %GLOBAL_SPARE
159 1: subcc %g1, 0x1, %g1
160 EX_LD(LOAD(ldub, %o1 + 0x00, %o3))
161 EX_ST(STORE(stb, %o3, %o1 + %GLOBAL_SPARE))
165 add %o1, %GLOBAL_SPARE, %o0
170 alignaddr %o1, %g0, %o1
172 EX_LD(LOAD(ldd, %o1, %f4))
173 1: EX_LD(LOAD(ldd, %o1 + 0x8, %f6))
176 faligndata %f4, %f6, %f0
177 EX_ST(STORE(std, %f0, %o0))
181 EX_LD(LOAD(ldd, %o1 + 0x8, %f4))
184 faligndata %f6, %f4, %f0
185 EX_ST(STORE(std, %f0, %o0))
189 /* Destination is 64-byte aligned. */
191 membar #LoadStore | #StoreStore | #StoreLoad
193 subcc %o2, 0x40, %GLOBAL_SPARE
195 andncc %GLOBAL_SPARE, (0x40 - 1), %GLOBAL_SPARE
197 sub %o2, %GLOBAL_SPARE, %g3
198 andn %o1, (0x40 - 1), %o1
203 sub %o2, %GLOBAL_SPARE, %o2
205 add %g1, %GLOBAL_SPARE, %g1
208 EX_LD(LOAD_BLK(%o1, %f0))
211 EX_LD(LOAD_BLK(%o1, %f16))
213 sub %GLOBAL_SPARE, 0x80, %GLOBAL_SPARE
214 EX_LD(LOAD_BLK(%o1, %f32))
217 /* There are 8 instances of the unrolled loop,
218 * one for each possible alignment of the
219 * source buffer. Each loop instance is 452
228 add %o3, %lo(1f - 1b), %o3
233 1: FREG_FROB(f0, f2, f4, f6, f8, f10,f12,f14,f16)
234 LOOP_CHUNK1(o1, o0, GLOBAL_SPARE, 1f)
235 FREG_FROB(f16,f18,f20,f22,f24,f26,f28,f30,f32)
236 LOOP_CHUNK2(o1, o0, GLOBAL_SPARE, 2f)
237 FREG_FROB(f32,f34,f36,f38,f40,f42,f44,f46,f0)
238 LOOP_CHUNK3(o1, o0, GLOBAL_SPARE, 3f)
240 faligndata %f0, %f2, %f48
241 1: FREG_FROB(f16,f18,f20,f22,f24,f26,f28,f30,f32)
242 STORE_SYNC(o0, f48) membar #Sync
243 FREG_FROB(f32,f34,f36,f38,f40,f42,f44,f46,f0)
244 STORE_JUMP(o0, f48, 40f) membar #Sync
245 2: FREG_FROB(f32,f34,f36,f38,f40,f42,f44,f46,f0)
246 STORE_SYNC(o0, f48) membar #Sync
247 FREG_FROB(f0, f2, f4, f6, f8, f10,f12,f14,f16)
248 STORE_JUMP(o0, f48, 48f) membar #Sync
249 3: FREG_FROB(f0, f2, f4, f6, f8, f10,f12,f14,f16)
250 STORE_SYNC(o0, f48) membar #Sync
251 FREG_FROB(f16,f18,f20,f22,f24,f26,f28,f30,f32)
252 STORE_JUMP(o0, f48, 56f) membar #Sync
254 1: FREG_FROB(f2, f4, f6, f8, f10,f12,f14,f16,f18)
255 LOOP_CHUNK1(o1, o0, GLOBAL_SPARE, 1f)
256 FREG_FROB(f18,f20,f22,f24,f26,f28,f30,f32,f34)
257 LOOP_CHUNK2(o1, o0, GLOBAL_SPARE, 2f)
258 FREG_FROB(f34,f36,f38,f40,f42,f44,f46,f0, f2)
259 LOOP_CHUNK3(o1, o0, GLOBAL_SPARE, 3f)
261 faligndata %f2, %f4, %f48
262 1: FREG_FROB(f18,f20,f22,f24,f26,f28,f30,f32,f34)
263 STORE_SYNC(o0, f48) membar #Sync
264 FREG_FROB(f34,f36,f38,f40,f42,f44,f46,f0, f2)
265 STORE_JUMP(o0, f48, 41f) membar #Sync
266 2: FREG_FROB(f34,f36,f38,f40,f42,f44,f46,f0, f2)
267 STORE_SYNC(o0, f48) membar #Sync
268 FREG_FROB(f2, f4, f6, f8, f10,f12,f14,f16,f18)
269 STORE_JUMP(o0, f48, 49f) membar #Sync
270 3: FREG_FROB(f2, f4, f6, f8, f10,f12,f14,f16,f18)
271 STORE_SYNC(o0, f48) membar #Sync
272 FREG_FROB(f18,f20,f22,f24,f26,f28,f30,f32,f34)
273 STORE_JUMP(o0, f48, 57f) membar #Sync
275 1: FREG_FROB(f4, f6, f8, f10,f12,f14,f16,f18,f20)
276 LOOP_CHUNK1(o1, o0, GLOBAL_SPARE, 1f)
277 FREG_FROB(f20,f22,f24,f26,f28,f30,f32,f34,f36)
278 LOOP_CHUNK2(o1, o0, GLOBAL_SPARE, 2f)
279 FREG_FROB(f36,f38,f40,f42,f44,f46,f0, f2, f4)
280 LOOP_CHUNK3(o1, o0, GLOBAL_SPARE, 3f)
282 faligndata %f4, %f6, %f48
283 1: FREG_FROB(f20,f22,f24,f26,f28,f30,f32,f34,f36)
284 STORE_SYNC(o0, f48) membar #Sync
285 FREG_FROB(f36,f38,f40,f42,f44,f46,f0, f2, f4)
286 STORE_JUMP(o0, f48, 42f) membar #Sync
287 2: FREG_FROB(f36,f38,f40,f42,f44,f46,f0, f2, f4)
288 STORE_SYNC(o0, f48) membar #Sync
289 FREG_FROB(f4, f6, f8, f10,f12,f14,f16,f18,f20)
290 STORE_JUMP(o0, f48, 50f) membar #Sync
291 3: FREG_FROB(f4, f6, f8, f10,f12,f14,f16,f18,f20)
292 STORE_SYNC(o0, f48) membar #Sync
293 FREG_FROB(f20,f22,f24,f26,f28,f30,f32,f34,f36)
294 STORE_JUMP(o0, f48, 58f) membar #Sync
296 1: FREG_FROB(f6, f8, f10,f12,f14,f16,f18,f20,f22)
297 LOOP_CHUNK1(o1, o0, GLOBAL_SPARE, 1f)
298 FREG_FROB(f22,f24,f26,f28,f30,f32,f34,f36,f38)
299 LOOP_CHUNK2(o1, o0, GLOBAL_SPARE, 2f)
300 FREG_FROB(f38,f40,f42,f44,f46,f0, f2, f4, f6)
301 LOOP_CHUNK3(o1, o0, GLOBAL_SPARE, 3f)
303 faligndata %f6, %f8, %f48
304 1: FREG_FROB(f22,f24,f26,f28,f30,f32,f34,f36,f38)
305 STORE_SYNC(o0, f48) membar #Sync
306 FREG_FROB(f38,f40,f42,f44,f46,f0, f2, f4, f6)
307 STORE_JUMP(o0, f48, 43f) membar #Sync
308 2: FREG_FROB(f38,f40,f42,f44,f46,f0, f2, f4, f6)
309 STORE_SYNC(o0, f48) membar #Sync
310 FREG_FROB(f6, f8, f10,f12,f14,f16,f18,f20,f22)
311 STORE_JUMP(o0, f48, 51f) membar #Sync
312 3: FREG_FROB(f6, f8, f10,f12,f14,f16,f18,f20,f22)
313 STORE_SYNC(o0, f48) membar #Sync
314 FREG_FROB(f22,f24,f26,f28,f30,f32,f34,f36,f38)
315 STORE_JUMP(o0, f48, 59f) membar #Sync
317 1: FREG_FROB(f8, f10,f12,f14,f16,f18,f20,f22,f24)
318 LOOP_CHUNK1(o1, o0, GLOBAL_SPARE, 1f)
319 FREG_FROB(f24,f26,f28,f30,f32,f34,f36,f38,f40)
320 LOOP_CHUNK2(o1, o0, GLOBAL_SPARE, 2f)
321 FREG_FROB(f40,f42,f44,f46,f0, f2, f4, f6, f8)
322 LOOP_CHUNK3(o1, o0, GLOBAL_SPARE, 3f)
324 faligndata %f8, %f10, %f48
325 1: FREG_FROB(f24,f26,f28,f30,f32,f34,f36,f38,f40)
326 STORE_SYNC(o0, f48) membar #Sync
327 FREG_FROB(f40,f42,f44,f46,f0, f2, f4, f6, f8)
328 STORE_JUMP(o0, f48, 44f) membar #Sync
329 2: FREG_FROB(f40,f42,f44,f46,f0, f2, f4, f6, f8)
330 STORE_SYNC(o0, f48) membar #Sync
331 FREG_FROB(f8, f10,f12,f14,f16,f18,f20,f22,f24)
332 STORE_JUMP(o0, f48, 52f) membar #Sync
333 3: FREG_FROB(f8, f10,f12,f14,f16,f18,f20,f22,f24)
334 STORE_SYNC(o0, f48) membar #Sync
335 FREG_FROB(f24,f26,f28,f30,f32,f34,f36,f38,f40)
336 STORE_JUMP(o0, f48, 60f) membar #Sync
338 1: FREG_FROB(f10,f12,f14,f16,f18,f20,f22,f24,f26)
339 LOOP_CHUNK1(o1, o0, GLOBAL_SPARE, 1f)
340 FREG_FROB(f26,f28,f30,f32,f34,f36,f38,f40,f42)
341 LOOP_CHUNK2(o1, o0, GLOBAL_SPARE, 2f)
342 FREG_FROB(f42,f44,f46,f0, f2, f4, f6, f8, f10)
343 LOOP_CHUNK3(o1, o0, GLOBAL_SPARE, 3f)
345 faligndata %f10, %f12, %f48
346 1: FREG_FROB(f26,f28,f30,f32,f34,f36,f38,f40,f42)
347 STORE_SYNC(o0, f48) membar #Sync
348 FREG_FROB(f42,f44,f46,f0, f2, f4, f6, f8, f10)
349 STORE_JUMP(o0, f48, 45f) membar #Sync
350 2: FREG_FROB(f42,f44,f46,f0, f2, f4, f6, f8, f10)
351 STORE_SYNC(o0, f48) membar #Sync
352 FREG_FROB(f10,f12,f14,f16,f18,f20,f22,f24,f26)
353 STORE_JUMP(o0, f48, 53f) membar #Sync
354 3: FREG_FROB(f10,f12,f14,f16,f18,f20,f22,f24,f26)
355 STORE_SYNC(o0, f48) membar #Sync
356 FREG_FROB(f26,f28,f30,f32,f34,f36,f38,f40,f42)
357 STORE_JUMP(o0, f48, 61f) membar #Sync
359 1: FREG_FROB(f12,f14,f16,f18,f20,f22,f24,f26,f28)
360 LOOP_CHUNK1(o1, o0, GLOBAL_SPARE, 1f)
361 FREG_FROB(f28,f30,f32,f34,f36,f38,f40,f42,f44)
362 LOOP_CHUNK2(o1, o0, GLOBAL_SPARE, 2f)
363 FREG_FROB(f44,f46,f0, f2, f4, f6, f8, f10,f12)
364 LOOP_CHUNK3(o1, o0, GLOBAL_SPARE, 3f)
366 faligndata %f12, %f14, %f48
367 1: FREG_FROB(f28,f30,f32,f34,f36,f38,f40,f42,f44)
368 STORE_SYNC(o0, f48) membar #Sync
369 FREG_FROB(f44,f46,f0, f2, f4, f6, f8, f10,f12)
370 STORE_JUMP(o0, f48, 46f) membar #Sync
371 2: FREG_FROB(f44,f46,f0, f2, f4, f6, f8, f10,f12)
372 STORE_SYNC(o0, f48) membar #Sync
373 FREG_FROB(f12,f14,f16,f18,f20,f22,f24,f26,f28)
374 STORE_JUMP(o0, f48, 54f) membar #Sync
375 3: FREG_FROB(f12,f14,f16,f18,f20,f22,f24,f26,f28)
376 STORE_SYNC(o0, f48) membar #Sync
377 FREG_FROB(f28,f30,f32,f34,f36,f38,f40,f42,f44)
378 STORE_JUMP(o0, f48, 62f) membar #Sync
380 1: FREG_FROB(f14,f16,f18,f20,f22,f24,f26,f28,f30)
381 LOOP_CHUNK1(o1, o0, GLOBAL_SPARE, 1f)
382 FREG_FROB(f30,f32,f34,f36,f38,f40,f42,f44,f46)
383 LOOP_CHUNK2(o1, o0, GLOBAL_SPARE, 2f)
384 FREG_FROB(f46,f0, f2, f4, f6, f8, f10,f12,f14)
385 LOOP_CHUNK3(o1, o0, GLOBAL_SPARE, 3f)
387 faligndata %f14, %f16, %f48
388 1: FREG_FROB(f30,f32,f34,f36,f38,f40,f42,f44,f46)
389 STORE_SYNC(o0, f48) membar #Sync
390 FREG_FROB(f46,f0, f2, f4, f6, f8, f10,f12,f14)
391 STORE_JUMP(o0, f48, 47f) membar #Sync
392 2: FREG_FROB(f46,f0, f2, f4, f6, f8, f10,f12,f14)
393 STORE_SYNC(o0, f48) membar #Sync
394 FREG_FROB(f14,f16,f18,f20,f22,f24,f26,f28,f30)
395 STORE_JUMP(o0, f48, 55f) membar #Sync
396 3: FREG_FROB(f14,f16,f18,f20,f22,f24,f26,f28,f30)
397 STORE_SYNC(o0, f48) membar #Sync
398 FREG_FROB(f30,f32,f34,f36,f38,f40,f42,f44,f46)
399 STORE_JUMP(o0, f48, 63f) membar #Sync
401 40: FINISH_VISCHUNK(o0, f0, f2, g3)
402 41: FINISH_VISCHUNK(o0, f2, f4, g3)
403 42: FINISH_VISCHUNK(o0, f4, f6, g3)
404 43: FINISH_VISCHUNK(o0, f6, f8, g3)
405 44: FINISH_VISCHUNK(o0, f8, f10, g3)
406 45: FINISH_VISCHUNK(o0, f10, f12, g3)
407 46: FINISH_VISCHUNK(o0, f12, f14, g3)
408 47: UNEVEN_VISCHUNK(o0, f14, f0, g3)
409 48: FINISH_VISCHUNK(o0, f16, f18, g3)
410 49: FINISH_VISCHUNK(o0, f18, f20, g3)
411 50: FINISH_VISCHUNK(o0, f20, f22, g3)
412 51: FINISH_VISCHUNK(o0, f22, f24, g3)
413 52: FINISH_VISCHUNK(o0, f24, f26, g3)
414 53: FINISH_VISCHUNK(o0, f26, f28, g3)
415 54: FINISH_VISCHUNK(o0, f28, f30, g3)
416 55: UNEVEN_VISCHUNK(o0, f30, f0, g3)
417 56: FINISH_VISCHUNK(o0, f32, f34, g3)
418 57: FINISH_VISCHUNK(o0, f34, f36, g3)
419 58: FINISH_VISCHUNK(o0, f36, f38, g3)
420 59: FINISH_VISCHUNK(o0, f38, f40, g3)
421 60: FINISH_VISCHUNK(o0, f40, f42, g3)
422 61: FINISH_VISCHUNK(o0, f42, f44, g3)
423 62: FINISH_VISCHUNK(o0, f44, f46, g3)
424 63: UNEVEN_VISCHUNK_LAST(o0, f46, f0, g3)
426 93: EX_LD(LOAD(ldd, %o1, %f2))
429 faligndata %f0, %f2, %f8
430 EX_ST(STORE(std, %f8, %o0))
433 EX_LD(LOAD(ldd, %o1, %f0))
436 faligndata %f2, %f0, %f8
437 EX_ST(STORE(std, %f8, %o0))
444 1: EX_LD(LOAD(ldub, %o1, %o3))
447 EX_ST(STORE(stb, %o3, %o0))
451 2: membar #StoreLoad | #StoreStore
454 mov EX_RETVAL(%o4), %o0
457 70: /* 16 < len <= (5 * 64) */
461 72: andn %o2, 0xf, %GLOBAL_SPARE
463 1: EX_LD(LOAD(ldx, %o1 + 0x00, %o5))
464 EX_LD(LOAD(ldx, %o1 + 0x08, %g1))
465 subcc %GLOBAL_SPARE, 0x10, %GLOBAL_SPARE
466 EX_ST(STORE(stx, %o5, %o1 + %o3))
468 EX_ST(STORE(stx, %g1, %o1 + %o3))
471 73: andcc %o2, 0x8, %g0
474 EX_LD(LOAD(ldx, %o1, %o5))
476 EX_ST(STORE(stx, %o5, %o1 + %o3))
478 1: andcc %o2, 0x4, %g0
481 EX_LD(LOAD(lduw, %o1, %o5))
483 EX_ST(STORE(stw, %o5, %o1 + %o3))
491 75: andcc %o0, 0x7, %g1
497 1: EX_LD(LOAD(ldub, %o1, %o5))
499 EX_ST(STORE(stb, %o5, %o1 + %o3))
515 EX_LD(LOAD(ldx, %o1, %g2))
517 andn %o2, 0x7, %GLOBAL_SPARE
519 1: EX_LD(LOAD(ldx, %o1 + 0x8, %g3))
520 subcc %GLOBAL_SPARE, 0x8, %GLOBAL_SPARE
524 EX_ST(STORE(stx, %o5, %o0))
537 80: /* 0 < len <= 16 */
542 1: EX_LD(LOAD(lduw, %o1, %g1))
544 EX_ST(STORE(stw, %g1, %o1 + %o3))
549 mov EX_RETVAL(%o4), %o0
552 90: EX_LD(LOAD(ldub, %o1, %g1))
554 EX_ST(STORE(stb, %g1, %o1 + %o3))
558 mov EX_RETVAL(%o4), %o0
560 .size FUNC_NAME, .-FUNC_NAME