[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-ppc] [PATCH v2 4/7] ppc/pnv: add a core mask to PnvChip
From: |
Benjamin Herrenschmidt |
Subject: |
Re: [Qemu-ppc] [PATCH v2 4/7] ppc/pnv: add a core mask to PnvChip |
Date: |
Mon, 05 Sep 2016 21:30:10 +1000 |
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.