[cfe-dev] [libcxx] Win32 port must not use __popcnt intrinsect

Jens Ayton mailing-lists.jens at ayton.se
Thu Nov 24 11:57:49 PST 2011


On Nov 24, 2011, at 12:42, Ruben Van Boxem wrote:
> 2011/11/24 Jean-Daniel Dupas <devlists at shadowlab.org>:
>> 
>> Hello,
>> While browsing win32 support headers of the libcxx, I found these macros:
>> #define __builtin_popcount __popcnt
>> #define __builtin_popcountl __popcnt
>> #define __builtin_popcountll(__i) static_cast<int>(__popcnt64(__i))
>> While using _BitScanReverse and other built-in is fine, using  __popcnt is
>> not safe at all. Whatever the cpu target is, the compiler will generate a
>> __popcnt instruction, even if it does not support it.
> 
> That's my fault. After further investigation, you are completely
> correct: I thought I found that all x86 processors supported these
> instructions, but that was only valid for the _BitScan* functions). I
> don't know how to fix this (I'm just a humble hobbyist), so patches
> are welcome.

There are several portable implementations of popcount on http://graphics.stanford.edu/~seander/bithacks.html (under Counting bits set), with various speed/space tradeoffs.


-- 
Jens Ayton





More information about the cfe-dev mailing list