This is the mail archive of the libc-help@sourceware.org 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: strcmp


Hi StÃphane,

StÃphane FORNENGO wrote:

> may be a stupid question but reading the source code of
> string/strcmp.c I wonder why not using word comparaisons rather than
> byte to byte comparaisons.

In practice architecture-specific implementations tend to be used.

 $ git ls-files -- '*/strcmp.*'
 string/strcmp.c
 sysdeps/i386/i686/multiarch/strcmp.S
 sysdeps/i386/i686/strcmp.S
 sysdeps/ia64/strcmp.S
 sysdeps/powerpc/powerpc32/strcmp.S
 sysdeps/powerpc/powerpc64/strcmp.S
 sysdeps/s390/s390-32/strcmp.S
 sysdeps/s390/s390-64/strcmp.S
 sysdeps/sparc/sparc32/sparcv9/strcmp.S
 sysdeps/sparc/sparc32/strcmp.S
 sysdeps/sparc/sparc64/strcmp.S
 sysdeps/x86_64/multiarch/strcmp.S
 sysdeps/x86_64/strcmp.S

If string/strcmp.c can be portably made to make competitive or better
code than some of those implementations, I believe it would be
worthwhile, since it should make speed on i486 and on new
architectures a little better.  (Though I am a nobody.  Please don't
place much stock in my opinion.)

A quick web search reveals that some optimization along the lines you
suggest has been done for newlib; maybe that could be usable.
http://sourceware.org/ml/newlib/1997/msg00022.html
http://sourceware.org/cgi-bin/cvsweb.cgi/src/newlib/libc/string/?cvsroot=src

Hope that helps,
Jonathan


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