Checking if an Integer is an Exact Binary Power

David Nadlinger via Digitalmars-d digitalmars-d at puremagic.com
Sat Apr 23 16:23:26 PDT 2016


On Saturday, 23 April 2016 at 20:34:52 UTC, Nordlöw wrote:
> So is there a way to check if popcnt builtin is available on 
> current platform?

As Andrei pointed out, it's not only popcnt being available, it's 
also it being fast. A function implementing the classic 
hand-written version compiles down to something like

	lea	eax, [rdi - 1]
	test	eax, edi
	sete	al
	ret

which is already quite good.

There is also blsi to consider on Haswell and above.

  — David




More information about the Digitalmars-d mailing list