Skip to content

Commit

Permalink
Cleanup unused popcount functions
Browse files Browse the repository at this point in the history
  • Loading branch information
stickz committed Jul 12, 2024
1 parent 09b3fcd commit af31667
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 95 deletions.
2 changes: 0 additions & 2 deletions libtorrent/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ AC_CHECK_FUNCS(posix_memalign)

TORRENT_CHECK_MADVISE()
TORRENT_CHECK_CACHELINE()
TORRENT_CHECK_POPCOUNT()
TORRENT_CPU_POPCOUNT()
TORRENT_HOSTED_MODE()
TORRENT_CHECK_EXECINFO()
TORRENT_CHECK_PTHREAD_SETNAME_NP()
Expand Down
49 changes: 0 additions & 49 deletions libtorrent/rak/libpopcnt.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,6 @@

#include <stdint.h>

#ifndef __has_builtin
#define __has_builtin(x) 0
#endif

#ifndef __has_attribute
#define __has_attribute(x) 0
#endif

#ifndef __has_include
#define __has_include(x) 0
#endif

#ifdef __GNUC__
#define LIBPOPCNT_GNUC_PREREQ(x, y) \
(__GNUC__ > x || (__GNUC__ == x && __GNUC_MINOR__ >= y))
Expand All @@ -72,48 +60,11 @@
#define LIBPOPCNT_X86_OR_X64
#endif

#if LIBPOPCNT_GNUC_PREREQ(4, 2) || \
__has_builtin(__builtin_popcount)
#define LIBPOPCNT_HAVE_BUILTIN_POPCOUNT
#endif

#if LIBPOPCNT_GNUC_PREREQ(4, 2) || \
LIBPOPCNT_CLANG_PREREQ(3, 0)
#define LIBPOPCNT_HAVE_ASM_POPCNT
#endif

#if defined(LIBPOPCNT_X86_OR_X64) && \
(defined(LIBPOPCNT_HAVE_ASM_POPCNT) || \
defined(_MSC_VER))
#define LIBPOPCNT_HAVE_POPCNT
#endif

/* GCC compiler */
#if defined(LIBPOPCNT_X86_OR_X64) && \
LIBPOPCNT_GNUC_PREREQ(5, 0)
#define LIBPOPCNT_HAVE_AVX2
#endif

/* GCC compiler */
#if defined(LIBPOPCNT_X86_OR_X64) && \
LIBPOPCNT_GNUC_PREREQ(11, 0)
#define LIBPOPCNT_HAVE_AVX512
#endif

/* Clang (Unix-like OSes) */
#if defined(LIBPOPCNT_X86_OR_X64) && !defined(_MSC_VER)
#if LIBPOPCNT_CLANG_PREREQ(3, 8) && \
__has_attribute(target) && \
(!defined(__apple_build_version__) || __apple_build_version__ >= 8000000)
#define LIBPOPCNT_HAVE_AVX2
#endif
#if LIBPOPCNT_CLANG_PREREQ(9, 0) && \
__has_attribute(target) && \
(!defined(__apple_build_version__) || __apple_build_version__ >= 8000000)
#define LIBPOPCNT_HAVE_AVX512
#endif
#endif

/*
* This uses fewer arithmetic operations than any other known
* implementation on machines with fast multiplication.
Expand Down
24 changes: 0 additions & 24 deletions libtorrent/scripts/common.m4
Original file line number Diff line number Diff line change
Expand Up @@ -111,30 +111,6 @@ AC_DEFUN([TORRENT_CHECK_MADVISE], [
])
])

AC_DEFUN([TORRENT_CHECK_POPCOUNT], [
AC_MSG_CHECKING(for __builtin_popcount)
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
int f() { return __builtin_popcount(0); }
])],
[
AC_MSG_RESULT(yes)
AC_DEFINE(USE_BUILTIN_POPCOUNT, 1, Use __builtin_popcount.)
], [
AC_MSG_RESULT(no)
])
])

AC_DEFUN([TORRENT_CPU_POPCOUNT], [
AC_ARG_ENABLE(cpu-popcount,
AC_HELP_STRING([--enable-cpu-popcount], [Enable cpu-popcount [[default=check]]]),
[
if test "$enableval" = "yes"; then
AC_DEFINE(USE_CPU_POPCOUNT, 1, Use CPU popcount.)
fi
])
])

AC_DEFUN([TORRENT_HOSTED_MODE], [
AC_ARG_ENABLE(hosted-mode,
AC_HELP_STRING([--enable-hosted-mode], [Enable hosted mode [[default=check]]]),
Expand Down
20 changes: 0 additions & 20 deletions rtorrent/rak/algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,26 +156,6 @@ 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
}

// Get the median of an unordered set of numbers of arbitrary
// type by modifing the underlying dataset
template <typename T = double, typename _InputIter>
Expand Down

0 comments on commit af31667

Please sign in to comment.