OSDN Git Service

- trim any trailing whitespace
[uclinux-h8/uClibc.git] / libc / string / cris / memmove.c
1 /* 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
30 /* Experimentally off - libc_hidden_proto(memmove) */
31 void *memmove (void *dest, const void *src, size_t len)
32 {
33   unsigned long int dstp = (long int) dest;
34   unsigned long int srcp = (long int) src;
35
36   /* This test makes the forward copying code be used whenever possible.
37      Reduces the working set.  */
38   if (dstp - srcp >= len)       /* *Unsigned* compare!  */
39     {
40 #if 1
41 #warning REMINDER: Cris arch-opt memmove assumes memcpy does forward copying!
42       memcpy(dest, src, len);
43 #else
44       /* Copy from the beginning to the end.  */
45
46       /* If there not too few bytes to copy, use word copy.  */
47       if (len >= OP_T_THRES)
48         {
49           /* Copy just a few bytes to make DSTP aligned.  */
50           len -= (-dstp) % OPSIZ;
51           BYTE_COPY_FWD (dstp, srcp, (-dstp) % OPSIZ);
52
53           /* Copy whole pages from SRCP to DSTP by virtual address
54              manipulation, as much as possible.  */
55
56           PAGE_COPY_FWD_MAYBE (dstp, srcp, len, len);
57
58           /* Copy from SRCP to DSTP taking advantage of the known
59              alignment of DSTP.  Number of bytes remaining is put
60              in the third argument, i.e. in LEN.  This number may
61              vary from machine to machine.  */
62
63           WORD_COPY_FWD (dstp, srcp, len, len);
64
65           /* Fall out and copy the tail.  */
66         }
67
68       /* There are just a few bytes to copy.  Use byte memory operations.  */
69       BYTE_COPY_FWD (dstp, srcp, len);
70 #endif
71     }
72   else
73     {
74       /* Copy from the end to the beginning.  */
75       srcp += len;
76       dstp += len;
77
78       /* If there not too few bytes to copy, use word copy.  */
79       if (len >= OP_T_THRES)
80         {
81           /* Copy just a few bytes to make DSTP aligned.  */
82           len -= dstp % OPSIZ;
83           BYTE_COPY_BWD (dstp, srcp, dstp % OPSIZ);
84
85           /* Copy from SRCP to DSTP taking advantage of the known
86              alignment of DSTP.  Number of bytes remaining is put
87              in the third argument, i.e. in LEN.  This number may
88              vary from machine to machine.  */
89
90           WORD_COPY_BWD (dstp, srcp, len, len);
91
92           /* Fall out and copy the tail.  */
93         }
94
95       /* There are just a few bytes to copy.  Use byte memory operations.  */
96       BYTE_COPY_BWD (dstp, srcp, len);
97     }
98
99   return (dest);
100 }
101 libc_hidden_def(memmove)