Browse Source

Litecoin: enable support for SSE2 instructions in scrypt via configure --enable-sse2 (#362)

0.15
Romano 7 years ago committed by Adrian Gallagher
parent
commit
d8b8d96d23
No known key found for this signature in database
GPG Key ID: FE3348877809386C
  1. 10
      .travis.yml
  2. 18
      configure.ac
  3. 1
      src/Makefile.am
  4. 4
      src/crypto/scrypt-sse2.cpp
  5. 10
      src/crypto/scrypt.cpp
  6. 3
      src/crypto/scrypt.h
  7. 7
      src/init.cpp
  8. 2
      src/test/scrypt_tests.cpp

10
.travis.yml

@ -29,13 +29,13 @@ env:
# 32-bit + dash # 32-bit + dash
- HOST=i686-pc-linux-gnu PACKAGES="g++-multilib bc python3-zmq" DEP_OPTS="NO_QT=1" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-zmq --enable-glibc-back-compat --enable-reduce-exports LDFLAGS=-static-libstdc++" USE_SHELL="/bin/dash" LITECOIN_SCRYPT=1 - HOST=i686-pc-linux-gnu PACKAGES="g++-multilib bc python3-zmq" DEP_OPTS="NO_QT=1" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-zmq --enable-glibc-back-compat --enable-reduce-exports LDFLAGS=-static-libstdc++" USE_SHELL="/bin/dash" LITECOIN_SCRYPT=1
# Win64 # Win64
- HOST=x86_64-w64-mingw32 DPKG_ADD_ARCH="i386" DEP_OPTS="NO_QT=1" PACKAGES="python3 nsis g++-mingw-w64-x86-64 wine1.6 bc" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-reduce-exports" LITECOIN_SCRYPT=1 - HOST=x86_64-w64-mingw32 DPKG_ADD_ARCH="i386" DEP_OPTS="NO_QT=1" PACKAGES="python3 nsis g++-mingw-w64-x86-64 wine1.6 bc" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-reduce-exports --enable-sse2" LITECOIN_SCRYPT=1
# x86_64 Linux (uses qt5 dev package instead of depends Qt to speed up build and avoid timeout) # x86_64 Linux (uses qt5 dev package instead of depends Qt to speed up build and avoid timeout)
- HOST=x86_64-unknown-linux-gnu PACKAGES="python3-zmq qtbase5-dev qttools5-dev-tools protobuf-compiler libdbus-1-dev libharfbuzz-dev" DEP_OPTS="NO_QT=1 NO_UPNP=1 DEBUG=1 ALLOW_HOST_PACKAGES=1" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-zmq --with-gui=qt5 --enable-glibc-back-compat --enable-reduce-exports CPPFLAGS=-DDEBUG_LOCKORDER" LITECOIN_SCRYPT=1 - HOST=x86_64-unknown-linux-gnu PACKAGES="python3-zmq qtbase5-dev qttools5-dev-tools protobuf-compiler libdbus-1-dev libharfbuzz-dev" DEP_OPTS="NO_QT=1 NO_UPNP=1 DEBUG=1 ALLOW_HOST_PACKAGES=1" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-zmq --with-gui=qt5 --enable-glibc-back-compat --enable-reduce-exports --enable-sse2 CPPFLAGS=-DDEBUG_LOCKORDER" LITECOIN_SCRYPT=1
# x86_64 Linux, No wallet # x86_64 Linux, No wallet
- HOST=x86_64-unknown-linux-gnu PACKAGES="python3" DEP_OPTS="NO_WALLET=1" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-glibc-back-compat --enable-reduce-exports" LITECOIN_SCRYPT=1 - HOST=x86_64-unknown-linux-gnu PACKAGES="python3" DEP_OPTS="NO_WALLET=1" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-glibc-back-compat --enable-reduce-exports --enable-sse2" LITECOIN_SCRYPT=1
# Cross-Mac # Cross-Mac
- HOST=x86_64-apple-darwin11 PACKAGES="cmake imagemagick libcap-dev librsvg2-bin libz-dev libbz2-dev libtiff-tools python-dev" BITCOIN_CONFIG="--enable-gui --enable-reduce-exports" OSX_SDK=10.11 GOAL="deploy" - HOST=x86_64-apple-darwin11 PACKAGES="cmake imagemagick libcap-dev librsvg2-bin libz-dev libbz2-dev libtiff-tools python-dev" BITCOIN_CONFIG="--enable-gui --enable-reduce-exports --enable-sse2" OSX_SDK=10.11 GOAL="deploy"
before_install: before_install:
- export PATH=$(echo $PATH | tr ':' "\n" | sed '/\/opt\/python/d' | tr "\n" ":" | sed "s|::|:|g") - export PATH=$(echo $PATH | tr ':' "\n" | sed '/\/opt\/python/d' | tr "\n" ":" | sed "s|::|:|g")
@ -65,7 +65,7 @@ script:
- mkdir build && cd build - mkdir build && cd build
- ../configure --cache-file=config.cache $BITCOIN_CONFIG_ALL $BITCOIN_CONFIG || ( cat config.log && false) - ../configure --cache-file=config.cache $BITCOIN_CONFIG_ALL $BITCOIN_CONFIG || ( cat config.log && false)
- make distdir VERSION=$HOST - make distdir VERSION=$HOST
- cd bitcoin-$HOST - cd litecoin-$HOST
- ./configure --cache-file=../config.cache $BITCOIN_CONFIG_ALL $BITCOIN_CONFIG || ( cat config.log && false) - ./configure --cache-file=../config.cache $BITCOIN_CONFIG_ALL $BITCOIN_CONFIG || ( cat config.log && false)
- make $MAKEJOBS $GOAL || ( echo "Build failure. Verbose build follows." && make $GOAL V=1 ; false ) - make $MAKEJOBS $GOAL || ( echo "Build failure. Verbose build follows." && make $GOAL V=1 ; false )
- export LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/depends/$HOST/lib - export LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/depends/$HOST/lib

18
configure.ac

@ -199,6 +199,12 @@ AC_ARG_ENABLE([zmq],
[use_zmq=$enableval], [use_zmq=$enableval],
[use_zmq=yes]) [use_zmq=yes])
AC_ARG_ENABLE([sse2],
[AS_HELP_STRING([--enable-sse2],
[enable SSE2 instructions in the scrypt library. (default is disabled)])],
[use_sse2=$enableval],
[use_sse2=no])
AC_ARG_WITH([protoc-bindir],[AS_HELP_STRING([--with-protoc-bindir=BIN_DIR],[specify protoc bin path])], [protoc_bin_path=$withval], []) AC_ARG_WITH([protoc-bindir],[AS_HELP_STRING([--with-protoc-bindir=BIN_DIR],[specify protoc bin path])], [protoc_bin_path=$withval], [])
AC_ARG_ENABLE(man, AC_ARG_ENABLE(man,
@ -1155,6 +1161,16 @@ else
BUILD_TEST="" BUILD_TEST=""
fi fi
AC_MSG_CHECKING([whether to enable sse2 instructions])
if test x$use_sse2 != xno; then
AC_MSG_RESULT(yes)
AC_DEFINE([USE_SSE2],[1],[Define if SSE2 support should be compiled in])
use_sse2=yes
CPPFLAGS="$CPPFLAGS -DUSE_SSE2=1"
else
AC_MSG_RESULT(no)
fi
AC_MSG_CHECKING([whether to reduce exports]) AC_MSG_CHECKING([whether to reduce exports])
if test x$use_reduce_exports = xyes; then if test x$use_reduce_exports = xyes; then
AC_MSG_RESULT([yes]) AC_MSG_RESULT([yes])
@ -1175,6 +1191,7 @@ AM_CONDITIONAL([ENABLE_QT],[test x$bitcoin_enable_qt = xyes])
AM_CONDITIONAL([ENABLE_QT_TESTS],[test x$BUILD_TEST_QT = xyes]) AM_CONDITIONAL([ENABLE_QT_TESTS],[test x$BUILD_TEST_QT = xyes])
AM_CONDITIONAL([ENABLE_BENCH],[test x$use_bench = xyes]) AM_CONDITIONAL([ENABLE_BENCH],[test x$use_bench = xyes])
AM_CONDITIONAL([USE_QRCODE], [test x$use_qr = xyes]) AM_CONDITIONAL([USE_QRCODE], [test x$use_qr = xyes])
AM_CONDITIONAL([USE_SSE2], [test x$use_sse2 = xyes])
AM_CONDITIONAL([USE_LCOV],[test x$use_lcov = xyes]) AM_CONDITIONAL([USE_LCOV],[test x$use_lcov = xyes])
AM_CONDITIONAL([GLIBC_BACK_COMPAT],[test x$use_glibc_compat = xyes]) AM_CONDITIONAL([GLIBC_BACK_COMPAT],[test x$use_glibc_compat = xyes])
AM_CONDITIONAL([HARDEN],[test x$use_hardening = xyes]) AM_CONDITIONAL([HARDEN],[test x$use_hardening = xyes])
@ -1216,6 +1233,7 @@ AC_SUBST(SSE42_CXXFLAGS)
AC_SUBST(LIBTOOL_APP_LDFLAGS) AC_SUBST(LIBTOOL_APP_LDFLAGS)
AC_SUBST(USE_UPNP) AC_SUBST(USE_UPNP)
AC_SUBST(USE_QRCODE) AC_SUBST(USE_QRCODE)
AC_SUBST(USE_SSE2)
AC_SUBST(BOOST_LIBS) AC_SUBST(BOOST_LIBS)
AC_SUBST(TESTDEFS) AC_SUBST(TESTDEFS)
AC_SUBST(LEVELDB_TARGET_FLAGS) AC_SUBST(LEVELDB_TARGET_FLAGS)

1
src/Makefile.am

@ -261,6 +261,7 @@ crypto_libbitcoin_crypto_a_SOURCES = \
crypto/ripemd160.cpp \ crypto/ripemd160.cpp \
crypto/ripemd160.h \ crypto/ripemd160.h \
crypto/scrypt.cpp \ crypto/scrypt.cpp \
crypto/scrypt-sse2.cpp \
crypto/scrypt.h \ crypto/scrypt.h \
crypto/sha1.cpp \ crypto/sha1.cpp \
crypto/sha1.h \ crypto/sha1.h \

4
src/crypto/scrypt-sse2.cpp

@ -27,6 +27,8 @@
* online backup system. * online backup system.
*/ */
#if defined(USE_SSE2)
#include "crypto/scrypt.h" #include "crypto/scrypt.h"
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
@ -134,3 +136,5 @@ void scrypt_1024_1_1_256_sp_sse2(const char *input, char *output, char *scratchp
PBKDF2_SHA256((const uint8_t *)input, 80, B, 128, 1, (uint8_t *)output, 32); PBKDF2_SHA256((const uint8_t *)input, 80, B, 128, 1, (uint8_t *)output, 32);
} }
#endif // USE_SSE2

10
src/crypto/scrypt.cpp

@ -290,10 +290,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 // 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_1024_1_1_256_sp_detected)(const char *input, char *output, char *scratchpad) = &scrypt_1024_1_1_256_sp_generic;
void scrypt_detect_sse2() std::string scrypt_detect_sse2()
{ {
std::string ret;
#if defined(USE_SSE2_ALWAYS) #if defined(USE_SSE2_ALWAYS)
printf("scrypt: using scrypt-sse2 as built.\n"); ret = "scrypt: using scrypt-sse2 as built.";
#else // USE_SSE2_ALWAYS #else // USE_SSE2_ALWAYS
// 32bit x86 Linux or Windows, detect cpuid features // 32bit x86 Linux or Windows, detect cpuid features
unsigned int cpuid_edx=0; unsigned int cpuid_edx=0;
@ -311,14 +312,15 @@ void scrypt_detect_sse2()
if (cpuid_edx & 1<<26) if (cpuid_edx & 1<<26)
{ {
scrypt_1024_1_1_256_sp_detected = &scrypt_1024_1_1_256_sp_sse2; scrypt_1024_1_1_256_sp_detected = &scrypt_1024_1_1_256_sp_sse2;
printf("scrypt: using scrypt-sse2 as detected.\n"); ret = "scrypt: using scrypt-sse2 as detected");
} }
else else
{ {
scrypt_1024_1_1_256_sp_detected = &scrypt_1024_1_1_256_sp_generic; scrypt_1024_1_1_256_sp_detected = &scrypt_1024_1_1_256_sp_generic;
printf("scrypt: using scrypt-generic, SSE2 unavailable.\n"); ret = "scrypt: using scrypt-generic, SSE2 unavailable";
} }
#endif // USE_SSE2_ALWAYS #endif // USE_SSE2_ALWAYS
return ret;
} }
#endif #endif

