blob: 4184fc96d1efee19cf7a60bc6927d85d629ab63d [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/* Taken from generic/memmove.c; trivially modified to work with
2 arch-specific memcopy.h for Cris.
3
4 Copy memory to memory until the specified number of bytes
5 has been copied. Overlap is handled correctly.
6 Copyright (C) 1991, 1995, 1996, 1997, 2003 Free Software Foundation, Inc.
7 This file is part of the GNU C Library.
8 Contributed by Torbjorn Granlund (tege@sics.se).
9
10 The GNU C Library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 2.1 of the License, or (at your option) any later version.
14
15 The GNU C Library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public
21 License along with the GNU C Library; if not, write to the Free
22 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23 02111-1307 USA. */
24
25#include <string.h>
26
27#include "memcopy.h"
28#include "../generic/pagecopy.h"
29
30void *memmove (void *dest, const void *src, size_t len)
31{
32 unsigned long int dstp = (long int) dest;
33 unsigned long int srcp = (long int) src;
34
35 /* This test makes the forward copying code be used whenever possible.
36 Reduces the working set. */
37 if (dstp - srcp >= len) /* *Unsigned* compare! */
38 {
39#if 1
40#warning REMINDER: Cris arch-opt memmove assumes memcpy does forward copying!
41 memcpy(dest, src, len);
42#else
43 /* Copy from the beginning to the end. */
44
45 /* If there not too few bytes to copy, use word copy. */
46 if (len >= OP_T_THRES)
47 {
48 /* Copy just a few bytes to make DSTP aligned. */
49 len -= (-dstp) % OPSIZ;
50 BYTE_COPY_FWD (dstp, srcp, (-dstp) % OPSIZ);
51
52 /* Copy whole pages from SRCP to DSTP by virtual address
53 manipulation, as much as possible. */
54
55 PAGE_COPY_FWD_MAYBE (dstp, srcp, len, len);
56
57 /* Copy from SRCP to DSTP taking advantage of the known
58 alignment of DSTP. Number of bytes remaining is put
59 in the third argument, i.e. in LEN. This number may
60 vary from machine to machine. */
61
62 WORD_COPY_FWD (dstp, srcp, len, len);
63
64 /* Fall out and copy the tail. */
65 }
66
67 /* There are just a few bytes to copy. Use byte memory operations. */
68 BYTE_COPY_FWD (dstp, srcp, len);
69#endif
70 }
71 else
72 {
73 /* Copy from the end to the beginning. */
74 srcp += len;
75 dstp += len;
76
77 /* If there not too few bytes to copy, use word copy. */
78 if (len >= OP_T_THRES)
79 {
80 /* Copy just a few bytes to make DSTP aligned. */
81 len -= dstp % OPSIZ;
82 BYTE_COPY_BWD (dstp, srcp, dstp % OPSIZ);
83
84 /* Copy from SRCP to DSTP taking advantage of the known
85 alignment of DSTP. Number of bytes remaining is put
86 in the third argument, i.e. in LEN. This number may
87 vary from machine to machine. */
88
89 WORD_COPY_BWD (dstp, srcp, len, len);
90
91 /* Fall out and copy the tail. */
92 }
93
94 /* There are just a few bytes to copy. Use byte memory operations. */
95 BYTE_COPY_BWD (dstp, srcp, len);
96 }
97
98 return (dest);
99}
100libc_hidden_def(memmove)