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]

Re: [PATCH][RFC] Avoid table lookup in isascii, isxdigit.


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


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