blob: 857ad4f8905f942f44ac40770c9277323e4e3c09 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* 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
David S. Miller8695c372012-05-11 20:33:22 -07007#include <linux/linkage.h>
8
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 .text
David S. Miller8695c372012-05-11 20:33:22 -070010ENTRY(memmove) /* o0=dst o1=src o2=len */
David S. Miller2077cef2015-03-23 09:22:10 -070011 brz,pn %o2, 99f
12 mov %o0, %g1
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 cmp %o0, %o1
David S. Miller2077cef2015-03-23 09:22:10 -070015 bleu,pt %xcc, 2f
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 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
David S. Miller2077cef2015-03-23 09:22:10 -07002999:
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 retl
31 mov %g1, %o0
David S. Miller2077cef2015-03-23 09:22:10 -070032
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
David S. Miller8695c372012-05-11 20:33:22 -070059ENDPROC(memmove)