All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Knutsson <ricknu-0@student.ltu.se>
To: kernel-janitors@vger.kernel.org
Subject: Re: [KJ] powers of 2, and the boundary case of zero
Date: Tue, 09 Jan 2007 13:01:01 +0000	[thread overview]
Message-ID: <45A3920D.5070408@student.ltu.se> (raw)
In-Reply-To: <Pine.LNX.4.64.0701090539520.7476@localhost.localdomain>

Robert P. J. Day wrote:
> On Tue, 9 Jan 2007, Richard Knutsson wrote:
>
>   
>> Robert P. J. Day wrote:
>>     
>
> ... big snip involving power of 2 stuff ...
>
>   
>>> p.s.  personally, i would define an "is_power_of_2" macro to
>>> explicitly reject zero, the way the current definitions do.
>>>
>>>       
>> I agree! But should it not be "IS_POWER_OF_2" to reflect it is a
>> macro?
>>     
>
> not necessarily.  currently, the aesthetics of macro names is a bit
> inconsistent, as in kernel.h:
>
>   #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
>   #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
>
> and, given that there is already a precedent (albeit a small one) for
> the lower case form, i'd be tempted to keep it like that, *if*
> anything is to be done along those lines.
>   
Just quoting "CodingStyle" :)
>> However, I think the only thing is to check all the occurrences of
>> the (x & (x-1)) and see what it really is suppose to be (and if
>> possible, ask the maintainer).
>>     
>
> i agree -- each case should be examined to see what the intent was.
> in some cases, the code can be seriously obscure, as in
> drivers/pcmcia/i82365.c:
>
>       if (!poll_interval) {
>         u_int tmp = (mask & 0xff20);
>         tmp = tmp & (tmp-1);		// power of 2 test?
>         if ((tmp & (tmp-1)) = 0)       // and test again???
>             poll_interval = HZ;
>
> in the case of the above, that first assignment is not actually
> testing, it's calculating the bit mask.  the *second* expression
> represents a power-of-2 test, though, and it would be fair to replace
> that with the macro invocation.
>
>   
>> What about something like:
>>
>> #define LESS_THEN_2_BITS(x)  (x & (x - 1))
>>     
Oops, forgot a '= 0' there...
>> #define IS_POWER_OF_2(x)   (x != 0 && LESS_THEN_2_BITS(x))
>>     
>
> i'm not sure i'd bother with the "LESS_THAN_2_BITS" macro, since i
> doubt it would have widespread application.  in any event, this is
> just something to think about for future consideration.
>   
So just leaving those who are (with right) accepting non-zero alone?

Richard Knutsson

_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors

  parent reply	other threads:[~2007-01-09 13:01 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-09 11:18 [KJ] powers of 2, and the boundary case of zero Robert P. J. Day
2007-01-09 12:16 ` Richard Knutsson
2007-01-09 12:25 ` Robert P. J. Day
2007-01-09 13:01 ` Richard Knutsson [this message]
2007-01-09 13:04 ` Robert P. J. Day
2007-01-09 13:57 ` Darren Jenkins
2007-01-09 14:27 ` Robert P. J. Day
2007-01-09 14:39 ` Jaco Kroon
2007-01-09 14:42 ` Robert P. J. Day
2007-01-09 14:46 ` Robert P. J. Day
2007-01-09 15:25 ` Darren Jenkins
2007-01-09 15:27 ` Robert P. J. Day
2007-01-09 16:16 ` Robert P. J. Day
2007-01-09 17:31 ` Randy Dunlap
2007-01-09 18:57 ` Robert P. J. Day
2007-01-09 20:03 ` Arnaldo Carvalho de Melo
2007-01-09 22:41 ` Martin Olsen
2007-01-10  6:08 ` Robert P. J. Day
2007-01-10  8:25 ` Robert P. J. Day
2007-01-10 11:50 ` Martin Olsen
2007-01-10 12:12 ` Jaco Kroon
2007-01-10 13:31 ` Martin Olsen
2007-01-10 13:36 ` Robert P. J. Day
2007-01-10 13:40 ` Robert P. J. Day
2007-01-10 13:51 ` Robert P. J. Day
2007-01-10 13:53 ` Robert P. J. Day
2007-01-10 15:25 ` Martin Olsen
2007-01-10 15:40 ` Robert P. J. Day
2007-01-10 16:44 ` Darren Jenkins
2007-01-10 17:53 ` Martin Olsen
2007-01-10 18:04 ` Robert P. J. Day
2007-01-10 18:29 ` Martin Olsen
2007-01-10 19:44 ` Alexey Dobriyan
2007-01-10 23:01 ` Paul Bonser
2007-01-10 23:30 ` Paul Bonser
2007-01-11  2:06 ` Darren Jenkins
2007-01-11  4:33 ` Robert P. J. Day
2007-01-11  6:41 ` Jaco Kroon
2007-01-11  6:44 ` Robert P. J. Day
2007-01-11  9:30 ` Robert P. J. Day
2007-01-11 11:37 ` Paul Bonser
2007-01-11 11:40 ` Paul Bonser

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=45A3920D.5070408@student.ltu.se \
    --to=ricknu-0@student.ltu.se \
    --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.