All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Robert P. J. Day" <rpjday@mindspring.com>
To: kernel-janitors@vger.kernel.org
Subject: Re: [KJ] anyone interested in the "power of 2" stuff?
Date: Tue, 13 Feb 2007 11:56:01 +0000	[thread overview]
Message-ID: <Pine.LNX.4.64.0702130632400.4141@localhost.localdomain> (raw)
In-Reply-To: <Pine.LNX.4.64.0702081713530.5222@localhost.localdomain>

On Tue, 13 Feb 2007, Vignesh Babu BM wrote:

>
> On Tue, 2007-02-13 at 04:46 -0500, Robert P. J. Day wrote:
> > On Tue, 13 Feb 2007, Vignesh Babu BM wrote:
> >
> > >
> > > I have a doubt:
> > > There are instances as follows:
> > >
> > > if(!iobase_reg && !is_power_of_2(iobase_reg))
> > > ---where we are checking for 0 at 2 places-both inside and outside of
> > > is_power_of_2
> > >
> > > But the n & (n-1) is just one step.
> > > Is this not more optimised?
> > >
> > > What would you suggest here?
> >
>
> > and while that might seem *superficially* almost the same thing,
> > semantically it's quite different.
> Agreed.
>
> >
> > it might be worth defining a macro:
> >
> >   #define at_most_one_bit_set(n)      ((n) & ((n) - 1))
> >
> > thoughts?
> >
> > rday
> >
>
> There are around 80 instances of code similar to the above. So
> instead of a macro why not do an inline function? And btw where
> would it go?

sorry, i meant an inline function -- force of habit.  but let's not
rush into anything.  for now, just work on those tests that *clearly*
represent power-of-two tests, and nothing else.

so even if you find a test of the form "n & (n - 1)", depending on the
context, the coder might really have meant it to not include zero.
conversely, if you find a test of the form "n != 0 && (n & (n - 1))",
even though that's *exactly* our power-of-two test, it's possible the
coder might have been testing for exactly one bit being set.  (those
tests are, obviously, identical, but semantically, they have different
meanings.)

so, for now, just submit patches for what are *clearly* power-of-two
tests and leave the rest alone.  those can be handled later by a more
appropriate inline function that better represents their semantic
meaning.

rday

-- 
====================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

http://fsdev.net/wiki/index.php?title=Main_Page
====================================
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors

      parent reply	other threads:[~2007-02-13 11:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-08 22:17 [KJ] anyone interested in the "power of 2" stuff? Robert P. J. Day
2007-02-09  5:18 ` Vignesh Babu BM
2007-02-09 12:39 ` Robert P. J. Day
2007-02-13  9:04 ` Vignesh Babu BM
2007-02-13  9:46 ` Robert P. J. Day
2007-02-13 10:38 ` Vignesh Babu BM
2007-02-13 11:56 ` Robert P. J. Day [this message]

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=Pine.LNX.4.64.0702130632400.4141@localhost.localdomain \
    --to=rpjday@mindspring.com \
    --cc=kernel-janitors@vger.kernel.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 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.