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: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Andrew Morton <akpm@osdl.org>
Subject: Re: [PATCH] Introduce a boolean "single_bit_set" function.
Date: Thu, 28 May 2009 08:27:35 -0400 (EDT)	[thread overview]
Message-ID: <alpine.LFD.2.00.0905280820510.30888@localhost.localdomain> (raw)
In-Reply-To: <1243513274.3170.1.camel@nathan.suse.cz>

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

On Thu, 28 May 2009, Petr Tesarik wrote:

> Robert P. J. Day píše v Čt 23. 04. 2009 v 13:43 -0400:
> > A boolean single_bit_set() routine would simplify the numerous
> > constructs of the form (((n & (n - 1)) == 0)) when testing for
> > single-bitness.
> >
> > Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>
> >
> > ---
> >
> > This is similar to the current is_power_of_2() routine defined in
> > include/linux/log2.h, which is mathematically identical but,
> > semantically, should be defined independently just so the code is
> > more readable.
> >
> > I'm open to an alternative function name.
>
> ispow2() ?
>
> Because what it really does is to check that a value is a power of
> two, doesn'it.

  yes, mathematically it's identical, but *semantically*, i think it's
worth distinguishing between those two tests.  there's still a number
of places in the code that can be rewritten with "is power of 2"
tests, but that rewriting makes sense only if that's really what
you're asking, as in checking an alleged block size value you've been
passed, or something similar.

  OTOH, there are lots of places in the code that have to verify that
only a single (flag?) bit has been set, and that code would read a lot
better using a better worded test.  someone already pointed out that
perhaps one of the hweight*() routines from include/linux/bitops.h
would be appropriate.

  and, yes, i realize that there would be no functional change, but
rewriting tests like this not only makes the code more readable, it
allows for the removal of accompanying comments that have to explain
to the reader what's going on.  but i'll leave the decision to those
higher up the food chain.

rday
--

========================================================================
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-05-28 12:29 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
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 [this message]
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.0905280820510.30888@localhost.localdomain \
    --to=rpjday@crashcourse.ca \
    --cc=akpm@osdl.org \
    --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.