diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7186d049c..9bbfbf910 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -170,7 +170,7 @@ jobs: run-bench: true run-tests: true dep-opts: "AVX2=1" - config-opts: "--with-intel-avx2 --enable-gui=qt5 --enable-zmq --enable-glibc-back-compat --enable-reduce-exports" + config-opts: "--enable-scrypt-sse2 --with-intel-avx2 --enable-gui=qt5 --enable-zmq --enable-glibc-back-compat --enable-reduce-exports" goal: install runs-on: ${{ matrix.os }} diff --git a/configure.ac b/configure.ac index ad26d3050..49bd59745 100644 --- a/configure.ac +++ b/configure.ac @@ -177,6 +177,12 @@ AC_ARG_ENABLE([zmq], [use_zmq=$enableval], [use_zmq=yes]) +AC_ARG_ENABLE([scrypt-sse2], + [AS_HELP_STRING([--enable-scrypt-sse2], + [Build with scrypt sse2 implementation (default is no)])], + [use_scrypt_sse2=$enableval], + [use_scrypt_sse2=no]) + AC_ARG_WITH([intel-avx2], [AS_HELP_STRING([--with-intel-avx2], [Build with intel avx2 (default is no)])], @@ -725,6 +731,11 @@ BOOST_LIBS="$BOOST_LDFLAGS $BOOST_SYSTEM_LIB $BOOST_FILESYSTEM_LIB $BOOST_PROGRA fi +# Configure Scrypt SSE2 +if test x$use_scrypt_sse2 = xyes; then + AC_DEFINE(USE_SSE2, 1, [Define this symbol if SSE2 works]) +fi + if test x$intel_avx2 = xyes; then case $host in x86_64-*-linux*) @@ -1028,6 +1039,7 @@ AM_CONDITIONAL([USE_LCOV],[test x$use_lcov = xyes]) AM_CONDITIONAL([GLIBC_BACK_COMPAT],[test x$use_glibc_compat = xyes]) AM_CONDITIONAL([HARDEN],[test x$use_hardening = xyes]) AM_CONDITIONAL([WORDS_BIGENDIAN],[test x$ac_cv_c_bigendian = xyes]) +AM_CONDITIONAL([USE_SCRYPT_SSE2], [test x$use_scrypt_sse2 = xyes]) AC_DEFINE(CLIENT_VERSION_MAJOR, _CLIENT_VERSION_MAJOR, [Major version]) AC_DEFINE(CLIENT_VERSION_MINOR, _CLIENT_VERSION_MINOR, [Minor version]) diff --git a/src/Makefile.am b/src/Makefile.am index bf2284005..1574df227 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -267,6 +267,11 @@ crypto_libdogecoin_crypto_a_SOURCES = \ crypto/sha512.cpp \ crypto/sha512.h +# only include SSE2 scrypt sources if USE_SCRYPT_SSE2 is defined +if USE_SCRYPT_SSE2 +crypto_libdogecoin_crypto_a_SOURCES += crypto/scrypt-sse2.cpp +endif + # consensus: shared between all executables that validate any consensus rules. libdogecoin_consensus_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) libdogecoin_consensus_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) diff --git a/src/crypto/scrypt.cpp b/src/crypto/scrypt.cpp index 4a04f409d..858bfcd18 100644 --- a/src/crypto/scrypt.cpp +++ b/src/crypto/scrypt.cpp @@ -222,10 +222,11 @@ void scrypt_1024_1_1_256_sp_generic(const char *input, char *output, char *scrat // By default, set to generic scrypt function. This will prevent crash in case when scrypt_detect_sse2() wasn't called void (*scrypt_1024_1_1_256_sp_detected)(const char *input, char *output, char *scratchpad) = &scrypt_1024_1_1_256_sp_generic; -void scrypt_detect_sse2() +bool scrypt_detect_sse2() { + bool fUsingSSE2; #if defined(USE_SSE2_ALWAYS) - printf("scrypt: using scrypt-sse2 as built.\n"); + fUsingSSE2 = true; #else // USE_SSE2_ALWAYS // 32bit x86 Linux or Windows, detect cpuid features unsigned int cpuid_edx=0; @@ -243,14 +244,16 @@ void scrypt_detect_sse2() if (cpuid_edx & 1<<26) { scrypt_1024_1_1_256_sp_detected = &scrypt_1024_1_1_256_sp_sse2; - printf("scrypt: using scrypt-sse2 as detected.\n"); + fUsingSSE2 = true; } else { scrypt_1024_1_1_256_sp_detected = &scrypt_1024_1_1_256_sp_generic; - printf("scrypt: using scrypt-generic, SSE2 unavailable.\n"); + fUsingSSE2 = false; } #endif // USE_SSE2_ALWAYS + + return fUsingSSE2; } #endif diff --git a/src/crypto/scrypt.h b/src/crypto/scrypt.h index 8c1158a32..414c961bc 100644 --- a/src/crypto/scrypt.h +++ b/src/crypto/scrypt.h @@ -1,8 +1,12 @@ -#ifndef SCRYPT_H -#define SCRYPT_H +#ifndef BITCOIN_CRYPTO_SCRYPT_H +#define BITCOIN_CRYPTO_SCRYPT_H #include #include +#if defined(HAVE_CONFIG_H) +#include "bitcoin-config.h" // for USE_SSE2 +#endif + static const int SCRYPT_SCRATCHPAD_SIZE = 131072 + 63; void scrypt_1024_1_1_256(const char *input, char *output); @@ -16,7 +20,7 @@ void scrypt_1024_1_1_256_sp_generic(const char *input, char *output, char *scrat #define scrypt_1024_1_1_256_sp(input, output, scratchpad) scrypt_1024_1_1_256_sp_detected((input), (output), (scratchpad)) #endif -void scrypt_detect_sse2(); +bool scrypt_detect_sse2(); void scrypt_1024_1_1_256_sp_sse2(const char *input, char *output, char *scratchpad); extern void (*scrypt_1024_1_1_256_sp_detected)(const char *input, char *output, char *scratchpad); #else @@ -44,4 +48,4 @@ static inline void le32enc(void *pp, uint32_t x) p[3] = (x >> 24) & 0xff; } #endif -#endif +#endif // BITCOIN_CRYPTO_SCRYPT_H diff --git a/src/init.cpp b/src/init.cpp index 38305f2cf..316efaa76 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -17,6 +17,7 @@ #include "checkpoints.h" #include "compat/sanity.h" #include "consensus/validation.h" +#include "crypto/scrypt.h" // for scrypt_detect_sse2 #include "httpserver.h" #include "httprpc.h" #include "key.h" @@ -1231,7 +1232,11 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler) int64_t nStart; #if defined(USE_SSE2) - scrypt_detect_sse2(); + if (scrypt_detect_sse2()) { + LogPrintf("scrypt: using SSE2 implementation\n"); + } else { + LogPrintf("scrypt: using generic implementation\n"); + } #endif // ********************************************************* Step 5: verify wallet database integrity