3
src/crypto/scrypt.h

@ -9,6 +9,7 @@ void scrypt_1024_1_1_256(const char *input, char *output);
void scrypt_1024_1_1_256_sp_generic(const char *input, char *output, char *scratchpad); void scrypt_1024_1_1_256_sp_generic(const char *input, char *output, char *scratchpad);
#if defined(USE_SSE2) #if defined(USE_SSE2)
#include <string>
#if defined(_M_X64) || defined(__x86_64__) || defined(_M_AMD64) || (defined(MAC_OSX) && defined(__i386__)) #if defined(_M_X64) || defined(__x86_64__) || defined(_M_AMD64) || (defined(MAC_OSX) && defined(__i386__))
#define USE_SSE2_ALWAYS 1 #define USE_SSE2_ALWAYS 1
#define scrypt_1024_1_1_256_sp(input, output, scratchpad) scrypt_1024_1_1_256_sp_sse2((input), (output), (scratchpad)) #define scrypt_1024_1_1_256_sp(input, output, scratchpad) scrypt_1024_1_1_256_sp_sse2((input), (output), (scratchpad))
@ -16,7 +17,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)) #define scrypt_1024_1_1_256_sp(input, output, scratchpad) scrypt_1024_1_1_256_sp_detected((input), (output), (scratchpad))
#endif #endif
void scrypt_detect_sse2(); std::string scrypt_detect_sse2();
void scrypt_1024_1_1_256_sp_sse2(const char *input, char *output, char *scratchpad); 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); extern void (*scrypt_1024_1_1_256_sp_detected)(const char *input, char *output, char *scratchpad);
#else #else

