[U-Boot] [PATCH] lib/string: memmove: use memcpy if it is safe to do so
Peter Korsgaard
jacmet at sunsite.dk
Fri Oct 28 10:04:06 CEST 2011
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 <jacmet at sunsite.dk>
---
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
More information about the U-Boot
mailing list