This is the mail archive of the libc-alpha@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]

Optimized? strchr implementations.


On Tue, May 26, 2015 at 01:23:36PM +0100, Wilco Dijkstra wrote:
> > OndÅej BÃlka wrote:
> > On Sun, May 24, 2015 at 06:32:14PM +0200, OndÅej BÃlka wrote:
> > > Hi,
> > > this is nontrivial optimization of string inlines.
> > > First it decreases icache pressure as you don't need strchr.
> 
> It's not obvious to me that is the right thing to do. Generally it is best
> to use the standard C90/C99 functions rather than infrequently used
> non-standard ones. A quick grep of GLIBC shows strchr is used a lot more
> than strchrnul, and 9 targets have an optimized strchr vs 5 for strchrnul.
>
I looked at how architectures optimize strchr and that number is less.

Some of these are not optimized implementations. If you do gcc
string/strchr.c -S then you get assembly implementation. Several
architectures don't exploit any hardware capabilities, just use same
algorithm as generic so these could be deleted.

I know that generic implementation could be improved and will post a
patches.

Only two that are real optimizations and don't have strchnul are armv6
and alpha
So could you adapt armv6 one? 

Richard as you added alpha could you adapt it to strchnul? And why you
do a binary search there? Accoring to wiki alpha supports ctlz
instruction that does exactly that.


So here follows list of strchr(nul)? 

./sysdeps/powerpc/powerpc64/power7/strchr.S
./sysdeps/powerpc/powerpc64/power7/strchrnul.S
./sysdeps/powerpc/powerpc64/strchr.S
./sysdeps/powerpc/powerpc32/power7/strchr.S
./sysdeps/powerpc/powerpc32/power7/strchrnul.S
./sysdeps/powerpc/powerpc32/strchr.S

Power7 hardware support.

A generic could be replaced by one from string.h

./sysdeps/m68k/strchr.S
./sysdeps/m68k/strchrnul.S

replace by generic

./sysdeps/i386/strchr.S
./sysdeps/i386/strchrnul.S

replace by generic

./sysdeps/ia64/strchr.S

hardware dont have strchrnul

./sysdeps/sparc/sparc64/strchr.S
./sysdeps/sparc/sparc32/strchr.S

replace with generic

./sysdeps/alpha/strchr.S

harware

./sysdeps/arm/armv6/strchr.S

hardware

./sysdeps/aarch64/strchr.S
./sysdeps/aarch64/strchrnul.S

hardware




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