It is not a matter of size, the fact that the table will end up in the data segment is enough to create misses if your program does something else than calling that function.
But you guys inspired me, so I attempted to fool around with the ascii table layout:
/**
* Assuming c is in "0123456789abcdef", the result will be wrong otherwise.
*/
char hexchartodec(const char c) {
char d = c - '0';
/* This if kind of means c >= '@', the compiler can't assume that c < 128
* (i also can't do that, but i don't give a fuck) */
if (c & 0x40) { //c to avoid a pipeline stall (we will have more below)
/* The point here is that ('1'+16='A')+32='a'.*/
--d; //or maybe d = c - '1';
d &= 0xf; /* from the alignment of the ascii table, the least
* significant decimal is ready */
d += 10;
}
return d;
}
However I couldn't get rid of the if and there are stalls inside the if as well. I'm sure that someone has a completly obsfucated version that does better than mine.