1 /* $Id: U3copy_from_user.S,v 1.4 2002/01/15 07:16:26 davem Exp $
2 * U3memcpy.S: UltraSparc-III optimized copy from userspace.
4 * Copyright (C) 1999, 2000 David S. Miller (davem@redhat.com)
8 #include <asm/visasm.h>
11 #include <asm/spitfire.h>
12 #undef SMALL_COPY_USES_FPU
13 #define EXNV(x,y,a,b) \
20 .section __ex_table; \
32 .section __ex_table; \
42 and %o2, (0x40 - 1), %o1; \
45 add %o1, 0x1c0, %o1; \
46 .section __ex_table; \
56 and %o2, (0x40 - 1), %o1; \
61 .section __ex_table; \
71 and %o2, (0x40 - 1), %o1; \
75 .section __ex_table; \
81 #define ASI_BLK_P 0xf0
83 #define VISEntryHalf rd %fprs, %o5; wr %g0, FPRS_FEF, %fprs
84 #define VISExitHalf and %o5, FPRS_FEF, %o5; wr %o5, 0x0, %fprs
85 #define SMALL_COPY_USES_FPU
86 #define EXNV(x,y,a,b) x,y;
87 #define EX(x,y,a,b) x,y;
93 /* Special/non-trivial issues of this code:
95 * 1) %o5 is preserved from VISEntryHalf to VISExitHalf
96 * 2) Only low 32 FPU registers are used so that only the
97 * lower half of the FPU register set is dirtied by this
98 * code. This is especially important in the kernel.
99 * 3) This code never prefetches cachelines past the end
100 * of the source buffer.
106 /* The cheetah's flexible spine, oversized liver, enlarged heart,
107 * slender muscular body, and claws make it the swiftest hunter
108 * in Africa and the fastest animal on land. Can reach speeds
109 * of up to 2.4GB per second.
112 .globl U3copy_from_user
113 U3copy_from_user: /* %o0=dst, %o1=src, %o2=len */
115 /* Save away original 'dst' for memcpy return value. */
116 mov %o0, %g3 ! A0 Group
118 /* Anything to copy at all? */
120 ble,pn %icc, U3copy_from_user_short_ret! BR
122 /* Extremely small copy? */
123 cmp %o2, 31 ! A0 Group
124 ble,pn %icc, U3copy_from_user_short ! BR
126 /* Large enough to use unrolled prefetch loops? */
128 bge,a,pt %icc, U3copy_from_user_enter ! BR Group
129 andcc %o0, 0x3f, %g2 ! A0
131 ba,pt %xcc, U3copy_from_user_toosmall ! BR Group
132 andcc %o0, 0x7, %g2 ! A0
135 U3copy_from_user_short:
136 /* Copy %o2 bytes from src to dst, one byte at a time. */
137 EXNV(lduba [%o1 + 0x00] %asi, %o3, add %o2, %g0)! MS Group
138 add %o1, 0x1, %o1 ! A0
139 add %o0, 0x1, %o0 ! A1
140 subcc %o2, 1, %o2 ! A0 Group
142 bg,pt %icc, U3copy_from_user_short ! BR
143 stb %o3, [%o0 + -1] ! MS Group (1-cycle stall)
145 U3copy_from_user_short_ret:
147 retl ! BR Group (0-4 cycle stall)
150 retl ! BR Group (0-4 cycle stall)
154 /* Here len >= (6 * 64) and condition codes reflect execution
155 * of "andcc %o0, 0x7, %g2", done by caller.
158 U3copy_from_user_enter:
159 /* Is 'dst' already aligned on an 64-byte boundary? */
162 /* Compute abs((dst & 0x3f) - 0x40) into %g2. This is the number
163 * of bytes to copy to make 'dst' 64-byte aligned. We pre-
164 * subtract this from 'len'.
166 sub %g2, 0x40, %g2 ! A0 Group
167 sub %g0, %g2, %g2 ! A0 Group
168 sub %o2, %g2, %o2 ! A0 Group
170 /* Copy %g2 bytes from src to dst, one byte at a time. */
171 1: EXNV(lduba [%o1 + 0x00] %asi, %o3, add %o2, %g2)! MS (Group)
172 add %o1, 0x1, %o1 ! A1
173 add %o0, 0x1, %o0 ! A0 Group
174 subcc %g2, 0x1, %g2 ! A1
176 bg,pt %icc, 1b ! BR Group
177 stb %o3, [%o0 + -1] ! MS Group
179 2: VISEntryHalf ! MS+MS
180 and %o1, 0x7, %g1 ! A1
181 ba,pt %xcc, U3copy_from_user_begin ! BR
182 alignaddr %o1, %g0, %o1 ! MS (Break-after)
185 U3copy_from_user_begin:
187 .globl U3copy_from_user_nop_1_6
188 U3copy_from_user_nop_1_6:
189 ldxa [%g0] ASI_DCU_CONTROL_REG, %g3
190 sethi %uhi(DCU_PE), %o3
193 stxa %o3, [%g0] ASI_DCU_CONTROL_REG ! Enable P-cache
196 prefetcha [%o1 + 0x000] %asi, #one_read ! MS Group1
197 prefetcha [%o1 + 0x040] %asi, #one_read ! MS Group2
198 andn %o2, (0x40 - 1), %o4 ! A0
199 prefetcha [%o1 + 0x080] %asi, #one_read ! MS Group3
201 prefetcha [%o1 + 0x0c0] %asi, #one_read ! MS Group4
202 EX(ldda [%o1 + 0x000] %asi, %f0, add %o2, %g0) ! MS Group5 (%f0 results at G8)
203 bge,a,pt %icc, 1f ! BR
205 prefetcha [%o1 + 0x100] %asi, #one_read ! MS Group6
206 1: EX(ldda [%o1 + 0x008] %asi, %f2, add %o2, %g0) ! AX (%f2 results at G9)
208 bge,a,pt %icc, 1f ! BR
209 prefetcha [%o1 + 0x140] %asi, #one_read ! MS Group7
210 1: EX(ldda [%o1 + 0x010] %asi, %f4, add %o2, %g0) ! AX (%f4 results at G10)
212 bge,a,pt %icc, 1f ! BR
214 prefetcha [%o1 + 0x180] %asi, #one_read ! MS Group8
215 1: faligndata %f0, %f2, %f16 ! FGA Group9 (%f16 at G12)
216 EX(ldda [%o1 + 0x018] %asi, %f6, add %o2, %g0) ! AX (%f6 results at G12)
217 faligndata %f2, %f4, %f18 ! FGA Group10 (%f18 results at G13)
218 EX(ldda [%o1 + 0x020] %asi, %f8, add %o2, %g0) ! MS (%f8 results at G13)
219 faligndata %f4, %f6, %f20 ! FGA Group12 (1-cycle stall,%f20 at G15)
220 EX(ldda [%o1 + 0x028] %asi, %f10, add %o2, %g0) ! MS (%f10 results at G15)
221 faligndata %f6, %f8, %f22 ! FGA Group13 (%f22 results at G16)
223 EX(ldda [%o1 + 0x030] %asi, %f12, add %o2, %g0) ! MS (%f12 results at G16)
224 faligndata %f8, %f10, %f24 ! FGA Group15 (1-cycle stall,%f24 at G18)
225 EX(ldda [%o1 + 0x038] %asi, %f14, add %o2, %g0) ! MS (%f14 results at G18)
226 faligndata %f10, %f12, %f26 ! FGA Group16 (%f26 results at G19)
227 EX(ldda [%o1 + 0x040] %asi, %f0, add %o2, %g0) ! MS (%f0 results at G19)
229 /* We only use the first loop if len > (7 * 64). */
230 subcc %o4, 0x1c0, %o4 ! A0 Group17
231 bg,pt %icc, U3copy_from_user_loop1 ! BR
232 add %o1, 0x40, %o1 ! A1
234 add %o4, 0x140, %o4 ! A0 Group18
235 ba,pt %xcc, U3copy_from_user_loop2 ! BR
236 srl %o4, 6, %o3 ! A0 Group19
246 /* This loop performs the copy and queues new prefetches.
247 * We drop into the second loop when len <= (5 * 64). Note
248 * that this (5 * 64) factor has been subtracted from len
251 U3copy_from_user_loop1:
252 EX2(ldda [%o1 + 0x008] %asi, %f2) ! MS Group2 (%f2 results at G5)
253 faligndata %f12, %f14, %f28 ! FGA (%f28 results at G5)
254 EX2(ldda [%o1 + 0x010] %asi, %f4) ! MS Group3 (%f4 results at G6)
255 faligndata %f14, %f0, %f30 ! FGA Group4 (1-cycle stall, %f30 at G7)
256 stda %f16, [%o0] ASI_BLK_P ! MS
257 EX2(ldda [%o1 + 0x018] %asi, %f6) ! AX (%f6 results at G7)
259 faligndata %f0, %f2, %f16 ! FGA Group12 (7-cycle stall)
260 EX2(ldda [%o1 + 0x020] %asi, %f8) ! MS (%f8 results at G15)
261 faligndata %f2, %f4, %f18 ! FGA Group13 (%f18 results at G16)
262 EX2(ldda [%o1 + 0x028] %asi, %f10) ! MS (%f10 results at G16)
263 faligndata %f4, %f6, %f20 ! FGA Group14 (%f20 results at G17)
264 EX2(ldda [%o1 + 0x030] %asi, %f12) ! MS (%f12 results at G17)
265 faligndata %f6, %f8, %f22 ! FGA Group15 (%f22 results at G18)
266 EX2(ldda [%o1 + 0x038] %asi, %f14) ! MS (%f14 results at G18)
268 faligndata %f8, %f10, %f24 ! FGA Group16 (%f24 results at G19)
269 EX2(ldda [%o1 + 0x040] %asi, %f0) ! AX (%f0 results at G19)
270 prefetcha [%o1 + 0x180] %asi, #one_read ! MS
271 faligndata %f10, %f12, %f26 ! FGA Group17 (%f26 results at G20)
272 subcc %o4, 0x40, %o4 ! A0
273 add %o1, 0x40, %o1 ! A1
274 bg,pt %xcc, U3copy_from_user_loop1 ! BR
275 add %o0, 0x40, %o0 ! A0 Group18
277 U3copy_from_user_loop2_enter:
280 /* This loop performs on the copy, no new prefetches are
281 * queued. We do things this way so that we do not perform
282 * any spurious prefetches past the end of the src buffer.
284 U3copy_from_user_loop2:
285 EX3(ldda [%o1 + 0x008] %asi, %f2) ! MS
286 faligndata %f12, %f14, %f28 ! FGA Group2
287 EX3(ldda [%o1 + 0x010] %asi, %f4) ! MS
288 faligndata %f14, %f0, %f30 ! FGA Group4 (1-cycle stall)
289 stda %f16, [%o0] ASI_BLK_P ! MS
290 EX3(ldda [%o1 + 0x018] %asi, %f6) ! AX
291 faligndata %f0, %f2, %f16 ! FGA Group12 (7-cycle stall)
293 EX3(ldda [%o1 + 0x020] %asi, %f8) ! MS
294 faligndata %f2, %f4, %f18 ! FGA Group13
295 EX3(ldda [%o1 + 0x028] %asi, %f10) ! MS
296 faligndata %f4, %f6, %f20 ! FGA Group14
297 EX3(ldda [%o1 + 0x030] %asi, %f12) ! MS
298 faligndata %f6, %f8, %f22 ! FGA Group15
299 EX3(ldda [%o1 + 0x038] %asi, %f14) ! MS
300 faligndata %f8, %f10, %f24 ! FGA Group16
302 EX3(ldda [%o1 + 0x040] %asi, %f0) ! AX
303 faligndata %f10, %f12, %f26 ! FGA Group17
304 subcc %o3, 0x01, %o3 ! A0
305 add %o1, 0x40, %o1 ! A1
306 bg,pt %xcc, U3copy_from_user_loop2 ! BR
307 add %o0, 0x40, %o0 ! A0 Group18
309 /* Finally we copy the last full 64-byte block. */
310 U3copy_from_user_loopfini:
311 EX3(ldda [%o1 + 0x008] %asi, %f2) ! MS
312 faligndata %f12, %f14, %f28 ! FGA
313 EX3(ldda [%o1 + 0x010] %asi, %f4) ! MS Group19
314 faligndata %f14, %f0, %f30 ! FGA
315 stda %f16, [%o0] ASI_BLK_P ! MS Group20
316 EX3(ldda [%o1 + 0x018] %asi, %f6) ! AX
317 faligndata %f0, %f2, %f16 ! FGA Group11 (7-cycle stall)
318 EX3(ldda [%o1 + 0x020] %asi, %f8) ! MS
319 faligndata %f2, %f4, %f18 ! FGA Group12
320 EX3(ldda [%o1 + 0x028] %asi, %f10) ! MS
321 faligndata %f4, %f6, %f20 ! FGA Group13
322 EX3(ldda [%o1 + 0x030] %asi, %f12) ! MS
323 faligndata %f6, %f8, %f22 ! FGA Group14
324 EX3(ldda [%o1 + 0x038] %asi, %f14) ! MS
325 faligndata %f8, %f10, %f24 ! FGA Group15
328 add %o0, 0x40, %o0 ! A1
329 EX4(ldda [%o1 + 0x040] %asi, %f0) ! MS
330 1: faligndata %f10, %f12, %f26 ! FGA Group16
331 faligndata %f12, %f14, %f28 ! FGA Group17
332 faligndata %f14, %f0, %f30 ! FGA Group18
333 stda %f16, [%o0] ASI_BLK_P ! MS
334 add %o0, 0x40, %o0 ! A0
335 add %o1, 0x40, %o1 ! A1
337 .globl U3copy_from_user_nop_2_3
338 U3copy_from_user_nop_2_3:
339 mov PRIMARY_CONTEXT, %o3
340 stxa %g0, [%o3] ASI_DMMU ! Flush P-cache
341 stxa %g3, [%g0] ASI_DCU_CONTROL_REG ! Disable P-cache
343 membar #Sync ! MS Group26 (7-cycle stall)
345 /* Now we copy the (len modulo 64) bytes at the end.
346 * Note how we borrow the %f0 loaded above.
348 * Also notice how this code is careful not to perform a
349 * load past the end of the src buffer just like similar
350 * code found in U3copy_from_user_toosmall processing.
352 U3copy_from_user_loopend:
353 and %o2, 0x3f, %o2 ! A0 Group
354 andcc %o2, 0x38, %g2 ! A0 Group
355 be,pn %icc, U3copy_from_user_endcruft ! BR
356 subcc %g2, 0x8, %g2 ! A1
357 be,pn %icc, U3copy_from_user_endcruft ! BR Group
360 be,a,pt %icc, 1f ! BR Group
361 EX(ldda [%o1 + 0x00] %asi, %f0, add %o2, %g0) ! MS
363 1: EX(ldda [%o1 + 0x08] %asi, %f2, add %o2, %g0) ! MS Group
364 add %o1, 0x8, %o1 ! A0
365 sub %o2, 0x8, %o2 ! A1
366 subcc %g2, 0x8, %g2 ! A0 Group
367 faligndata %f0, %f2, %f8 ! FGA Group
368 std %f8, [%o0 + 0x00] ! MS (XXX does it stall here? XXX)
369 be,pn %icc, U3copy_from_user_endcruft ! BR
370 add %o0, 0x8, %o0 ! A0
371 EX(ldda [%o1 + 0x08] %asi, %f0, add %o2, %g0) ! MS Group
372 add %o1, 0x8, %o1 ! A0
373 sub %o2, 0x8, %o2 ! A1
374 subcc %g2, 0x8, %g2 ! A0 Group
375 faligndata %f2, %f0, %f8 ! FGA
376 std %f8, [%o0 + 0x00] ! MS (XXX does it stall here? XXX)
378 add %o0, 0x8, %o0 ! A0 Group
380 /* If anything is left, we copy it one byte at a time.
381 * Note that %g1 is (src & 0x3) saved above before the
382 * alignaddr was performed.
384 U3copy_from_user_endcruft:
388 be,pn %icc, U3copy_from_user_short_ret
390 ba,a,pt %xcc, U3copy_from_user_short
392 /* If we get here, then 32 <= len < (6 * 64) */
393 U3copy_from_user_toosmall:
395 #ifdef SMALL_COPY_USES_FPU
397 /* Is 'dst' already aligned on an 8-byte boundary? */
398 be,pt %xcc, 2f ! BR Group
400 /* Compute abs((dst & 7) - 8) into %g2. This is the number
401 * of bytes to copy to make 'dst' 8-byte aligned. We pre-
402 * subtract this from 'len'.
404 sub %g2, 0x8, %g2 ! A0
405 sub %g0, %g2, %g2 ! A0 Group (reg-dep)
406 sub %o2, %g2, %o2 ! A0 Group (reg-dep)
408 /* Copy %g2 bytes from src to dst, one byte at a time. */
409 1: EXNV(lduba [%o1 + 0x00] %asi, %o3, add %o2, %g2)! MS (Group) (%o3 in 3 cycles)
410 add %o1, 0x1, %o1 ! A1
411 add %o0, 0x1, %o0 ! A0 Group
412 subcc %g2, 0x1, %g2 ! A1
414 bg,pt %icc, 1b ! BR Group
415 stb %o3, [%o0 + -1] ! MS Group
417 2: VISEntryHalf ! MS+MS
419 /* Compute (len - (len % 8)) into %g2. This is guaranteed
422 andn %o2, 0x7, %g2 ! A0 Group
424 /* You may read this and believe that it allows reading
425 * one 8-byte longword past the end of src. It actually
426 * does not, as %g2 is subtracted as loads are done from
427 * src, so we always stop before running off the end.
428 * Also, we are guaranteed to have at least 0x10 bytes
431 sub %g2, 0x8, %g2 ! A0 Group (reg-dep)
432 alignaddr %o1, %g0, %g1 ! MS (Break-after)
433 EX(ldda [%g1 + 0x00] %asi, %f0, add %o2, %g0) ! MS Group (1-cycle stall)
434 add %g1, 0x8, %g1 ! A0
436 1: EX(ldda [%g1 + 0x00] %asi, %f2, add %o2, %g0) ! MS Group
437 add %g1, 0x8, %g1 ! A0
438 sub %o2, 0x8, %o2 ! A1
439 subcc %g2, 0x8, %g2 ! A0 Group
441 faligndata %f0, %f2, %f8 ! FGA Group (1-cycle stall)
442 std %f8, [%o0 + 0x00] ! MS Group (2-cycle stall)
443 add %o1, 0x8, %o1 ! A0
446 add %o0, 0x8, %o0 ! A1
447 EX(ldda [%g1 + 0x00] %asi, %f0, add %o2, %g0) ! MS Group
448 add %g1, 0x8, %g1 ! A0
449 sub %o2, 0x8, %o2 ! A1
451 subcc %g2, 0x8, %g2 ! A0 Group
452 faligndata %f2, %f0, %f8 ! FGA Group (1-cycle stall)
453 std %f8, [%o0 + 0x00] ! MS Group (2-cycle stall)
454 add %o1, 0x8, %o1 ! A0
457 add %o0, 0x8, %o0 ! A1
459 /* Nothing left to copy? */
460 2: cmp %o2, 0 ! A0 Group
462 be,pn %icc, U3copy_from_user_short_ret! BR Group
464 ba,a,pt %xcc, U3copy_from_user_short ! BR Group
466 #else /* !(SMALL_COPY_USES_FPU) */
470 bne,pn %icc, U3copy_from_user_short
478 1: EXNV(lduba [%o1 + 0x00] %asi, %o3, add %o2, %g2)
485 2: andn %o2, 0x7, %g2
488 3: EXNV(ldxa [%o1 + 0x00] %asi, %o3, add %o2, %g2)
496 bne,pn %icc, U3copy_from_user_short
498 ba,a,pt %xcc, U3copy_from_user_short_ret
500 #endif /* !(SMALL_COPY_USES_FPU) */
505 /* Since this is copy_from_user(), zero out the rest of the