From a2819c68747023952e02e83512c5e8fc9e4861c9 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Tue, 4 Oct 2016 16:45:42 +0200 Subject: [PATCH] minor improvements in memset (usage of stosq instead of stosb) --- hermit/arch/x86/include/asm/string.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/hermit/arch/x86/include/asm/string.h b/hermit/arch/x86/include/asm/string.h index 5d74fed40..5252e96e6 100644 --- a/hermit/arch/x86/include/asm/string.h +++ b/hermit/arch/x86/include/asm/string.h @@ -66,9 +66,19 @@ inline static void *memset(void* dest, int val, size_t count) if (BUILTIN_EXPECT(!dest, 0)) return dest; - asm volatile ("cld; rep stosb" - : "=&c"(i), "=&D"(j) - : "a"(val), "1"(dest), "0"(count) : "memory","cc"); + if (val) { + asm volatile ("cld; rep stosb" + : "=&c"(i), "=&D"(j) + : "a"(val), "1"(dest), "0"(count) : "memory","cc"); + } else { + asm volatile ( + "cld; rep stosq\n\t" + "movq %5, %%rcx\n\t" + "andq $7, %%rcx\n\t" + "rep stosb\n\t" + : "=&c"(i), "=&D"(j) + : "a"((size_t)val), "1"(dest), "0"(count/8), "g"(count): "memory","cc"); + } return dest; }