From ecb64a53a940bf93c870c3eb271055bcda9fd4f3 Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Tue, 28 Jun 2016 00:34:21 -0400 Subject: [PATCH] backport of popcnt asm for x86 and gcc/clang (#864) backport of popcnt asm for x86 and gcc/clang --- src/bitfield.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/bitfield.cpp b/src/bitfield.cpp index 089491b1c..dab1d2259 100644 --- a/src/bitfield.cpp +++ b/src/bitfield.cpp @@ -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