lkml.org 
[lkml]   [2009]   [Apr]   [24]   [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 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;
> }
>
> or something to that effect, *if* people think it's worth it.
> obviously, none of the above is strictly necessary, but it would make
> a lot of code semantically cleaner.
>

Doing plain old

if (hweight32(foo) == 1)

(say) at the call sites quite clearly expresses what the code is trying
to do.

> rday
>
> p.s. i notice that, even in a single header file like bitops.h, there
> is a mixture of both "inline" and "__inline__". what's the
> recommended choice these days?

`inline'. Or uninline the function ;)


\
 
 \ /
  Last update: 2009-04-24 19:51    [W:0.280 / U:0.100 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site