using popcnt asm for x86 and gcc/clang (#862)

This commit is contained in:
Alden Torres 2016-06-27 18:51:00 -04:00 committed by Arvid Norberg
parent 31b2a03005
commit 9233edae4e
1 changed files with 5 additions and 1 deletions

View File

@ -65,7 +65,11 @@ namespace libtorrent
for (int i = 0; i < words; ++i)
{
#ifdef __GNUC__
ret += __builtin_popcount(m_buf[i]);
std::uint32_t cnt = 0;
__asm__("popcnt %1, %0"
: "=r"(cnt)
: "r"(m_buf[i]));
ret += cnt;
#else
ret += _mm_popcnt_u32(m_buf[i]);
#endif