Browse Source

* 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
pull/30/head
rakshasa 14 years ago
parent
commit
0784d6540f
  1. 20
      rak/algorithm.h
  2. 15
      scripts/common.m4

20
rak/algorithm.h

@ -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

15
scripts/common.m4

@ -181,6 +181,21 @@ AC_DEFUN([TORRENT_CHECK_MADVISE], [
])
])
AC_DEFUN([TORRENT_CHECK_POPCOUNT], [
AC_MSG_CHECKING(for __builtin_popcount)
AC_COMPILE_IFELSE(
[[
void f() { __builtin_popcount(0); }
]],
[
AC_MSG_RESULT(yes)
AC_DEFINE(USE_BUILTIN_POPCOUNT, 1, Use __builtin_popcount.)
], [
AC_MSG_RESULT(no)
])
])
AC_DEFUN([TORRENT_CHECK_CACHELINE], [
AC_MSG_CHECKING(for cacheline)

Loading…
Cancel
Save