lkml.org 
[lkml]   [2009]   [Jun]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] Introduce a boolean "single_bit_set" function.
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@crashcourse.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.

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
========================================================================
\
 
 \ /
  Last update: 2009-06-29 20:55    [W:0.063 / U:12.788 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site