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:	Tue, 30 Jun 2009 08:12:59 +0200
From:	Petr Tesarik <ptesarik@...e.cz>
To:	"Robert P. J. Day" <rpjday@...shcourse.ca>
Cc:	Andrew Morton <akpm@...ux-foundation.org>,
	David Daney <ddaney@...iumnetworks.com>,
	Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] Introduce a boolean "single_bit_set" function.

Robert P. J. Day píše v Po 29. 06. 2009 v 14:50 -0400:
> On Mon, 29 Jun 2009, Petr Tesarik wrote:
> 
> > Andrew Morton píše v Pá 24. 04. 2009 v 10:46 -0700:
> > > On Fri, 24 Apr 2009 06:40:39 -0400 (EDT) "Robert P. J. Day" <rpjday@...shcourse.ca> wrote:
> > >
> > > >   so it would be a simple matter to define the bit set boolean in
> > > > terms of hweight_long(), yes?  so what about, in bitops.h:
> > > >
> > > >   static inline bool
> > > >   exactly_one_bit_set(unsigned long w)
> > > >   {
> > > > 	return hweight_long(w) == 1;
> > > >   }
> > > >
> > > >   static inline bool
> > > >   more_than_one_bit_set(unsigned long w)
> > > >   {
> > > > 	return hweight_long(w) > 1;
> > > >   }
> > > >
> >
> > Andrew, you must be kidding! Are you seriously suggesting to replace
> > a simple and instruction with a call to an extern library function
> > with 17 instructions (not including the call and ret)?
> >
> > I'd better check the use of hweight in the kernel to eradicate as
> > many calls to it as possible...
> 
>   since i originally muttered about this, the rationale behind it was
> not for performance (obviously), but for semantic clarification, so
> that when you saw the expression "n & (n-1)", it was more obvious
> which test you were doing semantically:
> 
> 1) is n a power of 2?
> 2) does n represent a single set bit?
> 
> nothing ever came of that, but that was the thinking behind it.

Yes, I can remember and I would still appreciate it. It's always better
to show _what_ the code does rather than _how_ it does it.

IIRC Andrew rejected your patch on the grounds that it is possible to
replace the expression "n & (n-1)" with "hweight(n) == 1" if one wants
to show that it really tests for a single bit set. But I don't like his
proposal quite as much as yours, because of the big overhead.

In short, if you re-post your patch, I'll gladly join you in the battle
of getting it in. ;-)

Petr Tesarik


--
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