Checking if an Integer is an Exact Binary Power
Marco Leise via Digitalmars-d
digitalmars-d at puremagic.com
Tue Apr 26 07:37:46 PDT 2016
Am Mon, 25 Apr 2016 17:04:43 +0000
schrieb tsbockman <thomas.bockman at gmail.com>:
> 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.
Can we just use __traits(hasTargetFeature, "popcnt") already
and get rid of _popcnt?
--
Marco
More information about the Digitalmars-d
mailing list