]> git.ipfire.org Git - thirdparty/glibc.git/blame - string/memmove.c
Remove "Contributed by" lines
[thirdparty/glibc.git] / string / memmove.c
CommitLineData
ebbad4cc 1/* Copy memory to memory until the specified number of bytes
28f540f4 2 has been copied. Overlap is handled correctly.
2b778ceb 3 Copyright (C) 1991-2021 Free Software Foundation, Inc.
41bdb6e2 4 This file is part of the GNU C Library.
28f540f4 5
6d52618b 6 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
28f540f4 10
6d52618b
UD
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
41bdb6e2 14 Lesser General Public License for more details.
28f540f4 15
41bdb6e2 16 You should have received a copy of the GNU Lesser General Public
59ba27a6 17 License along with the GNU C Library; if not, see
5a82c748 18 <https://www.gnu.org/licenses/>. */
28f540f4 19
28f540f4
RM
20#include <string.h>
21#include <memcopy.h>
22
23/* All this is so that bcopy.c can #include
24 this file after defining some things. */
25#ifndef a1
26#define a1 dest /* First arg is DEST. */
27#define a1const
28#define a2 src /* Second arg is SRC. */
ebbad4cc 29#define a2const const
9a0a462c 30#undef memmove
28f540f4
RM
31#endif
32#if !defined(RETURN) || !defined(rettype)
33#define RETURN(s) return (s) /* Return DEST. */
ebbad4cc 34#define rettype void *
28f540f4
RM
35#endif
36
6fb8cbcb
L
37#ifndef MEMMOVE
38#define MEMMOVE memmove
39#endif
9a0a462c 40
28f540f4 41rettype
85c2e611 42inhibit_loop_to_libcall
9d46370c 43MEMMOVE (a1const void *a1, a2const void *a2, size_t len)
28f540f4
RM
44{
45 unsigned long int dstp = (long int) dest;
46 unsigned long int srcp = (long int) src;
47
48 /* This test makes the forward copying code be used whenever possible.
49 Reduces the working set. */
50 if (dstp - srcp >= len) /* *Unsigned* compare! */
51 {
52 /* Copy from the beginning to the end. */
53
19218757
MK
54#if MEMCPY_OK_FOR_FWD_MEMMOVE
55 dest = memcpy (dest, src, len);
56#else
28f540f4
RM
57 /* If there not too few bytes to copy, use word copy. */
58 if (len >= OP_T_THRES)
59 {
60 /* Copy just a few bytes to make DSTP aligned. */
61 len -= (-dstp) % OPSIZ;
62 BYTE_COPY_FWD (dstp, srcp, (-dstp) % OPSIZ);
63
67a87b93
RM
64 /* Copy whole pages from SRCP to DSTP by virtual address
65 manipulation, as much as possible. */
66
67 PAGE_COPY_FWD_MAYBE (dstp, srcp, len, len);
68
28f540f4
RM
69 /* Copy from SRCP to DSTP taking advantage of the known
70 alignment of DSTP. Number of bytes remaining is put
6d52618b 71 in the third argument, i.e. in LEN. This number may
28f540f4
RM
72 vary from machine to machine. */
73
74 WORD_COPY_FWD (dstp, srcp, len, len);
75
76 /* Fall out and copy the tail. */
77 }
78
79 /* There are just a few bytes to copy. Use byte memory operations. */
80 BYTE_COPY_FWD (dstp, srcp, len);
19218757 81#endif /* MEMCPY_OK_FOR_FWD_MEMMOVE */
28f540f4
RM
82 }
83 else
84 {
85 /* Copy from the end to the beginning. */
86 srcp += len;
87 dstp += len;
88
89 /* If there not too few bytes to copy, use word copy. */
90 if (len >= OP_T_THRES)
91 {
92 /* Copy just a few bytes to make DSTP aligned. */
93 len -= dstp % OPSIZ;
94 BYTE_COPY_BWD (dstp, srcp, dstp % OPSIZ);
95
96 /* Copy from SRCP to DSTP taking advantage of the known
97 alignment of DSTP. Number of bytes remaining is put
6d52618b 98 in the third argument, i.e. in LEN. This number may
28f540f4
RM
99 vary from machine to machine. */
100
101 WORD_COPY_BWD (dstp, srcp, len, len);
102
103 /* Fall out and copy the tail. */
104 }
105
106 /* There are just a few bytes to copy. Use byte memory operations. */
107 BYTE_COPY_BWD (dstp, srcp, len);
108 }
109
ebbad4cc 110 RETURN (dest);
28f540f4 111}
85dd1003
UD
112#ifndef memmove
113libc_hidden_builtin_def (memmove)
114#endif