Ceiling of the Logarthim Base Two

Joe Keane jgk at speech2.cs.cmu.edu
Wed Jul 6 09:55:49 AEST 1988


Too many branches!  A table-driven macro is much faster:

extern int ***FFSTable[256];
#define FFS(X) FFSTable[((unsigned)(X))>>24][(X)>>16&0xff][(X)>>8&0xff][(X)&0xff]

With good compilation, the FFS macro could be eight instructions on
many machines.  I'll let you figure out what the tables look like.
They take up 52K, which could be worth it if this takes up much time.
If speed isn't so important, you can do it a nibble at a time.

--Joe



More information about the Comp.lang.c mailing list