Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!mit-eddie!uw-beaver!cornell!rochester!pt.cs.cmu.edu!speech2.cs.cmu.edu!jgk
From: jgk@speech2.cs.cmu.edu (Joe Keane)
Newsgroups: comp.lang.c
Subject: Re: Ceiling of the Logarthim Base Two
Message-ID: <2174@pt.cs.cmu.edu>
Date: 5 Jul 88 23:55:49 GMT
References: <1802@loral.UUCP> <690009@hpfelg.HP.COM> <10978@sol.ARPA> <540@philmds.UUCP>
Sender: netnews@pt.cs.cmu.edu
Organization: Carnegie Mellon Computer Science
Lines: 11

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