1/* memmove.S: Simple memmove implementation.
2 *
3 * Copyright (C) 1997, 2004 David S. Miller (davem@redhat.com)
4 * Copyright (C) 1996, 1997, 1998, 1999 Jakub Jelinek (jj@ultra.linux.cz)
5 */
6
7#include <linux/linkage.h>
8
9	.text
10ENTRY(memmove) /* o0=dst o1=src o2=len */
11	brz,pn		%o2, 99f
12	 mov		%o0, %g1
13
14	cmp		%o0, %o1
15	bleu,pt		%xcc, 2f
16	 add		%o1, %o2, %g7
17	cmp		%g7, %o0
18	bleu,pt		%xcc, memcpy
19	 add		%o0, %o2, %o5
20	sub		%g7, 1, %o1
21
22	sub		%o5, 1, %o0
231:	ldub		[%o1], %g7
24	subcc		%o2, 1, %o2
25	sub		%o1, 1, %o1
26	stb		%g7, [%o0]
27	bne,pt		%icc, 1b
28	 sub		%o0, 1, %o0
2999:
30	retl
31	 mov		%g1, %o0
32
33	/* We can't just call memcpy for these memmove cases.  On some
34	 * chips the memcpy uses cache initializing stores and when dst
35	 * and src are close enough, those can clobber the source data
36	 * before we've loaded it in.
37	 */
382:	or		%o0, %o1, %g7
39	or		%o2, %g7, %g7
40	andcc		%g7, 0x7, %g0
41	bne,pn		%xcc, 4f
42	 nop
43
443:	ldx		[%o1], %g7
45	add		%o1, 8, %o1
46	subcc		%o2, 8, %o2
47	add		%o0, 8, %o0
48	bne,pt		%icc, 3b
49	 stx		%g7, [%o0 - 0x8]
50	ba,a,pt		%xcc, 99b
51
524:	ldub		[%o1], %g7
53	add		%o1, 1, %o1
54	subcc		%o2, 1, %o2
55	add		%o0, 1, %o0
56	bne,pt		%icc, 4b
57	 stb		%g7, [%o0 - 0x1]
58	ba,a,pt		%xcc, 99b
59ENDPROC(memmove)
60