This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: More backref performance - no strncmp


> 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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]