From: Alexey Dobriyan Date: Sun, 11 Dec 2011 18:13:19 +0000 (+0300) Subject: x86/i386: Use less assembly in strlen(), speed things up a bit X-Git-Tag: Ubuntu-5.4-5.4.0-11.14~19993^2~7 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=890890cb8e415e1e7a61bfe3c8e246f710196824;p=mirror_ubuntu-focal-kernel.git x86/i386: Use less assembly in strlen(), speed things up a bit Current i386 strlen() hardcodes NOT/DEC sequence. DEC is mentioned to be suboptimal on Core2. So, put only REPNE SCASB sequence in assembly, compiler can do the rest. The difference in generated code is like below (MCORE2=y): : push %edi mov $0xffffffff,%ecx mov %eax,%edi xor %eax,%eax repnz scas %es:(%edi),%al not %ecx - dec %ecx - mov %ecx,%eax + lea -0x1(%ecx),%eax pop %edi ret Signed-off-by: Alexey Dobriyan Cc: Linus Torvalds Cc: Jan Beulich Link: http://lkml.kernel.org/r/20111211181319.GA17097@p183.telecom.by Signed-off-by: Ingo Molnar --- diff --git a/arch/x86/lib/string_32.c b/arch/x86/lib/string_32.c index 82004d2bf05e..bd59090825db 100644 --- a/arch/x86/lib/string_32.c +++ b/arch/x86/lib/string_32.c @@ -164,15 +164,13 @@ EXPORT_SYMBOL(strchr); size_t strlen(const char *s) { int d0; - int res; + size_t res; asm volatile("repne\n\t" - "scasb\n\t" - "notl %0\n\t" - "decl %0" + "scasb" : "=c" (res), "=&D" (d0) : "1" (s), "a" (0), "0" (0xffffffffu) : "memory"); - return res; + return ~res - 1; } EXPORT_SYMBOL(strlen); #endif