- 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
This commit is contained in:
stefan 2010-08-10 20:16:09 +00:00
parent 67ba4fba6a
commit d07aed31e9

View file

@ -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