1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* U3memcpy.S: UltraSparc-III optimized memcpy.
4 * Copyright (C) 1999, 2000, 2004 David S. Miller (davem@redhat.com)
8 #include <linux/linkage.h>
9 #include <asm/visasm.h>
11 #define GLOBAL_SPARE %g7
13 #define ASI_BLK_P 0xf0
16 #define VISEntryHalf rd %fprs, %o5; wr %g0, FPRS_FEF, %fprs; \
17 clr %g1; clr %g2; clr %g3; subcc %g0, %g0, %g0;
18 #define VISExitHalf and %o5, FPRS_FEF, %o5; wr %o5, 0x0, %fprs
20 #define VISEntryHalf rd %fprs, %o5; wr %g0, FPRS_FEF, %fprs
21 #define VISExitHalf and %o5, FPRS_FEF, %o5; wr %o5, 0x0, %fprs
23 #define GLOBAL_SPARE %g5
30 #define EX_LD_FP(x,y) x
37 #define EX_ST_FP(x,y) x
41 #define LOAD(type,addr,dest) type [addr], dest
45 #define STORE(type,src,addr) type src, [addr]
49 #define STORE_BLK(src,addr) stda src, [addr] ASI_BLK_P
53 #define FUNC_NAME U3memcpy
64 .register %g2,#scratch
65 .register %g3,#scratch
67 /* Special/non-trivial issues of this code:
69 * 1) %o5 is preserved from VISEntryHalf to VISExitHalf
70 * 2) Only low 32 FPU registers are used so that only the
71 * lower half of the FPU register set is dirtied by this
72 * code. This is especially important in the kernel.
73 * 3) This code never prefetches cachelines past the end
74 * of the source buffer.
79 #define EX_RETVAL(x) x
84 ENTRY(U3_retl_o2_plus_g2_plus_g1_plus_1_fp)
87 ba,pt %xcc, __restore_fp
89 ENDPROC(U3_retl_o2_plus_g2_plus_g1_plus_1_fp)
90 ENTRY(U3_retl_o2_plus_g2_fp)
91 ba,pt %xcc, __restore_fp
93 ENDPROC(U3_retl_o2_plus_g2_fp)
94 ENTRY(U3_retl_o2_plus_g2_plus_8_fp)
96 ba,pt %xcc, __restore_fp
98 ENDPROC(U3_retl_o2_plus_g2_plus_8_fp)
103 ENTRY(U3_retl_o2_plus_1)
106 ENDPROC(U3_retl_o2_plus_1)
107 ENTRY(U3_retl_o2_plus_4)
110 ENDPROC(U3_retl_o2_plus_4)
111 ENTRY(U3_retl_o2_plus_8)
114 ENDPROC(U3_retl_o2_plus_8)
115 ENTRY(U3_retl_o2_plus_g1_plus_1)
119 ENDPROC(U3_retl_o2_plus_g1_plus_1)
121 ba,pt %xcc, __restore_fp
123 ENDPROC(U3_retl_o2_fp)
124 ENTRY(U3_retl_o2_plus_o3_sll_6_plus_0x80_fp)
127 ba,pt %xcc, __restore_fp
129 ENDPROC(U3_retl_o2_plus_o3_sll_6_plus_0x80_fp)
130 ENTRY(U3_retl_o2_plus_o3_sll_6_plus_0x40_fp)
133 ba,pt %xcc, __restore_fp
135 ENDPROC(U3_retl_o2_plus_o3_sll_6_plus_0x40_fp)
136 ENTRY(U3_retl_o2_plus_GS_plus_0x10)
137 add GLOBAL_SPARE, 0x10, GLOBAL_SPARE
139 add %o2, GLOBAL_SPARE, %o0
140 ENDPROC(U3_retl_o2_plus_GS_plus_0x10)
141 ENTRY(U3_retl_o2_plus_GS_plus_0x08)
142 add GLOBAL_SPARE, 0x08, GLOBAL_SPARE
144 add %o2, GLOBAL_SPARE, %o0
145 ENDPROC(U3_retl_o2_plus_GS_plus_0x08)
146 ENTRY(U3_retl_o2_and_7_plus_GS)
149 add %o2, GLOBAL_SPARE, %o0
150 ENDPROC(U3_retl_o2_and_7_plus_GS)
151 ENTRY(U3_retl_o2_and_7_plus_GS_plus_8)
152 add GLOBAL_SPARE, 8, GLOBAL_SPARE
155 add %o2, GLOBAL_SPARE, %o0
156 ENDPROC(U3_retl_o2_and_7_plus_GS_plus_8)
161 /* The cheetah's flexible spine, oversized liver, enlarged heart,
162 * slender muscular body, and claws make it the swiftest hunter
163 * in Africa and the fastest animal on land. Can reach speeds
164 * of up to 2.4GB per second.
168 .type FUNC_NAME,#function
169 FUNC_NAME: /* %o0=dst, %o1=src, %o2=len */
173 /* software trap 5 "Range Check" if dst >= 0x80000000 */
180 be,pn %XCC, end_return
185 blu,a,pn %XCC, less_than_16
190 blu,pt %XCC, less_than_192
193 /* Clobbers o5/g1/g2/g3/g7/icc/xcc. We must preserve
194 * o5 from here until we hit VISExitHalf.
198 /* Is 'dst' already aligned on an 64-byte boundary? */
202 /* Compute abs((dst & 0x3f) - 0x40) into %g2. This is the number
203 * of bytes to copy to make 'dst' 64-byte aligned. We pre-
204 * subtract this from 'len'.
206 sub %o0, %o1, GLOBAL_SPARE
214 1: subcc %g1, 0x1, %g1
215 EX_LD_FP(LOAD(ldub, %o1 + 0x00, %o3), U3_retl_o2_plus_g2_plus_g1_plus_1)
216 EX_ST_FP(STORE(stb, %o3, %o1 + GLOBAL_SPARE), U3_retl_o2_plus_g2_plus_g1_plus_1)
220 add %o1, GLOBAL_SPARE, %o0
225 alignaddr %o1, %g0, %o1
227 EX_LD_FP(LOAD(ldd, %o1, %f4), U3_retl_o2_plus_g2)
228 1: EX_LD_FP(LOAD(ldd, %o1 + 0x8, %f6), U3_retl_o2_plus_g2)
231 faligndata %f4, %f6, %f0
232 EX_ST_FP(STORE(std, %f0, %o0), U3_retl_o2_plus_g2_plus_8)
236 EX_LD_FP(LOAD(ldd, %o1 + 0x8, %f4), U3_retl_o2_plus_g2)
239 faligndata %f6, %f4, %f2
240 EX_ST_FP(STORE(std, %f2, %o0), U3_retl_o2_plus_g2_plus_8)
244 3: LOAD(prefetch, %o1 + 0x000, #one_read)
245 LOAD(prefetch, %o1 + 0x040, #one_read)
246 andn %o2, (0x40 - 1), GLOBAL_SPARE
247 LOAD(prefetch, %o1 + 0x080, #one_read)
248 LOAD(prefetch, %o1 + 0x0c0, #one_read)
249 LOAD(prefetch, %o1 + 0x100, #one_read)
250 EX_LD_FP(LOAD(ldd, %o1 + 0x000, %f0), U3_retl_o2)
251 LOAD(prefetch, %o1 + 0x140, #one_read)
252 EX_LD_FP(LOAD(ldd, %o1 + 0x008, %f2), U3_retl_o2)
253 LOAD(prefetch, %o1 + 0x180, #one_read)
254 EX_LD_FP(LOAD(ldd, %o1 + 0x010, %f4), U3_retl_o2)
255 LOAD(prefetch, %o1 + 0x1c0, #one_read)
256 faligndata %f0, %f2, %f16
257 EX_LD_FP(LOAD(ldd, %o1 + 0x018, %f6), U3_retl_o2)
258 faligndata %f2, %f4, %f18
259 EX_LD_FP(LOAD(ldd, %o1 + 0x020, %f8), U3_retl_o2)
260 faligndata %f4, %f6, %f20
261 EX_LD_FP(LOAD(ldd, %o1 + 0x028, %f10), U3_retl_o2)
262 faligndata %f6, %f8, %f22
264 EX_LD_FP(LOAD(ldd, %o1 + 0x030, %f12), U3_retl_o2)
265 faligndata %f8, %f10, %f24
266 EX_LD_FP(LOAD(ldd, %o1 + 0x038, %f14), U3_retl_o2)
267 faligndata %f10, %f12, %f26
268 EX_LD_FP(LOAD(ldd, %o1 + 0x040, %f0), U3_retl_o2)
270 subcc GLOBAL_SPARE, 0x80, GLOBAL_SPARE
273 srl GLOBAL_SPARE, 6, %o3
279 EX_LD_FP(LOAD(ldd, %o1 + 0x008, %f2), U3_retl_o2_plus_o3_sll_6_plus_0x80)
280 faligndata %f12, %f14, %f28
281 EX_LD_FP(LOAD(ldd, %o1 + 0x010, %f4), U3_retl_o2_plus_o3_sll_6_plus_0x80)
282 faligndata %f14, %f0, %f30
283 EX_ST_FP(STORE_BLK(%f16, %o0), U3_retl_o2_plus_o3_sll_6_plus_0x80)
284 EX_LD_FP(LOAD(ldd, %o1 + 0x018, %f6), U3_retl_o2_plus_o3_sll_6_plus_0x40)
285 faligndata %f0, %f2, %f16
288 EX_LD_FP(LOAD(ldd, %o1 + 0x020, %f8), U3_retl_o2_plus_o3_sll_6_plus_0x40)
289 faligndata %f2, %f4, %f18
290 EX_LD_FP(LOAD(ldd, %o1 + 0x028, %f10), U3_retl_o2_plus_o3_sll_6_plus_0x40)
291 faligndata %f4, %f6, %f20
292 EX_LD_FP(LOAD(ldd, %o1 + 0x030, %f12), U3_retl_o2_plus_o3_sll_6_plus_0x40)
294 faligndata %f6, %f8, %f22
295 EX_LD_FP(LOAD(ldd, %o1 + 0x038, %f14), U3_retl_o2_plus_o3_sll_6_plus_0x80)
297 faligndata %f8, %f10, %f24
298 EX_LD_FP(LOAD(ldd, %o1 + 0x040, %f0), U3_retl_o2_plus_o3_sll_6_plus_0x80)
299 LOAD(prefetch, %o1 + 0x1c0, #one_read)
300 faligndata %f10, %f12, %f26
304 /* Finally we copy the last full 64-byte block. */
306 EX_LD_FP(LOAD(ldd, %o1 + 0x008, %f2), U3_retl_o2_plus_o3_sll_6_plus_0x80)
307 faligndata %f12, %f14, %f28
308 EX_LD_FP(LOAD(ldd, %o1 + 0x010, %f4), U3_retl_o2_plus_o3_sll_6_plus_0x80)
309 faligndata %f14, %f0, %f30
310 EX_ST_FP(STORE_BLK(%f16, %o0), U3_retl_o2_plus_o3_sll_6_plus_0x80)
311 EX_LD_FP(LOAD(ldd, %o1 + 0x018, %f6), U3_retl_o2_plus_o3_sll_6_plus_0x40)
312 faligndata %f0, %f2, %f16
313 EX_LD_FP(LOAD(ldd, %o1 + 0x020, %f8), U3_retl_o2_plus_o3_sll_6_plus_0x40)
314 faligndata %f2, %f4, %f18
315 EX_LD_FP(LOAD(ldd, %o1 + 0x028, %f10), U3_retl_o2_plus_o3_sll_6_plus_0x40)
316 faligndata %f4, %f6, %f20
317 EX_LD_FP(LOAD(ldd, %o1 + 0x030, %f12), U3_retl_o2_plus_o3_sll_6_plus_0x40)
318 faligndata %f6, %f8, %f22
319 EX_LD_FP(LOAD(ldd, %o1 + 0x038, %f14), U3_retl_o2_plus_o3_sll_6_plus_0x40)
320 faligndata %f8, %f10, %f24
324 EX_LD_FP(LOAD(ldd, %o1 + 0x040, %f0), U3_retl_o2_plus_o3_sll_6_plus_0x40)
325 1: faligndata %f10, %f12, %f26
326 faligndata %f12, %f14, %f28
327 faligndata %f14, %f0, %f30
328 EX_ST_FP(STORE_BLK(%f16, %o0), U3_retl_o2_plus_o3_sll_6_plus_0x40)
333 /* Now we copy the (len modulo 64) bytes at the end.
334 * Note how we borrow the %f0 loaded above.
336 * Also notice how this code is careful not to perform a
337 * load past the end of the src buffer.
348 EX_LD_FP(LOAD(ldd, %o1 + 0x00, %f0), U3_retl_o2_plus_g2)
350 1: EX_LD_FP(LOAD(ldd, %o1 + 0x08, %f2), U3_retl_o2_plus_g2)
353 faligndata %f0, %f2, %f8
354 EX_ST_FP(STORE(std, %f8, %o0), U3_retl_o2_plus_g2_plus_8)
357 EX_LD_FP(LOAD(ldd, %o1 + 0x08, %f0), U3_retl_o2_plus_g2)
360 faligndata %f2, %f0, %f8
361 EX_ST_FP(STORE(std, %f8, %o0), U3_retl_o2_plus_g2_plus_8)
365 /* If anything is left, we copy it one byte at a time.
366 * Note that %g1 is (src & 0x3) saved above before the
367 * alignaddr was performed.
373 be,pn %XCC, end_return
381 EX_LD(LOAD(ldx, %o1, %o5), U3_retl_o2)
382 EX_ST(STORE(stx, %o5, %o1 + %o3), U3_retl_o2)
386 1: andcc %o2, 0x4, %g0
389 EX_LD(LOAD(lduw, %o1, %o5), U3_retl_o2)
390 EX_ST(STORE(stw, %o5, %o1 + %o3), U3_retl_o2)
394 1: andcc %o2, 0x2, %g0
397 EX_LD(LOAD(lduh, %o1, %o5), U3_retl_o2)
398 EX_ST(STORE(sth, %o5, %o1 + %o3), U3_retl_o2)
402 1: andcc %o2, 0x1, %g0
403 be,pt %icc, end_return
405 EX_LD(LOAD(ldub, %o1, %o5), U3_retl_o2)
406 ba,pt %xcc, end_return
407 EX_ST(STORE(stb, %o5, %o1 + %o3), U3_retl_o2)
410 /* 16 <= len < 192 */
416 andn %o2, 0xf, GLOBAL_SPARE
418 1: subcc GLOBAL_SPARE, 0x10, GLOBAL_SPARE
419 EX_LD(LOAD(ldx, %o1 + 0x00, %o5), U3_retl_o2_plus_GS_plus_0x10)
420 EX_LD(LOAD(ldx, %o1 + 0x08, %g1), U3_retl_o2_plus_GS_plus_0x10)
421 EX_ST(STORE(stx, %o5, %o1 + %o3), U3_retl_o2_plus_GS_plus_0x10)
423 EX_ST(STORE(stx, %g1, %o1 + %o3), U3_retl_o2_plus_GS_plus_0x08)
426 73: andcc %o2, 0x8, %g0
430 EX_LD(LOAD(ldx, %o1, %o5), U3_retl_o2_plus_8)
431 EX_ST(STORE(stx, %o5, %o1 + %o3), U3_retl_o2_plus_8)
433 1: andcc %o2, 0x4, %g0
437 EX_LD(LOAD(lduw, %o1, %o5), U3_retl_o2_plus_4)
438 EX_ST(STORE(stw, %o5, %o1 + %o3), U3_retl_o2_plus_4)
441 be,pt %XCC, end_return
454 EX_LD(LOAD(ldub, %o1, %o5), U3_retl_o2_plus_g1_plus_1)
455 EX_ST(STORE(stb, %o5, %o1 + %o3), U3_retl_o2_plus_g1_plus_1)
471 EX_LD(LOAD(ldx, %o1, %g2), U3_retl_o2)
473 andn %o2, 0x7, GLOBAL_SPARE
475 1: EX_LD(LOAD(ldx, %o1 + 0x8, %g3), U3_retl_o2_and_7_plus_GS)
476 subcc GLOBAL_SPARE, 0x8, GLOBAL_SPARE
480 EX_ST(STORE(stx, %o5, %o0), U3_retl_o2_and_7_plus_GS_plus_8)
487 be,pn %icc, end_return
501 EX_LD(LOAD(lduw, %o1, %g1), U3_retl_o2_plus_4)
502 EX_ST(STORE(stw, %g1, %o1 + %o3), U3_retl_o2_plus_4)
508 mov EX_RETVAL(%o4), %o0
513 EX_LD(LOAD(ldub, %o1, %g1), U3_retl_o2_plus_1)
514 EX_ST(STORE(stb, %g1, %o1 + %o3), U3_retl_o2_plus_1)
518 mov EX_RETVAL(%o4), %o0
520 .size FUNC_NAME, .-FUNC_NAME