3 <<mempcpy>>---copy memory regions and return end pointer
7 void* mempcpy(void *<[out]>, const void *<[in]>, size_t <[n]>);
10 void *mempcpy(<[out]>, <[in]>, <[n]>
16 This function copies <[n]> bytes from the memory region
17 pointed to by <[in]> to the memory region pointed to by
20 If the regions overlap, the behavior is undefined.
23 <<mempcpy>> returns a pointer to the byte following the
24 last byte copied to the <[out]> region.
27 <<mempcpy>> is a GNU extension.
29 <<mempcpy>> requires no supporting OS subroutines.
38 /* Nonzero if either X or Y is not aligned on a "long" boundary. */
39 #define UNALIGNED(X, Y) \
40 (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))
42 /* How many bytes are copied each iteration of the 4X unrolled loop. */
43 #define BIGBLOCKSIZE (sizeof (long) << 2)
45 /* How many bytes are copied each iteration of the word copy loop. */
46 #define LITTLEBLOCKSIZE (sizeof (long))
48 /* Threshhold for punting to the byte copier. */
49 #define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE)
52 _DEFUN (mempcpy
, (dst0
, src0
, len0
),
57 #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
58 char *dst
= (char *) dst0
;
59 char *src
= (char *) src0
;
69 _CONST
char *src
= src0
;
71 _CONST
long *aligned_src
;
74 /* If the size is small, or either SRC or DST is unaligned,
75 then punt into the byte copy loop. This should be rare. */
76 if (!TOO_SMALL(len
) && !UNALIGNED (src
, dst
))
78 aligned_dst
= (long*)dst
;
79 aligned_src
= (long*)src
;
81 /* Copy 4X long words at a time if possible. */
82 while (len
>= BIGBLOCKSIZE
)
84 *aligned_dst
++ = *aligned_src
++;
85 *aligned_dst
++ = *aligned_src
++;
86 *aligned_dst
++ = *aligned_src
++;
87 *aligned_dst
++ = *aligned_src
++;
91 /* Copy one long word at a time if possible. */
92 while (len
>= LITTLEBLOCKSIZE
)
94 *aligned_dst
++ = *aligned_src
++;
95 len
-= LITTLEBLOCKSIZE
;
98 /* Pick up any residual with a byte copier. */
99 dst
= (char*)aligned_dst
;
100 src
= (char*)aligned_src
;
107 #endif /* not PREFER_SIZE_OVER_SPEED */