Android C库:
http://androidxref.com/9.0.0_r3/xref/bionic/libc/upstream-openbsd/lib/libc/string/
/*
37 * sizeof(word) MUST BE A POWER OF TWO
38 * SO THAT wmask BELOW IS ALL ONES
39 */
40typedef long word; /* "word" used for optimal copy speed */
41
42#define wsize sizeof(word)
43#define wmask (wsize - 1)
44
45/*
46 * Copy a block of memory, handling overlap.拷贝一块内存
47 */
48void *
49memmove(void *dst0, const void *src0, size_t length)
50{
51 char *dst = dst0;
52 const char *src = src0;
53 size_t t;
54
55 if (length == 0 || dst == src) /* nothing to do */
56 goto done;
57
58 /*
59 * Macros: loop-t-times; and loop-t-times, t>0
60 */
61#define TLOOP(s) if (t) TLOOP1(s)
62#define TLOOP1(s) do {
s; } while (--t)
63
64 if ((unsigned long)dst < (unsigned long)src) {
65 /*
66 * Copy forward.
67 */
68 t = (long)src; /* only need low bits */
69 if ((t | (long)dst) & wmask) {
70 /*
71 * Try to align operands. This cannot be done
72 * unless the low bits match.
73 */
74 if ((t ^ (long)dst) & wmask || length < wsize)
75 t = length;
76 else
77 t = wsize - (t & wmask);
78 length -= t;
79 TLOOP1(*dst++ = *src++);
80 }
81 /*
82 * Copy whole words, then mop up any trailing bytes.
83 */
84 t = length / wsize;
85 TLOOP(*(word *)dst = *(word *)src; src += wsize; dst += wsize);
86 t = length & wmask;
87 TLOOP(*dst++ = *src++);
88 } else {
89 /*
90 * Copy backwards. Otherwise essentially the same.
91 * Alignment works as before, except that it takes
92 * (t&wmask) bytes to align, not wsize-(t&wmask).
93 */
94 src += length;
95 dst += length;
96 t = (long)src;
97 if ((t | (long)dst) & wmask) {
98 if ((t ^ (long)dst) & wmask || length <= wsize)
99 t = length;
100 else
101 t &= wmask;
102 length -= t;
103 TLOOP1(*--dst = *--src);
104 }
105 t = length / wsize;
106 TLOOP(src -= wsize; dst