On Thu, 23 Aug 2018 at 00:17, Andrey Semashev via Boost < boost@lists.boost.org> wrote:
I think such an optimization would be useful. Note that MSVC also has intrinsics for popcount[1], although I don't think those are supported when the target CPU doesn't implement the corresponding instructions.
This instruction is supported on Intel Penryn (x86, 2007) and AMD 3rd Gen. and onward from there. You would have to check at compile time whether the target CPU
supports it (e.g. by checking if __AVX__ is defined).
On a Penryn, __AVX__ will give a false negative. Checking __cpuid as Gavin writes should also work on that processor. On ARM, which appears to have become an important cpu-type, there is the corresponding VCNT instruction: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0489c/CIHCFDB... , but this instruction does not seem to be provided as an intrinsic by Microsoft. degski -- *“If something cannot go on forever, it will stop" - Herbert Stein* *“No, it isn’t truth. Truth isn’t truth" - Rudolph W. L. Giuliani*