[PATCH] string: Use memcpy() within memmove() when we can

Patrick Delaunay patrick.delaunay at st.com
Wed Nov 25 12:26:14 CET 2020


A common use of memmove() can be handled by memcpy(). Also memcpy()
includes an optimization for large sizes: it copies a word at a time. So
we can get a speed-up by calling memcpy() to handle our move in this case.

Update memmove() to call also memcpy() if the source don't overlap
the destination (src + count <= dest).

Signed-off-by: Patrick Delaunay <patrick.delaunay at st.com>
---
This patch allows to save 38ms for Kernel Image extraction (7327624 Bytes)
from FIT loaded at 0xC2000000 for ARMV7 board STM32MP157C-EV1,
and with kernel destination = Load Address: 0xc4000000,
located after the FIT without overlap, compared with
destination = Load Address: 0xc0008000.

-> 14,332 us vs 52,239 in bootstage report

In this case the memmove funtion is called in common/image.c::memmove_wd()
to handle overlap.


 lib/string.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/string.c b/lib/string.c
index ae7835f600..ef8ead976c 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -567,7 +567,7 @@ void * memmove(void * dest,const void *src,size_t count)
 {
 	char *tmp, *s;
 
-	if (dest <= src) {
+	if (dest <= src || (src + count) <= dest) {
 		memcpy(dest, src, count);
 	} else {
 		tmp = (char *) dest + count;
-- 
2.17.1



More information about the U-Boot mailing list