More backref performance - no strncmp
Paolo Bonzini
paolo.bonzini@polimi.it
Thu Oct 24 00:54:00 GMT 2002
> 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
More information about the Libc-alpha
mailing list