From e9f1d8c27261070d209a28570ad36fe91531cdd2 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Sun, 23 Oct 2022 15:00:20 +0100 Subject: [PATCH] Squashed 'src/minisketch/' changes from 47f0a2d26f..a571ba20f9 a571ba20f9 Merge sipa/minisketch#68: Add missed `#include ` b9a7f7e2bc Merge sipa/minisketch#69: refactor: Drop unused `total` local variables 8a5af94edc Merge sipa/minisketch#70: build: Remove `-Qunused-arguments` workaround for clang + ccache c36f1f03a3 Merge sipa/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 ` git-subtree-dir: src/minisketch git-subtree-split: a571ba20f9dd1accab6a2309d066369878042ca6 --- configure.ac | 3 --- src/bench.cpp | 4 ---- src/int_utils.h | 24 ++++++++++++------------ src/test.cpp | 1 + 4 files changed, 13 insertions(+), 19 deletions(-) diff --git a/configure.ac b/configure.ac index 9dc66e7fd2f..83910448a2c 100644 --- a/configure.ac +++ b/configure.ac @@ -124,9 +124,6 @@ if test "x$use_ccache" != "xno"; then fi AC_MSG_RESULT($use_ccache) fi -if test "x$use_ccache" = "xyes"; then - AX_CHECK_COMPILE_FLAG([-Qunused-arguments],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Qunused-arguments"],,[[$CXXFLAG_WERROR]]) -fi VERIFY_DEFINES=-DMINISKETCH_VERIFY RELEASE_DEFINES= diff --git a/src/bench.cpp b/src/bench.cpp index f55944a448a..dc44379fdb5 100644 --- a/src/bench.cpp +++ b/src/bench.cpp @@ -62,13 +62,11 @@ int main(int argc, char** argv) { if (!states[0]) { printf(" -\t"); } else { - double total = 0.0; for (auto& state : states) { auto start = std::chrono::steady_clock::now(); minisketch_decode(state, 2 * syndromes, roots.data()); auto stop = std::chrono::steady_clock::now(); std::chrono::duration dur(stop - start); - total += dur.count(); benches.push_back(dur.count()); } std::sort(benches.begin(), benches.end()); @@ -98,7 +96,6 @@ int main(int argc, char** argv) { if (!states[0]) { printf(" -\t"); } else { - double total = 0.0; for (auto& state : states) { auto start = std::chrono::steady_clock::now(); for (auto val : data) { @@ -106,7 +103,6 @@ int main(int argc, char** argv) { } auto stop = std::chrono::steady_clock::now(); std::chrono::duration dur(stop - start); - total += dur.count(); benches.push_back(dur.count()); } std::sort(benches.begin(), benches.end()); diff --git a/src/int_utils.h b/src/int_utils.h index 62b2c38a294..d21ba56f336 100644 --- a/src/int_utils.h +++ b/src/int_utils.h @@ -129,17 +129,7 @@ constexpr inline I Mask() { return ((I((I(-1)) << (std::numeric_limits::digit /** Compute the smallest power of two that is larger than val. */ template static inline int CountBits(I val, int max) { -#ifdef HAVE_CLZ - (void)max; - if (val == 0) return 0; - if (std::numeric_limits::digits >= std::numeric_limits::digits) { - return std::numeric_limits::digits - __builtin_clz(val); - } else if (std::numeric_limits::digits >= std::numeric_limits::digits) { - return std::numeric_limits::digits - __builtin_clzl(val); - } else { - return std::numeric_limits::digits - __builtin_clzll(val); - } -#elif _MSC_VER +#ifdef _MSC_VER (void)max; unsigned long index; unsigned char ret; @@ -149,7 +139,17 @@ static inline int CountBits(I val, int max) { ret = _BitScanReverse64(&index, val); } if (!ret) return 0; - return index; + return index + 1; +#elif HAVE_CLZ + (void)max; + if (val == 0) return 0; + if (std::numeric_limits::digits >= std::numeric_limits::digits) { + return std::numeric_limits::digits - __builtin_clz(val); + } else if (std::numeric_limits::digits >= std::numeric_limits::digits) { + return std::numeric_limits::digits - __builtin_clzl(val); + } else { + return std::numeric_limits::digits - __builtin_clzll(val); + } #else while (max && (val >> (max - 1) == 0)) --max; return max; diff --git a/src/test.cpp b/src/test.cpp index 417937ea5f6..85b9e9e3967 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include "../include/minisketch.h"