123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- #include <string.h>
- #undef memcpy
- void attribute_hidden *__memcpy(void *to, const void *from, size_t n)
- {
- unsigned long rem, chunks, tmp1, tmp2;
- unsigned char *tmp_to;
- unsigned char *tmp_from = (unsigned char *)from;
- chunks = n / 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:
- n = n % 8;
- if (n >= 4) {
- *(unsigned long *)(tmp_to+4) = *(unsigned long *)(tmp_from+4);
- tmp_from += 4;
- tmp_to += 4;
- n = n-4;
- }
- if (!n ) return to;
- tmp_from += 3;
- tmp_to += 3;
- do {
- *++tmp_to = *++tmp_from;
- } while (--n);
-
- return to;
- align:
- rem = 4 - rem;
- n = n - rem;
- do {
- *(tmp_to+4) = *(tmp_from+4);
- ++tmp_from;
- ++tmp_to;
- } while (--rem);
- chunks = n / 8;
- if (chunks)
- goto copy_chunks;
- goto lessthan8;
- }
- strong_alias(__memcpy, memcpy)
|