Subject: Re: Bitfields and kernel
To: Matt Thomas <matt@3am-software.com>
From: Mike Cheponis <mac@Wireless.Com>
List: tech-kern
Date: 09/30/1999 20:17:23
On Thu, 30 Sep 1999, Matt Thomas wrote:
> At 09:57 PM 9/30/99 , Mike Cheponis wrote:
> >I like: if ((msr&POW_BIT) && !(msr&ILE_BIT)) or
> >
> > if (msr.pow && !msr.ile)
> >Let the compiler smash the logicals & bits together efficiently.
>
> But it can't. The C language specifies that msr.pow if evaluates to
> false then !msr.ile must not be evaluated. This is so you can do
>
> if (foo != NULL && foo->bar)
>
> Things get even nastier if you through volatile into the mess.
The point is that the C compiler can often optimize, and it should. In
this case, you are exactly right, there must be a couple of compares,
bitfields or no.
Imagine if(msr.pow || msr.bar)
could be easily coded as a single constant test against msr.
-Mike Cheponis <mac@Wireless.Com>