On Mon, 2016-09-05 at 13:13 +0200, Cédric Le Goater wrote:
> > Is it worth having this cores_max field, since AFAICT you can
> > calculate it as hweight(~cores_mask)?
> 
> Sure. I looked for it and missed it. 
> 
> Here is a slightly improved version from Brian Kernighan :
> 
>         unsigned int v; // count the number of bits set in v
>         unsigned int c; // c accumulates the total bits set in v
> 
>         for (c = 0; v; c++)
>         {
>                 v &= v - 1; // clear the least significant bit set
>         }

Use the accessor (ie, hweight). The compiler might turn it into a
popcnt instruction of some sort if the CPU has one :-)

Ben.

Reply via email to