Skip to content

Commit 890890c

Browse files
Alexey DobriyanIngo Molnar
authored andcommitted
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): <strlen>: 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 <adobriyan@gmail.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Jan Beulich <JBeulich@suse.com> Link: http://lkml.kernel.org/r/20111211181319.GA17097@p183.telecom.by Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent 79f1ddd commit 890890c

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

‎arch/x86/lib/string_32.c‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,13 @@ EXPORT_SYMBOL(strchr);
164164
size_t strlen(const char *s)
165165
{
166166
int d0;
167-
int res;
167+
size_t res;
168168
asm volatile("repne\n\t"
169-
"scasb\n\t"
170-
"notl %0\n\t"
171-
"decl %0"
169+
"scasb"
172170
: "=c" (res), "=&D" (d0)
173171
: "1" (s), "a" (0), "0" (0xffffffffu)
174172
: "memory");
175-
return res;
173+
return ~res - 1;
176174
}
177175
EXPORT_SYMBOL(strlen);
178176
#endif

0 commit comments

Comments
 (0)