[Skiboot] [PATCH 11/34] libc: Use 8-bytes stores for non-0 memset too

Benjamin Herrenschmidt benh at kernel.crashing.org
Sun Jul 24 09:27:05 AEST 2016


Memory poisoning hammers this, so let's be a bit smart about it and
avoid falling back to byte stores when the data is not 0

Signed-off-by: Benjamin Herrenschmidt <benh at kernel.crashing.org>
---
 libc/string/memset.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/libc/string/memset.c b/libc/string/memset.c
index 18b7619..dae4366 100644
--- a/libc/string/memset.c
+++ b/libc/string/memset.c
@@ -18,6 +18,7 @@ void *
 memset(void *dest, int c, size_t size)
 {
 	unsigned char *d = (unsigned char *)dest;
+	unsigned long big_c = 0;
 
 #if defined(__powerpc__) || defined(__powerpc64__)
 	if (size > CACHE_LINE_SIZE && c==0) {
@@ -33,8 +34,14 @@ memset(void *dest, int c, size_t size)
 	}
 #endif
 
+	if (c) {
+		big_c = c;
+		big_c |= (big_c << 8) | big_c;
+		big_c |= (big_c << 16) | big_c;
+		big_c |= (big_c << 32) | big_c;
+	}
 	while (size >= 8 && c == 0) {
-		*((unsigned long long*)d) = 0ULL;
+		*((unsigned long *)d) = big_c;
 		d+=8;
 		size-=8;
 	}
-- 
2.7.4



More information about the Skiboot mailing list