1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #include <asm/asmmacro.h>
18 #include <asm/page.h>
19 #include <asm/export.h>
20
21 #define EK(y...) EX(y)
22
23
24
25 #define retval r8
26 #define saved_pfs r31
27 #define saved_lc r10
28 #define saved_pr r11
29 #define saved_in0 r14
30 #define saved_in1 r15
31 #define saved_in2 r16
32
33 #define src0 r2
34 #define src1 r3
35 #define dst0 r17
36 #define dst1 r18
37 #define cnt r9
38
39
40 #define PREFETCH_DIST 8
41 #define src_pre_mem r19
42 #define dst_pre_mem r20
43 #define src_pre_l2 r21
44 #define dst_pre_l2 r22
45 #define t1 r23
46 #define t2 r24
47 #define t3 r25
48 #define t4 r26
49 #define t5 t1
50 #define t6 t2
51 #define t7 t3
52 #define n8 r27
53 #define t9 t5
54 #define t10 t4
55 #define t11 t7
56 #define t12 t6
57 #define t14 t10
58 #define t13 r28
59 #define t15 r29
60 #define tmp r30
61
62
63 #define A 0
64 #define B (PREFETCH_DIST)
65 #define C (B + PREFETCH_DIST)
66 #define D (C + 1)
67 #define N (D + 1)
68 #define Nrot ((N + 7) & ~7)
69
70
71 #define in0 r32
72 #define in1 r33
73 #define in2 r34
74
75 GLOBAL_ENTRY(memcpy)
76 and r28=0x7,in0
77 and r29=0x7,in1
78 mov f6=f0
79 mov retval=in0
80 br.cond.sptk .common_code
81 ;;
82 END(memcpy)
83 EXPORT_SYMBOL(memcpy)
84 GLOBAL_ENTRY(__copy_user)
85 .prologue
86
87 and r28=0x7,in0
88 and r29=0x7,in1
89 mov f6=f1
90 mov saved_in0=in0
91 mov saved_in1=in1
92 mov retval=r0
93 ;;
94 .common_code:
95 cmp.gt p15,p0=8,in2
96 cmp.ne p13,p0=0,r28
97 cmp.ne p14,p0=0,r29
98 add src0=0,in1
99 sub r30=8,r28
100 mov saved_in2=in2
101 ;;
102 add dst0=0,in0
103 add dst1=1,in0
104 cmp.le p6,p0 = 1,r30
105 (p15) br.cond.dpnt .memcpy_short
106 (p13) br.cond.dpnt .align_dest
107 (p14) br.cond.dpnt .unaligned_src
108 ;;
109
110
111 .aligned_src:
112 .save ar.pfs, saved_pfs
113 alloc saved_pfs=ar.pfs,3,Nrot-3,0,Nrot
114 .save pr, saved_pr
115 mov saved_pr=pr
116
117 shr.u cnt=in2,7
118 ;;
119 cmp.lt p6,p0=2*PREFETCH_DIST,cnt
120 cmp.lt p7,p8=1,cnt
121 .save ar.lc, saved_lc
122 mov saved_lc=ar.lc
123 .body
124 add cnt=-1,cnt
125 add src_pre_mem=0,in1
126 add dst_pre_mem=0,in0
127 ;;
128 (p7) mov ar.lc=cnt
129 (p8) mov ar.lc=r0
130 (p6) br.cond.dpnt .long_copy
131 ;;
132
133 .prefetch:
134 lfetch.fault [src_pre_mem], 128
135 lfetch.fault.excl [dst_pre_mem], 128
136 br.cloop.dptk.few .prefetch
137 ;;
138
139 .medium_copy:
140 and tmp=31,in2
141 shr.u r29=in2,5
142 add dst1=8,dst0
143 ;;
144 add cnt=-1,r29
145 cmp.eq p10,p0=r29,r0
146 add src1=8,src0
147 cmp.le p6,p0=8,tmp
148 ;;
149 cmp.le p7,p0=16,tmp
150 mov ar.lc=cnt
151 cmp.eq p16,p17 = r0,r0
152 mov ar.ec=2
153 (p10) br.dpnt.few .aligned_src_tail
154 ;;
155 TEXT_ALIGN(32)
156 1:
157 EX(.ex_handler, (p16) ld8 r34=[src0],16)
158 EK(.ex_handler, (p16) ld8 r38=[src1],16)
159 EX(.ex_handler, (p17) st8 [dst0]=r33,16)
160 EK(.ex_handler, (p17) st8 [dst1]=r37,16)
161 ;;
162 EX(.ex_handler, (p16) ld8 r32=[src0],16)
163 EK(.ex_handler, (p16) ld8 r36=[src1],16)
164 EX(.ex_handler, (p16) st8 [dst0]=r34,16)
165 EK(.ex_handler, (p16) st8 [dst1]=r38,16)
166 br.ctop.dptk.few 1b
167 ;;
168
169 .aligned_src_tail:
170 EX(.ex_handler, (p6) ld8 t1=[src0])
171 mov ar.lc=saved_lc
172 mov ar.pfs=saved_pfs
173 EX(.ex_hndlr_s, (p7) ld8 t2=[src1],8)
174 cmp.le p8,p0=24,tmp
175 and r21=-8,tmp
176 ;;
177 EX(.ex_hndlr_s, (p8) ld8 t3=[src1])
178 EX(.ex_handler, (p6) st8 [dst0]=t1)
179 and in2=7,tmp
180 EX(.ex_hndlr_d, (p7) st8 [dst1]=t2,8)
181 add src0=src0,r21
182 add dst0=dst0,r21
183 ;;
184 EX(.ex_handler, (p8) st8 [dst1]=t3)
185 mov pr=saved_pr,-1
186 br.dptk.many .memcpy_short
187 ;;
188
189
190 .long_copy:
191 .rotr v[2*PREFETCH_DIST]
192 .rotp p[N]
193
194 mov src_pre_mem = src0
195 mov pr.rot = 0x10000
196 mov ar.ec = 1
197
198 mov dst_pre_mem = dst0
199
200 add src_pre_l2 = 8*8, src0
201 add dst_pre_l2 = 8*8, dst0
202 ;;
203 add src0 = 8, src_pre_mem
204 mov ar.lc = 2*PREFETCH_DIST - 1
205 shr.u cnt=in2,7
206 add src1 = 3*8, src_pre_mem
207 add dst0 = 8, dst_pre_mem
208 add dst1 = 3*8, dst_pre_mem
209 ;;
210 and tmp=127,in2
211 add cnt = -(2*PREFETCH_DIST) - 1, cnt
212
213 .prefetch_loop:
214 EX(.ex_hndlr_lcpy_1, (p[A]) ld8 v[A] = [src_pre_mem], 128)
215 EK(.ex_hndlr_lcpy_1, (p[B]) st8 [dst_pre_mem] = v[B], 128)
216 br.ctop.sptk .prefetch_loop
217 ;;
218 cmp.eq p16, p0 = r0, r0
219 mov ar.lc = cnt
220 mov ar.ec = N
221 ;;
222 .line_copy:
223 EX(.ex_handler, (p[D]) ld8 t2 = [src0], 3*8)
224 EK(.ex_handler, (p[D]) ld8 t4 = [src1], 3*8)
225 EX(.ex_handler_lcpy, (p[B]) st8 [dst_pre_mem] = v[B], 128)
226 EK(.ex_handler_lcpy, (p[D]) st8 [dst_pre_l2] = n8, 128)
227 ;;
228 EX(.ex_handler_lcpy, (p[A]) ld8 v[A] = [src_pre_mem], 128)
229 EK(.ex_handler_lcpy, (p[C]) ld8 n8 = [src_pre_l2], 128)
230 EX(.ex_handler, (p[D]) st8 [dst0] = t1, 8)
231 EK(.ex_handler, (p[D]) st8 [dst1] = t3, 8)
232 ;;
233 EX(.ex_handler, (p[D]) ld8 t5 = [src0], 8)
234 EK(.ex_handler, (p[D]) ld8 t7 = [src1], 3*8)
235 EX(.ex_handler, (p[D]) st8 [dst0] = t2, 3*8)
236 EK(.ex_handler, (p[D]) st8 [dst1] = t4, 3*8)
237 ;;
238 EX(.ex_handler, (p[D]) ld8 t6 = [src0], 3*8)
239 EK(.ex_handler, (p[D]) ld8 t10 = [src1], 8)
240 EX(.ex_handler, (p[D]) st8 [dst0] = t5, 8)
241 EK(.ex_handler, (p[D]) st8 [dst1] = t7, 3*8)
242 ;;
243 EX(.ex_handler, (p[D]) ld8 t9 = [src0], 3*8)
244 EK(.ex_handler, (p[D]) ld8 t11 = [src1], 3*8)
245 EX(.ex_handler, (p[D]) st8 [dst0] = t6, 3*8)
246 EK(.ex_handler, (p[D]) st8 [dst1] = t10, 8)
247 ;;
248 EX(.ex_handler, (p[D]) ld8 t12 = [src0], 8)
249 EK(.ex_handler, (p[D]) ld8 t14 = [src1], 8)
250 EX(.ex_handler, (p[D]) st8 [dst0] = t9, 3*8)
251 EK(.ex_handler, (p[D]) st8 [dst1] = t11, 3*8)
252 ;;
253 EX(.ex_handler, (p[D]) ld8 t13 = [src0], 4*8)
254 EK(.ex_handler, (p[D]) ld8 t15 = [src1], 4*8)
255 EX(.ex_handler, (p[D]) st8 [dst0] = t12, 8)
256 EK(.ex_handler, (p[D]) st8 [dst1] = t14, 8)
257 ;;
258 EX(.ex_handler, (p[C]) ld8 t1 = [src0], 8)
259 EK(.ex_handler, (p[C]) ld8 t3 = [src1], 8)
260 EX(.ex_handler, (p[D]) st8 [dst0] = t13, 4*8)
261 EK(.ex_handler, (p[D]) st8 [dst1] = t15, 4*8)
262 br.ctop.sptk .line_copy
263 ;;
264
265 add dst0=-8,dst0
266 add src0=-8,src0
267 mov in2=tmp
268 .restore sp
269 br.sptk.many .medium_copy
270 ;;
271
272 #define BLOCK_SIZE 128*32
273 #define blocksize r23
274 #define curlen r24
275
276
277
278 .unaligned_src:
279 .prologue
280 .save ar.pfs, saved_pfs
281 alloc saved_pfs=ar.pfs,3,5,0,8
282 .save ar.lc, saved_lc
283 mov saved_lc=ar.lc
284 .save pr, saved_pr
285 mov saved_pr=pr
286 .body
287 .4k_block:
288 mov saved_in0=dst0
289 mov saved_in2=in2
290 mov blocksize=BLOCK_SIZE
291 ;;
292 cmp.lt p6,p7=blocksize,in2
293 mov saved_in1=src0
294 ;;
295 (p6) mov in2=blocksize
296 ;;
297 shr.u r21=in2,7
298 shr.u r22=in2,4
299 and curlen=15,in2
300 and r30=7,src0
301 ;;
302 cmp.lt p7,p8=1,r21
303 add cnt=-1,r21
304 ;;
305
306 add src_pre_mem=0,src0
307 add dst_pre_mem=0,dst0
308 and src0=-8,src0
309 (p7) mov ar.lc = cnt
310 (p8) mov ar.lc = r0
311 ;;
312 TEXT_ALIGN(32)
313 1: lfetch.fault [src_pre_mem], 128
314 lfetch.fault.excl [dst_pre_mem], 128
315 br.cloop.dptk.few 1b
316 ;;
317
318 shladd dst1=r22,3,dst0
319 shladd src1=r22,3,src0
320 cmp.eq p8,p9=r22,r0
321 cmp.le p6,p7=8,curlen;
322 add cnt=-1,r22
323 ;;
324 EX(.ex_handler, (p9) ld8 r33=[src0],8)
325 EK(.ex_handler, (p9) ld8 r37=[src1],8)
326 (p8) br.dpnt.few .noloop
327 ;;
328
329
330
331
332
333
334
335 #define LOOP_SIZE 6
336 1:
337 mov r29=ip
338 mov ar.lc=cnt
339 ;;
340 add r29=.jump_table - 1b - (.jmp1-.jump_table), r29
341 shl r28=r30, LOOP_SIZE
342 mov ar.ec=2
343 ;;
344 add r29=r29,r28
345 cmp.eq p16,p17=r0,r0
346 ;;
347 mov b6=r29
348 ;;
349 br.cond.sptk.few b6
350
351
352
353
354 .noloop:
355 EX(.ex_handler, (p6) ld8 r37=[src1],8)
356 add src0=8,src0
357 (p6) shl r25=r30,3
358 ;;
359 EX(.ex_handler, (p6) ld8 r27=[src1])
360 (p6) shr.u r28=r37,r25
361 (p6) sub r26=64,r25
362 ;;
363 (p6) shl r27=r27,r26
364 ;;
365 (p6) or r21=r28,r27
366
367 .unaligned_src_tail:
368
369 cmp.gt p8,p0=saved_in2,blocksize
370 ;;
371 (p8) add dst0=saved_in0,blocksize
372 (p8) add src0=saved_in1,blocksize
373 (p8) sub in2=saved_in2,blocksize
374 (p8) br.dpnt .4k_block
375 ;;
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395 EX(.ex_handler, (p6) st8 [dst1]=r21,8)
396 (p6) add curlen=-8,curlen
397 mov ar.pfs=saved_pfs
398 ;;
399 mov ar.lc=saved_lc
400 mov pr=saved_pr,-1
401 mov in2=curlen
402 mov dst0=dst1
403 add src0=src1,r30
404 ;;
405
406
407 .memcpy_short:
408 cmp.le p8,p9 = 1,in2
409 cmp.le p10,p11 = 2,in2
410 cmp.le p12,p13 = 3,in2
411 cmp.le p14,p15 = 4,in2
412 add src1=1,src0
413 add dst1=1,dst0
414 ;;
415
416 EX(.ex_handler_short, (p8) ld1 t1=[src0],2)
417 EK(.ex_handler_short, (p10) ld1 t2=[src1],2)
418 (p9) br.ret.dpnt rp
419 ;;
420
421 EX(.ex_handler_short, (p8) st1 [dst0]=t1,2)
422 EK(.ex_handler_short, (p10) st1 [dst1]=t2,2)
423 (p11) br.ret.dpnt rp
424
425 EX(.ex_handler_short, (p12) ld1 t3=[src0],2)
426 EK(.ex_handler_short, (p14) ld1 t4=[src1],2)
427 (p13) br.ret.dpnt rp
428 ;;
429
430 cmp.le p6,p7 = 5,in2
431 cmp.le p8,p9 = 6,in2
432 cmp.le p10,p11 = 7,in2
433
434 EX(.ex_handler_short, (p12) st1 [dst0]=t3,2)
435 EK(.ex_handler_short, (p14) st1 [dst1]=t4,2)
436 (p15) br.ret.dpnt rp
437 ;;
438
439 EX(.ex_handler_short, (p6) ld1 t5=[src0],2)
440 EK(.ex_handler_short, (p8) ld1 t6=[src1],2)
441 (p7) br.ret.dpnt rp
442 ;;
443
444 EX(.ex_handler_short, (p6) st1 [dst0]=t5,2)
445 EK(.ex_handler_short, (p8) st1 [dst1]=t6,2)
446 (p9) br.ret.dptk rp
447
448 EX(.ex_handler_short, (p10) ld1 t7=[src0],2)
449 (p11) br.ret.dptk rp
450 ;;
451
452 EX(.ex_handler_short, (p10) st1 [dst0]=t7,2)
453 br.ret.dptk rp
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468 .align_dest:
469 add src1=1,in1
470 cmp.le p7,p0 = 2,r30
471 cmp.le p8,p0 = 3,r30
472 EX(.ex_handler_short, (p6) ld1 t1=[src0],2)
473 cmp.le p9,p0 = 4,r30
474 cmp.le p10,p0 = 5,r30
475 ;;
476 EX(.ex_handler_short, (p7) ld1 t2=[src1],2)
477 EK(.ex_handler_short, (p8) ld1 t3=[src0],2)
478 cmp.le p11,p0 = 6,r30
479 EX(.ex_handler_short, (p6) st1 [dst0] = t1,2)
480 cmp.le p12,p0 = 7,r30
481 ;;
482 EX(.ex_handler_short, (p9) ld1 t4=[src1],2)
483 EK(.ex_handler_short, (p10) ld1 t5=[src0],2)
484 EX(.ex_handler_short, (p7) st1 [dst1] = t2,2)
485 EK(.ex_handler_short, (p8) st1 [dst0] = t3,2)
486 ;;
487 EX(.ex_handler_short, (p11) ld1 t6=[src1],2)
488 EK(.ex_handler_short, (p12) ld1 t7=[src0],2)
489 cmp.eq p6,p7=r28,r29
490 EX(.ex_handler_short, (p9) st1 [dst1] = t4,2)
491 EK(.ex_handler_short, (p10) st1 [dst0] = t5,2)
492 sub in2=in2,r30
493 ;;
494 EX(.ex_handler_short, (p11) st1 [dst1] = t6,2)
495 EK(.ex_handler_short, (p12) st1 [dst0] = t7)
496 add dst0=in0,r30
497 add src0=in1,r30
498 (p6) br.cond.dptk .aligned_src
499 (p7) br.cond.dpnt .unaligned_src
500 ;;
501
502
503 #define COPYU(shift) \
504 1: \
505 EX(.ex_handler, (p16) ld8 r32=[src0],8); \
506 EK(.ex_handler, (p16) ld8 r36=[src1],8); \
507 (p17) shrp r35=r33,r34,shift;; \
508 EX(.ex_handler, (p6) ld8 r22=[src1]); \
509 nop.m 0; \
510 (p16) shrp r38=r36,r37,shift; \
511 EX(.ex_handler, (p17) st8 [dst0]=r35,8); \
512 EK(.ex_handler, (p17) st8 [dst1]=r39,8); \
513 br.ctop.dptk.few 1b;; \
514 (p7) add src1=-8,src1; \
515 shrp r21=r22,r38,shift; \
516 br.sptk.few .unaligned_src_tail \
517 ;;
518 TEXT_ALIGN(32)
519 .jump_table:
520 COPYU(8)
521 .jmp1:
522 COPYU(16)
523 COPYU(24)
524 COPYU(32)
525 COPYU(40)
526 COPYU(48)
527 COPYU(56)
528
529 #undef A
530 #undef B
531 #undef C
532 #undef D
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554 #define A r19
555 #define B r20
556 #define C r21
557 #define D r22
558 #define F r28
559
560 #define saved_retval loc0
561 #define saved_rtlink loc1
562 #define saved_pfs_stack loc2
563
564 .ex_hndlr_s:
565 add src0=8,src0
566 br.sptk .ex_handler
567 ;;
568 .ex_hndlr_d:
569 add dst0=8,dst0
570 br.sptk .ex_handler
571 ;;
572 .ex_hndlr_lcpy_1:
573 mov src1=src_pre_mem
574 mov dst1=dst_pre_mem
575 cmp.gtu p10,p11=src_pre_mem,saved_in1
576 cmp.gtu p12,p13=dst_pre_mem,saved_in0
577 ;;
578 (p10) add src0=8,saved_in1
579 (p11) mov src0=saved_in1
580 (p12) add dst0=8,saved_in0
581 (p13) mov dst0=saved_in0
582 br.sptk .ex_handler
583 .ex_handler_lcpy:
584
585
586
587 mov src1=src_pre_mem
588 mov dst1=dst_pre_mem
589 .ex_handler:
590 mov pr=saved_pr,-1
591 mov ar.lc=saved_lc
592 mov ar.pfs=saved_pfs
593 ;;
594 .ex_handler_short:
595 cmp.ltu p6,p7=saved_in0, saved_in1
596 cmp.ltu p10,p11=src0,src1
597 cmp.ltu p12,p13=dst0,dst1
598 fcmp.eq p8,p0=f6,f0
599 mov tmp = dst0
600 ;;
601 (p11) mov src1 = src0
602 (p13) mov dst0 = dst1
603 (p13) mov dst1 = tmp
604 ;;
605 (p6) dep F = r0,dst1,0,PAGE_SHIFT
606 (p7) dep F = r0,src1,0,PAGE_SHIFT
607 ;;
608 (p6) cmp.le p14,p0=dst0,saved_in0
609 (p7) cmp.le p14,p0=src0,saved_in1
610 mov retval=saved_in2
611 (p8) ld1 tmp=[src1]
612 (p8) st1 [dst1]=r0
613 (p14) br.ret.sptk.many rp
614
615
616
617
618
619
620
621
622
623
624
625 (p6) sub A = F, saved_in0
626 (p7) sub A = F, saved_in1
627 clrrrb
628 ;;
629 alloc saved_pfs_stack=ar.pfs,3,3,3,0
630 cmp.lt p8,p0=A,r0
631 sub B = dst0, saved_in0
632 ;;
633 (p8) mov A = 0;
634 ;;
635 sub C = A, B
636 sub D = saved_in2, A
637 ;;
638 cmp.gt p8,p0=C,r0
639 mov r8=0
640 mov saved_retval = D
641 mov saved_rtlink = b0
642
643 add out0=saved_in0, B
644 add out1=saved_in1, B
645 mov out2=C
646 (p8) br.call.sptk.few b0=__copy_user
647 ;;
648
649 add saved_retval=saved_retval,r8
650 ;;
651
652 mov retval=saved_retval
653 mov ar.pfs=saved_pfs_stack
654 mov b0=saved_rtlink
655 br.ret.sptk.many rp
656
657
658 END(__copy_user)
659 EXPORT_SYMBOL(__copy_user)