1/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * ARCv2 memcpy implementation optimized for unaligned memory access using.
4 *
5 * Copyright (C) 2019 Synopsys
6 * Author: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
7 */
8
9#include <linux/linkage.h>
10
11#ifdef CONFIG_ARC_HAS_LL64
12# define LOADX(DST,RX)		ldd.ab	DST, [RX, 8]
13# define STOREX(SRC,RX)		std.ab	SRC, [RX, 8]
14# define ZOLSHFT		5
15# define ZOLAND			0x1F
16#else
17# define LOADX(DST,RX)		ld.ab	DST, [RX, 4]
18# define STOREX(SRC,RX)		st.ab	SRC, [RX, 4]
19# define ZOLSHFT		4
20# define ZOLAND			0xF
21#endif
22
23ENTRY_CFI(memcpy)
24	mov	r3, r0		; don;t clobber ret val
25
26	lsr.f	lp_count, r2, ZOLSHFT
27	lpnz	@.Lcopy32_64bytes
28	;; LOOP START
29	LOADX	(r6, r1)
30	LOADX	(r8, r1)
31	LOADX	(r10, r1)
32	LOADX	(r4, r1)
33	STOREX	(r6, r3)
34	STOREX	(r8, r3)
35	STOREX	(r10, r3)
36	STOREX	(r4, r3)
37.Lcopy32_64bytes:
38
39	and.f	lp_count, r2, ZOLAND ;Last remaining 31 bytes
40	lpnz	@.Lcopyremainingbytes
41	;; LOOP START
42	ldb.ab	r5, [r1, 1]
43	stb.ab	r5, [r3, 1]
44.Lcopyremainingbytes:
45
46	j	[blink]
47END_CFI(memcpy)
48