2 ms·
Unfortunately, if you compile with MSVC, or with Gcc or Clang but don't specify a more-recent-than-2003 target (e.g. "-mavx" or "-march=native"), you won't get
by ncmncm 5y ago
Unfortunately, if you compile with MSVC, or with Gcc or Clang but don't specify a more-recent-than-2003 target (e.g. "-mavx" or "-march=native"), you won't get a POPCNT instruction. Likewise, for the conforming extension __builtin_popcount.
On MSVC, _popcount gets you POPCNT regardless of target. But its std::bitset and std::popcount still won't use it.
C does not, in fact, offer any Standard way to get a popcount instruction. Gcc's and Clang's optimizers recognize certain naive counting loops and can substitute a POPCNT instruction if told that the target supports it.
On RISC-V, you don't get a POPC under any circumstances, nohow. I have been told that the RVA-22 target (supposed to be used in desk machines) will have it, but cannot find any confirmation online. I expect it to be tricky to get compilers for RISC-V to emit it, into the indefinite future, regardless of support on particular machines.