This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH][RFC] Avoid table lookup in isascii, isxdigit.
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: Carlos O'Donell <carlos at redhat dot com>
- Cc: libc-alpha at sourceware dot org, Siddhesh Poyarekar <siddhesh at redhat dot com>
- Date: Fri, 12 Apr 2013 20:45:12 +0200
- Subject: Re: [PATCH][RFC] Avoid table lookup in isascii, isxdigit.
- References: <20130409115706 dot GA7587 at domone dot kolej dot mff dot cuni dot cz> <5164176B dot 3090100 at redhat dot com>
On Tue, Apr 09, 2013 at 09:28:11AM -0400, Carlos O'Donell wrote:
> On 04/09/2013 07:57 AM, OndÅej BÃlka wrote:
> > Hi, I looked to ctype and thougth if it is possible to decrease table
> > size to 512 bytes. I did not succeed but made following three
> > optimizations.
> >
> > 1. In isdigit use & instead &&. Gcc contains bug that optimizes first
> > but not second case.
> > 2. Refactor isdigit macro
> > 3. Write isxdigit and isascii.
>
> You should add a microbenchmark for isdigit, isascii, and isxdigit :-)
>
When I tried to benchmark this I discovered that situation is bit more
complicated.
When you compile following (even without optimizations)
int foo(char *x)
{
return isdigit(x);
}
Then gcc optimizes call in same way as we internaly do.
However when ctype.h is included then we expand isdigit first with table
lookup.
#include <ctype.h>
int foo(char *x)
{
return isdigit(x);
}
As nobody complained at gcc I guess that we could always define isdigit
macro and we will get identical assembly as without ctype.
isxdigit should be exactly same case.
This expansion is problem that I cannot observe wild behaviour and
must rely on microbenchmarks (or recompile system which is very
time consuming.)
Ondra