* Switched to using '__builtin_popcount' for counting bits in bitfield.

git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1292 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2011-10-02 15:57:22 +00:00
parent 5f21e207c3
commit 0784d6540f
2 changed files with 35 additions and 0 deletions
+20
View File
@@ -155,6 +155,26 @@ make_base(_InputIter __first, _InputIter __last, _Ftor __ftor) {
return __base;
}
template<typename T>
inline int popcount_wrapper(T t) {
#if USE_BUILTIN_POPCOUNT
if (std::numeric_limits<T>::digits <= std::numeric_limits<unsigned int>::digits)
return __builtin_popcount(t);
else
return __builtin_popcountll(t);
#else
#error __builtin_popcount not found.
unsigned int count = 0;
while (t) {
count += t & 0x1;
t >> 1;
}
return count;
#endif
}
}
#endif