This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Re: More backref performance - no strncmp
- From: "Paolo Bonzini" <paolo dot bonzini at polimi dot it>
- To: <libc-alpha at sources dot redhat dot com>
- Date: Thu, 24 Oct 2002 09:46:39 +0200
- Subject: Re: More backref performance - no strncmp
- References: <006a01c27a79$dd47fff0$b71a1897@bonz> <m31y6h8cd8.fsf@code.and.org>
- Reply-to: "Paolo Bonzini" <bonzini at gnu dot org>
> Your my_memcmp() API is different from memcmp() only in the return
> value, and given the amount of optimization for the system one I'd be
> surprised if your version wasn't slower.
The system memcmp has higher startup times. Especially when the length is
small and the strings are unaligned, it boils down to the same code as mine,
except for the return value and for the startup overhead. my_memcmp is more
optimized than you'd think, for example I twiddled the builtin_expect values
in order to avoid that the code goes through dummy instruction inserted for
alignment purpose only.
On the x86, also, the return value actually means cutting the inner loop
from three to two instructions:
movzbl (%esi), %al
movzbl (%edi), %dl
subl %eax, %edx
to
movb (%edx), %al
cmpb %al, (%edi)
and also freeing a callee-save register.
Also note that, from my experiments, memcmp was actually slower than strncmp
(!), and my_memcmp was faster than strncmp. This is because I designed for
different conditions (strings possibly unaligned and small length) and
because it is easily inlined.
Paolo