backport of popcnt asm for x86 and gcc/clang (#864)

backport of popcnt asm for x86 and gcc/clang
This commit is contained in:
Alden Torres 2016-06-28 00:34:21 -04:00 committed by Arvid Norberg
parent 1a3e75b50a
commit ecb64a53a9
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]);
boost::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