Re: diff to speed up fdalloc using two-level bitmaps

Alan Barrett <[email protected]>
Newsgroups gmane.os.netbsd.devel.performance
Message-ID <[email protected]>
On Tue, 28 Oct 2003, Niels Provos wrote:
> An inline assembly function for finding the first zero bit in a
> word would be a great thing to have across architectures.

It's much easier to find the last (that is, least significant) set
or clear bit.  You can sometimes change the algorithm or the data
representation to suit.

    unsigned int find_last_set(unsigned int x)
    {
	return (x & -x);
    }

    unsigned int find_last_clear(unsigned int x)
    {
	return (~x & (x+1));
    }

--apb (Alan Barrett)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.