Re: [PATCH] resizeable printk ring buffer

From: dean gaudet (dean-list-linux-kernel@arctic.org)
Date: Mon Aug 21 2000 - 10:49:44 EST


On Mon, 21 Aug 2000, Paul Gortmaker wrote:

> + i = 128;
> + while (i != len && i != 4) i>>=1;
> + if (i != len)
> + goto out;

just as an aside, there's a cute operation which tells you if there's
exactly 1 bit on in a word, which in this case would look like:

        if (len & (len - 1))
                goto out; /* not a power of 2 */

it's easiest to prove it with pencil and paper, and represent len in
binary form.

(there's a natural extension of this to counting 1-bits in a word...
which is a fun interview question i hear.)

-dean

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Wed Aug 23 2000 - 21:00:04 EST