xref: /openbmc/linux/arch/csky/abiv2/memmove.S (revision 047f2d94)
1/* SPDX-License-Identifier: GPL-2.0 */
2// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
3
4#include <linux/linkage.h>
5#include "sysdep.h"
6
7	.weak memmove
8ENTRY(__memmove)
9ENTRY(memmove)
10	subu	r3, r0, r1
11	cmphs	r3, r2
12	bt	memcpy
13
14	mov	r12, r0
15	addu	r0, r0, r2
16	addu	r1, r1, r2
17
18	/* Test if len less than 4 bytes.  */
19	cmplti	r2, 4
20	bt	.L_copy_by_byte
21
22	andi	r13, r0, 3
23	/* Test if dest is not 4 bytes aligned.  */
24	bnez	r13, .L_dest_not_aligned
25	/* Hardware can handle unaligned access directly.  */
26.L_dest_aligned:
27	/* If dest is aligned, then copy.  */
28	zext	r18, r2, 31, 4
29	/* Test if len less than 16 bytes.  */
30	bez	r18, .L_len_less_16bytes
31	movi	r19, 0
32
33	/* len > 16 bytes */
34	LABLE_ALIGN
35.L_len_larger_16bytes:
36	subi	r1, 16
37	subi	r0, 16
38#if defined(__CSKY_VDSPV2__)
39	vldx.8	vr0, (r1), r19
40	PRE_BNEZAD (r18)
41	vstx.8	vr0, (r0), r19
42#elif defined(__CK860__)
43	ldw	r3, (r1, 12)
44	stw	r3, (r0, 12)
45	ldw	r3, (r1, 8)
46	stw	r3, (r0, 8)
47	ldw	r3, (r1, 4)
48	stw	r3, (r0, 4)
49	ldw	r3, (r1, 0)
50	stw	r3, (r0, 0)
51#else
52	ldw	r20, (r1, 0)
53	ldw	r21, (r1, 4)
54	ldw	r22, (r1, 8)
55	ldw	r23, (r1, 12)
56	stw	r20, (r0, 0)
57	stw	r21, (r0, 4)
58	stw	r22, (r0, 8)
59	stw	r23, (r0, 12)
60	PRE_BNEZAD (r18)
61#endif
62	BNEZAD (r18, .L_len_larger_16bytes)
63
64.L_len_less_16bytes:
65	zext	r18, r2, 3, 2
66	bez	r18, .L_copy_by_byte
67.L_len_less_16bytes_loop:
68	subi	r1, 4
69	subi	r0, 4
70	ldw	r3, (r1, 0)
71	PRE_BNEZAD (r18)
72	stw	r3, (r0, 0)
73	BNEZAD (r18, .L_len_less_16bytes_loop)
74
75	/* Test if len less than 4 bytes.  */
76.L_copy_by_byte:
77	zext	r18, r2, 1, 0
78	bez	r18, .L_return
79.L_copy_by_byte_loop:
80	subi	r1, 1
81	subi	r0, 1
82	ldb	r3, (r1, 0)
83	PRE_BNEZAD (r18)
84	stb	r3, (r0, 0)
85	BNEZAD (r18, .L_copy_by_byte_loop)
86
87.L_return:
88	mov	r0, r12
89	rts
90
91	/* If dest is not aligned, just copy some bytes makes the dest
92	   align.  */
93.L_dest_not_aligned:
94	sub	r2, r13
95.L_dest_not_aligned_loop:
96	subi	r1, 1
97	subi	r0, 1
98	/* Makes the dest align.  */
99	ldb	r3, (r1, 0)
100	PRE_BNEZAD (r13)
101	stb	r3, (r0, 0)
102	BNEZAD (r13, .L_dest_not_aligned_loop)
103	cmplti	r2, 4
104	bt	.L_copy_by_byte
105	/* Check whether the src is aligned.  */
106	jbr	.L_dest_aligned
107ENDPROC(memmove)
108ENDPROC(__memmove)
109