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