Checking if an Integer is an Exact Binary Power

Lass Safin via Digitalmars-d digitalmars-d at puremagic.com
Sat Apr 23 13:42:25 PDT 2016


On Saturday, 23 April 2016 at 20:34:52 UTC, Nordlöw wrote:
> 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?

CPUID: https://en.wikipedia.org/wiki/CPUID.
You can check for the presence of a lot of instructions with this 
instruction.
However this will only work on x86 and only run-time.


More information about the Digitalmars-d mailing list