2000-02-18 03:39:52 +08:00
|
|
|
/*
|
|
|
|
FUNCTION
|
|
|
|
<<memcpy>>---copy memory regions
|
|
|
|
|
2017-11-30 16:20:06 +08:00
|
|
|
SYNOPSIS
|
2000-02-18 03:39:52 +08:00
|
|
|
#include <string.h>
|
* libc/sys/linux/include/netdb.h, libc/sys/linux/net/getaddrinfo.c,
libc/sys/linux/net/getnameinfo.c: Add restrict keyword to getnameinfo()
and getaddrinfo() to increase standards compliance and match glibc.
* libc/include/string.h, libc/string/memccpy.c, libc/string/memcpy.c,
libc/string/stpcpy.c, libc/string/stpncpy.c, libc/string/strcat.c,
libc/string/strncat.c, libc/string/strncpy.c, libc/string/strtok.c,
libc/string/strtok_r.c, libc/string/strxfrm.c
libc/machine/microblaze/strcpy.c, libc/machine/xscale/memcpy.c,
libc/machine/cris/memcpy.c: Add __restrict to prototype to
increase standards compliance.
2013-07-23 15:05:31 +08:00
|
|
|
void* memcpy(void *restrict <[out]>, const void *restrict <[in]>,
|
|
|
|
size_t <[n]>);
|
2000-02-18 03:39:52 +08:00
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
This function copies <[n]> bytes from the memory region
|
|
|
|
pointed to by <[in]> to the memory region pointed to by
|
|
|
|
<[out]>.
|
|
|
|
|
|
|
|
If the regions overlap, the behavior is undefined.
|
|
|
|
|
|
|
|
RETURNS
|
|
|
|
<<memcpy>> returns a pointer to the first byte of the <[out]>
|
|
|
|
region.
|
|
|
|
|
|
|
|
PORTABILITY
|
|
|
|
<<memcpy>> is ANSI C.
|
|
|
|
|
|
|
|
<<memcpy>> requires no supporting OS subroutines.
|
|
|
|
|
|
|
|
QUICKREF
|
|
|
|
memcpy ansi pure
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <_ansi.h>
|
2008-12-11 Craig Howland <howland@LGSInnovations.com>
* libc/include/sys/lock.h: Add void cast to avoid "statement has no
effect" warnings from gcc.
* libc/include/sys/stdio.h: Ditto.
* libc/include/sys/time.h: Correct gettimeofday() prototype.
* libc/stdlib/__exp10.c: Add #include "std.h" for function prototype.
* libc/stdlib/__ten_mu.c: Ditto.
* libc/stdlib/std.h: Correct __exp10's ANSI prototype.
* libc/stdlib/ldtoa.c: Change eiisinf definition to ANSI form. (Are
already others in file without _ansi method, so did not bother.)
* libc/stdlib/system.c: Use _ansi forms for function prototypes and
definitions.
* libc/time/mktime.c: Ditto.
* libc/misc/__dprintf.c: Ditto.
* libc/include/stdio.h: Add function prototypes for _fgetc_r,
_fgetpos_r, _fsetpos_r, _freopen_r, _rewind_r, freopen64, _freopen64_r,
_funopen_r, and _fopencookie_r.
* libc/include/reent.h: Add function prototype for _stat64_r, align
_execve_r prototype with POSIX definition for execve.
* libc/reent/execr.c: Align function prototype with POSIX definition.
* libc/stdio/asniprintf.c: Add #include "local.h".
* libc/stdio/vasniprintf.c: Ditto.
* libc/stdio/fread.c: Remove unused variable newcount.
* libc/stdio/local.h: Add function prototype for __sccl.
* libc/stdio/open_memstream.c: Remove unused variable flags.
* libc/stdio/vfscanf.c: Proper prototyping for ccfn, remove prototype
for __sccl since now in local.h.
* libc/string/memcpy.c: Add #include <string.h> (for real and for
traditional synopsis), remove extraneous stddef.h and limits.h.
* libc/syscalls/sysclose.c: Add #include <unistd.h>.
* libc/syscalls/sysfork.c: Ditto.
* libc/syscalls/sysgetpid.c: Ditto.
* libc/syscalls/sysexecve.c: Add #include <unistd.h>, align function
prototype with POSIX definition.
* libc/syscalls/sysfstat.c: Add #include <sys/stat.h>.
* libc/syscalls/sysgettod.c: Correct sys/times.h to sys/time.h.
* libc/syscalls/syskill.c: Add #include <signal.h>.
* libc/syscalls/syslink.c: Add #include <unistd.h>, fix prototype.
* libc/syscalls/sysunlink.c: Ditto.
* libc/syscalls/sysstat.c: Add #include <sys/stat.h>, fix prototype.
* libc/syscalls/syswait.c: Add #include <sys/wait.h>, fix prototype.
2008-12-12 01:27:56 +08:00
|
|
|
#include <string.h>
|
2018-08-28 02:32:31 +08:00
|
|
|
#include "local.h"
|
2000-02-18 03:39:52 +08:00
|
|
|
|
|
|
|
/* Nonzero if either X or Y is not aligned on a "long" boundary. */
|
|
|
|
#define UNALIGNED(X, Y) \
|
|
|
|
(((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))
|
|
|
|
|
|
|
|
/* How many bytes are copied each iteration of the 4X unrolled loop. */
|
|
|
|
#define BIGBLOCKSIZE (sizeof (long) << 2)
|
|
|
|
|
|
|
|
/* How many bytes are copied each iteration of the word copy loop. */
|
|
|
|
#define LITTLEBLOCKSIZE (sizeof (long))
|
|
|
|
|
|
|
|
/* Threshhold for punting to the byte copier. */
|
|
|
|
#define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE)
|
|
|
|
|
2017-12-04 10:53:22 +08:00
|
|
|
void *
|
2018-08-28 02:32:31 +08:00
|
|
|
__inhibit_loop_to_libcall
|
2017-12-04 11:43:30 +08:00
|
|
|
memcpy (void *__restrict dst0,
|
2017-12-04 10:53:22 +08:00
|
|
|
const void *__restrict src0,
|
2000-02-18 03:39:52 +08:00
|
|
|
size_t len0)
|
|
|
|
{
|
|
|
|
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
|
|
|
|
char *dst = (char *) dst0;
|
|
|
|
char *src = (char *) src0;
|
|
|
|
|
2017-12-04 10:53:22 +08:00
|
|
|
void *save = dst0;
|
2000-02-18 03:39:52 +08:00
|
|
|
|
|
|
|
while (len0--)
|
|
|
|
{
|
|
|
|
*dst++ = *src++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return save;
|
|
|
|
#else
|
|
|
|
char *dst = dst0;
|
2017-12-04 10:25:16 +08:00
|
|
|
const char *src = src0;
|
2000-02-18 03:39:52 +08:00
|
|
|
long *aligned_dst;
|
2017-12-04 10:25:16 +08:00
|
|
|
const long *aligned_src;
|
2000-02-18 03:39:52 +08:00
|
|
|
|
|
|
|
/* If the size is small, or either SRC or DST is unaligned,
|
|
|
|
then punt into the byte copy loop. This should be rare. */
|
2010-09-22 11:15:07 +08:00
|
|
|
if (!TOO_SMALL(len0) && !UNALIGNED (src, dst))
|
2000-02-18 03:39:52 +08:00
|
|
|
{
|
|
|
|
aligned_dst = (long*)dst;
|
|
|
|
aligned_src = (long*)src;
|
|
|
|
|
|
|
|
/* Copy 4X long words at a time if possible. */
|
2010-09-22 11:15:07 +08:00
|
|
|
while (len0 >= BIGBLOCKSIZE)
|
2000-02-18 03:39:52 +08:00
|
|
|
{
|
|
|
|
*aligned_dst++ = *aligned_src++;
|
|
|
|
*aligned_dst++ = *aligned_src++;
|
|
|
|
*aligned_dst++ = *aligned_src++;
|
|
|
|
*aligned_dst++ = *aligned_src++;
|
2010-09-22 11:15:07 +08:00
|
|
|
len0 -= BIGBLOCKSIZE;
|
2000-02-18 03:39:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy one long word at a time if possible. */
|
2010-09-22 11:15:07 +08:00
|
|
|
while (len0 >= LITTLEBLOCKSIZE)
|
2000-02-18 03:39:52 +08:00
|
|
|
{
|
|
|
|
*aligned_dst++ = *aligned_src++;
|
2010-09-22 11:15:07 +08:00
|
|
|
len0 -= LITTLEBLOCKSIZE;
|
2000-02-18 03:39:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Pick up any residual with a byte copier. */
|
|
|
|
dst = (char*)aligned_dst;
|
|
|
|
src = (char*)aligned_src;
|
|
|
|
}
|
|
|
|
|
2010-09-22 11:15:07 +08:00
|
|
|
while (len0--)
|
2000-02-18 03:39:52 +08:00
|
|
|
*dst++ = *src++;
|
|
|
|
|
|
|
|
return dst0;
|
|
|
|
#endif /* not PREFER_SIZE_OVER_SPEED */
|
|
|
|
}
|