* sysdeps/ieee754/ldbl-128ibm/mpn2ldbl.c
[glibc/history.git] / string / memmove.c
blob16671f7bb50352288259d45803a8b9a49a597698
1 /* Copy memory to memory until the specified number of bytes
2 has been copied. Overlap is handled correctly.
3 Copyright (C) 1991, 1995, 1996, 1997, 2003 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5 Contributed by Torbjorn Granlund (tege@sics.se).
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, write to the Free
19 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307 USA. */
22 #include <string.h>
23 #include <memcopy.h>
24 #include <pagecopy.h>
26 /* All this is so that bcopy.c can #include
27 this file after defining some things. */
28 #ifndef a1
29 #define a1 dest /* First arg is DEST. */
30 #define a1const
31 #define a2 src /* Second arg is SRC. */
32 #define a2const const
33 #undef memmove
34 #endif
35 #if !defined(RETURN) || !defined(rettype)
36 #define RETURN(s) return (s) /* Return DEST. */
37 #define rettype void *
38 #endif
41 rettype
42 memmove (a1, a2, len)
43 a1const void *a1;
44 a2const void *a2;
45 size_t len;
47 unsigned long int dstp = (long int) dest;
48 unsigned long int srcp = (long int) src;
50 /* This test makes the forward copying code be used whenever possible.
51 Reduces the working set. */
52 if (dstp - srcp >= len) /* *Unsigned* compare! */
54 /* Copy from the beginning to the end. */
56 /* If there not too few bytes to copy, use word copy. */
57 if (len >= OP_T_THRES)
59 /* Copy just a few bytes to make DSTP aligned. */
60 len -= (-dstp) % OPSIZ;
61 BYTE_COPY_FWD (dstp, srcp, (-dstp) % OPSIZ);
63 /* Copy whole pages from SRCP to DSTP by virtual address
64 manipulation, as much as possible. */
66 PAGE_COPY_FWD_MAYBE (dstp, srcp, len, len);
68 /* Copy from SRCP to DSTP taking advantage of the known
69 alignment of DSTP. Number of bytes remaining is put
70 in the third argument, i.e. in LEN. This number may
71 vary from machine to machine. */
73 WORD_COPY_FWD (dstp, srcp, len, len);
75 /* Fall out and copy the tail. */
78 /* There are just a few bytes to copy. Use byte memory operations. */
79 BYTE_COPY_FWD (dstp, srcp, len);
81 else
83 /* Copy from the end to the beginning. */
84 srcp += len;
85 dstp += len;
87 /* If there not too few bytes to copy, use word copy. */
88 if (len >= OP_T_THRES)
90 /* Copy just a few bytes to make DSTP aligned. */
91 len -= dstp % OPSIZ;
92 BYTE_COPY_BWD (dstp, srcp, dstp % OPSIZ);
94 /* Copy from SRCP to DSTP taking advantage of the known
95 alignment of DSTP. Number of bytes remaining is put
96 in the third argument, i.e. in LEN. This number may
97 vary from machine to machine. */
99 WORD_COPY_BWD (dstp, srcp, len, len);
101 /* Fall out and copy the tail. */
104 /* There are just a few bytes to copy. Use byte memory operations. */
105 BYTE_COPY_BWD (dstp, srcp, len);
108 RETURN (dest);
110 #ifndef memmove
111 libc_hidden_builtin_def (memmove)
112 #endif