Skip to content

Commit 00941de

Browse files
hebastojanus
authored andcommitted
Squashed 'src/minisketch/' changes from 47f0a2d26f..a571ba20f9
a571ba20f9 Merge bitcoin-core/minisketch#68: Add missed `#include <string>` b9a7f7e2bc Merge bitcoin-core/minisketch#69: refactor: Drop unused `total` local variables 8a5af94edc Merge bitcoin-core/minisketch#70: build: Remove `-Qunused-arguments` workaround for clang + ccache c36f1f03a3 Merge bitcoin-core/minisketch#72: Fix MSVC implementation of `CountBits()` function 0078bedda6 Ignore `HAVE_CLZ` macro when building with MSVC 1c772918c4 Fix MSVC implementation of `CountBits()` function 98f87c55f4 build: Remove `-Qunused-arguments` workaround for clang + ccache 11a1e25c81 refactor: Drop unused `total` local variables ed6c8fcfd9 Add missed `#include <string>` git-subtree-dir: src/minisketch git-subtree-split: a571ba20f9dd1accab6a2309d066369878042ca6
1 parent 1b5d403 commit 00941de

File tree

3 files changed

+12
-44
lines changed

3 files changed

+12
-44
lines changed

configure.ac

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,34 +1782,6 @@ else
17821782
fi
17831783
fi
17841784

1785-
dnl Enable NAT-PMP support.
1786-
AC_MSG_CHECKING([whether to build with support for NAT-PMP])
1787-
if test "$have_natpmp" = "no"; then
1788-
if test "$use_natpmp" = "yes"; then
1789-
AC_MSG_ERROR([NAT-PMP requested but cannot be built. Use --without-natpmp])
1790-
fi
1791-
AC_MSG_RESULT([no])
1792-
use_natpmp=no
1793-
else
1794-
if test "$use_natpmp" != "no"; then
1795-
AC_MSG_RESULT([yes])
1796-
AC_MSG_CHECKING([whether to build with NAT-PMP enabled by default])
1797-
use_natpmp=yes
1798-
natpmp_setting=0
1799-
if test "$use_natpmp_default" != "no"; then
1800-
use_natpmp_default=yes
1801-
natpmp_setting=1
1802-
fi
1803-
AC_MSG_RESULT($use_natpmp_default)
1804-
AC_DEFINE_UNQUOTED([USE_NATPMP], [$natpmp_setting], [NAT-PMP support not compiled if undefined, otherwise value (0 or 1) determines default state])
1805-
if test "$TARGET_OS" = "windows"; then
1806-
NATPMP_CPPFLAGS="$NATPMP_CPPFLAGS -DSTATICLIB -DNATPMP_STATICLIB"
1807-
fi
1808-
else
1809-
AC_MSG_RESULT([no])
1810-
fi
1811-
fi
1812-
18131785
dnl these are only used when qt is enabled
18141786
BUILD_TEST_QT=""
18151787
if test "$BGL_enable_qt" != "no"; then

src/minisketch/src/bench.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,11 @@ int main(int argc, char** argv) {
6262
if (!states[0]) {
6363
printf(" -\t");
6464
} else {
65-
double total = 0.0;
6665
for (auto& state : states) {
6766
auto start = std::chrono::steady_clock::now();
6867
minisketch_decode(state, 2 * syndromes, roots.data());
6968
auto stop = std::chrono::steady_clock::now();
7069
std::chrono::duration<double> dur(stop - start);
71-
total += dur.count();
7270
benches.push_back(dur.count());
7371
}
7472
std::sort(benches.begin(), benches.end());
@@ -98,15 +96,13 @@ int main(int argc, char** argv) {
9896
if (!states[0]) {
9997
printf(" -\t");
10098
} else {
101-
double total = 0.0;
10299
for (auto& state : states) {
103100
auto start = std::chrono::steady_clock::now();
104101
for (auto val : data) {
105102
minisketch_add_uint64(state, val);
106103
}
107104
auto stop = std::chrono::steady_clock::now();
108105
std::chrono::duration<double> dur(stop - start);
109-
total += dur.count();
110106
benches.push_back(dur.count());
111107
}
112108
std::sort(benches.begin(), benches.end());

src/minisketch/src/int_utils.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,7 @@ constexpr inline I Mask() { return ((I((I(-1)) << (std::numeric_limits<I>::digit
129129
/** Compute the smallest power of two that is larger than val. */
130130
template<typename I>
131131
static inline int CountBits(I val, int max) {
132-
#ifdef HAVE_CLZ
133-
(void)max;
134-
if (val == 0) return 0;
135-
if (std::numeric_limits<unsigned>::digits >= std::numeric_limits<I>::digits) {
136-
return std::numeric_limits<unsigned>::digits - __builtin_clz(val);
137-
} else if (std::numeric_limits<unsigned long>::digits >= std::numeric_limits<I>::digits) {
138-
return std::numeric_limits<unsigned long>::digits - __builtin_clzl(val);
139-
} else {
140-
return std::numeric_limits<unsigned long long>::digits - __builtin_clzll(val);
141-
}
142-
#elif _MSC_VER
132+
#ifdef _MSC_VER
143133
(void)max;
144134
unsigned long index;
145135
unsigned char ret;
@@ -149,7 +139,17 @@ static inline int CountBits(I val, int max) {
149139
ret = _BitScanReverse64(&index, val);
150140
}
151141
if (!ret) return 0;
152-
return index;
142+
return index + 1;
143+
#elif HAVE_CLZ
144+
(void)max;
145+
if (val == 0) return 0;
146+
if (std::numeric_limits<unsigned>::digits >= std::numeric_limits<I>::digits) {
147+
return std::numeric_limits<unsigned>::digits - __builtin_clz(val);
148+
} else if (std::numeric_limits<unsigned long>::digits >= std::numeric_limits<I>::digits) {
149+
return std::numeric_limits<unsigned long>::digits - __builtin_clzl(val);
150+
} else {
151+
return std::numeric_limits<unsigned long long>::digits - __builtin_clzll(val);
152+
}
153153
#else
154154
while (max && (val >> (max - 1) == 0)) --max;
155155
return max;

0 commit comments

Comments
 (0)