From d07aed31e95fb596d452aaa96b3c9c3c28bd98f8 Mon Sep 17 00:00:00 2001 From: stefan Date: Tue, 10 Aug 2010 20:16:09 +0000 Subject: [PATCH] - add optimized assembler code for strlen git-svn-id: http://svn.lfbs.rwth-aachen.de/svn/scc/trunk/MetalSVM@61 315a16e6-25f9-4109-90ae-ca3045a26c18 --- arch/x86/include/asm/string.h | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/string.h b/arch/x86/include/asm/string.h index 4ef4f3b5..67d89da6 100644 --- a/arch/x86/include/asm/string.h +++ b/arch/x86/include/asm/string.h @@ -35,7 +35,7 @@ inline static void *memcpy(void *dest, const void *src, size_t count) return dest; asm volatile ( - "rep ; movsl\n\t" + "cld; rep ; movsl\n\t" "movl %4, %%ecx\n\t" "andl $3, %%ecx\n\t" "rep ; movsb\n\t" @@ -54,12 +54,32 @@ inline static void *memset(void *dest, int val, size_t count) if (BUILTIN_EXPECT(!dest, 0)) return dest; - asm volatile ("rep ; stosb" : "=&c"(i), "=&D"(j) : "a"(val), "1"(dest), "0"(count) : "memory"); + asm volatile ("cld; rep ; stosb" + : "=&c"(i), "=&D"(j) + : "a"(val), "1"(dest), "0"(count) : "memory"); return dest; } #endif +#ifdef HAVE_ARCH_STRLEN +inline static size_t strlen(const char *str) +{ + size_t len = 0; + uint32_t i, j = 0; + + if (BUILTIN_EXPECT(!str, 0)) + return len; + + asm volatile("not %%ecx; cld; repne ; scasb; not %%ecx; dec %%ecx" + : "=&c"(len), "=&D"(i), "=&a"(j) + : "2"(j), "1"(str), "0"(len) + : "memory"); + + return len; +} +#endif + #ifdef __cplusplus } #endif