Skip to content

Commit 30bf19d

Browse files
committed
crypto: isolate sphlib sources and apply stronger optimizations to it
Alongside availing more aggressive optimization if the compiler supports it, Cubehash and JH perform better with their small footprint variants so let's default to those variants. We aren't enabling _all_ small footprint variants as algorithms like Groestl perform significantly worse.
1 parent 3ec483e commit 30bf19d

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

configure.ac

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,9 @@ if test "$enable_debug" = "yes"; then
378378
AX_CHECK_PREPROC_FLAG([-DABORT_ON_FAILED_ASSUME], [DEBUG_CPPFLAGS="$DEBUG_CPPFLAGS -DABORT_ON_FAILED_ASSUME"], [], [$CXXFLAG_WERROR])
379379
AX_CHECK_COMPILE_FLAG([-ftrapv], [DEBUG_CXXFLAGS="$DEBUG_CXXFLAGS -ftrapv"], [], [$CXXFLAG_WERROR])
380380
else
381+
dnl If not debugging, enable more aggressive optimizations for sphlib sources
382+
AX_CHECK_COMPILE_FLAG([-O3], [SPHLIB_CFLAGS="$SPHLIB_CFLAGS -O3"], [], [$CXXFLAG_WERROR])
383+
381384
# We always enable at at least -g1 debug info to support proper stacktraces in crash infos
382385
# Stacktraces will be suboptimal due to optimization, but better than nothing. Also, -fno-omit-frame-pointer
383386
# mitigates this a little bit
@@ -1874,6 +1877,7 @@ AC_SUBST(PIC_FLAGS)
18741877
AC_SUBST(PIE_FLAGS)
18751878
AC_SUBST(SANITIZER_CXXFLAGS)
18761879
AC_SUBST(SANITIZER_LDFLAGS)
1880+
AC_SUBST(SPHLIB_CFLAGS)
18771881
AC_SUBST(SSE42_CXXFLAGS)
18781882
AC_SUBST(SSE41_CXXFLAGS)
18791883
AC_SUBST(CLMUL_CXXFLAGS)

src/Makefile.am

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ LIBBITCOIN_WALLET_TOOL=libbitcoin_wallet_tool.a
7373
endif
7474

7575
LIBBITCOIN_CRYPTO = $(LIBBITCOIN_CRYPTO_BASE)
76+
LIBBITCOIN_CRYPTO_SPH = crypto/libbitcoin_crypto_sph.la
77+
LIBBITCOIN_CRYPTO += $(LIBBITCOIN_CRYPTO_SPH)
7678
if ENABLE_SSE41
7779
LIBBITCOIN_CRYPTO_SSE41 = crypto/libbitcoin_crypto_sse41.la
7880
LIBBITCOIN_CRYPTO += $(LIBBITCOIN_CRYPTO_SSE41)
@@ -718,8 +720,16 @@ crypto_libbitcoin_crypto_avx2_la_CXXFLAGS += $(AVX2_CXXFLAGS)
718720
crypto_libbitcoin_crypto_avx2_la_CPPFLAGS += -DENABLE_AVX2
719721
crypto_libbitcoin_crypto_avx2_la_SOURCES = crypto/sha256_avx2.cpp
720722

721-
# x11
722-
crypto_libbitcoin_crypto_base_la_SOURCES += \
723+
# See explanation for -static in crypto_libbitcoin_crypto_base_la's LDFLAGS and
724+
# CXXFLAGS above
725+
crypto_libbitcoin_crypto_sph_la_LDFLAGS = $(AM_LDFLAGS) -static
726+
crypto_libbitcoin_crypto_sph_la_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) -static
727+
crypto_libbitcoin_crypto_sph_la_CPPFLAGS = $(AM_CPPFLAGS)
728+
crypto_libbitcoin_crypto_sph_la_CFLAGS = $(SPHLIB_CFLAGS)
729+
crypto_libbitcoin_crypto_sph_la_CPPFLAGS += \
730+
-DSPH_SMALL_FOOTPRINT_CUBEHASH=1 \
731+
-DSPH_SMALL_FOOTPRINT_JH=1
732+
crypto_libbitcoin_crypto_sph_la_SOURCES = \
723733
crypto/x11/aes_helper.c \
724734
crypto/x11/blake.c \
725735
crypto/x11/bmw.c \
@@ -1009,7 +1019,7 @@ endif
10091019
# dashconsensus library #
10101020
if BUILD_BITCOIN_LIBS
10111021
include_HEADERS = script/bitcoinconsensus.h
1012-
libdashconsensus_la_SOURCES = support/cleanse.cpp $(crypto_libbitcoin_crypto_base_la_SOURCES) $(libbitcoin_consensus_a_SOURCES)
1022+
libdashconsensus_la_SOURCES = support/cleanse.cpp $(crypto_libbitcoin_crypto_base_la_SOURCES) $(crypto_libbitcoin_crypto_sph_la_SOURCES) $(libbitcoin_consensus_a_SOURCES)
10131023

10141024
libdashconsensus_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined $(RELDFLAGS)
10151025
libdashconsensus_la_LIBADD = $(LIBDASHBLS) $(LIBSECP256K1) $(GMP_LIBS)

0 commit comments

Comments
 (0)