From f2e140f2888bc91aca185c0383419a8e949705e4 Mon Sep 17 00:00:00 2001 From: Andrew Waterman Date: Mon, 8 Dec 2014 13:29:50 -0800 Subject: newlib, glibc: fix memcpy bug h/t Martin Maas --- newlib/newlib/libc/machine/riscv/memcpy.c | 42 ++++++++++++++++++------------- 1 file changed, 25 insertions(+), 17 deletions(-) (limited to 'newlib') diff --git a/newlib/newlib/libc/machine/riscv/memcpy.c b/newlib/newlib/libc/machine/riscv/memcpy.c index 12618eb..56349da 100644 --- a/newlib/newlib/libc/machine/riscv/memcpy.c +++ b/newlib/newlib/libc/machine/riscv/memcpy.c @@ -15,7 +15,7 @@ void* memcpy(void* aa, const void* bb, size_t n) uintptr_t msk = sizeof(long)-1; if (__builtin_expect(((uintptr_t)a & msk) != ((uintptr_t)b & msk) || n < sizeof(long), 0)) { -foo: +small: if (__builtin_expect(a < end, 1)) while (a < end) BODY(a, b, char); @@ -26,34 +26,42 @@ foo: while ((uintptr_t)a & msk) BODY(a, b, char); - long* __restrict__ la = (long*)a; - const long* __restrict__ lb = (const long*)b; + long* la = (long*)a; + const long* lb = (const long*)b; long* lend = (long*)((uintptr_t)end & ~msk); if (__builtin_expect(la < lend-8, 0)) { while (la < lend-8) { - *la++ = *lb++; - *la++ = *lb++; - *la++ = *lb++; - *la++ = *lb++; - *la++ = *lb++; - *la++ = *lb++; - *la++ = *lb++; - *la++ = *lb++; - *la++ = *lb++; + long b0 = *lb++; + long b1 = *lb++; + long b2 = *lb++; + long b3 = *lb++; + long b4 = *lb++; + long b5 = *lb++; + long b6 = *lb++; + long b7 = *lb++; + long b8 = *lb++; + *la++ = b0; + *la++ = b1; + *la++ = b2; + *la++ = b3; + *la++ = b4; + *la++ = b5; + *la++ = b6; + *la++ = b7; + *la++ = b8; } - if (la == lend) - goto bar; } - do BODY(la, lb, long) while (la < lend); + while (la < lend) + BODY(la, lb, long); -bar: +maybe_done: a = (char*)la; b = (const char*)lb; if (__builtin_expect(a < end, 0)) - goto foo; + goto small; return aa; } -- cgit v1.1