All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Robert P. J. Day" <rpjday@crashcourse.ca>
To: Petr Tesarik <ptesarik@suse.cz>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	David Daney <ddaney@caviumnetworks.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] Introduce a boolean "single_bit_set" function.
Date: Tue, 30 Jun 2009 06:18:01 -0400 (EDT)	[thread overview]
Message-ID: <alpine.LFD.2.00.0906300608001.10353@localhost> (raw)
In-Reply-To: <1246342379.31661.5.camel@nathan.suse.cz>

[-- Attachment #1: Type: TEXT/PLAIN, Size: 2235 bytes --]

On Tue, 30 Jun 2009, Petr Tesarik wrote:

> Robert P. J. Day píše v Po 29. 06. 2009 v 14:50 -0400:

> >   since i originally muttered about this, the rationale behind it
> > was not for performance (obviously), but for semantic
> > clarification, so that when you saw the expression "n & (n-1)", it
> > was more obvious which test you were doing semantically:
> >
> > 1) is n a power of 2?
> > 2) does n represent a single set bit?
> >
> > nothing ever came of that, but that was the thinking behind it.
>
> Yes, I can remember and I would still appreciate it. It's always
> better to show _what_ the code does rather than _how_ it does it.
>
> IIRC Andrew rejected your patch on the grounds that it is possible
> to replace the expression "n & (n-1)" with "hweight(n) == 1" if one
> wants to show that it really tests for a single bit set. But I don't
> like his proposal quite as much as yours, because of the big
> overhead.
>
> In short, if you re-post your patch, I'll gladly join you in the
> battle of getting it in. ;-)

  i never meant for this to turn into a pitched battle of
philosophies -- it just seemed like a simple way to make the code
clearer, particularly since some of the patches i've submitted allowed
for the removal of comments like "test that blocksize is a power of
2" given that what you're testing is now painfully obvious. :-)

  if someone has a quick, simple and performance non-crippling
suggestion for this, i'm all ears.  but there's no point thinking
about it if it's actually going to cause performance issues.

rday

p.s.  a simple grep to find potential cleanup of the form n&(n-1):

grep -Ern "([^\(\)]+) ?\& ?\(\1 ?- ?1\)" * | less

--

========================================================================
Robert P. J. Day                               Waterloo, Ontario, CANADA

        Linux Consulting, Training and Annoying Kernel Pedantry.

Web page:                                          http://crashcourse.ca
Linked In:                             http://www.linkedin.com/in/rpjday
Twitter:                                       http://twitter.com/rpjday
========================================================================

  reply	other threads:[~2009-06-30 10:20 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-23 17:43 [PATCH] Introduce a boolean "single_bit_set" function Robert P. J. Day
2009-04-23 19:57 ` David Daney
2009-04-23 20:11   ` Robert P. J. Day
2009-04-23 23:57   ` Andrew Morton
2009-04-24 10:40     ` Robert P. J. Day
2009-04-24 17:46       ` Andrew Morton
2009-04-25 22:09         ` Robert P. J. Day
2009-06-29 18:15         ` Petr Tesarik
2009-06-29 18:50           ` Robert P. J. Day
2009-06-30  6:12             ` Petr Tesarik
2009-06-30 10:18               ` Robert P. J. Day [this message]
2009-04-24 13:51     ` Robert P. J. Day
2009-05-28 12:21 ` Petr Tesarik
2009-05-28 12:27   ` Robert P. J. Day
2009-05-28 12:32   ` Robert P. J. Day
2009-05-28 13:12     ` Petr Tesarik
2009-06-29 18:50       ` H. Peter Anvin

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=alpine.LFD.2.00.0906300608001.10353@localhost \
    --to=rpjday@crashcourse.ca \
    --cc=akpm@linux-foundation.org \
    --cc=ddaney@caviumnetworks.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ptesarik@suse.cz \
    /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.