Checking if an Integer is an Exact Binary Power
Marco Leise via Digitalmars-d
digitalmars-d at puremagic.com
Sat Apr 23 17:02:57 PDT 2016
Am Sat, 23 Apr 2016 20:34:52 +0000
schrieb Nordlöw <per.nordlow at gmail.com>:
> On Saturday, 23 April 2016 at 17:28:21 UTC, Andrei Alexandrescu
> wrote:
> >> Yah, that's the canonical. I forgot why I chose (x & -x) > (x
> >> - 1) over
> >> it. -- Andrei
>
> So is there a way to check if popcnt builtin is available on
> current platform?
We argued in another, unrelated thread ("Any usable SIMD
implementation?") for compile-time information on the target.
That would include __traits("hasTargetFeature", "popcnt")
A runtime check requires at least a read of a global variable
and I doubt it is faster than `x & (x-1)`.
--
Marco
More information about the Digitalmars-d
mailing list