5 ms·
Interesting to see this on HN, just a couple months after I ran into the same problem with GCC's intrinsic popcount myself on a project! I found that I needed t
by alexdowad 12y ago
Interesting to see this on HN, just a couple months after I ran into the same problem with GCC's intrinsic popcount myself on a project! I found that I needed to use an "-march" argument for GCC to actually emit POPCNT instructions.
- pja 12y agoThat's unsurprising, since without -march, gcc will emit code for a generic cpu that doesn't have a popcnt instruction. Early x86_64 cpus didn't have popcnt, so neither will the code that gcc emits & it's the same for any other architecture. If you want to use instructions that are only available on or after a specific cpu generation, then you need to tell your compiler to target that cpu's instruction set.
- wolf550e 12y agoIsn't gcc's default march=native so it would emit popcount if the host supports it?
- gsg 12y agoNo, the default produces binaries that are compatible with as many machines as possible.
- wolf550e 12y agoYou're right [0], but I couldn't find which march value [1] corresponds to the settings used for "x86_64-linux-gnu". EDIT: running "echo | gcc -v -E - 2>&1 | grep cc1" shows the command line, which says "-mtune=generic -march=x86-64". I do not know what "-march=x86-64" implies, except SSE2. 0 - https://gcc.gnu.org/ml/gcc-help/2012-12/msg00074.html https://gcc.gnu.org/ml/gcc-help/2012-12/msg00074.html 1 - https://gcc.gnu.org/onlinedocs/gcc/i386-and-x86-64-Options.html https://gcc.gnu.org/onlinedocs/gcc/i386-and-x86-64-Options.h...