public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "David M. Lloyd" <dmlloyd@flurg.com>
To: "David M. Lloyd" <dmlloyd@flurg.com>
Cc: Jan Engelhardt <jengelh@computergmbh.de>,
	Vegard Nossum <vegard.nossum@gmail.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	"H. Peter Anvin" <hpa@zytor.com>,
	"Robert P. J. Day" <rpjday@mindspring.com>
Subject: Re: [PATCH] Optimize is_power_of_2().
Date: Fri, 15 Jun 2007 14:57:23 -0500	[thread overview]
Message-ID: <20070615145723.7aa7aaa0@localhost> (raw)
In-Reply-To: <20070615145420.3a824477@localhost>

On Fri, 15 Jun 2007 14:54:20 -0500
"David M. Lloyd" <dmlloyd@flurg.com> wrote:

> On Fri, 15 Jun 2007 21:47:50 +0200 (CEST)
> Jan Engelhardt <jengelh@computergmbh.de> wrote:
> 
> > On Jun 15 2007 18:56, Vegard Nossum wrote:
> > > bool is_power_of_2(unsigned long n)
> > > {
> > >-	return (n != 0 && ((n & (n - 1)) == 0));
> > >+	return n * !(n & (n - 1));
> > > }
> > 
> > There is a third way which uses neither * nor &&, but []:
> 
> I assume using something GCC-specific is right out?
> 
> bool is_power_of_to(unsigned long n)
> {
> 	return __builtin_ffsl(n) == 1;

Pretend I typed this instead:

bool is_power_of_2(unsigned long n)
{
	return __builtin_popcountl(n) == 1;
}

All I can say is, it's really hot here :P

- DML

      reply	other threads:[~2007-06-15 19:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-15 16:56 [PATCH] Optimize is_power_of_2() Vegard Nossum
2007-06-15 18:21 ` H. Peter Anvin
2007-06-15 18:28   ` Robert P. J. Day
2007-06-15 20:26     ` H. Peter Anvin
2007-06-15 19:47 ` Jan Engelhardt
2007-06-15 19:54   ` David M. Lloyd
2007-06-15 19:57     ` David M. Lloyd [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=20070615145723.7aa7aaa0@localhost \
    --to=dmlloyd@flurg.com \
    --cc=hpa@zytor.com \
    --cc=jengelh@computergmbh.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rpjday@mindspring.com \
    --cc=vegard.nossum@gmail.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox