Re: new dentry feature in 2.1.78

Linus Torvalds (torvalds@transmeta.com)
Sat, 10 Jan 1998 15:48:07 -0800 (PST)


On Sat, 10 Jan 1998, David S. Miller wrote:
>
> #define i (((unsigned long) inode)/(sizeof(struct inode) & ~ (sizeof(struct inode) - 1)))
>
> It was so easy, I had to answer. ;-)
> It removes the non-significant bits from the inode address ;-)

Right.

> And even when struct inode is not a strict power of 2 (which it
> typically isn't) gcc still does a decent job since most of the
> operations are constant and get optimized away. Gcc in this case,
> has a very good idea what you are trying to do ;-)

Note that even when the size is not a strict power of two, the sequence
will find the largest power of two that the size is divisible by - which
tends to be just the size of an "unsigned long", but instead of just using
that directly the above at least has a small chance of finding a larger
power of two if one were to be available.

Whether the calculation helps I can't really say, but it may help, and it
certainly cannot make matters worse.

Linus