This is the mail archive of the
libc-ports@sources.redhat.com
mailing list for the libc-ports project.
Re: [Patch, mips] Faster strcmp for mips
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: Steve Ellcey <sellcey at mips dot com>
- Cc: libc-ports at sourceware dot org
- Date: Tue, 19 Nov 2013 00:50:11 +0100
- Subject: Re: [Patch, mips] Faster strcmp for mips
- Authentication-results: sourceware.org; auth=none
- References: <1384464221 dot 2484 dot 86 dot camel at ubuntu-sellcey> <20131114231434 dot GA5331 at domone dot podge> <1384539604 dot 2484 dot 102 dot camel at ubuntu-sellcey> <20131115190200 dot GA28546 at domone dot podge> <1384817878 dot 2484 dot 137 dot camel at ubuntu-sellcey>
On Mon, Nov 18, 2013 at 03:37:58PM -0800, Steve Ellcey wrote:
> On Fri, 2013-11-15 at 20:02 +0100, OndÅej BÃlka wrote:
>
> > I decided that using ffls was shorter but for some reasons I kept
> > bitfirst there. A correct version is
> >
> > uint64_t bitmask = DETECTNULL8(x) | (x ^ y);
> > int pos = (ffsl(bitmask) - 1) / 8;
> > return a[pos] - b[pos];
>
> Yes, that works much better. But it only works in little-endian mode. I
> think I would need a fls (find last set) or something similar for
> big-endian wouldn't I? Or else I would need to swap the bytes around
> before using ffs/ffsl.
>
Yes, a correct function is __builtin_clzl. Difference from ffs is that when you pass zero then result is undefined which should not be problem here.
There are more builtins here:
http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html