From 79aa24389fa401c4bde3c9be69109a8f9daba59f Mon Sep 17 00:00:00 2001 From: Patrick Lodder Date: Tue, 21 Dec 2021 19:34:24 -0400 Subject: [PATCH] build: configure scrypt-sse2 through autoconf - Add --enable/disable-scrypt-sse2 configuration flag - use bitcoin-config.h instead of CPPFLAGS, like all other features - make the scrypt.h header guard to be similar to everything else --- configure.ac | 12 ++++++++++++ src/Makefile.am | 5 +++++ src/crypto/scrypt.h | 10 +++++++--- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 653fe7133..b58ee2c13 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.h b/src/crypto/scrypt.h index 171fb9215..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); @@ -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