diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/ia64/lib/memcpy_mck.S |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'arch/ia64/lib/memcpy_mck.S')
-rw-r--r-- | arch/ia64/lib/memcpy_mck.S | 661 |
1 files changed, 661 insertions, 0 deletions
diff --git a/arch/ia64/lib/memcpy_mck.S b/arch/ia64/lib/memcpy_mck.S new file mode 100644 index 000000000000..6f26ef7cc236 --- /dev/null +++ b/arch/ia64/lib/memcpy_mck.S | |||
@@ -0,0 +1,661 @@ | |||
1 | /* | ||
2 | * Itanium 2-optimized version of memcpy and copy_user function | ||
3 | * | ||
4 | * Inputs: | ||
5 | * in0: destination address | ||
6 | * in1: source address | ||
7 | * in2: number of bytes to copy | ||
8 | * Output: | ||
9 | * 0 if success, or number of byte NOT copied if error occurred. | ||
10 | * | ||
11 | * Copyright (C) 2002 Intel Corp. | ||
12 | * Copyright (C) 2002 Ken Chen <kenneth.w.chen@intel.com> | ||
13 | */ | ||
14 | #include <linux/config.h> | ||
15 | #include <asm/asmmacro.h> | ||
16 | #include <asm/page.h> | ||
17 | |||
18 | #define EK(y...) EX(y) | ||
19 | |||
20 | /* McKinley specific optimization */ | ||
21 | |||
22 | #define retval r8 | ||
23 | #define saved_pfs r31 | ||
24 | #define saved_lc r10 | ||
25 | #define saved_pr r11 | ||
26 | #define saved_in0 r14 | ||
27 | #define saved_in1 r15 | ||
28 | #define saved_in2 r16 | ||
29 | |||
30 | #define src0 r2 | ||
31 | #define src1 r3 | ||
32 | #define dst0 r17 | ||
33 | #define dst1 r18 | ||
34 | #define cnt r9 | ||
35 | |||
36 | /* r19-r30 are temp for each code section */ | ||
37 | #define PREFETCH_DIST 8 | ||
38 | #define src_pre_mem r19 | ||
39 | #define dst_pre_mem r20 | ||
40 | #define src_pre_l2 r21 | ||
41 | #define dst_pre_l2 r22 | ||
42 | #define t1 r23 | ||
43 | #define t2 r24 | ||
44 | #define t3 r25 | ||
45 | #define t4 r26 | ||
46 | #define t5 t1 // alias! | ||
47 | #define t6 t2 // alias! | ||
48 | #define t7 t3 // alias! | ||
49 | #define n8 r27 | ||
50 | #define t9 t5 // alias! | ||
51 | #define t10 t4 // alias! | ||
52 | #define t11 t7 // alias! | ||
53 | #define t12 t6 // alias! | ||
54 | #define t14 t10 // alias! | ||
55 | #define t13 r28 | ||
56 | #define t15 r29 | ||
57 | #define tmp r30 | ||
58 | |||
59 | /* defines for long_copy block */ | ||
60 | #define A 0 | ||
61 | #define B (PREFETCH_DIST) | ||
62 | #define C (B + PREFETCH_DIST) | ||
63 | #define D (C + 1) | ||
64 | #define N (D + 1) | ||
65 | #define Nrot ((N + 7) & ~7) | ||
66 | |||
67 | /* alias */ | ||
68 | #define in0 r32 | ||
69 | #define in1 r33 | ||
70 | #define in2 r34 | ||
71 | |||
72 | GLOBAL_ENTRY(memcpy) | ||
73 | and r28=0x7,in0 | ||
74 | and r29=0x7,in1 | ||
75 | mov f6=f0 | ||
76 | br.cond.sptk .common_code | ||
77 | ;; | ||
78 | GLOBAL_ENTRY(__copy_user) | ||
79 | .prologue | ||
80 | // check dest alignment | ||
81 | and r28=0x7,in0 | ||
82 | and r29=0x7,in1 | ||
83 | mov f6=f1 | ||
84 | mov saved_in0=in0 // save dest pointer | ||
85 | mov saved_in1=in1 // save src pointer | ||
86 | mov saved_in2=in2 // save len | ||
87 | ;; | ||
88 | .common_code: | ||
89 | cmp.gt p15,p0=8,in2 // check for small size | ||
90 | cmp.ne p13,p0=0,r28 // check dest alignment | ||
91 | cmp.ne p14,p0=0,r29 // check src alignment | ||
92 | add src0=0,in1 | ||
93 | sub r30=8,r28 // for .align_dest | ||
94 | mov retval=r0 // initialize return value | ||
95 | ;; | ||
96 | add dst0=0,in0 | ||
97 | add dst1=1,in0 // dest odd index | ||
98 | cmp.le p6,p0 = 1,r30 // for .align_dest | ||
99 | (p15) br.cond.dpnt .memcpy_short | ||
100 | (p13) br.cond.dpnt .align_dest | ||
101 | (p14) br.cond.dpnt .unaligned_src | ||
102 | ;; | ||
103 | |||
104 | // both dest and src are aligned on 8-byte boundary | ||
105 | .aligned_src: | ||
106 | .save ar.pfs, saved_pfs | ||
107 | alloc saved_pfs=ar.pfs,3,Nrot-3,0,Nrot | ||
108 | .save pr, saved_pr | ||
109 | mov saved_pr=pr | ||
110 | |||
111 | shr.u cnt=in2,7 // this much cache line | ||
112 | ;; | ||
113 | cmp.lt p6,p0=2*PREFETCH_DIST,cnt | ||
114 | cmp.lt p7,p8=1,cnt | ||
115 | .save ar.lc, saved_lc | ||
116 | mov saved_lc=ar.lc | ||
117 | .body | ||
118 | add cnt=-1,cnt | ||
119 | add src_pre_mem=0,in1 // prefetch src pointer | ||
120 | add dst_pre_mem=0,in0 // prefetch dest pointer | ||
121 | ;; | ||
122 | (p7) mov ar.lc=cnt // prefetch count | ||
123 | (p8) mov ar.lc=r0 | ||
124 | (p6) br.cond.dpnt .long_copy | ||
125 | ;; | ||
126 | |||
127 | .prefetch: | ||
128 | lfetch.fault [src_pre_mem], 128 | ||
129 | lfetch.fault.excl [dst_pre_mem], 128 | ||
130 | br.cloop.dptk.few .prefetch | ||
131 | ;; | ||
132 | |||
133 | .medium_copy: | ||
134 | and tmp=31,in2 // copy length after iteration | ||
135 | shr.u r29=in2,5 // number of 32-byte iteration | ||
136 | add dst1=8,dst0 // 2nd dest pointer | ||
137 | ;; | ||
138 | add cnt=-1,r29 // ctop iteration adjustment | ||
139 | cmp.eq p10,p0=r29,r0 // do we really need to loop? | ||
140 | add src1=8,src0 // 2nd src pointer | ||
141 | cmp.le p6,p0=8,tmp | ||
142 | ;; | ||
143 | cmp.le p7,p0=16,tmp | ||
144 | mov ar.lc=cnt // loop setup | ||
145 | cmp.eq p16,p17 = r0,r0 | ||
146 | mov ar.ec=2 | ||
147 | (p10) br.dpnt.few .aligned_src_tail | ||
148 | ;; | ||
149 | TEXT_ALIGN(32) | ||
150 | 1: | ||
151 | EX(.ex_handler, (p16) ld8 r34=[src0],16) | ||
152 | EK(.ex_handler, (p16) ld8 r38=[src1],16) | ||
153 | EX(.ex_handler, (p17) st8 [dst0]=r33,16) | ||
154 | EK(.ex_handler, (p17) st8 [dst1]=r37,16) | ||
155 | ;; | ||
156 | EX(.ex_handler, (p16) ld8 r32=[src0],16) | ||
157 | EK(.ex_handler, (p16) ld8 r36=[src1],16) | ||
158 | EX(.ex_handler, (p16) st8 [dst0]=r34,16) | ||
159 | EK(.ex_handler, (p16) st8 [dst1]=r38,16) | ||
160 | br.ctop.dptk.few 1b | ||
161 | ;; | ||
162 | |||
163 | .aligned_src_tail: | ||
164 | EX(.ex_handler, (p6) ld8 t1=[src0]) | ||
165 | mov ar.lc=saved_lc | ||
166 | mov ar.pfs=saved_pfs | ||
167 | EX(.ex_hndlr_s, (p7) ld8 t2=[src1],8) | ||
168 | cmp.le p8,p0=24,tmp | ||
169 | and r21=-8,tmp | ||
170 | ;; | ||
171 | EX(.ex_hndlr_s, (p8) ld8 t3=[src1]) | ||
172 | EX(.ex_handler, (p6) st8 [dst0]=t1) // store byte 1 | ||
173 | and in2=7,tmp // remaining length | ||
174 | EX(.ex_hndlr_d, (p7) st8 [dst1]=t2,8) // store byte 2 | ||
175 | add src0=src0,r21 // setting up src pointer | ||
176 | add dst0=dst0,r21 // setting up dest pointer | ||
177 | ;; | ||
178 | EX(.ex_handler, (p8) st8 [dst1]=t3) // store byte 3 | ||
179 | mov pr=saved_pr,-1 | ||
180 | br.dptk.many .memcpy_short | ||
181 | ;; | ||
182 | |||
183 | /* code taken from copy_page_mck */ | ||
184 | .long_copy: | ||
185 | .rotr v[2*PREFETCH_DIST] | ||
186 | .rotp p[N] | ||
187 | |||
188 | mov src_pre_mem = src0 | ||
189 | mov pr.rot = 0x10000 | ||
190 | mov ar.ec = 1 // special unrolled loop | ||
191 | |||
192 | mov dst_pre_mem = dst0 | ||
193 | |||
194 | add src_pre_l2 = 8*8, src0 | ||
195 | add dst_pre_l2 = 8*8, dst0 | ||
196 | ;; | ||
197 | add src0 = 8, src_pre_mem // first t1 src | ||
198 | mov ar.lc = 2*PREFETCH_DIST - 1 | ||
199 | shr.u cnt=in2,7 // number of lines | ||
200 | add src1 = 3*8, src_pre_mem // first t3 src | ||
201 | add dst0 = 8, dst_pre_mem // first t1 dst | ||
202 | add dst1 = 3*8, dst_pre_mem // first t3 dst | ||
203 | ;; | ||
204 | and tmp=127,in2 // remaining bytes after this block | ||
205 | add cnt = -(2*PREFETCH_DIST) - 1, cnt | ||
206 | // same as .line_copy loop, but with all predicated-off instructions removed: | ||
207 | .prefetch_loop: | ||
208 | EX(.ex_hndlr_lcpy_1, (p[A]) ld8 v[A] = [src_pre_mem], 128) // M0 | ||
209 | EK(.ex_hndlr_lcpy_1, (p[B]) st8 [dst_pre_mem] = v[B], 128) // M2 | ||
210 | br.ctop.sptk .prefetch_loop | ||
211 | ;; | ||
212 | cmp.eq p16, p0 = r0, r0 // reset p16 to 1 | ||
213 | mov ar.lc = cnt | ||
214 | mov ar.ec = N // # of stages in pipeline | ||
215 | ;; | ||
216 | .line_copy: | ||
217 | EX(.ex_handler, (p[D]) ld8 t2 = [src0], 3*8) // M0 | ||
218 | EK(.ex_handler, (p[D]) ld8 t4 = [src1], 3*8) // M1 | ||
219 | EX(.ex_handler_lcpy, (p[B]) st8 [dst_pre_mem] = v[B], 128) // M2 prefetch dst from memory | ||
220 | EK(.ex_handler_lcpy, (p[D]) st8 [dst_pre_l2] = n8, 128) // M3 prefetch dst from L2 | ||
221 | ;; | ||
222 | EX(.ex_handler_lcpy, (p[A]) ld8 v[A] = [src_pre_mem], 128) // M0 prefetch src from memory | ||
223 | EK(.ex_handler_lcpy, (p[C]) ld8 n8 = [src_pre_l2], 128) // M1 prefetch src from L2 | ||
224 | EX(.ex_handler, (p[D]) st8 [dst0] = t1, 8) // M2 | ||
225 | EK(.ex_handler, (p[D]) st8 [dst1] = t3, 8) // M3 | ||
226 | ;; | ||
227 | EX(.ex_handler, (p[D]) ld8 t5 = [src0], 8) | ||
228 | EK(.ex_handler, (p[D]) ld8 t7 = [src1], 3*8) | ||
229 | EX(.ex_handler, (p[D]) st8 [dst0] = t2, 3*8) | ||
230 | EK(.ex_handler, (p[D]) st8 [dst1] = t4, 3*8) | ||
231 | ;; | ||
232 | EX(.ex_handler, (p[D]) ld8 t6 = [src0], 3*8) | ||
233 | EK(.ex_handler, (p[D]) ld8 t10 = [src1], 8) | ||
234 | EX(.ex_handler, (p[D]) st8 [dst0] = t5, 8) | ||
235 | EK(.ex_handler, (p[D]) st8 [dst1] = t7, 3*8) | ||
236 | ;; | ||
237 | EX(.ex_handler, (p[D]) ld8 t9 = [src0], 3*8) | ||
238 | EK(.ex_handler, (p[D]) ld8 t11 = [src1], 3*8) | ||
239 | EX(.ex_handler, (p[D]) st8 [dst0] = t6, 3*8) | ||
240 | EK(.ex_handler, (p[D]) st8 [dst1] = t10, 8) | ||
241 | ;; | ||
242 | EX(.ex_handler, (p[D]) ld8 t12 = [src0], 8) | ||
243 | EK(.ex_handler, (p[D]) ld8 t14 = [src1], 8) | ||
244 | EX(.ex_handler, (p[D]) st8 [dst0] = t9, 3*8) | ||
245 | EK(.ex_handler, (p[D]) st8 [dst1] = t11, 3*8) | ||
246 | ;; | ||
247 | EX(.ex_handler, (p[D]) ld8 t13 = [src0], 4*8) | ||
248 | EK(.ex_handler, (p[D]) ld8 t15 = [src1], 4*8) | ||
249 | EX(.ex_handler, (p[D]) st8 [dst0] = t12, 8) | ||
250 | EK(.ex_handler, (p[D]) st8 [dst1] = t14, 8) | ||
251 | ;; | ||
252 | EX(.ex_handler, (p[C]) ld8 t1 = [src0], 8) | ||
253 | EK(.ex_handler, (p[C]) ld8 t3 = [src1], 8) | ||
254 | EX(.ex_handler, (p[D]) st8 [dst0] = t13, 4*8) | ||
255 | EK(.ex_handler, (p[D]) st8 [dst1] = t15, 4*8) | ||
256 | br.ctop.sptk .line_copy | ||
257 | ;; | ||
258 | |||
259 | add dst0=-8,dst0 | ||
260 | add src0=-8,src0 | ||
261 | mov in2=tmp | ||
262 | .restore sp | ||
263 | br.sptk.many .medium_copy | ||
264 | ;; | ||
265 | |||
266 | #define BLOCK_SIZE 128*32 | ||
267 | #define blocksize r23 | ||
268 | #define curlen r24 | ||
269 | |||
270 | // dest is on 8-byte boundary, src is not. We need to do | ||
271 | // ld8-ld8, shrp, then st8. Max 8 byte copy per cycle. | ||
272 | .unaligned_src: | ||
273 | .prologue | ||
274 | .save ar.pfs, saved_pfs | ||
275 | alloc saved_pfs=ar.pfs,3,5,0,8 | ||
276 | .save ar.lc, saved_lc | ||
277 | mov saved_lc=ar.lc | ||
278 | .save pr, saved_pr | ||
279 | mov saved_pr=pr | ||
280 | .body | ||
281 | .4k_block: | ||
282 | mov saved_in0=dst0 // need to save all input arguments | ||
283 | mov saved_in2=in2 | ||
284 | mov blocksize=BLOCK_SIZE | ||
285 | ;; | ||
286 | cmp.lt p6,p7=blocksize,in2 | ||
287 | mov saved_in1=src0 | ||
288 | ;; | ||
289 | (p6) mov in2=blocksize | ||
290 | ;; | ||
291 | shr.u r21=in2,7 // this much cache line | ||
292 | shr.u r22=in2,4 // number of 16-byte iteration | ||
293 | and curlen=15,in2 // copy length after iteration | ||
294 | and r30=7,src0 // source alignment | ||
295 | ;; | ||
296 | cmp.lt p7,p8=1,r21 | ||
297 | add cnt=-1,r21 | ||
298 | ;; | ||
299 | |||
300 | add src_pre_mem=0,src0 // prefetch src pointer | ||
301 | add dst_pre_mem=0,dst0 // prefetch dest pointer | ||
302 | and src0=-8,src0 // 1st src pointer | ||
303 | (p7) mov ar.lc = r21 | ||
304 | (p8) mov ar.lc = r0 | ||
305 | ;; | ||
306 | TEXT_ALIGN(32) | ||
307 | 1: lfetch.fault [src_pre_mem], 128 | ||
308 | lfetch.fault.excl [dst_pre_mem], 128 | ||
309 | br.cloop.dptk.few 1b | ||
310 | ;; | ||
311 | |||
312 | shladd dst1=r22,3,dst0 // 2nd dest pointer | ||
313 | shladd src1=r22,3,src0 // 2nd src pointer | ||
314 | cmp.eq p8,p9=r22,r0 // do we really need to loop? | ||
315 | cmp.le p6,p7=8,curlen; // have at least 8 byte remaining? | ||
316 | add cnt=-1,r22 // ctop iteration adjustment | ||
317 | ;; | ||
318 | EX(.ex_handler, (p9) ld8 r33=[src0],8) // loop primer | ||
319 | EK(.ex_handler, (p9) ld8 r37=[src1],8) | ||
320 | (p8) br.dpnt.few .noloop | ||
321 | ;; | ||
322 | |||
323 | // The jump address is calculated based on src alignment. The COPYU | ||
324 | // macro below need to confine its size to power of two, so an entry | ||
325 | // can be caulated using shl instead of an expensive multiply. The | ||
326 | // size is then hard coded by the following #define to match the | ||
327 | // actual size. This make it somewhat tedious when COPYU macro gets | ||
328 | // changed and this need to be adjusted to match. | ||
329 | #define LOOP_SIZE 6 | ||
330 | 1: | ||
331 | mov r29=ip // jmp_table thread | ||
332 | mov ar.lc=cnt | ||
333 | ;; | ||
334 | add r29=.jump_table - 1b - (.jmp1-.jump_table), r29 | ||
335 | shl r28=r30, LOOP_SIZE // jmp_table thread | ||
336 | mov ar.ec=2 // loop setup | ||
337 | ;; | ||
338 | add r29=r29,r28 // jmp_table thread | ||
339 | cmp.eq p16,p17=r0,r0 | ||
340 | ;; | ||
341 | mov b6=r29 // jmp_table thread | ||
342 | ;; | ||
343 | br.cond.sptk.few b6 | ||
344 | |||
345 | // for 8-15 byte case | ||
346 | // We will skip the loop, but need to replicate the side effect | ||
347 | // that the loop produces. | ||
348 | .noloop: | ||
349 | EX(.ex_handler, (p6) ld8 r37=[src1],8) | ||
350 | add src0=8,src0 | ||
351 | (p6) shl r25=r30,3 | ||
352 | ;; | ||
353 | EX(.ex_handler, (p6) ld8 r27=[src1]) | ||
354 | (p6) shr.u r28=r37,r25 | ||
355 | (p6) sub r26=64,r25 | ||
356 | ;; | ||
357 | (p6) shl r27=r27,r26 | ||
358 | ;; | ||
359 | (p6) or r21=r28,r27 | ||
360 | |||
361 | .unaligned_src_tail: | ||
362 | /* check if we have more than blocksize to copy, if so go back */ | ||
363 | cmp.gt p8,p0=saved_in2,blocksize | ||
364 | ;; | ||
365 | (p8) add dst0=saved_in0,blocksize | ||
366 | (p8) add src0=saved_in1,blocksize | ||
367 | (p8) sub in2=saved_in2,blocksize | ||
368 | (p8) br.dpnt .4k_block | ||
369 | ;; | ||
370 | |||
371 | /* we have up to 15 byte to copy in the tail. | ||
372 | * part of work is already done in the jump table code | ||
373 | * we are at the following state. | ||
374 | * src side: | ||
375 | * | ||
376 | * xxxxxx xx <----- r21 has xxxxxxxx already | ||
377 | * -------- -------- -------- | ||
378 | * 0 8 16 | ||
379 | * ^ | ||
380 | * | | ||
381 | * src1 | ||
382 | * | ||
383 | * dst | ||
384 | * -------- -------- -------- | ||
385 | * ^ | ||
386 | * | | ||
387 | * dst1 | ||
388 | */ | ||
389 | EX(.ex_handler, (p6) st8 [dst1]=r21,8) // more than 8 byte to copy | ||
390 | (p6) add curlen=-8,curlen // update length | ||
391 | mov ar.pfs=saved_pfs | ||
392 | ;; | ||
393 | mov ar.lc=saved_lc | ||
394 | mov pr=saved_pr,-1 | ||
395 | mov in2=curlen // remaining length | ||
396 | mov dst0=dst1 // dest pointer | ||
397 | add src0=src1,r30 // forward by src alignment | ||
398 | ;; | ||
399 | |||
400 | // 7 byte or smaller. | ||
401 | .memcpy_short: | ||
402 | cmp.le p8,p9 = 1,in2 | ||
403 | cmp.le p10,p11 = 2,in2 | ||
404 | cmp.le p12,p13 = 3,in2 | ||
405 | cmp.le p14,p15 = 4,in2 | ||
406 | add src1=1,src0 // second src pointer | ||
407 | add dst1=1,dst0 // second dest pointer | ||
408 | ;; | ||
409 | |||
410 | EX(.ex_handler_short, (p8) ld1 t1=[src0],2) | ||
411 | EK(.ex_handler_short, (p10) ld1 t2=[src1],2) | ||
412 | (p9) br.ret.dpnt rp // 0 byte copy | ||
413 | ;; | ||
414 | |||
415 | EX(.ex_handler_short, (p8) st1 [dst0]=t1,2) | ||
416 | EK(.ex_handler_short, (p10) st1 [dst1]=t2,2) | ||
417 | (p11) br.ret.dpnt rp // 1 byte copy | ||
418 | |||
419 | EX(.ex_handler_short, (p12) ld1 t3=[src0],2) | ||
420 | EK(.ex_handler_short, (p14) ld1 t4=[src1],2) | ||
421 | (p13) br.ret.dpnt rp // 2 byte copy | ||
422 | ;; | ||
423 | |||
424 | cmp.le p6,p7 = 5,in2 | ||
425 | cmp.le p8,p9 = 6,in2 | ||
426 | cmp.le p10,p11 = 7,in2 | ||
427 | |||
428 | EX(.ex_handler_short, (p12) st1 [dst0]=t3,2) | ||
429 | EK(.ex_handler_short, (p14) st1 [dst1]=t4,2) | ||
430 | (p15) br.ret.dpnt rp // 3 byte copy | ||
431 | ;; | ||
432 | |||
433 | EX(.ex_handler_short, (p6) ld1 t5=[src0],2) | ||
434 | EK(.ex_handler_short, (p8) ld1 t6=[src1],2) | ||
435 | (p7) br.ret.dpnt rp // 4 byte copy | ||
436 | ;; | ||
437 | |||
438 | EX(.ex_handler_short, (p6) st1 [dst0]=t5,2) | ||
439 | EK(.ex_handler_short, (p8) st1 [dst1]=t6,2) | ||
440 | (p9) br.ret.dptk rp // 5 byte copy | ||
441 | |||
442 | EX(.ex_handler_short, (p10) ld1 t7=[src0],2) | ||
443 | (p11) br.ret.dptk rp // 6 byte copy | ||
444 | ;; | ||
445 | |||
446 | EX(.ex_handler_short, (p10) st1 [dst0]=t7,2) | ||
447 | br.ret.dptk rp // done all cases | ||
448 | |||
449 | |||
450 | /* Align dest to nearest 8-byte boundary. We know we have at | ||
451 | * least 7 bytes to copy, enough to crawl to 8-byte boundary. | ||
452 | * Actual number of byte to crawl depend on the dest alignment. | ||
453 | * 7 byte or less is taken care at .memcpy_short | ||
454 | |||
455 | * src0 - source even index | ||
456 | * src1 - source odd index | ||
457 | * dst0 - dest even index | ||
458 | * dst1 - dest odd index | ||
459 | * r30 - distance to 8-byte boundary | ||
460 | */ | ||
461 | |||
462 | .align_dest: | ||
463 | add src1=1,in1 // source odd index | ||
464 | cmp.le p7,p0 = 2,r30 // for .align_dest | ||
465 | cmp.le p8,p0 = 3,r30 // for .align_dest | ||
466 | EX(.ex_handler_short, (p6) ld1 t1=[src0],2) | ||
467 | cmp.le p9,p0 = 4,r30 // for .align_dest | ||
468 | cmp.le p10,p0 = 5,r30 | ||
469 | ;; | ||
470 | EX(.ex_handler_short, (p7) ld1 t2=[src1],2) | ||
471 | EK(.ex_handler_short, (p8) ld1 t3=[src0],2) | ||
472 | cmp.le p11,p0 = 6,r30 | ||
473 | EX(.ex_handler_short, (p6) st1 [dst0] = t1,2) | ||
474 | cmp.le p12,p0 = 7,r30 | ||
475 | ;; | ||
476 | EX(.ex_handler_short, (p9) ld1 t4=[src1],2) | ||
477 | EK(.ex_handler_short, (p10) ld1 t5=[src0],2) | ||
478 | EX(.ex_handler_short, (p7) st1 [dst1] = t2,2) | ||
479 | EK(.ex_handler_short, (p8) st1 [dst0] = t3,2) | ||
480 | ;; | ||
481 | EX(.ex_handler_short, (p11) ld1 t6=[src1],2) | ||
482 | EK(.ex_handler_short, (p12) ld1 t7=[src0],2) | ||
483 | cmp.eq p6,p7=r28,r29 | ||
484 | EX(.ex_handler_short, (p9) st1 [dst1] = t4,2) | ||
485 | EK(.ex_handler_short, (p10) st1 [dst0] = t5,2) | ||
486 | sub in2=in2,r30 | ||
487 | ;; | ||
488 | EX(.ex_handler_short, (p11) st1 [dst1] = t6,2) | ||
489 | EK(.ex_handler_short, (p12) st1 [dst0] = t7) | ||
490 | add dst0=in0,r30 // setup arguments | ||
491 | add src0=in1,r30 | ||
492 | (p6) br.cond.dptk .aligned_src | ||
493 | (p7) br.cond.dpnt .unaligned_src | ||
494 | ;; | ||
495 | |||
496 | /* main loop body in jump table format */ | ||
497 | #define COPYU(shift) \ | ||
498 | 1: \ | ||
499 | EX(.ex_handler, (p16) ld8 r32=[src0],8); /* 1 */ \ | ||
500 | EK(.ex_handler, (p16) ld8 r36=[src1],8); \ | ||
501 | (p17) shrp r35=r33,r34,shift;; /* 1 */ \ | ||
502 | EX(.ex_handler, (p6) ld8 r22=[src1]); /* common, prime for tail section */ \ | ||
503 | nop.m 0; \ | ||
504 | (p16) shrp r38=r36,r37,shift; \ | ||
505 | EX(.ex_handler, (p17) st8 [dst0]=r35,8); /* 1 */ \ | ||
506 | EK(.ex_handler, (p17) st8 [dst1]=r39,8); \ | ||
507 | br.ctop.dptk.few 1b;; \ | ||
508 | (p7) add src1=-8,src1; /* back out for <8 byte case */ \ | ||
509 | shrp r21=r22,r38,shift; /* speculative work */ \ | ||
510 | br.sptk.few .unaligned_src_tail /* branch out of jump table */ \ | ||
511 | ;; | ||
512 | TEXT_ALIGN(32) | ||
513 | .jump_table: | ||
514 | COPYU(8) // unaligned cases | ||
515 | .jmp1: | ||
516 | COPYU(16) | ||
517 | COPYU(24) | ||
518 | COPYU(32) | ||
519 | COPYU(40) | ||
520 | COPYU(48) | ||
521 | COPYU(56) | ||
522 | |||
523 | #undef A | ||
524 | #undef B | ||
525 | #undef C | ||
526 | #undef D | ||
527 | END(memcpy) | ||
528 | |||
529 | /* | ||
530 | * Due to lack of local tag support in gcc 2.x assembler, it is not clear which | ||
531 | * instruction failed in the bundle. The exception algorithm is that we | ||
532 | * first figure out the faulting address, then detect if there is any | ||
533 | * progress made on the copy, if so, redo the copy from last known copied | ||
534 | * location up to the faulting address (exclusive). In the copy_from_user | ||
535 | * case, remaining byte in kernel buffer will be zeroed. | ||
536 | * | ||
537 | * Take copy_from_user as an example, in the code there are multiple loads | ||
538 | * in a bundle and those multiple loads could span over two pages, the | ||
539 | * faulting address is calculated as page_round_down(max(src0, src1)). | ||
540 | * This is based on knowledge that if we can access one byte in a page, we | ||
541 | * can access any byte in that page. | ||
542 | * | ||
543 | * predicate used in the exception handler: | ||
544 | * p6-p7: direction | ||
545 | * p10-p11: src faulting addr calculation | ||
546 | * p12-p13: dst faulting addr calculation | ||
547 | */ | ||
548 | |||
549 | #define A r19 | ||
550 | #define B r20 | ||
551 | #define C r21 | ||
552 | #define D r22 | ||
553 | #define F r28 | ||
554 | |||
555 | #define memset_arg0 r32 | ||
556 | #define memset_arg2 r33 | ||
557 | |||
558 | #define saved_retval loc0 | ||
559 | #define saved_rtlink loc1 | ||
560 | #define saved_pfs_stack loc2 | ||
561 | |||
562 | .ex_hndlr_s: | ||
563 | add src0=8,src0 | ||
564 | br.sptk .ex_handler | ||
565 | ;; | ||
566 | .ex_hndlr_d: | ||
567 | add dst0=8,dst0 | ||
568 | br.sptk .ex_handler | ||
569 | ;; | ||
570 | .ex_hndlr_lcpy_1: | ||
571 | mov src1=src_pre_mem | ||
572 | mov dst1=dst_pre_mem | ||
573 | cmp.gtu p10,p11=src_pre_mem,saved_in1 | ||
574 | cmp.gtu p12,p13=dst_pre_mem,saved_in0 | ||
575 | ;; | ||
576 | (p10) add src0=8,saved_in1 | ||
577 | (p11) mov src0=saved_in1 | ||
578 | (p12) add dst0=8,saved_in0 | ||
579 | (p13) mov dst0=saved_in0 | ||
580 | br.sptk .ex_handler | ||
581 | .ex_handler_lcpy: | ||
582 | // in line_copy block, the preload addresses should always ahead | ||
583 | // of the other two src/dst pointers. Furthermore, src1/dst1 should | ||
584 | // always ahead of src0/dst0. | ||
585 | mov src1=src_pre_mem | ||
586 | mov dst1=dst_pre_mem | ||
587 | .ex_handler: | ||
588 | mov pr=saved_pr,-1 // first restore pr, lc, and pfs | ||
589 | mov ar.lc=saved_lc | ||
590 | mov ar.pfs=saved_pfs | ||
591 | ;; | ||
592 | .ex_handler_short: // fault occurred in these sections didn't change pr, lc, pfs | ||
593 | cmp.ltu p6,p7=saved_in0, saved_in1 // get the copy direction | ||
594 | cmp.ltu p10,p11=src0,src1 | ||
595 | cmp.ltu p12,p13=dst0,dst1 | ||
596 | fcmp.eq p8,p0=f6,f0 // is it memcpy? | ||
597 | mov tmp = dst0 | ||
598 | ;; | ||
599 | (p11) mov src1 = src0 // pick the larger of the two | ||
600 | (p13) mov dst0 = dst1 // make dst0 the smaller one | ||
601 | (p13) mov dst1 = tmp // and dst1 the larger one | ||
602 | ;; | ||
603 | (p6) dep F = r0,dst1,0,PAGE_SHIFT // usr dst round down to page boundary | ||
604 | (p7) dep F = r0,src1,0,PAGE_SHIFT // usr src round down to page boundary | ||
605 | ;; | ||
606 | (p6) cmp.le p14,p0=dst0,saved_in0 // no progress has been made on store | ||
607 | (p7) cmp.le p14,p0=src0,saved_in1 // no progress has been made on load | ||
608 | mov retval=saved_in2 | ||
609 | (p8) ld1 tmp=[src1] // force an oops for memcpy call | ||
610 | (p8) st1 [dst1]=r0 // force an oops for memcpy call | ||
611 | (p14) br.ret.sptk.many rp | ||
612 | |||
613 | /* | ||
614 | * The remaining byte to copy is calculated as: | ||
615 | * | ||
616 | * A = (faulting_addr - orig_src) -> len to faulting ld address | ||
617 | * or | ||
618 | * (faulting_addr - orig_dst) -> len to faulting st address | ||
619 | * B = (cur_dst - orig_dst) -> len copied so far | ||
620 | * C = A - B -> len need to be copied | ||
621 | * D = orig_len - A -> len need to be zeroed | ||
622 | */ | ||
623 | (p6) sub A = F, saved_in0 | ||
624 | (p7) sub A = F, saved_in1 | ||
625 | clrrrb | ||
626 | ;; | ||
627 | alloc saved_pfs_stack=ar.pfs,3,3,3,0 | ||
628 | sub B = dst0, saved_in0 // how many byte copied so far | ||
629 | ;; | ||
630 | sub C = A, B | ||
631 | sub D = saved_in2, A | ||
632 | ;; | ||
633 | cmp.gt p8,p0=C,r0 // more than 1 byte? | ||
634 | add memset_arg0=saved_in0, A | ||
635 | (p6) mov memset_arg2=0 // copy_to_user should not call memset | ||
636 | (p7) mov memset_arg2=D // copy_from_user need to have kbuf zeroed | ||
637 | mov r8=0 | ||
638 | mov saved_retval = D | ||
639 | mov saved_rtlink = b0 | ||
640 | |||
641 | add out0=saved_in0, B | ||
642 | add out1=saved_in1, B | ||
643 | mov out2=C | ||
644 | (p8) br.call.sptk.few b0=__copy_user // recursive call | ||
645 | ;; | ||
646 | |||
647 | add saved_retval=saved_retval,r8 // above might return non-zero value | ||
648 | cmp.gt p8,p0=memset_arg2,r0 // more than 1 byte? | ||
649 | mov out0=memset_arg0 // *s | ||
650 | mov out1=r0 // c | ||
651 | mov out2=memset_arg2 // n | ||
652 | (p8) br.call.sptk.few b0=memset | ||
653 | ;; | ||
654 | |||
655 | mov retval=saved_retval | ||
656 | mov ar.pfs=saved_pfs_stack | ||
657 | mov b0=saved_rtlink | ||
658 | br.ret.sptk.many rp | ||
659 | |||
660 | /* end of McKinley specific optimization */ | ||
661 | END(__copy_user) | ||