[coreboot] r3236 - in trunk/payloads/libpayload: include libc

Segher Boessenkool segher at kernel.crashing.org
Sat Apr 12 01:16:14 CEST 2008


> >> +int isxdigit(int c)
> >> +{
> >> + return isdigit(c) || (tolower(c)>= 'a' && tolower(c) <= 'z');
> >> +}
> >
> > Shouldn't this be
> >
> > return isdigit(c) || (tolower(c)>= 'a' && tolower(c) <= 'f');
> jep it should..
> but why not :
>  return isdigit(c) || c>= 'a' && c <= 'f' || c>= 'A' && c <= 'F' );

For one thing, because it doesn't compile.  Also, the compiler
will generate equivalent code (also wrt size and speed).

> it might be even faster if you do
> return isdigit(c) || (c & ~0x20)>= 'A' && (c & ~0x20) <= 'F' );

Or we could write it as

	return ((c >= '0') + (c > '9') + (c >= 'a') + (c > 'f') + (c >= 'A') + 
(c > 'F')) & 1;

which might be even faster!

You cannot tell without measuring, and it doesn't matter anyway:
the most important things to optimise for are readability and
maintainability (and those two are very much related).


Segher





More information about the coreboot mailing list