Subject: Re: Bitfields and kernel
To: None <tech-kern@netbsd.org>
From: Mike Cheponis <mac@Wireless.Com>
List: tech-kern
Date: 09/30/1999 18:57:30
> On Thu, 30 Sep 1999 15:03:55 -0500 
>  "Brian C. Grayson" <bgrayson@marvin.ece.utexas.edu> wrote:
> 
>  >   For testing multiple bits, to me it is more clear to say
>  > if ((msr.pow == 1) && (msr.ile == 0))
>  > than
>  > if ((msr&POW_BIT) && !(msr&ILE_BIT))
>  > or
>  > if ((msr&POW_BIT == POW_BIT) && (msr&ILE_BIT == 0))


> 	if ((msr & (POW_BIT|ILE_BIT)) == POW_BIT)

I find this little example exceedingly complicated compared with any of
the previous options.


>  >   It looks like there's no clear consensus :), so I'll just do
>  > what I like for private userland code, and I'll try to match
>  > the current style whenever doing any NetBSD devel. 
> 
> Bitfields bad.  Evil.  Bad.  Just my $.02 :-)
> 
>         -- Jason R. Thorpe <thorpej@nas.nasa.gov>

I like:  if ((msr&POW_BIT) && !(msr&ILE_BIT)) or

         if (msr.pow && !msr.ile)


Let the compiler smash the logicals & bits together efficiently.


-Mike Cheponis <mac@wireless.com>