1/* Copyright (c) 2019  SiFive Inc. All rights reserved.
2
3   This copyrighted material is made available to anyone wishing to use,
4   modify, copy, or redistribute it subject to the terms and conditions
5   of the FreeBSD License.   This program is distributed in the hope that
6   it will be useful, but WITHOUT ANY WARRANTY expressed or implied,
7   including the implied warranties of MERCHANTABILITY or FITNESS FOR
8   A PARTICULAR PURPOSE.  A copy of this license is available at
9   http://www.opensource.org/licenses.
10*/
11
12#include <picolibc.h>
13
14#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
15.section .text.memmove
16.global memmove
17.type	memmove, @function
18memmove:
19  beqz a2, 2f
20
21  mv t1, a0
22  li a3, 1
23  bgtu  a1, a0, 1f
24
25  li a3, -1
26  addi  a4, a2 , -1
27  add t1, t1, a4
28  add a1, a1, a4
29
301:
31  lb t2, 0(a1)
32  sb t2, 0(t1)
33  add   a2, a2, -1
34  add   t1, t1, a3
35  add   a1, a1, a3
36  bnez a2, 1b
37
382:
39  ret
40
41  .size	memmove, .-memmove
42#endif
43