From: Matthew Wilcox <matthew@wil.cx>
To: "Robert P. J. Day" <rpjday@crashcourse.ca>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH] SCSI: Use is_power_of_2() macro for simplicity.
Date: Tue, 6 Nov 2007 09:22:28 -0700 [thread overview]
Message-ID: <20071106162227.GH4113@parisc-linux.org> (raw)
In-Reply-To: <Pine.LNX.4.64.0711061107480.21836@localhost.localdomain>
On Tue, Nov 06, 2007 at 11:09:51AM -0500, Robert P. J. Day wrote:
> > > bits &= ~esp->scsi_id_mask;
> > > - if (!bits || (bits & (bits - 1)))
> > > + if (!is_power_of_2(bits))
> > > goto do_reset;
> >
> > Non-equivalent transform. Definitely a bug.
>
> ok, that one i'm curious about. how is that not an equivalent
> transform? am i missing something painfully obvious?
Apologies, I got my boolean algebra wrong. It is equivalent:
bool is_power_of_2(unsigned long n)
return (n != 0 && ((n & (n - 1)) == 0));
substitute it in:
if (!is_power_of_2(bits))
if (!(bits != 0 && ((bits & (bits - 1)) == 0)))
push the ! inside brackets:
if (bits == 0 || ((bits & (bits - 1)) != 0))
> > > - if (!bits || (bits & (bits - 1)))
Clearly the same thing. Still ... I don't like it because we're not
really looking for 'is this a power of two', we want to know 'is there
exactly one bit set'. Which, after a bit of thinking, is the same
thing, but it's a bad name for this usage. Perhaps we could add
#define exactly_one_bit_set is_power_of_2
to the header file.
--
Intel are signing my paycheques ... these opinions are still mine
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours. We can't possibly take such
a retrograde step."
next prev parent reply other threads:[~2007-11-06 16:22 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-06 15:20 [PATCH] SCSI: Use is_power_of_2() macro for simplicity Robert P. J. Day
2007-11-06 15:30 ` Matthew Wilcox
2007-11-06 16:09 ` Robert P. J. Day
2007-11-06 16:22 ` Matthew Wilcox [this message]
2007-11-06 16:32 ` Robert P. J. Day
2007-11-07 9:49 ` Robert P. J. Day
2007-11-07 20:59 ` Mike Christie
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=20071106162227.GH4113@parisc-linux.org \
--to=matthew@wil.cx \
--cc=linux-scsi@vger.kernel.org \
--cc=rpjday@crashcourse.ca \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.