From: "Darren Jenkins" <darrenrjenkins-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Linus Torvalds
<torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
Cc: Ivo van Doorn <ivdoorn-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
Johannes Berg <johannes-cdvu00un1VgdHxzADdlk8Q@public.gmane.org>,
Pavel Roskin <proski-mXXj517/zsQ@public.gmane.org>,
linux-wireless-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-sparse-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: sparse using insane amounts of memory
Date: Sat, 10 Mar 2007 16:05:08 +1100 [thread overview]
Message-ID: <82faac5b0703092105x75149bcdx5813e18f96db8004@mail.gmail.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0703081104010.10832-5CScLwifNT1QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>
On 3/9/07, Linus Torvalds <torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org> wrote:
>
>
> On Thu, 8 Mar 2007, Linus Torvalds wrote:
> >
> > To check a value for being a nice range of consecutive bits, you can
> > simply do:
> >
> > #define is_power_of_two(x) (!((x) & ((x)-1)))
There is already an inline for this in log2.h
/*
* Determine whether some value is a power of two, where zero is
* *not* considered a power of two.
*/
static inline __attribute__((const))
bool is_power_of_2(unsigned long n)
{
return (n != 0 && ((n & (n - 1)) == 0));
}
> - 0 is special, and is generally considered to be a power of two (and
> this is more fundamental than you'd think: it's not just fall-out from
> the particular expression chosen, it is fundamentally *required* to
> handle overflow, and you can think of 0 as 2**x, x > wordsize if that
> makes you more comfortable with the notion that zero is a power-of-two
> in any finite representation of 2's complement)
>
> The "zero is special" thing means that if you don't want to accept zero as
> a valid mask (it technically *is* a contiguous set of bits set - it's just
> the empty set) you'd need to check for it specially.
I guess the person who wrote it wasn't thinking discrete maths at the time.
Darren J.
next prev parent reply other threads:[~2007-03-10 5:05 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-08 2:02 sparse using insane amounts of memory Johannes Berg
[not found] ` <1173319356.3546.54.camel-YfaajirXv214zXjbi5bjpg@public.gmane.org>
2007-03-08 16:33 ` Pavel Roskin
2007-03-08 16:45 ` Johannes Berg
2007-03-08 17:13 ` Pavel Roskin
2007-03-08 17:31 ` Chris Wedgwood
2007-03-08 17:43 ` Linus Torvalds
[not found] ` <1173372315.3248.19.camel-YfaajirXv214zXjbi5bjpg@public.gmane.org>
2007-03-08 17:34 ` Pavel Roskin
2007-03-08 17:42 ` Johannes Berg
2007-03-08 17:43 ` Johannes Berg
2007-03-08 18:08 ` Ivo van Doorn
2007-03-08 18:54 ` Linus Torvalds
[not found] ` <Pine.LNX.4.64.0703081023490.10832-5CScLwifNT1QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>
2007-03-08 19:02 ` Sam Ravnborg
2007-03-08 19:08 ` Linus Torvalds
[not found] ` <Pine.LNX.4.64.0703081104010.10832-5CScLwifNT1QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>
2007-03-10 5:05 ` Darren Jenkins [this message]
2007-03-08 19:26 ` Ivo van Doorn
2007-03-09 1:12 ` OT [Re: sparse using insane amounts of memory] Tommy Thorn
2007-03-09 2:15 ` OT David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=82faac5b0703092105x75149bcdx5813e18f96db8004@mail.gmail.com \
--to=darrenrjenkins-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=ivdoorn-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=johannes-cdvu00un1VgdHxzADdlk8Q@public.gmane.org \
--cc=linux-sparse-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-wireless-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=proski-mXXj517/zsQ@public.gmane.org \
--cc=torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).