This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Optimized? strchr implementations.
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: Matt Turner <mattst88 at gmail dot com>
- Cc: Wilco Dijkstra <wdijkstr at arm dot com>, GNU C Library <libc-alpha at sourceware dot org>, Richard henderson <rth at redhat dot com>
- Date: Tue, 26 May 2015 19:06:15 +0200
- Subject: Re: Optimized? strchr implementations.
- Authentication-results: sourceware.org; auth=none
- References: <20150524150715 dot GA31589 at domone> <20150524163214 dot GA28053 at domone> <20150524171036 dot GA20947 at domone> <000b01d097ae$ca78c340$5f6a49c0$ at com> <20150526143854 dot GA24529 at domone> <CAEdQ38FotH=A7aE78q=e790n-MwonaJST3YerWo-j4Xcy6ugQQ at mail dot gmail dot com>
On Tue, May 26, 2015 at 09:58:01AM -0700, Matt Turner wrote:
> On Tue, May 26, 2015 at 7:38 AM, OndÅej BÃlka <neleai@seznam.cz> wrote:
> > 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.
>
> It's because Alphas < EV67 don't have ctlz.
OK. You could try optimize it bit by implementing ctl with
multiplication but that likely doesn't matter.