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