12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- #include <string.h>
- void *memcpy(void *to, const void *from, size_t len)
- {
- unsigned long rem, chunks, tmp1, tmp2;
- unsigned char *tmp_to;
- unsigned char *tmp_from = (unsigned char *)from;
- chunks = len / 8;
- tmp_from -= 4;
- tmp_to = to - 4;
- if (!chunks)
- goto lessthan8;
- rem = (unsigned long )tmp_to % 4;
- if (rem)
- goto align;
- copy_chunks:
- do {
-
- tmp1 = *(unsigned long *)(tmp_from+4);
- tmp_from += 8;
- tmp2 = *(unsigned long *)tmp_from;
- *(unsigned long *)(tmp_to+4) = tmp1;
- tmp_to += 8;
- *(unsigned long *)tmp_to = tmp2;
- } while (--chunks);
- lessthan8:
- len = len % 8;
- if (len >= 4) {
- tmp_from += 4;
- tmp_to += 4;
- *(unsigned long *)(tmp_to) = *(unsigned long *)(tmp_from);
- len -= 4;
- }
- if (!len)
- return to;
- tmp_from += 3;
- tmp_to += 3;
- do {
- *++tmp_to = *++tmp_from;
- } while (--len);
- return to;
- align:
-
- rem = 4 - rem;
- len -= rem;
- do {
- *(tmp_to+4) = *(tmp_from+4);
- ++tmp_from;
- ++tmp_to;
- } while (--rem);
- chunks = len / 8;
- if (chunks)
- goto copy_chunks;
- goto lessthan8;
- }
- libc_hidden_def(memcpy)
|