7
src/init.cpp

@ -66,6 +66,10 @@
#include "zmq/zmqnotificationinterface.h" #include "zmq/zmqnotificationinterface.h"
#endif #endif
#ifdef USE_SSE2
#include "crypto/scrypt.h"
#endif
bool fFeeEstimatesInitialized = false; bool fFeeEstimatesInitialized = false;
static const bool DEFAULT_PROXYRANDOMIZE = true; static const bool DEFAULT_PROXYRANDOMIZE = true;
static const bool DEFAULT_REST_ENABLE = false; static const bool DEFAULT_REST_ENABLE = false;
@ -1273,7 +1277,8 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
int64_t nStart; int64_t nStart;
#if defined(USE_SSE2) #if defined(USE_SSE2)
scrypt_detect_sse2(); std::string sse2detect = scrypt_detect_sse2();
LogPrintf("%s\n", sse2detect);
#endif #endif
// ********************************************************* Step 5: verify wallet database integrity // ********************************************************* Step 5: verify wallet database integrity

2
src/test/scrypt_tests.cpp

@ -14,7 +14,7 @@ BOOST_AUTO_TEST_CASE(scrypt_hashtest)
const char* inputhex[HASHCOUNT] = { "020000004c1271c211717198227392b029a64a7971931d351b387bb80db027f270411e398a07046f7d4a08dd815412a8712f874a7ebf0507e3878bd24e20a3b73fd750a667d2f451eac7471b00de6659", "0200000011503ee6a855e900c00cfdd98f5f55fffeaee9b6bf55bea9b852d9de2ce35828e204eef76acfd36949ae56d1fbe81c1ac9c0209e6331ad56414f9072506a77f8c6faf551eac7471b00389d01", "02000000a72c8a177f523946f42f22c3e86b8023221b4105e8007e59e81f6beb013e29aaf635295cb9ac966213fb56e046dc71df5b3f7f67ceaeab24038e743f883aff1aaafaf551eac7471b0166249b", "010000007824bc3a8a1b4628485eee3024abd8626721f7f870f8ad4d2f33a27155167f6a4009d1285049603888fe85a84b6c803a53305a8d497965a5e896e1a00568359589faf551eac7471b0065434e", "0200000050bfd4e4a307a8cb6ef4aef69abc5c0f2d579648bd80d7733e1ccc3fbc90ed664a7f74006cb11bde87785f229ecd366c2d4e44432832580e0608c579e4cb76f383f7f551eac7471b00c36982" }; const char* inputhex[HASHCOUNT] = { "020000004c1271c211717198227392b029a64a7971931d351b387bb80db027f270411e398a07046f7d4a08dd815412a8712f874a7ebf0507e3878bd24e20a3b73fd750a667d2f451eac7471b00de6659", "0200000011503ee6a855e900c00cfdd98f5f55fffeaee9b6bf55bea9b852d9de2ce35828e204eef76acfd36949ae56d1fbe81c1ac9c0209e6331ad56414f9072506a77f8c6faf551eac7471b00389d01", "02000000a72c8a177f523946f42f22c3e86b8023221b4105e8007e59e81f6beb013e29aaf635295cb9ac966213fb56e046dc71df5b3f7f67ceaeab24038e743f883aff1aaafaf551eac7471b0166249b", "010000007824bc3a8a1b4628485eee3024abd8626721f7f870f8ad4d2f33a27155167f6a4009d1285049603888fe85a84b6c803a53305a8d497965a5e896e1a00568359589faf551eac7471b0065434e", "0200000050bfd4e4a307a8cb6ef4aef69abc5c0f2d579648bd80d7733e1ccc3fbc90ed664a7f74006cb11bde87785f229ecd366c2d4e44432832580e0608c579e4cb76f383f7f551eac7471b00c36982" };
const char* expected[HASHCOUNT] = { "00000000002bef4107f882f6115e0b01f348d21195dacd3582aa2dabd7985806" , "00000000003a0d11bdd5eb634e08b7feddcfbbf228ed35d250daf19f1c88fc94", "00000000000b40f895f288e13244728a6c2d9d59d8aff29c65f8dd5114a8ca81", "00000000003007005891cd4923031e99d8e8d72f6e8e7edc6a86181897e105fe", "000000000018f0b426a4afc7130ccb47fa02af730d345b4fe7c7724d3800ec8c" }; const char* expected[HASHCOUNT] = { "00000000002bef4107f882f6115e0b01f348d21195dacd3582aa2dabd7985806" , "00000000003a0d11bdd5eb634e08b7feddcfbbf228ed35d250daf19f1c88fc94", "00000000000b40f895f288e13244728a6c2d9d59d8aff29c65f8dd5114a8ca81", "00000000003007005891cd4923031e99d8e8d72f6e8e7edc6a86181897e105fe", "000000000018f0b426a4afc7130ccb47fa02af730d345b4fe7c7724d3800ec8c" };
#if defined(USE_SSE2) #if defined(USE_SSE2)
scrypt_detect_sse2(); (void) scrypt_detect_sse2();
#endif #endif
uint256 scrypthash; uint256 scrypthash;
std::vector<unsigned char> inputbytes; std::vector<unsigned char> inputbytes;

Loading…
Cancel
Save