Checking if an Integer is an Exact Binary Power
tsbockman via Digitalmars-d
digitalmars-d at puremagic.com
Mon Apr 25 10:04:43 PDT 2016
On Monday, 25 April 2016 at 16:48:14 UTC, Lass Safin wrote:
> Example;
>
> import core.bitop;
> import core.cpuid;
>
> int count;
> if(hasPopcnt)
> count = _popcnt; // Uses x86-instruction "popcnt".
> else
> count = popcnt; // Phobos's software implementation.
>
> // Do stuff with count
That is not right (since 2.069, I think?). Adding that check just
makes things slower and more complicated:
core.bitop.popcnt() itself already checks hasPopcnt, and forwards
to the intrinsic if it is available.
More information about the Digitalmars-d
mailing list