lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Fri, 15 Jun 2007 14:57:23 -0500
From:	"David M. Lloyd" <dmlloyd@...rg.com>
To:	"David M. Lloyd" <dmlloyd@...rg.com>
Cc:	Jan Engelhardt <jengelh@...putergmbh.de>,
	Vegard Nossum <vegard.nossum@...il.com>,
	Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
	"H. Peter Anvin" <hpa@...or.com>,
	"Robert P. J. Day" <rpjday@...dspring.com>
Subject: Re: [PATCH] Optimize is_power_of_2().

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

> On Fri, 15 Jun 2007 21:47:50 +0200 (CEST)
> Jan Engelhardt <jengelh@...putergmbh.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
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