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