diff --git a/configure.ac b/configure.ac index d1751ad55c7f6..c2598bd69da80 100644 --- a/configure.ac +++ b/configure.ac @@ -242,16 +242,6 @@ AC_ARG_ENABLE([threadlocal], [use_thread_local=$enableval], [use_thread_local=auto]) -AC_ARG_ENABLE([asm], - [AS_HELP_STRING([--disable-asm], - [disable assembly routines (enabled by default)])], - [use_asm=$enableval], - [use_asm=yes]) - -if test "$use_asm" = "yes"; then - AC_DEFINE([USE_ASM], [1], [Define this symbol to build in assembly routines]) -fi - AC_ARG_ENABLE([zmq], [AS_HELP_STRING([--disable-zmq], [disable ZMQ notifications])], @@ -556,8 +546,6 @@ enable_sse41=no enable_avx2=no enable_x86_shani=no -if test "$use_asm" = "yes"; then - dnl Check for optional instruction set support. Enabling these does _not_ imply that all code will dnl be compiled with them, rather that specific objects/libs may use them after checking for runtime dnl compatibility. @@ -612,11 +600,12 @@ TEMP_CXXFLAGS="$CXXFLAGS" CXXFLAGS="$SSE41_CXXFLAGS $CXXFLAGS" AC_MSG_CHECKING([for SSE4.1 intrinsics]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ - #include #include ]],[[ - __m128i l = _mm_set1_epi32(0); - return _mm_extract_epi32(l, 3); + __m128i a = _mm_set1_epi32(0); + __m128i b = _mm_set1_epi32(1); + __m128i r = _mm_blend_epi16(a, b, 0xFF); + return _mm_extract_epi32(r, 3); ]])], [ AC_MSG_RESULT([yes]); enable_sse41=yes; AC_DEFINE([ENABLE_SSE41], [1], [Define this symbol to build code that uses SSE4.1 intrinsics]) ], [ AC_MSG_RESULT([no])] @@ -696,8 +685,6 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ) CXXFLAGS="$TEMP_CXXFLAGS" -fi - CORE_CPPFLAGS="$CORE_CPPFLAGS -DHAVE_BUILD_INFO -DGSL_NO_IOSTREAMS" AC_ARG_WITH([utils], @@ -1843,7 +1830,6 @@ AM_CONDITIONAL([ENABLE_AVX2], [test "$enable_avx2" = "yes"]) AM_CONDITIONAL([ENABLE_X86_SHANI], [test "$enable_x86_shani" = "yes"]) AM_CONDITIONAL([ENABLE_ARM_CRC], [test "$enable_arm_crc" = "yes"]) AM_CONDITIONAL([ENABLE_ARM_SHANI], [test "$enable_arm_shani" = "yes"]) -AM_CONDITIONAL([USE_ASM], [test "$use_asm" = "yes"]) AM_CONDITIONAL([WORDS_BIGENDIAN], [test "$ac_cv_c_bigendian" = "yes"]) AM_CONDITIONAL([USE_NATPMP], [test "$use_natpmp" = "yes"]) AM_CONDITIONAL([USE_UPNP], [test "$use_upnp" = "yes"]) @@ -1988,7 +1974,6 @@ echo " with fuzz binary = $enable_fuzz_binary" echo " with bench = $use_bench" echo " with upnp = $use_upnp" echo " with natpmp = $use_natpmp" -echo " use asm = $use_asm" echo " USDT tracing = $use_usdt" echo " sanitizers = $use_sanitizers" echo " debug enabled = $enable_debug" diff --git a/doc/developer-notes.md b/doc/developer-notes.md index c05c87e9c4896..91616f46bceec 100644 --- a/doc/developer-notes.md +++ b/doc/developer-notes.md @@ -569,13 +569,6 @@ export UBSAN_OPTIONS="suppressions=$(pwd)/test/sanitizer_suppressions/ubsan:prin See the CI config for more examples, and upstream documentation for more information about any additional options. -There are a number of known problems when using the `address` sanitizer. The -address sanitizer is known to fail in -[sha256_sse4::Transform](/src/crypto/sha256_sse4.cpp) which makes it unusable -unless you also use `--disable-asm` when running configure. We would like to fix -sanitizer issues, so please send pull requests if you can fix any errors found -by the address sanitizer (or any other sanitizer). - Not all sanitizer options can be enabled at the same time, e.g. trying to build with `--with-sanitizers=address,thread` will fail in the configure script as these sanitizers are mutually incompatible. Refer to your compiler manual to diff --git a/doc/fuzzing.md b/doc/fuzzing.md index 82f3ac8b31657..c8a121341c5b5 100644 --- a/doc/fuzzing.md +++ b/doc/fuzzing.md @@ -127,11 +127,6 @@ The default Clang/LLVM version supplied by Apple on macOS does not include fuzzing libraries, so macOS users will need to install a full version, for example using `brew install llvm`. -Should you run into problems with the address sanitizer, it is possible you -may need to run `./configure` with `--disable-asm` to avoid errors -with certain assembly code from Dash Core's code. See [developer notes on sanitizers](https://github.com/dashpay/dash/blob/develop/doc/developer-notes.md#sanitizers) -for more information. - You may also need to take care of giving the correct path for `clang` and `clang++`, like `CC=/path/to/clang CXX=/path/to/clang++` if the non-systems `clang` does not come first in your path. @@ -139,7 +134,7 @@ You may also need to take care of giving the correct path for `clang` and Full configure that was tested on macOS with `brew` installed `llvm`: ```sh -./configure --enable-fuzz --with-sanitizers=fuzzer,address,undefined --disable-asm CC=$(brew --prefix llvm)/bin/clang CXX=$(brew --prefix llvm)/bin/clang++ +./configure --enable-fuzz --with-sanitizers=fuzzer,address,undefined CC=$(brew --prefix llvm)/bin/clang CXX=$(brew --prefix llvm)/bin/clang++ ``` Read the [libFuzzer documentation](https://llvm.org/docs/LibFuzzer.html) for more information. This [libFuzzer tutorial](https://github.com/google/fuzzing/blob/master/tutorial/libFuzzerTutorial.md) might also be of interest. diff --git a/src/Makefile.am b/src/Makefile.am index 23ecb98e47860..829773eaef8f4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,6 +18,15 @@ AM_LIBTOOLFLAGS = --preserve-dup-deps PTHREAD_FLAGS = $(PTHREAD_CFLAGS) $(PTHREAD_LIBS) EXTRA_LIBRARIES = +lib_LTLIBRARIES = $(LIBBITCOINCONSENSUS) +noinst_LTLIBRARIES = + +bin_PROGRAMS = +noinst_PROGRAMS = +check_PROGRAMS = +TESTS = +BENCHMARKS = + if ENABLE_STACKTRACES if ENABLE_CRASH_HOOKS if CRASH_HOOKS_WRAPPED_CXX_ABI @@ -47,7 +56,7 @@ LIBBITCOIN_COMMON=libbitcoin_common.a LIBBITCOIN_CONSENSUS=libbitcoin_consensus.a LIBBITCOIN_CLI=libbitcoin_cli.a LIBBITCOIN_UTIL=libbitcoin_util.a -LIBBITCOIN_CRYPTO_BASE=crypto/libbitcoin_crypto_base.a +LIBBITCOIN_CRYPTO_BASE=crypto/libbitcoin_crypto_base.la LIBBITCOINQT=qt/libbitcoinqt.a LIBDASHBLS=dashbls/libdashbls.la LIBSECP256K1=secp256k1/libsecp256k1.la @@ -63,23 +72,24 @@ LIBBITCOIN_WALLET=libbitcoin_wallet.a LIBBITCOIN_WALLET_TOOL=libbitcoin_wallet_tool.a endif -LIBBITCOIN_CRYPTO= $(LIBBITCOIN_CRYPTO_BASE) +LIBBITCOIN_CRYPTO = $(LIBBITCOIN_CRYPTO_BASE) if ENABLE_SSE41 -LIBBITCOIN_CRYPTO_SSE41 = crypto/libbitcoin_crypto_sse41.a +LIBBITCOIN_CRYPTO_SSE41 = crypto/libbitcoin_crypto_sse41.la LIBBITCOIN_CRYPTO += $(LIBBITCOIN_CRYPTO_SSE41) +if ENABLE_X86_SHANI +LIBBITCOIN_CRYPTO_X86_SHANI = crypto/libbitcoin_crypto_x86_shani.la +LIBBITCOIN_CRYPTO += $(LIBBITCOIN_CRYPTO_X86_SHANI) +endif endif if ENABLE_AVX2 -LIBBITCOIN_CRYPTO_AVX2 = crypto/libbitcoin_crypto_avx2.a +LIBBITCOIN_CRYPTO_AVX2 = crypto/libbitcoin_crypto_avx2.la LIBBITCOIN_CRYPTO += $(LIBBITCOIN_CRYPTO_AVX2) endif -if ENABLE_X86_SHANI -LIBBITCOIN_CRYPTO_X86_SHANI = crypto/libbitcoin_crypto_x86_shani.a -LIBBITCOIN_CRYPTO += $(LIBBITCOIN_CRYPTO_X86_SHANI) -endif if ENABLE_ARM_SHANI -LIBBITCOIN_CRYPTO_ARM_SHANI = crypto/libbitcoin_crypto_arm_shani.a +LIBBITCOIN_CRYPTO_ARM_SHANI = crypto/libbitcoin_crypto_arm_shani.la LIBBITCOIN_CRYPTO += $(LIBBITCOIN_CRYPTO_ARM_SHANI) endif +noinst_LTLIBRARIES += $(LIBBITCOIN_CRYPTO) $(LIBDASHBLS): $(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C $(@D) @@ -90,7 +100,6 @@ $(LIBSECP256K1): $(wildcard secp256k1/src/*.h) $(wildcard secp256k1/src/*.c) $(w # Make is not made aware of per-object dependencies to avoid limiting building parallelization # But to build the less dependent modules first, we manually select their order here: EXTRA_LIBRARIES += \ - $(LIBBITCOIN_CRYPTO) \ $(LIBBITCOIN_UTIL) \ $(LIBBITCOIN_COMMON) \ $(LIBBITCOIN_CONSENSUS) \ @@ -101,15 +110,6 @@ EXTRA_LIBRARIES += \ $(LIBBITCOIN_WALLET_TOOL) \ $(LIBBITCOIN_ZMQ) -lib_LTLIBRARIES = $(LIBBITCOINCONSENSUS) -noinst_LTLIBRARIES = - -bin_PROGRAMS = -noinst_PROGRAMS = -check_PROGRAMS = -TESTS = -BENCHMARKS = - if BUILD_BITCOIND bin_PROGRAMS += dashd endif @@ -546,8 +546,9 @@ libbitcoin_node_a_SOURCES = \ rpc/mempool.cpp \ rpc/governance.cpp \ rpc/mining.cpp \ - rpc/misc.cpp \ + rpc/node.cpp \ rpc/net.cpp \ + rpc/output_script.cpp \ rpc/quorums.cpp \ rpc/rawtransaction.cpp \ rpc/server.cpp \ @@ -641,9 +642,20 @@ libbitcoin_wallet_tool_a_SOURCES = \ $(BITCOIN_CORE_H) # crypto primitives library -crypto_libbitcoin_crypto_base_a_CPPFLAGS = $(AM_CPPFLAGS) $(PIC_FLAGS) -crypto_libbitcoin_crypto_base_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) $(PIC_FLAGS) -crypto_libbitcoin_crypto_base_a_SOURCES = \ + +# crypto_base contains the unspecialized (unoptimized) versions of our +# crypto functions. Functions that require custom compiler flags and/or +# runtime opt-in are omitted. +crypto_libbitcoin_crypto_base_la_CPPFLAGS = $(AM_CPPFLAGS) $(PIC_FLAGS) + +# Specify -static in both CXXFLAGS and LDFLAGS so libtool will only build a +# static version of this library. We don't need a dynamic version, and a dynamic +# version can't be used on windows anyway because the library doesn't currently +# export DLL symbols. +crypto_libbitcoin_crypto_base_la_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) $(PIC_FLAGS) -static +crypto_libbitcoin_crypto_base_la_LDFLAGS = $(AM_LDFLAGS) -static + +crypto_libbitcoin_crypto_base_la_SOURCES = \ crypto/aes.cpp \ crypto/aes.h \ crypto/chacha20.h \ @@ -669,6 +681,7 @@ crypto_libbitcoin_crypto_base_a_SOURCES = \ crypto/sha1.h \ crypto/sha256.cpp \ crypto/sha256.h \ + crypto/sha256_sse4.cpp \ crypto/sha3.cpp \ crypto/sha3.h \ crypto/sha512.cpp \ @@ -676,24 +689,26 @@ crypto_libbitcoin_crypto_base_a_SOURCES = \ crypto/siphash.cpp \ crypto/siphash.h -if USE_ASM -crypto_libbitcoin_crypto_base_a_SOURCES += crypto/sha256_sse4.cpp -endif - -crypto_libbitcoin_crypto_sse41_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) -crypto_libbitcoin_crypto_sse41_a_CPPFLAGS = $(AM_CPPFLAGS) -crypto_libbitcoin_crypto_sse41_a_CXXFLAGS += $(SSE41_CXXFLAGS) -crypto_libbitcoin_crypto_sse41_a_CPPFLAGS += -DENABLE_SSE41 -crypto_libbitcoin_crypto_sse41_a_SOURCES = crypto/sha256_sse41.cpp - -crypto_libbitcoin_crypto_avx2_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) -crypto_libbitcoin_crypto_avx2_a_CPPFLAGS = $(AM_CPPFLAGS) -crypto_libbitcoin_crypto_avx2_a_CXXFLAGS += $(AVX2_CXXFLAGS) -crypto_libbitcoin_crypto_avx2_a_CPPFLAGS += -DENABLE_AVX2 -crypto_libbitcoin_crypto_avx2_a_SOURCES = crypto/sha256_avx2.cpp +# See explanation for -static in crypto_libbitcoin_crypto_base_la's LDFLAGS and +# CXXFLAGS above +crypto_libbitcoin_crypto_sse41_la_LDFLAGS = $(AM_LDFLAGS) -static +crypto_libbitcoin_crypto_sse41_la_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) -static +crypto_libbitcoin_crypto_sse41_la_CPPFLAGS = $(AM_CPPFLAGS) +crypto_libbitcoin_crypto_sse41_la_CXXFLAGS += $(SSE41_CXXFLAGS) +crypto_libbitcoin_crypto_sse41_la_CPPFLAGS += -DENABLE_SSE41 +crypto_libbitcoin_crypto_sse41_la_SOURCES = crypto/sha256_sse41.cpp + +# See explanation for -static in crypto_libbitcoin_crypto_base_la's LDFLAGS and +# CXXFLAGS above +crypto_libbitcoin_crypto_avx2_la_LDFLAGS = $(AM_LDFLAGS) -static +crypto_libbitcoin_crypto_avx2_la_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) -static +crypto_libbitcoin_crypto_avx2_la_CPPFLAGS = $(AM_CPPFLAGS) +crypto_libbitcoin_crypto_avx2_la_CXXFLAGS += $(AVX2_CXXFLAGS) +crypto_libbitcoin_crypto_avx2_la_CPPFLAGS += -DENABLE_AVX2 +crypto_libbitcoin_crypto_avx2_la_SOURCES = crypto/sha256_avx2.cpp # x11 -crypto_libbitcoin_crypto_base_a_SOURCES += \ +crypto_libbitcoin_crypto_base_la_SOURCES += \ crypto/x11/aes_helper.c \ crypto/x11/blake.c \ crypto/x11/bmw.c \ @@ -719,17 +734,23 @@ crypto_libbitcoin_crypto_base_a_SOURCES += \ crypto/x11/sph_skein.h \ crypto/x11/sph_types.h -crypto_libbitcoin_crypto_x86_shani_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) -crypto_libbitcoin_crypto_x86_shani_a_CPPFLAGS = $(AM_CPPFLAGS) -crypto_libbitcoin_crypto_x86_shani_a_CXXFLAGS += $(X86_SHANI_CXXFLAGS) -crypto_libbitcoin_crypto_x86_shani_a_CPPFLAGS += -DENABLE_X86_SHANI -crypto_libbitcoin_crypto_x86_shani_a_SOURCES = crypto/sha256_x86_shani.cpp - -crypto_libbitcoin_crypto_arm_shani_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) -crypto_libbitcoin_crypto_arm_shani_a_CPPFLAGS = $(AM_CPPFLAGS) -crypto_libbitcoin_crypto_arm_shani_a_CXXFLAGS += $(ARM_SHANI_CXXFLAGS) -crypto_libbitcoin_crypto_arm_shani_a_CPPFLAGS += -DENABLE_ARM_SHANI -crypto_libbitcoin_crypto_arm_shani_a_SOURCES = crypto/sha256_arm_shani.cpp +# See explanation for -static in crypto_libbitcoin_crypto_base_la's LDFLAGS and +# CXXFLAGS above +crypto_libbitcoin_crypto_x86_shani_la_LDFLAGS = $(AM_LDFLAGS) -static +crypto_libbitcoin_crypto_x86_shani_la_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) -static +crypto_libbitcoin_crypto_x86_shani_la_CPPFLAGS = $(AM_CPPFLAGS) +crypto_libbitcoin_crypto_x86_shani_la_CXXFLAGS += $(X86_SHANI_CXXFLAGS) +crypto_libbitcoin_crypto_x86_shani_la_CPPFLAGS += -DENABLE_SSE41 -DENABLE_X86_SHANI +crypto_libbitcoin_crypto_x86_shani_la_SOURCES = crypto/sha256_x86_shani.cpp + +# See explanation for -static in crypto_libbitcoin_crypto_base_la's LDFLAGS and +# CXXFLAGS above +crypto_libbitcoin_crypto_arm_shani_la_LDFLAGS = $(AM_LDFLAGS) -static +crypto_libbitcoin_crypto_arm_shani_la_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) -static +crypto_libbitcoin_crypto_arm_shani_la_CPPFLAGS = $(AM_CPPFLAGS) +crypto_libbitcoin_crypto_arm_shani_la_CXXFLAGS += $(ARM_SHANI_CXXFLAGS) +crypto_libbitcoin_crypto_arm_shani_la_CPPFLAGS += -DENABLE_ARM_SHANI +crypto_libbitcoin_crypto_arm_shani_la_SOURCES = crypto/sha256_arm_shani.cpp # consensus: shared between all executables that validate any consensus rules. libbitcoin_consensus_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(BOOST_CPPFLAGS) @@ -905,7 +926,6 @@ bitcoin_bin_ldadd = \ $(LIBBITCOIN_CRYPTO) \ $(LIBDASHBLS) \ $(LIBLEVELDB) \ - $(LIBLEVELDB_SSE42) \ $(LIBMEMENV) \ $(LIBSECP256K1) @@ -978,11 +998,11 @@ endif # dashconsensus library # if BUILD_BITCOIN_LIBS include_HEADERS = script/bitcoinconsensus.h -libdashconsensus_la_SOURCES = support/cleanse.cpp $(crypto_libbitcoin_crypto_base_a_SOURCES) $(libbitcoin_consensus_a_SOURCES) +libdashconsensus_la_SOURCES = support/cleanse.cpp $(crypto_libbitcoin_crypto_base_la_SOURCES) $(libbitcoin_consensus_a_SOURCES) libdashconsensus_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined $(RELDFLAGS) libdashconsensus_la_LIBADD = $(LIBDASHBLS) $(LIBSECP256K1) $(GMP_LIBS) -libdashconsensus_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(builddir)/obj -I$(srcdir)/secp256k1/include -DBUILD_BITCOIN_INTERNAL +libdashconsensus_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(builddir)/obj -I$(srcdir)/secp256k1/include -DBUILD_BITCOIN_INTERNAL -DDISABLE_OPTIMIZED_SHA256 libdashconsensus_la_CPPFLAGS += -isystem$(srcdir)/dashbls/include -isystem$(srcdir)/dashbls/depends/relic/include -isystem$(srcdir)/dashbls/depends/minialloc/include libdashconsensus_la_CPPFLAGS += -isystem$(srcdir)/immer libdashconsensus_la_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) diff --git a/src/Makefile.bench.include b/src/Makefile.bench.include index 81779269c7105..bc788ac810f8b 100644 --- a/src/Makefile.bench.include +++ b/src/Makefile.bench.include @@ -61,6 +61,7 @@ bench_bench_dash_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(BOOST_CPPFLAGS) bench_bench_dash_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) bench_bench_dash_LDFLAGS = $(LDFLAGS_WRAP_EXCEPTIONS) $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(PTHREAD_FLAGS) bench_bench_dash_LDADD = \ + $(LIBTEST_UTIL) \ $(LIBBITCOIN_NODE) \ $(LIBBITCOIN_WALLET) \ $(LIBBITCOIN_COMMON) \ @@ -68,9 +69,7 @@ bench_bench_dash_LDADD = \ $(LIBBITCOIN_CONSENSUS) \ $(LIBBITCOIN_CRYPTO) \ $(LIBDASHBLS) \ - $(LIBTEST_UTIL) \ $(LIBLEVELDB) \ - $(LIBLEVELDB_SSE42) \ $(LIBMEMENV) \ $(LIBSECP256K1) \ $(LIBUNIVALUE) \ diff --git a/src/Makefile.crc32c.include b/src/Makefile.crc32c.include index 3cbe71792cae8..c4dd84991d277 100644 --- a/src/Makefile.crc32c.include +++ b/src/Makefile.crc32c.include @@ -2,10 +2,9 @@ # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. -LIBCRC32C_INT = crc32c/libcrc32c.a -LIBLEVELDB_SSE42_INT = leveldb/libleveldb_sse42.a +LIBCRC32C_INT = crc32c/libcrc32c.la -EXTRA_LIBRARIES += $(LIBCRC32C_INT) +noinst_LTLIBRARIES += $(LIBCRC32C_INT) LIBCRC32C = $(LIBCRC32C_INT) @@ -34,41 +33,49 @@ else CRC32C_CPPFLAGS_INT += -DBYTE_ORDER_BIG_ENDIAN=0 endif -crc32c_libcrc32c_a_CPPFLAGS = $(AM_CPPFLAGS) $(CRC32C_CPPFLAGS_INT) $(CRC32C_CPPFLAGS) -crc32c_libcrc32c_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) - -crc32c_libcrc32c_a_SOURCES = -crc32c_libcrc32c_a_SOURCES += crc32c/include/crc32c/crc32c.h -crc32c_libcrc32c_a_SOURCES += crc32c/src/crc32c_arm64.h -crc32c_libcrc32c_a_SOURCES += crc32c/src/crc32c_arm64_check.h -crc32c_libcrc32c_a_SOURCES += crc32c/src/crc32c_internal.h -crc32c_libcrc32c_a_SOURCES += crc32c/src/crc32c_prefetch.h -crc32c_libcrc32c_a_SOURCES += crc32c/src/crc32c_read_le.h -crc32c_libcrc32c_a_SOURCES += crc32c/src/crc32c_round_up.h -crc32c_libcrc32c_a_SOURCES += crc32c/src/crc32c_sse42_check.h -crc32c_libcrc32c_a_SOURCES += crc32c/src/crc32c_sse42.h - -crc32c_libcrc32c_a_SOURCES += crc32c/src/crc32c.cc -crc32c_libcrc32c_a_SOURCES += crc32c/src/crc32c_portable.cc +crc32c_libcrc32c_la_CPPFLAGS = $(AM_CPPFLAGS) $(CRC32C_CPPFLAGS_INT) $(CRC32C_CPPFLAGS) + +# Specify -static in both CXXFLAGS and LDFLAGS so libtool will only build a +# static version of this library. We don't need a dynamic version, and a dynamic +# version can't be used on windows anyway because the library doesn't currently +# export DLL symbols. +crc32c_libcrc32c_la_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) -static +crc32c_libcrc32c_la_LDFLAGS = $(AM_LDFLAGS) -static + +crc32c_libcrc32c_la_SOURCES = +crc32c_libcrc32c_la_SOURCES += crc32c/include/crc32c/crc32c.h +crc32c_libcrc32c_la_SOURCES += crc32c/src/crc32c_arm64.h +crc32c_libcrc32c_la_SOURCES += crc32c/src/crc32c_arm64_check.h +crc32c_libcrc32c_la_SOURCES += crc32c/src/crc32c_internal.h +crc32c_libcrc32c_la_SOURCES += crc32c/src/crc32c_prefetch.h +crc32c_libcrc32c_la_SOURCES += crc32c/src/crc32c_read_le.h +crc32c_libcrc32c_la_SOURCES += crc32c/src/crc32c_round_up.h +crc32c_libcrc32c_la_SOURCES += crc32c/src/crc32c_sse42_check.h +crc32c_libcrc32c_la_SOURCES += crc32c/src/crc32c_sse42.h + +crc32c_libcrc32c_la_SOURCES += crc32c/src/crc32c.cc +crc32c_libcrc32c_la_SOURCES += crc32c/src/crc32c_portable.cc if ENABLE_SSE42 -LIBCRC32C_SSE42_INT = crc32c/libcrc32c_sse42.a -EXTRA_LIBRARIES += $(LIBCRC32C_SSE42_INT) +LIBCRC32C_SSE42_INT = crc32c/libcrc32c_sse42.la +noinst_LTLIBRARIES += $(LIBCRC32C_SSE42_INT) LIBCRC32C += $(LIBCRC32C_SSE42_INT) -crc32c_libcrc32c_sse42_a_CPPFLAGS = $(crc32c_libcrc32c_a_CPPFLAGS) -crc32c_libcrc32c_sse42_a_CXXFLAGS = $(crc32c_libcrc32c_a_CXXFLAGS) $(SSE42_CXXFLAGS) +crc32c_libcrc32c_sse42_la_CPPFLAGS = $(crc32c_libcrc32c_la_CPPFLAGS) +crc32c_libcrc32c_sse42_la_CXXFLAGS = $(crc32c_libcrc32c_la_CXXFLAGS) $(SSE42_CXXFLAGS) +crc32c_libcrc32c_sse42_la_LDFLAGS = $(crc32c_libcrc32c_la_LDFLAGS) -crc32c_libcrc32c_sse42_a_SOURCES = crc32c/src/crc32c_sse42.cc +crc32c_libcrc32c_sse42_la_SOURCES = crc32c/src/crc32c_sse42.cc endif if ENABLE_ARM_CRC -LIBCRC32C_ARM_CRC_INT = crc32c/libcrc32c_arm_crc.a -EXTRA_LIBRARIES += $(LIBCRC32C_ARM_CRC_INT) +LIBCRC32C_ARM_CRC_INT = crc32c/libcrc32c_arm_crc.la +noinst_LTLIBRARIES += $(LIBCRC32C_ARM_CRC_INT) LIBCRC32C += $(LIBCRC32C_ARM_CRC_INT) -crc32c_libcrc32c_arm_crc_a_CPPFLAGS = $(crc32c_libcrc32c_a_CPPFLAGS) -crc32c_libcrc32c_arm_crc_a_CXXFLAGS = $(crc32c_libcrc32c_a_CXXFLAGS) $(ARM_CRC_CXXFLAGS) +crc32c_libcrc32c_arm_crc_la_CPPFLAGS = $(crc32c_libcrc32c_la_CPPFLAGS) +crc32c_libcrc32c_arm_crc_la_CXXFLAGS = $(crc32c_libcrc32c_la_CXXFLAGS) $(ARM_CRC_CXXFLAGS) +crc32c_libcrc32c_arm_crc_la_LDFLAGS = $(crc32c_libcrc32c_la_LDFLAGS) -crc32c_libcrc32c_arm_crc_a_SOURCES = crc32c/src/crc32c_arm64.cc +crc32c_libcrc32c_arm_crc_la_SOURCES = crc32c/src/crc32c_arm64.cc endif diff --git a/src/Makefile.leveldb.include b/src/Makefile.leveldb.include index 60616c5e08cd0..bf14fe206b926 100644 --- a/src/Makefile.leveldb.include +++ b/src/Makefile.leveldb.include @@ -2,11 +2,11 @@ # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. -LIBLEVELDB_INT = leveldb/libleveldb.a -LIBMEMENV_INT = leveldb/libmemenv.a +LIBLEVELDB_INT = leveldb/libleveldb.la +LIBMEMENV_INT = leveldb/libmemenv.la -EXTRA_LIBRARIES += $(LIBLEVELDB_INT) -EXTRA_LIBRARIES += $(LIBMEMENV_INT) +noinst_LTLIBRARIES += $(LIBLEVELDB_INT) +noinst_LTLIBRARIES += $(LIBMEMENV_INT) LIBLEVELDB = $(LIBLEVELDB_INT) $(LIBCRC32C) LIBMEMENV = $(LIBMEMENV_INT) @@ -36,111 +36,118 @@ else LEVELDB_CPPFLAGS_INT += -DLEVELDB_PLATFORM_POSIX endif -leveldb_libleveldb_a_CPPFLAGS = $(AM_CPPFLAGS) $(LEVELDB_CPPFLAGS_INT) $(LEVELDB_CPPFLAGS) -leveldb_libleveldb_a_CXXFLAGS = $(filter-out -Wconditional-uninitialized -Werror=conditional-uninitialized -Wsuggest-override -Werror=suggest-override, $(AM_CXXFLAGS)) $(PIE_FLAGS) +leveldb_libleveldb_la_CPPFLAGS = $(AM_CPPFLAGS) $(LEVELDB_CPPFLAGS_INT) $(LEVELDB_CPPFLAGS) -leveldb_libleveldb_a_SOURCES= -leveldb_libleveldb_a_SOURCES += leveldb/port/port_stdcxx.h -leveldb_libleveldb_a_SOURCES += leveldb/port/port.h -leveldb_libleveldb_a_SOURCES += leveldb/port/thread_annotations.h -leveldb_libleveldb_a_SOURCES += leveldb/include/leveldb/db.h -leveldb_libleveldb_a_SOURCES += leveldb/include/leveldb/options.h -leveldb_libleveldb_a_SOURCES += leveldb/include/leveldb/comparator.h -leveldb_libleveldb_a_SOURCES += leveldb/include/leveldb/filter_policy.h -leveldb_libleveldb_a_SOURCES += leveldb/include/leveldb/slice.h -leveldb_libleveldb_a_SOURCES += leveldb/include/leveldb/table_builder.h -leveldb_libleveldb_a_SOURCES += leveldb/include/leveldb/env.h -leveldb_libleveldb_a_SOURCES += leveldb/include/leveldb/export.h -leveldb_libleveldb_a_SOURCES += leveldb/include/leveldb/c.h -leveldb_libleveldb_a_SOURCES += leveldb/include/leveldb/iterator.h -leveldb_libleveldb_a_SOURCES += leveldb/include/leveldb/cache.h -leveldb_libleveldb_a_SOURCES += leveldb/include/leveldb/dumpfile.h -leveldb_libleveldb_a_SOURCES += leveldb/include/leveldb/table.h -leveldb_libleveldb_a_SOURCES += leveldb/include/leveldb/write_batch.h -leveldb_libleveldb_a_SOURCES += leveldb/include/leveldb/status.h -leveldb_libleveldb_a_SOURCES += leveldb/db/log_format.h -leveldb_libleveldb_a_SOURCES += leveldb/db/memtable.h -leveldb_libleveldb_a_SOURCES += leveldb/db/version_set.h -leveldb_libleveldb_a_SOURCES += leveldb/db/write_batch_internal.h -leveldb_libleveldb_a_SOURCES += leveldb/db/filename.h -leveldb_libleveldb_a_SOURCES += leveldb/db/version_edit.h -leveldb_libleveldb_a_SOURCES += leveldb/db/dbformat.h -leveldb_libleveldb_a_SOURCES += leveldb/db/builder.h -leveldb_libleveldb_a_SOURCES += leveldb/db/log_writer.h -leveldb_libleveldb_a_SOURCES += leveldb/db/db_iter.h -leveldb_libleveldb_a_SOURCES += leveldb/db/skiplist.h -leveldb_libleveldb_a_SOURCES += leveldb/db/db_impl.h -leveldb_libleveldb_a_SOURCES += leveldb/db/table_cache.h -leveldb_libleveldb_a_SOURCES += leveldb/db/snapshot.h -leveldb_libleveldb_a_SOURCES += leveldb/db/log_reader.h -leveldb_libleveldb_a_SOURCES += leveldb/table/filter_block.h -leveldb_libleveldb_a_SOURCES += leveldb/table/block_builder.h -leveldb_libleveldb_a_SOURCES += leveldb/table/block.h -leveldb_libleveldb_a_SOURCES += leveldb/table/two_level_iterator.h -leveldb_libleveldb_a_SOURCES += leveldb/table/merger.h -leveldb_libleveldb_a_SOURCES += leveldb/table/format.h -leveldb_libleveldb_a_SOURCES += leveldb/table/iterator_wrapper.h -leveldb_libleveldb_a_SOURCES += leveldb/util/crc32c.h -leveldb_libleveldb_a_SOURCES += leveldb/util/env_posix_test_helper.h -leveldb_libleveldb_a_SOURCES += leveldb/util/env_windows_test_helper.h -leveldb_libleveldb_a_SOURCES += leveldb/util/arena.h -leveldb_libleveldb_a_SOURCES += leveldb/util/random.h -leveldb_libleveldb_a_SOURCES += leveldb/util/posix_logger.h -leveldb_libleveldb_a_SOURCES += leveldb/util/hash.h -leveldb_libleveldb_a_SOURCES += leveldb/util/histogram.h -leveldb_libleveldb_a_SOURCES += leveldb/util/coding.h -leveldb_libleveldb_a_SOURCES += leveldb/util/testutil.h -leveldb_libleveldb_a_SOURCES += leveldb/util/mutexlock.h -leveldb_libleveldb_a_SOURCES += leveldb/util/logging.h -leveldb_libleveldb_a_SOURCES += leveldb/util/no_destructor.h -leveldb_libleveldb_a_SOURCES += leveldb/util/testharness.h -leveldb_libleveldb_a_SOURCES += leveldb/util/windows_logger.h +# Specify -static in both CXXFLAGS and LDFLAGS so libtool will only build a +# static version of this library. We don't need a dynamic version, and a dynamic +# version can't be used on windows anyway because the library doesn't currently +# export DLL symbols. +leveldb_libleveldb_la_CXXFLAGS = $(filter-out -Wconditional-uninitialized -Werror=conditional-uninitialized -Wsuggest-override -Werror=suggest-override, $(AM_CXXFLAGS)) $(PIE_FLAGS) -static +leveldb_libleveldb_la_LDFLAGS = $(AM_LDFLAGS) -static -leveldb_libleveldb_a_SOURCES += leveldb/db/builder.cc -leveldb_libleveldb_a_SOURCES += leveldb/db/c.cc -leveldb_libleveldb_a_SOURCES += leveldb/db/dbformat.cc -leveldb_libleveldb_a_SOURCES += leveldb/db/db_impl.cc -leveldb_libleveldb_a_SOURCES += leveldb/db/db_iter.cc -leveldb_libleveldb_a_SOURCES += leveldb/db/dumpfile.cc -leveldb_libleveldb_a_SOURCES += leveldb/db/filename.cc -leveldb_libleveldb_a_SOURCES += leveldb/db/log_reader.cc -leveldb_libleveldb_a_SOURCES += leveldb/db/log_writer.cc -leveldb_libleveldb_a_SOURCES += leveldb/db/memtable.cc -leveldb_libleveldb_a_SOURCES += leveldb/db/repair.cc -leveldb_libleveldb_a_SOURCES += leveldb/db/table_cache.cc -leveldb_libleveldb_a_SOURCES += leveldb/db/version_edit.cc -leveldb_libleveldb_a_SOURCES += leveldb/db/version_set.cc -leveldb_libleveldb_a_SOURCES += leveldb/db/write_batch.cc -leveldb_libleveldb_a_SOURCES += leveldb/table/block_builder.cc -leveldb_libleveldb_a_SOURCES += leveldb/table/block.cc -leveldb_libleveldb_a_SOURCES += leveldb/table/filter_block.cc -leveldb_libleveldb_a_SOURCES += leveldb/table/format.cc -leveldb_libleveldb_a_SOURCES += leveldb/table/iterator.cc -leveldb_libleveldb_a_SOURCES += leveldb/table/merger.cc -leveldb_libleveldb_a_SOURCES += leveldb/table/table_builder.cc -leveldb_libleveldb_a_SOURCES += leveldb/table/table.cc -leveldb_libleveldb_a_SOURCES += leveldb/table/two_level_iterator.cc -leveldb_libleveldb_a_SOURCES += leveldb/util/arena.cc -leveldb_libleveldb_a_SOURCES += leveldb/util/bloom.cc -leveldb_libleveldb_a_SOURCES += leveldb/util/cache.cc -leveldb_libleveldb_a_SOURCES += leveldb/util/coding.cc -leveldb_libleveldb_a_SOURCES += leveldb/util/comparator.cc -leveldb_libleveldb_a_SOURCES += leveldb/util/crc32c.cc -leveldb_libleveldb_a_SOURCES += leveldb/util/env.cc -leveldb_libleveldb_a_SOURCES += leveldb/util/filter_policy.cc -leveldb_libleveldb_a_SOURCES += leveldb/util/hash.cc -leveldb_libleveldb_a_SOURCES += leveldb/util/histogram.cc -leveldb_libleveldb_a_SOURCES += leveldb/util/logging.cc -leveldb_libleveldb_a_SOURCES += leveldb/util/options.cc -leveldb_libleveldb_a_SOURCES += leveldb/util/status.cc +leveldb_libleveldb_la_SOURCES= +leveldb_libleveldb_la_SOURCES += leveldb/port/port_stdcxx.h +leveldb_libleveldb_la_SOURCES += leveldb/port/port.h +leveldb_libleveldb_la_SOURCES += leveldb/port/thread_annotations.h +leveldb_libleveldb_la_SOURCES += leveldb/include/leveldb/db.h +leveldb_libleveldb_la_SOURCES += leveldb/include/leveldb/options.h +leveldb_libleveldb_la_SOURCES += leveldb/include/leveldb/comparator.h +leveldb_libleveldb_la_SOURCES += leveldb/include/leveldb/filter_policy.h +leveldb_libleveldb_la_SOURCES += leveldb/include/leveldb/slice.h +leveldb_libleveldb_la_SOURCES += leveldb/include/leveldb/table_builder.h +leveldb_libleveldb_la_SOURCES += leveldb/include/leveldb/env.h +leveldb_libleveldb_la_SOURCES += leveldb/include/leveldb/export.h +leveldb_libleveldb_la_SOURCES += leveldb/include/leveldb/c.h +leveldb_libleveldb_la_SOURCES += leveldb/include/leveldb/iterator.h +leveldb_libleveldb_la_SOURCES += leveldb/include/leveldb/cache.h +leveldb_libleveldb_la_SOURCES += leveldb/include/leveldb/dumpfile.h +leveldb_libleveldb_la_SOURCES += leveldb/include/leveldb/table.h +leveldb_libleveldb_la_SOURCES += leveldb/include/leveldb/write_batch.h +leveldb_libleveldb_la_SOURCES += leveldb/include/leveldb/status.h +leveldb_libleveldb_la_SOURCES += leveldb/db/log_format.h +leveldb_libleveldb_la_SOURCES += leveldb/db/memtable.h +leveldb_libleveldb_la_SOURCES += leveldb/db/version_set.h +leveldb_libleveldb_la_SOURCES += leveldb/db/write_batch_internal.h +leveldb_libleveldb_la_SOURCES += leveldb/db/filename.h +leveldb_libleveldb_la_SOURCES += leveldb/db/version_edit.h +leveldb_libleveldb_la_SOURCES += leveldb/db/dbformat.h +leveldb_libleveldb_la_SOURCES += leveldb/db/builder.h +leveldb_libleveldb_la_SOURCES += leveldb/db/log_writer.h +leveldb_libleveldb_la_SOURCES += leveldb/db/db_iter.h +leveldb_libleveldb_la_SOURCES += leveldb/db/skiplist.h +leveldb_libleveldb_la_SOURCES += leveldb/db/db_impl.h +leveldb_libleveldb_la_SOURCES += leveldb/db/table_cache.h +leveldb_libleveldb_la_SOURCES += leveldb/db/snapshot.h +leveldb_libleveldb_la_SOURCES += leveldb/db/log_reader.h +leveldb_libleveldb_la_SOURCES += leveldb/table/filter_block.h +leveldb_libleveldb_la_SOURCES += leveldb/table/block_builder.h +leveldb_libleveldb_la_SOURCES += leveldb/table/block.h +leveldb_libleveldb_la_SOURCES += leveldb/table/two_level_iterator.h +leveldb_libleveldb_la_SOURCES += leveldb/table/merger.h +leveldb_libleveldb_la_SOURCES += leveldb/table/format.h +leveldb_libleveldb_la_SOURCES += leveldb/table/iterator_wrapper.h +leveldb_libleveldb_la_SOURCES += leveldb/util/crc32c.h +leveldb_libleveldb_la_SOURCES += leveldb/util/env_posix_test_helper.h +leveldb_libleveldb_la_SOURCES += leveldb/util/env_windows_test_helper.h +leveldb_libleveldb_la_SOURCES += leveldb/util/arena.h +leveldb_libleveldb_la_SOURCES += leveldb/util/random.h +leveldb_libleveldb_la_SOURCES += leveldb/util/posix_logger.h +leveldb_libleveldb_la_SOURCES += leveldb/util/hash.h +leveldb_libleveldb_la_SOURCES += leveldb/util/histogram.h +leveldb_libleveldb_la_SOURCES += leveldb/util/coding.h +leveldb_libleveldb_la_SOURCES += leveldb/util/testutil.h +leveldb_libleveldb_la_SOURCES += leveldb/util/mutexlock.h +leveldb_libleveldb_la_SOURCES += leveldb/util/logging.h +leveldb_libleveldb_la_SOURCES += leveldb/util/no_destructor.h +leveldb_libleveldb_la_SOURCES += leveldb/util/testharness.h +leveldb_libleveldb_la_SOURCES += leveldb/util/windows_logger.h + +leveldb_libleveldb_la_SOURCES += leveldb/db/builder.cc +leveldb_libleveldb_la_SOURCES += leveldb/db/c.cc +leveldb_libleveldb_la_SOURCES += leveldb/db/dbformat.cc +leveldb_libleveldb_la_SOURCES += leveldb/db/db_impl.cc +leveldb_libleveldb_la_SOURCES += leveldb/db/db_iter.cc +leveldb_libleveldb_la_SOURCES += leveldb/db/dumpfile.cc +leveldb_libleveldb_la_SOURCES += leveldb/db/filename.cc +leveldb_libleveldb_la_SOURCES += leveldb/db/log_reader.cc +leveldb_libleveldb_la_SOURCES += leveldb/db/log_writer.cc +leveldb_libleveldb_la_SOURCES += leveldb/db/memtable.cc +leveldb_libleveldb_la_SOURCES += leveldb/db/repair.cc +leveldb_libleveldb_la_SOURCES += leveldb/db/table_cache.cc +leveldb_libleveldb_la_SOURCES += leveldb/db/version_edit.cc +leveldb_libleveldb_la_SOURCES += leveldb/db/version_set.cc +leveldb_libleveldb_la_SOURCES += leveldb/db/write_batch.cc +leveldb_libleveldb_la_SOURCES += leveldb/table/block_builder.cc +leveldb_libleveldb_la_SOURCES += leveldb/table/block.cc +leveldb_libleveldb_la_SOURCES += leveldb/table/filter_block.cc +leveldb_libleveldb_la_SOURCES += leveldb/table/format.cc +leveldb_libleveldb_la_SOURCES += leveldb/table/iterator.cc +leveldb_libleveldb_la_SOURCES += leveldb/table/merger.cc +leveldb_libleveldb_la_SOURCES += leveldb/table/table_builder.cc +leveldb_libleveldb_la_SOURCES += leveldb/table/table.cc +leveldb_libleveldb_la_SOURCES += leveldb/table/two_level_iterator.cc +leveldb_libleveldb_la_SOURCES += leveldb/util/arena.cc +leveldb_libleveldb_la_SOURCES += leveldb/util/bloom.cc +leveldb_libleveldb_la_SOURCES += leveldb/util/cache.cc +leveldb_libleveldb_la_SOURCES += leveldb/util/coding.cc +leveldb_libleveldb_la_SOURCES += leveldb/util/comparator.cc +leveldb_libleveldb_la_SOURCES += leveldb/util/crc32c.cc +leveldb_libleveldb_la_SOURCES += leveldb/util/env.cc +leveldb_libleveldb_la_SOURCES += leveldb/util/filter_policy.cc +leveldb_libleveldb_la_SOURCES += leveldb/util/hash.cc +leveldb_libleveldb_la_SOURCES += leveldb/util/histogram.cc +leveldb_libleveldb_la_SOURCES += leveldb/util/logging.cc +leveldb_libleveldb_la_SOURCES += leveldb/util/options.cc +leveldb_libleveldb_la_SOURCES += leveldb/util/status.cc if TARGET_WINDOWS -leveldb_libleveldb_a_SOURCES += leveldb/util/env_windows.cc +leveldb_libleveldb_la_SOURCES += leveldb/util/env_windows.cc else -leveldb_libleveldb_a_SOURCES += leveldb/util/env_posix.cc +leveldb_libleveldb_la_SOURCES += leveldb/util/env_posix.cc endif -leveldb_libmemenv_a_CPPFLAGS = $(leveldb_libleveldb_a_CPPFLAGS) -leveldb_libmemenv_a_CXXFLAGS = $(leveldb_libleveldb_a_CXXFLAGS) -leveldb_libmemenv_a_SOURCES = leveldb/helpers/memenv/memenv.cc -leveldb_libmemenv_a_SOURCES += leveldb/helpers/memenv/memenv.h +leveldb_libmemenv_la_CPPFLAGS = $(leveldb_libleveldb_la_CPPFLAGS) +leveldb_libmemenv_la_CXXFLAGS = $(leveldb_libleveldb_la_CXXFLAGS) +leveldb_libmemenv_la_LDFLAGS = $(leveldb_libleveldb_la_LDFLAGS) +leveldb_libmemenv_la_SOURCES = leveldb/helpers/memenv/memenv.cc +leveldb_libmemenv_la_SOURCES += leveldb/helpers/memenv/memenv.h diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 487bc3fa6e68e..c9f918c764676 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -408,7 +408,7 @@ endif if ENABLE_ZMQ bitcoin_qt_ldadd += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS) endif -bitcoin_qt_ldadd += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBDASHBLS) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBLEVELDB_SSE42) $(LIBMEMENV) \ +bitcoin_qt_ldadd += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBDASHBLS) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) \ $(BACKTRACE_LIB) $(QT_LIBS) $(QT_DBUS_LIBS) $(QR_LIBS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(NATPMP_LIBS) $(SQLITE_LIBS) $(LIBSECP256K1) \ $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(GMP_LIBS) bitcoin_qt_ldflags = $(LDFLAGS_WRAP_EXCEPTIONS) $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(PTHREAD_FLAGS) diff --git a/src/Makefile.qttest.include b/src/Makefile.qttest.include index b869637523b5a..56e9225cb9da4 100644 --- a/src/Makefile.qttest.include +++ b/src/Makefile.qttest.include @@ -59,7 +59,7 @@ if ENABLE_ZMQ qt_test_test_dash_qt_LDADD += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS) endif qt_test_test_dash_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBDASHBLS) $(LIBUNIVALUE) $(LIBLEVELDB) \ - $(LIBLEVELDB_SSE42) $(LIBMEMENV) $(BACKTRACE_LIB) $(QT_LIBS) $(QT_DBUS_LIBS) $(QT_TEST_LIBS) \ + $(LIBMEMENV) $(BACKTRACE_LIB) $(QT_LIBS) $(QT_DBUS_LIBS) $(QT_TEST_LIBS) \ $(QR_LIBS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(NATPMP_LIBS) $(SQLITE_LIBS) $(LIBSECP256K1) \ $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(GMP_LIBS) qt_test_test_dash_qt_LDFLAGS = $(LDFLAGS_WRAP_EXCEPTIONS) $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(PTHREAD_FLAGS) diff --git a/src/Makefile.test.include b/src/Makefile.test.include index 9e7651f99437c..8375969549ae1 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -40,11 +40,11 @@ BITCOIN_TEST_SUITE = \ $(TEST_UTIL_H) FUZZ_SUITE_LD_COMMON = \ + $(LIBTEST_FUZZ) \ + $(LIBTEST_UTIL) \ $(LIBBITCOIN_NODE) \ $(LIBBITCOIN_COMMON) \ $(LIBBITCOIN_UTIL) \ - $(LIBTEST_FUZZ) \ - $(LIBTEST_UTIL) \ $(LIBBITCOIN_CONSENSUS) \ $(LIBBITCOIN_WALLET) \ $(LIBBITCOIN_CRYPTO) \ @@ -54,7 +54,6 @@ FUZZ_SUITE_LD_COMMON = \ $(SQLITE_LIBS) \ $(LIBUNIVALUE) \ $(LIBLEVELDB) \ - $(LIBLEVELDB_SSE42) \ $(LIBMEMENV) \ $(LIBSECP256K1) \ $(MINISKETCH_LIBS) \ @@ -241,7 +240,7 @@ test_test_dash_LDADD += $(LIBBITCOIN_WALLET) test_test_dash_CPPFLAGS += $(BDB_CPPFLAGS) endif test_test_dash_LDADD += $(LIBBITCOIN_NODE) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) \ - $(LIBDASHBLS) $(LIBLEVELDB) $(LIBLEVELDB_SSE42) $(LIBMEMENV) $(BACKTRACE_LIB) $(LIBSECP256K1) $(EVENT_LIBS) $(EVENT_PTHREADS_LIBS) $(MINISKETCH_LIBS) + $(LIBDASHBLS) $(LIBLEVELDB) $(LIBMEMENV) $(BACKTRACE_LIB) $(LIBSECP256K1) $(EVENT_LIBS) $(EVENT_PTHREADS_LIBS) $(MINISKETCH_LIBS) test_test_dash_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) test_test_dash_LDADD += $(BDB_LIBS) $(MINIUPNPC_LIBS) $(SQLITE_LIBS) $(NATPMP_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(GMP_LIBS) @@ -399,9 +398,8 @@ endif if TARGET_WINDOWS else if ENABLE_BENCH -# Disabled because benchmarks are too heavy in Dash -# @echo "Running bench/bench_dash" -# $(BENCH_BINARY) + @echo "Running bench/bench_dash (one iteration sanity check, only high priority)..." + $(BENCH_BINARY) -sanity-check -priority-level=high endif endif $(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C secp256k1 check diff --git a/src/Makefile.test_fuzz.include b/src/Makefile.test_fuzz.include index 4cdb757a52f8b..143917357d78b 100644 --- a/src/Makefile.test_fuzz.include +++ b/src/Makefile.test_fuzz.include @@ -22,8 +22,3 @@ libtest_fuzz_a_SOURCES = \ test/fuzz/util.cpp \ test/fuzz/util/net.cpp \ $(TEST_FUZZ_H) - -LIBTEST_FUZZ += $(LIBBITCOIN_NODE) -LIBTEST_FUZZ += $(LIBBITCOIN_COMMON) -LIBTEST_FUZZ += $(LIBBITCOIN_UTIL) -LIBTEST_FUZZ += $(LIBBITCOIN_CRYPTO_BASE) diff --git a/src/Makefile.test_util.include b/src/Makefile.test_util.include index 10f6a9ffe0716..bad7a12d152e3 100644 --- a/src/Makefile.test_util.include +++ b/src/Makefile.test_util.include @@ -40,11 +40,3 @@ libtest_util_a_SOURCES = \ test/util/validation.cpp \ test/util/wallet.cpp \ $(TEST_UTIL_H) - -LIBTEST_UTIL += $(LIBBITCOIN_NODE) -LIBTEST_UTIL += $(LIBBITCOIN_COMMON) -LIBTEST_UTIL += $(LIBBITCOIN_UTIL) -LIBTEST_UTIL += $(LIBBITCOIN_CRYPTO_BASE) -if ENABLE_WALLET -LIBTEST_UTIL += $(LIBBITCOIN_WALLET) -endif diff --git a/src/bench/bench.cpp b/src/bench/bench.cpp index 178725d13ebd9..ae017833ce6bb 100644 --- a/src/bench/bench.cpp +++ b/src/bench/bench.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -42,35 +43,73 @@ void GenerateTemplateResults(const std::vector& bench } // namespace -benchmark::BenchRunner::BenchmarkMap& benchmark::BenchRunner::benchmarks() +namespace benchmark { + +// map a label to one or multiple priority levels +std::map map_label_priority = { + {"high", PriorityLevel::HIGH}, + {"low", PriorityLevel::LOW}, + {"all", 0xff} +}; + +std::string ListPriorities() +{ + using item_t = std::pair; + auto sort_by_priority = [](item_t a, item_t b){ return a.second < b.second; }; + std::set sorted_priorities(map_label_priority.begin(), map_label_priority.end(), sort_by_priority); + return Join(sorted_priorities, ',', [](const auto& entry){ return entry.first; }); +} + +uint8_t StringToPriority(const std::string& str) +{ + auto it = map_label_priority.find(str); + if (it == map_label_priority.end()) throw std::runtime_error(strprintf("Unknown priority level %s", str)); + return it->second; +} + +BenchRunner::BenchmarkMap& BenchRunner::benchmarks() { - static std::map benchmarks_map; + static BenchmarkMap benchmarks_map; return benchmarks_map; } -benchmark::BenchRunner::BenchRunner(std::string name, benchmark::BenchFunction func) +BenchRunner::BenchRunner(std::string name, BenchFunction func, PriorityLevel level) { - benchmarks().insert(std::make_pair(name, func)); + benchmarks().insert(std::make_pair(name, std::make_pair(func, level))); } -void benchmark::BenchRunner::RunAll(const Args& args) +void BenchRunner::RunAll(const Args& args) { std::regex reFilter(args.regex_filter); std::smatch baseMatch; + if (args.sanity_check) { + std::cout << "Running with -sanity-check option, output is being suppressed as benchmark results will be useless." << std::endl; + } + std::vector benchmarkResults; - for (const auto& p : benchmarks()) { - if (!std::regex_match(p.first, baseMatch, reFilter)) { + for (const auto& [name, bench_func] : benchmarks()) { + const auto& [func, priority_level] = bench_func; + + if (!(priority_level & args.priority)) { + continue; + } + + if (!std::regex_match(name, baseMatch, reFilter)) { continue; } if (args.is_list_only) { - std::cout << p.first << std::endl; + std::cout << name << std::endl; continue; } Bench bench; - bench.name(p.first); + if (args.sanity_check) { + bench.epochs(1).epochIterations(1); + bench.output(nullptr); + } + bench.name(name); if (args.min_time > 0ms) { // convert to nanos before dividing to reduce rounding errors std::chrono::nanoseconds min_time_ns = args.min_time; @@ -78,11 +117,11 @@ void benchmark::BenchRunner::RunAll(const Args& args) } if (args.asymptote.empty()) { - p.second(bench); + func(bench); } else { for (auto n : args.asymptote) { bench.complexityN(n); - p.second(bench); + func(bench); } std::cout << bench.complexityBigO() << std::endl; } @@ -97,3 +136,5 @@ void benchmark::BenchRunner::RunAll(const Args& args) "{{/result}}"); GenerateTemplateResults(benchmarkResults, args.output_json, ankerl::nanobench::templates::json()); } + +} // namespace benchmark diff --git a/src/bench/bench.h b/src/bench/bench.h index 6634138beb092..1f412c9aecbec 100644 --- a/src/bench/bench.h +++ b/src/bench/bench.h @@ -41,29 +41,42 @@ using ankerl::nanobench::Bench; typedef std::function BenchFunction; +enum PriorityLevel : uint8_t +{ + LOW = 1 << 0, + HIGH = 1 << 2, +}; + +// List priority labels, comma-separated and sorted by increasing priority +std::string ListPriorities(); +uint8_t StringToPriority(const std::string& str); + struct Args { bool is_list_only; + bool sanity_check; std::chrono::milliseconds min_time; std::vector asymptote; fs::path output_csv; fs::path output_json; std::string regex_filter; + uint8_t priority; }; class BenchRunner { - typedef std::map BenchmarkMap; + // maps from "name" -> (function, priority_level) + typedef std::map> BenchmarkMap; static BenchmarkMap& benchmarks(); public: - BenchRunner(std::string name, BenchFunction func); + BenchRunner(std::string name, BenchFunction func, PriorityLevel level); static void RunAll(const Args& args); }; } // namespace benchmark -// BENCHMARK(foo) expands to: benchmark::BenchRunner bench_11foo("foo", foo); +// BENCHMARK(foo) expands to: benchmark::BenchRunner bench_11foo("foo", foo, priority_level); #define BENCHMARK(n) \ - benchmark::BenchRunner PASTE2(bench_, PASTE2(__LINE__, n))(STRINGIZE(n), n); + benchmark::BenchRunner PASTE2(bench_, PASTE2(__LINE__, n))(STRINGIZE(n), n, benchmark::PriorityLevel::HIGH); #endif // BITCOIN_BENCH_BENCH_H diff --git a/src/bench/bench_bitcoin.cpp b/src/bench/bench_bitcoin.cpp index d1af79e4af65f..a52021cf0a27e 100644 --- a/src/bench/bench_bitcoin.cpp +++ b/src/bench/bench_bitcoin.cpp @@ -7,11 +7,9 @@ #include #include #include -#include #include #include -#include #include #include #include @@ -20,6 +18,8 @@ static const char* DEFAULT_BENCH_FILTER = ".*"; static constexpr int64_t DEFAULT_MIN_TIME_MS{10}; +/** Priority level default value, run "all" priority levels */ +static const std::string DEFAULT_PRIORITY{"all"}; static void SetupBenchArgs(ArgsManager& argsman) { @@ -28,9 +28,12 @@ static void SetupBenchArgs(ArgsManager& argsman) argsman.AddArg("-asymptote=", "Test asymptotic growth of the runtime of an algorithm, if supported by the benchmark", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); argsman.AddArg("-filter=", strprintf("Regular expression filter to select benchmark by name (default: %s)", DEFAULT_BENCH_FILTER), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); argsman.AddArg("-list", "List benchmarks without executing them", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); - argsman.AddArg("-min_time=", strprintf("Minimum runtime per benchmark, in milliseconds (default: %d)", DEFAULT_MIN_TIME_MS), ArgsManager::ALLOW_ANY | ArgsManager::DISALLOW_NEGATION, OptionsCategory::OPTIONS); - argsman.AddArg("-output_csv=", "Generate CSV file with the most important benchmark results", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); - argsman.AddArg("-output_json=", "Generate JSON file with all benchmark results", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); + argsman.AddArg("-min-time=", strprintf("Minimum runtime per benchmark, in milliseconds (default: %d)", DEFAULT_MIN_TIME_MS), ArgsManager::ALLOW_ANY | ArgsManager::DISALLOW_NEGATION, OptionsCategory::OPTIONS); + argsman.AddArg("-output-csv=", "Generate CSV file with the most important benchmark results", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); + argsman.AddArg("-output-json=", "Generate JSON file with all benchmark results", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); + argsman.AddArg("-sanity-check", "Run benchmarks for only one iteration with no output", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); + argsman.AddArg("-priority-level=", strprintf("Run benchmarks of one or multiple priority level(s) (%s), default: '%s'", + benchmark::ListPriorities(), DEFAULT_PRIORITY), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); } // parses a comma separated list like "10,20,30,50" @@ -46,6 +49,14 @@ static std::vector parseAsymptote(const std::string& str) { return numbers; } +static uint8_t parsePriorityLevel(const std::string& str) { + uint8_t levels{0}; + for (const auto& level: SplitString(str, ',')) { + levels |= benchmark::StringToPriority(level); + } + return levels; +} + int main(int argc, char** argv) { ArgsManager argsman; @@ -75,7 +86,7 @@ int main(int argc, char** argv) " sure each run has exactly the same preconditions.\n" "\n" " * If results are still not reliable, increase runtime with e.g.\n" - " -min_time=5000 to let a benchmark run for at least 5 seconds.\n" + " -min-time=5000 to let a benchmark run for at least 5 seconds.\n" "\n" " * bench_dash uses nanobench [3] for which there is extensive\n" " documentation available online.\n" @@ -107,15 +118,22 @@ int main(int argc, char** argv) return EXIT_SUCCESS; } - benchmark::Args args; - args.asymptote = parseAsymptote(argsman.GetArg("-asymptote", "")); - args.is_list_only = argsman.GetBoolArg("-list", false); - args.min_time = std::chrono::milliseconds(argsman.GetIntArg("-min_time", DEFAULT_MIN_TIME_MS)); - args.output_csv = argsman.GetPathArg("-output_csv"); - args.output_json = argsman.GetPathArg("-output_json"); - args.regex_filter = argsman.GetArg("-filter", DEFAULT_BENCH_FILTER); + try { + benchmark::Args args; + args.asymptote = parseAsymptote(argsman.GetArg("-asymptote", "")); + args.is_list_only = argsman.GetBoolArg("-list", false); + args.min_time = std::chrono::milliseconds(argsman.GetIntArg("-min-time", DEFAULT_MIN_TIME_MS)); + args.output_csv = argsman.GetPathArg("-output-csv"); + args.output_json = argsman.GetPathArg("-output-json"); + args.regex_filter = argsman.GetArg("-filter", DEFAULT_BENCH_FILTER); + args.sanity_check = argsman.GetBoolArg("-sanity-check", false); + args.priority = parsePriorityLevel(argsman.GetArg("-priority-level", DEFAULT_PRIORITY)); - benchmark::BenchRunner::RunAll(args); + benchmark::BenchRunner::RunAll(args); - return EXIT_SUCCESS; + return EXIT_SUCCESS; + } catch (const std::exception& e) { + tfm::format(std::cerr, "Error: %s\n", e.what()); + return EXIT_FAILURE; + } } diff --git a/src/bench/bls.cpp b/src/bench/bls.cpp index ffcd0ab6043c8..9199f1f333600 100644 --- a/src/bench/bls.cpp +++ b/src/bench/bls.cpp @@ -7,6 +7,7 @@ #include #include +#include #include static void BuildTestVectors(size_t count, size_t invalidCount, @@ -48,7 +49,7 @@ static void BLS_PubKeyAggregate_Normal(benchmark::Bench& bench) CBLSPublicKey pubKey2 = secKey2.GetPublicKey(); // Benchmark. - bench.minEpochIterations(100).run([&] { + bench.minEpochIterations(bench.output() ? 100 : 1).run([&] { pubKey1.AggregateInsecure(pubKey2); }); } @@ -125,10 +126,10 @@ static void BLS_Verify_LargeBlock(size_t txCount, benchmark::Bench& bench, uint3 std::vector sigs; std::vector msgHashes; std::vector invalid; - BuildTestVectors(txCount, 0, pubKeys, secKeys, sigs, msgHashes, invalid); + BuildTestVectors(bench.output() ? txCount : 1, 0, pubKeys, secKeys, sigs, msgHashes, invalid); // Benchmark. - bench.minEpochIterations(epoch_iters).run([&] { + bench.minEpochIterations(bench.output() ? epoch_iters : 1).run([&] { for (size_t i = 0; i < pubKeys.size(); i++) { bool ok = sigs[i].VerifyInsecure(pubKeys[i], msgHashes[i]); assert(ok); @@ -153,10 +154,10 @@ static void BLS_Verify_LargeBlockSelfAggregated(size_t txCount, benchmark::Bench std::vector sigs; std::vector msgHashes; std::vector invalid; - BuildTestVectors(txCount, 0, pubKeys, secKeys, sigs, msgHashes, invalid); + BuildTestVectors(bench.output() ? txCount : 1, 0, pubKeys, secKeys, sigs, msgHashes, invalid); // Benchmark. - bench.minEpochIterations(epoch_iters).run([&] { + bench.minEpochIterations(bench.output() ? epoch_iters : 1).run([&] { CBLSSignature aggSig = CBLSSignature::AggregateInsecure(sigs); bool ok = aggSig.VerifyInsecureAggregated(pubKeys, msgHashes); assert(ok); @@ -180,12 +181,12 @@ static void BLS_Verify_LargeAggregatedBlock(size_t txCount, benchmark::Bench& be std::vector sigs; std::vector msgHashes; std::vector invalid; - BuildTestVectors(txCount, 0, pubKeys, secKeys, sigs, msgHashes, invalid); + BuildTestVectors(bench.output() ? txCount : 1, 0, pubKeys, secKeys, sigs, msgHashes, invalid); CBLSSignature aggSig = CBLSSignature::AggregateInsecure(sigs); // Benchmark. - bench.minEpochIterations(epoch_iters).run([&] { + bench.minEpochIterations(bench.output() ? epoch_iters : 1).run([&] { bool ok = aggSig.VerifyInsecureAggregated(pubKeys, msgHashes); assert(ok); }); @@ -223,7 +224,7 @@ static void BLS_Verify_LargeAggregatedBlock1000PreVerified(benchmark::Bench& ben } // Benchmark. - bench.minEpochIterations(10).run([&] { + bench.minEpochIterations(bench.output() ? 10 : 1).run([&] { std::vector nonvalidatedPubKeys; std::vector nonvalidatedHashes; nonvalidatedPubKeys.reserve(pubKeys.size()); @@ -254,13 +255,13 @@ static void BLS_Verify_Batched(benchmark::Bench& bench) std::vector sigs; std::vector msgHashes; std::vector invalid; - BuildTestVectors(1000, 10, pubKeys, secKeys, sigs, msgHashes, invalid); + BuildTestVectors(bench.output() ? 1000 : 1, 10, pubKeys, secKeys, sigs, msgHashes, invalid); // Benchmark. size_t i = 0; size_t j = 0; size_t batchSize = 16; - bench.minEpochIterations(1000).run([&] { + bench.minEpochIterations(bench.output() ? 1000 : 1).run([&] { j++; if ((j % batchSize) != 0) { return; @@ -310,20 +311,20 @@ static void BLS_Verify_BatchedParallel(benchmark::Bench& bench) std::vector sigs; std::vector msgHashes; std::vector invalid; - BuildTestVectors(1000, 10, pubKeys, secKeys, sigs, msgHashes, invalid); + BuildTestVectors(bench.output() ? 1000 : 1, 10, pubKeys, secKeys, sigs, msgHashes, invalid); std::list>> futures; - volatile bool cancel = false; - auto cancelCond = [&]() { - return cancel; + std::atomic cancel{false}; + auto cancelCond = [&]() -> bool { + return cancel.load(); }; CBLSWorker blsWorker; blsWorker.Start(); // Benchmark. - bench.minEpochIterations(1000).run([&] { + bench.minEpochIterations(bench.output() ? 1000 : 1).run([&] { if (futures.size() < 100) { while (futures.size() < 10000) { size_t i = 0; @@ -348,7 +349,7 @@ static void BLS_Verify_BatchedParallel(benchmark::Bench& bench) } }); - cancel = true; + cancel.store(true); while (blsWorker.IsAsyncVerifyInProgress()) { UninterruptibleSleep(std::chrono::milliseconds{100}); diff --git a/src/bench/bls_dkg.cpp b/src/bench/bls_dkg.cpp index 079d2770ae8a1..14e83810a1003 100644 --- a/src/bench/bls_dkg.cpp +++ b/src/bench/bls_dkg.cpp @@ -113,6 +113,10 @@ static void BLSDKG_GenerateContributions(benchmark::Bench& bench, uint32_t epoch blsWorker.Start(); std::vector ids; std::vector members; + if (!bench.output()) { + epoch_iters = 1; + quorumSize = 1; + } for (const int i : irange::range(quorumSize)) { uint256 id; WriteLE64(id.begin(), i + 1); @@ -136,6 +140,10 @@ static void BLSDKG_GenerateContributions(benchmark::Bench& bench, uint32_t epoch static void BLSDKG_InitDKG(benchmark::Bench& bench, uint32_t epoch_iters, int quorumSize) { + if (!bench.output()) { + epoch_iters = 1; + quorumSize = 1; + } bench.minEpochIterations(epoch_iters).run([&] { DKG d(quorumSize); }); @@ -151,6 +159,12 @@ static void BLSDKG_InitDKG(benchmark::Bench& bench, uint32_t epoch_iters, int qu #define BENCH_BuildQuorumVerificationVectors(name, quorumSize, epoch_iters) \ static void BLSDKG_BuildQuorumVerificationVectors_##name##_##quorumSize(benchmark::Bench& bench) \ { \ + if (!bench.output()) { \ + std::unique_ptr ptr = std::make_unique(1); \ + ptr->Bench_BuildQuorumVerificationVectors(bench, 1); \ + ptr.reset(); \ + return; \ + } \ std::unique_ptr ptr = std::make_unique(quorumSize); \ ptr->Bench_BuildQuorumVerificationVectors(bench, epoch_iters); \ ptr.reset(); \ @@ -160,9 +174,15 @@ static void BLSDKG_InitDKG(benchmark::Bench& bench, uint32_t epoch_iters, int qu #define BENCH_VerifyContributionShares(name, quorumSize, invalidCount, aggregated, epoch_iters) \ static void BLSDKG_VerifyContributionShares_##name##_##quorumSize(benchmark::Bench& bench) \ { \ - std::unique_ptr ptr = std::make_unique(quorumSize); \ - ptr->Bench_VerifyContributionShares(bench, invalidCount, aggregated, epoch_iters); \ - ptr.reset(); \ + if (!bench.output()) { \ + std::unique_ptr ptr = std::make_unique(1); \ + ptr->Bench_VerifyContributionShares(bench, invalidCount, aggregated, 1); \ + ptr.reset(); \ + return; \ + } \ + std::unique_ptr ptr = std::make_unique(quorumSize); \ + ptr->Bench_VerifyContributionShares(bench, invalidCount, aggregated, epoch_iters); \ + ptr.reset(); \ } \ BENCHMARK(BLSDKG_VerifyContributionShares_##name##_##quorumSize) diff --git a/src/bench/checkblock.cpp b/src/bench/checkblock.cpp index 3dbb29ebe56c5..b4ff0ee3373f3 100644 --- a/src/bench/checkblock.cpp +++ b/src/bench/checkblock.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -36,6 +37,9 @@ static void DeserializeAndCheckBlockTest(benchmark::Bench& bench) ArgsManager bench_args; const auto chainParams = CreateChainParams(bench_args, CBaseChainParams::MAIN); + // CheckBlock calls g_stats_client internally, we aren't using a testing setup + // so we need to do this manually. + ::g_stats_client = InitStatsClient(bench_args); bench.unit("block").run([&] { CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here diff --git a/src/bench/crypto_hash.cpp b/src/bench/crypto_hash.cpp index ab4ea68819c3a..d184bdc8bf8b9 100644 --- a/src/bench/crypto_hash.cpp +++ b/src/bench/crypto_hash.cpp @@ -15,201 +15,181 @@ #include #include #include +#include #include /* Number of bytes to hash per iteration */ static const uint64_t BUFFER_SIZE = 1000*1000; -/* Hash BUFFER_SIZE bytes via different algos */ - -static void HASH_1MB_RIPEMD160(benchmark::Bench& bench) +static void BenchRIPEMD160(benchmark::Bench& bench) { uint8_t hash[CRIPEMD160::OUTPUT_SIZE]; std::vector in(BUFFER_SIZE,0); - bench.batch(in.size()).unit("byte").minEpochIterations(10).run([&] { + bench.batch(in.size()).unit("byte").run([&] { CRIPEMD160().Write(in.data(), in.size()).Finalize(hash); }); } -static void HASH_1MB_SHA1(benchmark::Bench& bench) +static void SHA1(benchmark::Bench& bench) { uint8_t hash[CSHA1::OUTPUT_SIZE]; std::vector in(BUFFER_SIZE,0); - bench.batch(in.size()).unit("byte").minEpochIterations(10).run([&] { + bench.batch(in.size()).unit("byte").run([&] { CSHA1().Write(in.data(), in.size()).Finalize(hash); }); } -static void HASH_1MB_SHA256(benchmark::Bench& bench) +static void SHA256_STANDARD(benchmark::Bench& bench) { + bench.name(strprintf("%s using the '%s' SHA256 implementation", __func__, SHA256AutoDetect(sha256_implementation::STANDARD))); uint8_t hash[CSHA256::OUTPUT_SIZE]; std::vector in(BUFFER_SIZE,0); - bench.batch(in.size()).unit("byte").minEpochIterations(10).run([&] { + bench.batch(in.size()).unit("byte").run([&] { CSHA256().Write(in.data(), in.size()).Finalize(hash); }); + SHA256AutoDetect(); } -static void HASH_1MB_DSHA256(benchmark::Bench& bench) +static void SHA256_SSE4(benchmark::Bench& bench) { + bench.name(strprintf("%s using the '%s' SHA256 implementation", __func__, SHA256AutoDetect(sha256_implementation::USE_SSE4))); uint8_t hash[CSHA256::OUTPUT_SIZE]; std::vector in(BUFFER_SIZE,0); - bench.batch(in.size()).unit("byte").minEpochIterations(10).run([&] { - CHash256().Write(in).Finalize(hash); + bench.batch(in.size()).unit("byte").run([&] { + CSHA256().Write(in.data(), in.size()).Finalize(hash); }); + SHA256AutoDetect(); } -static void HASH_1MB_SHA512(benchmark::Bench& bench) +static void SHA256_AVX2(benchmark::Bench& bench) { - uint8_t hash[CSHA512::OUTPUT_SIZE]; + bench.name(strprintf("%s using the '%s' SHA256 implementation", __func__, SHA256AutoDetect(sha256_implementation::USE_SSE4_AND_AVX2))); + uint8_t hash[CSHA256::OUTPUT_SIZE]; std::vector in(BUFFER_SIZE,0); - bench.batch(in.size()).unit("byte").minEpochIterations(10).run([&] { - CSHA512().Write(in.data(), in.size()).Finalize(hash); + bench.batch(in.size()).unit("byte").run([&] { + CSHA256().Write(in.data(), in.size()).Finalize(hash); }); + SHA256AutoDetect(); } -static void HASH_1MB_SHA3_256(benchmark::Bench& bench) +static void SHA256_SHANI(benchmark::Bench& bench) { - uint8_t hash[SHA3_256::OUTPUT_SIZE]; + bench.name(strprintf("%s using the '%s' SHA256 implementation", __func__, SHA256AutoDetect(sha256_implementation::USE_SSE4_AND_SHANI))); + uint8_t hash[CSHA256::OUTPUT_SIZE]; std::vector in(BUFFER_SIZE,0); - bench.batch(in.size()).unit("byte").minEpochIterations(10).run([&] { - SHA3_256().Write(in).Finalize(hash); + bench.batch(in.size()).unit("byte").run([&] { + CSHA256().Write(in.data(), in.size()).Finalize(hash); }); + SHA256AutoDetect(); } -static void HASH_1MB_X11(benchmark::Bench& bench) +static void SHA3_256_1M(benchmark::Bench& bench) { - uint256 hash; + uint8_t hash[SHA3_256::OUTPUT_SIZE]; std::vector in(BUFFER_SIZE,0); - bench.batch(in.size()).unit("byte").minEpochIterations(10).run([&] { - hash = HashX11(in.begin(), in.end()); + bench.batch(in.size()).unit("byte").run([&] { + SHA3_256().Write(in).Finalize(hash); }); } -/* Hash different number of bytes via DSHA256 */ - -static void HASH_DSHA256_0032b_single(benchmark::Bench& bench) +static void SHA256_32b_STANDARD(benchmark::Bench& bench) { - uint8_t hash[CSHA256::OUTPUT_SIZE]; + bench.name(strprintf("%s using the '%s' SHA256 implementation", __func__, SHA256AutoDetect(sha256_implementation::STANDARD))); std::vector in(32,0); - bench.minEpochIterations(100000).run([&] { - CHash256().Write(in).Finalize(hash); - }); -} - -static void HASH_DSHA256_0080b_single(benchmark::Bench& bench) -{ - uint8_t hash[CSHA256::OUTPUT_SIZE]; - std::vector in(80,0); - bench.minEpochIterations(100000).run([&] { - CHash256().Write(in).Finalize(hash); - }); -} - -static void HASH_DSHA256_0128b_single(benchmark::Bench& bench) -{ - uint8_t hash[CSHA256::OUTPUT_SIZE]; - std::vector in(128,0); - bench.minEpochIterations(100000).run([&] { - CHash256().Write(in).Finalize(hash); - }); -} - -static void HASH_DSHA256_0512b_single(benchmark::Bench& bench) -{ - uint8_t hash[CSHA256::OUTPUT_SIZE]; - std::vector in(512,0); - bench.minEpochIterations(100000).run([&] { - CHash256().Write(in).Finalize(hash); - }); -} - -static void HASH_DSHA256_1024b_single(benchmark::Bench& bench) -{ - uint8_t hash[CSHA256::OUTPUT_SIZE]; - std::vector in(1024,0); - bench.minEpochIterations(100000).run([&] { - CHash256().Write(in).Finalize(hash); + bench.batch(in.size()).unit("byte").run([&] { + CSHA256() + .Write(in.data(), in.size()) + .Finalize(in.data()); }); + SHA256AutoDetect(); } -static void HASH_DSHA256_2048b_single(benchmark::Bench& bench) +static void SHA256_32b_SSE4(benchmark::Bench& bench) { - uint8_t hash[CSHA256::OUTPUT_SIZE]; - std::vector in(2048,0); - bench.minEpochIterations(100000).run([&] { - CHash256().Write(in).Finalize(hash); + bench.name(strprintf("%s using the '%s' SHA256 implementation", __func__, SHA256AutoDetect(sha256_implementation::USE_SSE4))); + std::vector in(32,0); + bench.batch(in.size()).unit("byte").run([&] { + CSHA256() + .Write(in.data(), in.size()) + .Finalize(in.data()); }); + SHA256AutoDetect(); } -/* Hash different number of bytes via X11 */ - -static void HASH_X11_0032b_single(benchmark::Bench& bench) +static void SHA256_32b_AVX2(benchmark::Bench& bench) { - uint256 hash; + bench.name(strprintf("%s using the '%s' SHA256 implementation", __func__, SHA256AutoDetect(sha256_implementation::USE_SSE4_AND_AVX2))); std::vector in(32,0); - bench.minEpochIterations(10000).run([&] { - hash = HashX11(in.begin(), in.end()); + bench.batch(in.size()).unit("byte").run([&] { + CSHA256() + .Write(in.data(), in.size()) + .Finalize(in.data()); }); + SHA256AutoDetect(); } -static void HASH_X11_0080b_single(benchmark::Bench& bench) +static void SHA256_32b_SHANI(benchmark::Bench& bench) { - uint256 hash; - std::vector in(80,0); - bench.minEpochIterations(10000).run([&] { - hash = HashX11(in.begin(), in.end()); + bench.name(strprintf("%s using the '%s' SHA256 implementation", __func__, SHA256AutoDetect(sha256_implementation::USE_SSE4_AND_SHANI))); + std::vector in(32,0); + bench.batch(in.size()).unit("byte").run([&] { + CSHA256() + .Write(in.data(), in.size()) + .Finalize(in.data()); }); + SHA256AutoDetect(); } -static void HASH_X11_0128b_single(benchmark::Bench& bench) +static void SHA256D64_1024_STANDARD(benchmark::Bench& bench) { - uint256 hash; - std::vector in(128,0); - bench.minEpochIterations(10000).run([&] { - hash = HashX11(in.begin(), in.end()); + bench.name(strprintf("%s using the '%s' SHA256 implementation", __func__, SHA256AutoDetect(sha256_implementation::STANDARD))); + std::vector in(64 * 1024, 0); + bench.batch(in.size()).unit("byte").run([&] { + SHA256D64(in.data(), in.data(), 1024); }); + SHA256AutoDetect(); } -static void HASH_X11_0512b_single(benchmark::Bench& bench) +static void SHA256D64_1024_SSE4(benchmark::Bench& bench) { - uint256 hash; - std::vector in(512,0); - bench.minEpochIterations(10000).run([&] { - hash = HashX11(in.begin(), in.end()); + bench.name(strprintf("%s using the '%s' SHA256 implementation", __func__, SHA256AutoDetect(sha256_implementation::USE_SSE4))); + std::vector in(64 * 1024, 0); + bench.batch(in.size()).unit("byte").run([&] { + SHA256D64(in.data(), in.data(), 1024); }); + SHA256AutoDetect(); } -static void HASH_X11_1024b_single(benchmark::Bench& bench) +static void SHA256D64_1024_AVX2(benchmark::Bench& bench) { - uint256 hash; - std::vector in(1024,0); - bench.minEpochIterations(10000).run([&] { - hash = HashX11(in.begin(), in.end()); + bench.name(strprintf("%s using the '%s' SHA256 implementation", __func__, SHA256AutoDetect(sha256_implementation::USE_SSE4_AND_AVX2))); + std::vector in(64 * 1024, 0); + bench.batch(in.size()).unit("byte").run([&] { + SHA256D64(in.data(), in.data(), 1024); }); + SHA256AutoDetect(); } -static void HASH_X11_2048b_single(benchmark::Bench& bench) +static void SHA256D64_1024_SHANI(benchmark::Bench& bench) { - uint256 hash; - std::vector in(2048,0); - bench.minEpochIterations(10000).run([&] { - hash = HashX11(in.begin(), in.end()); + bench.name(strprintf("%s using the '%s' SHA256 implementation", __func__, SHA256AutoDetect(sha256_implementation::USE_SSE4_AND_SHANI))); + std::vector in(64 * 1024, 0); + bench.batch(in.size()).unit("byte").run([&] { + SHA256D64(in.data(), in.data(), 1024); }); + SHA256AutoDetect(); } -/* Hash 32 bytes via SHA and SipHash */ - -static void HASH_SHA256_32b(benchmark::Bench& bench) +static void SHA512(benchmark::Bench& bench) { - std::vector in(32,0); - bench.run([&] { - CSHA256() - .Write(in.data(), in.size()) - .Finalize(in.data()); + uint8_t hash[CSHA512::OUTPUT_SIZE]; + std::vector in(BUFFER_SIZE,0); + bench.batch(in.size()).unit("byte").run([&] { + CSHA512().Write(in.data(), in.size()).Finalize(hash); }); } -static void HASH_SipHash_32b(benchmark::Bench& bench) +static void SipHash_32b(benchmark::Bench& bench) { uint256 x; uint64_t k1 = 0; @@ -218,18 +198,6 @@ static void HASH_SipHash_32b(benchmark::Bench& bench) }); } -/* Hash 1024 blobs 64 bytes each via DSHA256 */ - -static void HASH_SHA256D64_1024(benchmark::Bench& bench) -{ - std::vector in(64 * 1024, 0); - bench.minEpochIterations(1000).run([&] { - SHA256D64(in.data(), in.data(), 1024); - }); -} - -/* FastRandom for uint32_t and bool */ - static void FastRandom_32bit(benchmark::Bench& bench) { FastRandomContext rng(true); @@ -290,32 +258,24 @@ static void MuHashPrecompute(benchmark::Bench& bench) }); } -BENCHMARK(HASH_1MB_DSHA256); -BENCHMARK(HASH_1MB_RIPEMD160); -BENCHMARK(HASH_1MB_SHA1); -BENCHMARK(HASH_1MB_SHA256); -BENCHMARK(HASH_1MB_SHA512); -BENCHMARK(HASH_1MB_SHA3_256); -BENCHMARK(HASH_1MB_X11); - -BENCHMARK(HASH_DSHA256_0032b_single); -BENCHMARK(HASH_DSHA256_0080b_single); -BENCHMARK(HASH_DSHA256_0128b_single); -BENCHMARK(HASH_DSHA256_0512b_single); -BENCHMARK(HASH_DSHA256_1024b_single); -BENCHMARK(HASH_DSHA256_2048b_single); -BENCHMARK(HASH_X11_0032b_single); -BENCHMARK(HASH_X11_0080b_single); -BENCHMARK(HASH_X11_0128b_single); -BENCHMARK(HASH_X11_0512b_single); -BENCHMARK(HASH_X11_1024b_single); -BENCHMARK(HASH_X11_2048b_single); - -BENCHMARK(HASH_SHA256_32b); -BENCHMARK(HASH_SipHash_32b); - -BENCHMARK(HASH_SHA256D64_1024); - +BENCHMARK(BenchRIPEMD160); +BENCHMARK(SHA1); +BENCHMARK(SHA256_STANDARD); +BENCHMARK(SHA256_SSE4); +BENCHMARK(SHA256_AVX2); +BENCHMARK(SHA256_SHANI); +BENCHMARK(SHA512); +BENCHMARK(SHA3_256_1M); + +BENCHMARK(SHA256_32b_STANDARD); +BENCHMARK(SHA256_32b_SSE4); +BENCHMARK(SHA256_32b_AVX2); +BENCHMARK(SHA256_32b_SHANI); +BENCHMARK(SipHash_32b); +BENCHMARK(SHA256D64_1024_STANDARD); +BENCHMARK(SHA256D64_1024_SSE4); +BENCHMARK(SHA256D64_1024_AVX2); +BENCHMARK(SHA256D64_1024_SHANI); BENCHMARK(FastRandom_32bit); BENCHMARK(FastRandom_1bit); @@ -323,3 +283,150 @@ BENCHMARK(MuHash); BENCHMARK(MuHashMul); BENCHMARK(MuHashDiv); BENCHMARK(MuHashPrecompute); + +/* --------------------------- Dash-specific tests start here --------------------------- */ + +static void DSHA256_1M(benchmark::Bench& bench) +{ + uint8_t hash[CSHA256::OUTPUT_SIZE]; + std::vector in(BUFFER_SIZE,0); + bench.batch(in.size()).unit("byte").run([&] { + CHash256().Write(in).Finalize(hash); + }); +} + +static void X11_1M(benchmark::Bench& bench) +{ + uint256 hash; + std::vector in(BUFFER_SIZE,0); + bench.batch(in.size()).unit("byte").run([&] { + hash = HashX11(in.begin(), in.end()); + }); +} + +/* Hash different number of bytes via DSHA256 */ +static void DSHA256_0032b_single(benchmark::Bench& bench) +{ + uint8_t hash[CSHA256::OUTPUT_SIZE]; + std::vector in(32,0); + bench.batch(in.size()).unit("byte").run([&] { + CHash256().Write(in).Finalize(hash); + }); +} + +static void DSHA256_0080b_single(benchmark::Bench& bench) +{ + uint8_t hash[CSHA256::OUTPUT_SIZE]; + std::vector in(80,0); + bench.batch(in.size()).unit("byte").run([&] { + CHash256().Write(in).Finalize(hash); + }); +} + +static void DSHA256_0128b_single(benchmark::Bench& bench) +{ + uint8_t hash[CSHA256::OUTPUT_SIZE]; + std::vector in(128,0); + bench.batch(in.size()).unit("byte").run([&] { + CHash256().Write(in).Finalize(hash); + }); +} + +static void DSHA256_0512b_single(benchmark::Bench& bench) +{ + uint8_t hash[CSHA256::OUTPUT_SIZE]; + std::vector in(512,0); + bench.batch(in.size()).unit("byte").run([&] { + CHash256().Write(in).Finalize(hash); + }); +} + +static void DSHA256_1024b_single(benchmark::Bench& bench) +{ + uint8_t hash[CSHA256::OUTPUT_SIZE]; + std::vector in(1024,0); + bench.batch(in.size()).unit("byte").run([&] { + CHash256().Write(in).Finalize(hash); + }); +} + +static void DSHA256_2048b_single(benchmark::Bench& bench) +{ + uint8_t hash[CSHA256::OUTPUT_SIZE]; + std::vector in(2048,0); + bench.batch(in.size()).unit("byte").run([&] { + CHash256().Write(in).Finalize(hash); + }); +} + +/* Hash different number of bytes via X11 */ +static void X11_0032b_single(benchmark::Bench& bench) +{ + uint256 hash; + std::vector in(32,0); + bench.batch(in.size()).unit("byte").run([&] { + hash = HashX11(in.begin(), in.end()); + }); +} + +static void X11_0080b_single(benchmark::Bench& bench) +{ + uint256 hash; + std::vector in(80,0); + bench.batch(in.size()).unit("byte").run([&] { + hash = HashX11(in.begin(), in.end()); + }); +} + +static void X11_0128b_single(benchmark::Bench& bench) +{ + uint256 hash; + std::vector in(128,0); + bench.batch(in.size()).unit("byte").run([&] { + hash = HashX11(in.begin(), in.end()); + }); +} + +static void X11_0512b_single(benchmark::Bench& bench) +{ + uint256 hash; + std::vector in(512,0); + bench.batch(in.size()).unit("byte").run([&] { + hash = HashX11(in.begin(), in.end()); + }); +} + +static void X11_1024b_single(benchmark::Bench& bench) +{ + uint256 hash; + std::vector in(1024,0); + bench.batch(in.size()).unit("byte").run([&] { + hash = HashX11(in.begin(), in.end()); + }); +} + +static void X11_2048b_single(benchmark::Bench& bench) +{ + uint256 hash; + std::vector in(2048,0); + bench.batch(in.size()).unit("byte").run([&] { + hash = HashX11(in.begin(), in.end()); + }); +} + +BENCHMARK(DSHA256_1M); +BENCHMARK(X11_1M); + +BENCHMARK(DSHA256_0032b_single); +BENCHMARK(DSHA256_0080b_single); +BENCHMARK(DSHA256_0128b_single); +BENCHMARK(DSHA256_0512b_single); +BENCHMARK(DSHA256_1024b_single); +BENCHMARK(DSHA256_2048b_single); + +BENCHMARK(X11_0032b_single); +BENCHMARK(X11_0080b_single); +BENCHMARK(X11_0128b_single); +BENCHMARK(X11_0512b_single); +BENCHMARK(X11_1024b_single); +BENCHMARK(X11_2048b_single); diff --git a/src/bench/ecdsa.cpp b/src/bench/ecdsa.cpp index e71fc4a3ee337..0b63d4621ebca 100644 --- a/src/bench/ecdsa.cpp +++ b/src/bench/ecdsa.cpp @@ -8,6 +8,8 @@ static void ECDSASign(benchmark::Bench& bench) { + ECC_Start(); + std::vector keys; std::vector hashes; for (size_t i = 0; i < 100; i++) { @@ -24,10 +26,14 @@ static void ECDSASign(benchmark::Bench& bench) keys[i].Sign(hashes[i], sig); i = (i + 1) % keys.size(); }); + + ECC_Stop(); } static void ECDSAVerify(benchmark::Bench& bench) { + ECC_Start(); + std::vector keys; std::vector hashes; std::vector> sigs; @@ -47,10 +53,14 @@ static void ECDSAVerify(benchmark::Bench& bench) keys[i].Verify(hashes[i], sigs[i]); i = (i + 1) % keys.size(); }); + + ECC_Stop(); } static void ECDSAVerify_LargeBlock(benchmark::Bench& bench) { + ECC_Start(); + std::vector keys; std::vector hashes; std::vector> sigs; @@ -70,6 +80,8 @@ static void ECDSAVerify_LargeBlock(benchmark::Bench& bench) keys[i].Verify(hashes[i], sigs[i]); } }); + + ECC_Stop(); } BENCHMARK(ECDSASign) diff --git a/src/crypto/sha256.cpp b/src/crypto/sha256.cpp index 196f81ea16e09..884719a1b097f 100644 --- a/src/crypto/sha256.cpp +++ b/src/crypto/sha256.cpp @@ -8,26 +8,25 @@ #include #include +#if !defined(DISABLE_OPTIMIZED_SHA256) #include -#if defined(__linux__) && defined(ENABLE_ARM_SHANI) && !defined(BUILD_BITCOIN_INTERNAL) +#if defined(__linux__) && defined(ENABLE_ARM_SHANI) #include #include #endif -#if defined(MAC_OSX) && defined(ENABLE_ARM_SHANI) && !defined(BUILD_BITCOIN_INTERNAL) +#if defined(__APPLE__) && defined(ENABLE_ARM_SHANI) #include #include #endif #if defined(__x86_64__) || defined(__amd64__) || defined(__i386__) -#if defined(USE_ASM) namespace sha256_sse4 { void Transform(uint32_t* s, const unsigned char* chunk, size_t blocks); } #endif -#endif namespace sha256d64_sse41 { @@ -58,6 +57,7 @@ namespace sha256d64_arm_shani { void Transform_2way(unsigned char* out, const unsigned char* in); } +#endif // DISABLE_OPTIMIZED_SHA256 // Internal implementation code. namespace @@ -567,7 +567,8 @@ bool SelfTest() { return true; } -#if defined(USE_ASM) && (defined(__x86_64__) || defined(__amd64__) || defined(__i386__)) +#if !defined(DISABLE_OPTIMIZED_SHA256) +#if (defined(__x86_64__) || defined(__amd64__) || defined(__i386__)) /** Check whether the OS has enabled AVX registers. */ bool AVXEnabled() { @@ -576,13 +577,21 @@ bool AVXEnabled() return (a & 6) == 6; } #endif +#endif // DISABLE_OPTIMIZED_SHA256 } // namespace -std::string SHA256AutoDetect() +std::string SHA256AutoDetect(sha256_implementation::UseImplementation use_implementation) { std::string ret = "standard"; -#if defined(USE_ASM) && defined(HAVE_GETCPUID) + Transform = sha256::Transform; + TransformD64 = sha256::TransformD64; + TransformD64_2way = nullptr; + TransformD64_4way = nullptr; + TransformD64_8way = nullptr; + +#if !defined(DISABLE_OPTIMIZED_SHA256) +#if defined(HAVE_GETCPUID) bool have_sse4 = false; bool have_xsave = false; bool have_avx = false; @@ -592,7 +601,9 @@ std::string SHA256AutoDetect() uint32_t eax, ebx, ecx, edx; GetCPUID(1, 0, eax, ebx, ecx, edx); - have_sse4 = (ecx >> 19) & 1; + if (use_implementation & sha256_implementation::USE_SSE4) { + have_sse4 = (ecx >> 19) & 1; + } have_xsave = (ecx >> 27) & 1; have_avx = (ecx >> 28) & 1; if (have_xsave && have_avx) { @@ -600,11 +611,15 @@ std::string SHA256AutoDetect() } if (have_sse4) { GetCPUID(7, 0, eax, ebx, ecx, edx); - have_avx2 = (ebx >> 5) & 1; - have_x86_shani = (ebx >> 29) & 1; + if (use_implementation & sha256_implementation::USE_AVX2) { + have_avx2 = (ebx >> 5) & 1; + } + if (use_implementation & sha256_implementation::USE_SHANI) { + have_x86_shani = (ebx >> 29) & 1; + } } -#if defined(ENABLE_X86_SHANI) && !defined(BUILD_BITCOIN_INTERNAL) +#if defined(ENABLE_SSE41) && defined(ENABLE_X86_SHANI) if (have_x86_shani) { Transform = sha256_x86_shani::Transform; TransformD64 = TransformD64Wrapper; @@ -621,43 +636,44 @@ std::string SHA256AutoDetect() TransformD64 = TransformD64Wrapper; ret = "sse4(1way)"; #endif -#if defined(ENABLE_SSE41) && !defined(BUILD_BITCOIN_INTERNAL) +#if defined(ENABLE_SSE41) TransformD64_4way = sha256d64_sse41::Transform_4way; ret += ",sse41(4way)"; #endif } -#if defined(ENABLE_AVX2) && !defined(BUILD_BITCOIN_INTERNAL) +#if defined(ENABLE_AVX2) if (have_avx2 && have_avx && enabled_avx) { TransformD64_8way = sha256d64_avx2::Transform_8way; ret += ",avx2(8way)"; } #endif -#endif // defined(USE_ASM) && defined(HAVE_GETCPUID) +#endif // defined(HAVE_GETCPUID) -#if defined(ENABLE_ARM_SHANI) && !defined(BUILD_BITCOIN_INTERNAL) +#if defined(ENABLE_ARM_SHANI) bool have_arm_shani = false; - + if (use_implementation & sha256_implementation::USE_SHANI) { #if defined(__linux__) #if defined(__arm__) // 32-bit - if (getauxval(AT_HWCAP2) & HWCAP2_SHA2) { - have_arm_shani = true; - } + if (getauxval(AT_HWCAP2) & HWCAP2_SHA2) { + have_arm_shani = true; + } #endif #if defined(__aarch64__) // 64-bit - if (getauxval(AT_HWCAP) & HWCAP_SHA2) { - have_arm_shani = true; - } + if (getauxval(AT_HWCAP) & HWCAP_SHA2) { + have_arm_shani = true; + } #endif #endif -#if defined(MAC_OSX) - int val = 0; - size_t len = sizeof(val); - if (sysctlbyname("hw.optional.arm.FEAT_SHA256", &val, &len, nullptr, 0) == 0) { - have_arm_shani = val != 0; - } +#if defined(__APPLE__) + int val = 0; + size_t len = sizeof(val); + if (sysctlbyname("hw.optional.arm.FEAT_SHA256", &val, &len, nullptr, 0) == 0) { + have_arm_shani = val != 0; + } #endif + } if (have_arm_shani) { Transform = sha256_arm_shani::Transform; @@ -666,6 +682,7 @@ std::string SHA256AutoDetect() ret = "arm_shani(1way,2way)"; } #endif +#endif // DISABLE_OPTIMIZED_SHA256 assert(SelfTest()); return ret; diff --git a/src/crypto/sha256.h b/src/crypto/sha256.h index 335b1236877f5..60b2237a74307 100644 --- a/src/crypto/sha256.h +++ b/src/crypto/sha256.h @@ -26,10 +26,22 @@ class CSHA256 CSHA256& Reset(); }; +namespace sha256_implementation { +enum UseImplementation : uint8_t { + STANDARD = 0, + USE_SSE4 = 1 << 0, + USE_AVX2 = 1 << 1, + USE_SHANI = 1 << 2, + USE_SSE4_AND_AVX2 = USE_SSE4 | USE_AVX2, + USE_SSE4_AND_SHANI = USE_SSE4 | USE_SHANI, + USE_ALL = USE_SSE4 | USE_AVX2 | USE_SHANI, +}; +} + /** Autodetect the best available SHA256 implementation. * Returns the name of the implementation. */ -std::string SHA256AutoDetect(); +std::string SHA256AutoDetect(sha256_implementation::UseImplementation use_implementation = sha256_implementation::USE_ALL); /** Compute multiple double-SHA256's of 64-byte blobs. * output: pointer to a blocks*32 byte output buffer diff --git a/src/crypto/sha256_x86_shani.cpp b/src/crypto/sha256_x86_shani.cpp index 398cf647f5a30..00c3e426d0444 100644 --- a/src/crypto/sha256_x86_shani.cpp +++ b/src/crypto/sha256_x86_shani.cpp @@ -6,7 +6,7 @@ // Written and placed in public domain by Jeffrey Walton. // Based on code from Intel, and by Sean Gulley for the miTLS project. -#ifdef ENABLE_X86_SHANI +#if defined(ENABLE_SSE41) && defined(ENABLE_X86_SHANI) #include #include diff --git a/src/rpc/misc.cpp b/src/rpc/node.cpp similarity index 81% rename from src/rpc/misc.cpp rename to src/rpc/node.cpp index 46cf2cb44e7a4..10d76dc99efb1 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/node.cpp @@ -25,11 +25,9 @@ #include #include #include -#include