From c5b1badd7b5df8c7602fc313a785d35dd899f409 Mon Sep 17 00:00:00 2001 From: Peter Korsgaard Date: Fri, 28 Oct 2011 09:44:58 +0200 Subject: [PATCH] lib/string: memmove: use memcpy if it is safe to do so memmove is used in a number of performance critical places, like copying the linux kernel from nor flash to ram, so optimizing it can be interesting. Unfortunately, an arch specific version of memmove often isn't used, and not supported at all on a number of archs (arm/mips/nds32/nios2/x86) - But memcpy typically is. Often memmove is called for copies where src/dest don't overlap, so we could use the more efficient memcpy instead. Detect these situations and forward those request to memcpy instead. Adds 40 bytes to memmove and speeds up boot with ~300ms on a 400MHz arm9. Signed-off-by: Peter Korsgaard --- lib/string.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/lib/string.c b/lib/string.c index 2c4f0ec..239cc11 100644 --- a/lib/string.c +++ b/lib/string.c @@ -504,12 +504,16 @@ void * memmove(void * dest,const void *src,size_t count) return dest; if (dest <= src) { + if (dest + count <= src) + return memcpy(dest, src, count); tmp = (char *) dest; s = (char *) src; while (count--) *tmp++ = *s++; } else { + if (src + count <= dest) + return memcpy(dest, src, count); tmp = (char *) dest + count; s = (char *) src + count; while (count--) -- 1.7.6.3