[Skiboot] [PATCH 09/11] Optimize memset() implementation to do word at a time
Stewart Smith
stewart at linux.vnet.ibm.com
Thu May 7 17:11:48 AEST 2015
Makes booting with gcov enabled take dozens of seconds faster
Signed-off-by: Stewart Smith <stewart at linux.vnet.ibm.com>
---
libc/string/memset.c | 15 ++++++++++++++-
libc/test/run-memops-test.c | 16 ++++++++++++++++
libc/test/run-memops.c | 3 +++
3 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/libc/string/memset.c b/libc/string/memset.c
index f8dfbf5..e7172b0 100644
--- a/libc/string/memset.c
+++ b/libc/string/memset.c
@@ -15,7 +15,20 @@
void *
memset(void *dest, int c, size_t size)
{
- unsigned char *d = (unsigned char *)dest;
+ unsigned char *d;
+ unsigned long long *d64 = (unsigned long long*)dest;
+ unsigned long long c8 = c;
+
+ if (size > 8) {
+ c8 = c8 | c8 << 8ULL | c8 << 16ULL | c8 << 24ULL | c8 << 32ULL
+ | c8 << 40ULL | c8 << 48ULL | c8 << 56ULL;
+ while (size > 8) {
+ *d64++ = c8;
+ size = size - 8;
+ }
+ }
+
+ d = (unsigned char *)d64;
while (size-- > 0) {
*d++ = (unsigned char)c;
diff --git a/libc/test/run-memops-test.c b/libc/test/run-memops-test.c
index 0979994..6ec5a27 100644
--- a/libc/test/run-memops-test.c
+++ b/libc/test/run-memops-test.c
@@ -41,3 +41,19 @@
#include "../string/strncpy.c"
#include "../string/strstr.c"
#include "../string/strtok.c"
+
+char buf[100];
+
+int test_memset(void);
+
+int test_memset(void)
+{
+ int i;
+ int r= 0;
+
+ memset(buf, 0x42, sizeof(buf));
+ for(i=0; i<sizeof(buf); i++)
+ if (buf[i] != 0x42)
+ r = -1;
+ return r;
+}
diff --git a/libc/test/run-memops.c b/libc/test/run-memops.c
index 15ec9bd..7158b6b 100644
--- a/libc/test/run-memops.c
+++ b/libc/test/run-memops.c
@@ -21,7 +21,10 @@
#include <string.h>
#include <stdio.h>
+int test_memset(void);
+
int main(void)
{
+ assert(test_memset() == 0);
return 0;
}
--
1.7.10.4
More information about the Skiboot
mailing list