1 /* Copy memory to memory until the specified number of bytes
2 has been copied. Overlap is handled correctly.
3 Copyright (C) 1991-2022 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
23 /* All this is so that bcopy.c can #include
24 this file after defining some things. */
26 #define a1 dest /* First arg is DEST. */
28 #define a2 src /* Second arg is SRC. */
32 #if !defined(RETURN) || !defined(rettype)
33 #define RETURN(s) return (s) /* Return DEST. */
34 #define rettype void *
38 #define MEMMOVE memmove
42 inhibit_loop_to_libcall
43 MEMMOVE (a1const
void *a1
, a2const
void *a2
, size_t len
)
45 unsigned long int dstp
= (long int) dest
;
46 unsigned long int srcp
= (long int) src
;
48 /* This test makes the forward copying code be used whenever possible.
49 Reduces the working set. */
50 if (dstp
- srcp
>= len
) /* *Unsigned* compare! */
52 /* Copy from the beginning to the end. */
54 #if MEMCPY_OK_FOR_FWD_MEMMOVE
55 dest
= memcpy (dest
, src
, len
);
57 /* If there not too few bytes to copy, use word copy. */
58 if (len
>= OP_T_THRES
)
60 /* Copy just a few bytes to make DSTP aligned. */
61 len
-= (-dstp
) % OPSIZ
;
62 BYTE_COPY_FWD (dstp
, srcp
, (-dstp
) % OPSIZ
);
64 /* Copy whole pages from SRCP to DSTP by virtual address
65 manipulation, as much as possible. */
67 PAGE_COPY_FWD_MAYBE (dstp
, srcp
, len
, len
);
69 /* Copy from SRCP to DSTP taking advantage of the known
70 alignment of DSTP. Number of bytes remaining is put
71 in the third argument, i.e. in LEN. This number may
72 vary from machine to machine. */
74 WORD_COPY_FWD (dstp
, srcp
, len
, len
);
76 /* Fall out and copy the tail. */
79 /* There are just a few bytes to copy. Use byte memory operations. */
80 BYTE_COPY_FWD (dstp
, srcp
, len
);
81 #endif /* MEMCPY_OK_FOR_FWD_MEMMOVE */
85 /* Copy from the end to the beginning. */
89 /* If there not too few bytes to copy, use word copy. */
90 if (len
>= OP_T_THRES
)
92 /* Copy just a few bytes to make DSTP aligned. */
94 BYTE_COPY_BWD (dstp
, srcp
, dstp
% OPSIZ
);
96 /* Copy from SRCP to DSTP taking advantage of the known
97 alignment of DSTP. Number of bytes remaining is put
98 in the third argument, i.e. in LEN. This number may
99 vary from machine to machine. */
101 WORD_COPY_BWD (dstp
, srcp
, len
, len
);
103 /* Fall out and copy the tail. */
106 /* There are just a few bytes to copy. Use byte memory operations. */
107 BYTE_COPY_BWD (dstp
, srcp
, len
);
113 libc_hidden_builtin_def (memmove
)