3 <<mempcpy>>---copy memory regions and return end pointer
7 void* mempcpy(void *<[out]>, const void *<[in]>, size_t <[n]>);
10 This function copies <[n]> bytes from the memory region
11 pointed to by <[in]> to the memory region pointed to by
14 If the regions overlap, the behavior is undefined.
17 <<mempcpy>> returns a pointer to the byte following the
18 last byte copied to the <[out]> region.
21 <<mempcpy>> is a GNU extension.
23 <<mempcpy>> requires no supporting OS subroutines.
32 /* Nonzero if either X or Y is not aligned on a "long" boundary. */
33 #define UNALIGNED(X, Y) \
34 (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))
36 /* How many bytes are copied each iteration of the 4X unrolled loop. */
37 #define BIGBLOCKSIZE (sizeof (long) << 2)
39 /* How many bytes are copied each iteration of the word copy loop. */
40 #define LITTLEBLOCKSIZE (sizeof (long))
42 /* Threshhold for punting to the byte copier. */
43 #define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE)
50 #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
51 char *dst
= (char *) dst0
;
52 char *src
= (char *) src0
;
62 const char *src
= src0
;
64 const long *aligned_src
;
66 /* If the size is small, or either SRC or DST is unaligned,
67 then punt into the byte copy loop. This should be rare. */
68 if (!TOO_SMALL(len0
) && !UNALIGNED (src
, dst
))
70 aligned_dst
= (long*)dst
;
71 aligned_src
= (long*)src
;
73 /* Copy 4X long words at a time if possible. */
74 while (len0
>= BIGBLOCKSIZE
)
76 *aligned_dst
++ = *aligned_src
++;
77 *aligned_dst
++ = *aligned_src
++;
78 *aligned_dst
++ = *aligned_src
++;
79 *aligned_dst
++ = *aligned_src
++;
83 /* Copy one long word at a time if possible. */
84 while (len0
>= LITTLEBLOCKSIZE
)
86 *aligned_dst
++ = *aligned_src
++;
87 len0
-= LITTLEBLOCKSIZE
;
90 /* Pick up any residual with a byte copier. */
91 dst
= (char*)aligned_dst
;
92 src
= (char*)aligned_src
;
99 #endif /* not PREFER_SIZE_OVER_SPEED */