Skip to content

Commit 6b8d872

Browse files
committed
Protect SSE4 code behind a compile-time flag
1 parent fa9be90 commit 6b8d872

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

configure.ac

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,16 @@ AC_ARG_ENABLE([glibc-back-compat],
177177
[use_glibc_compat=$enableval],
178178
[use_glibc_compat=no])
179179

180+
AC_ARG_ENABLE([experimental-asm],
181+
[AS_HELP_STRING([--enable-experimental-asm],
182+
[Enable experimental assembly routines (default is no)])],
183+
[experimental_asm=$enableval],
184+
[experimental_asm=no])
185+
186+
if test "x$experimental_asm" = xyes; then
187+
AC_DEFINE(EXPERIMENTAL_ASM, 1, [Define this symbol to build in experimental assembly routines])
188+
fi
189+
180190
AC_ARG_WITH([system-univalue],
181191
[AS_HELP_STRING([--with-system-univalue],
182192
[Build with system UniValue (default is no)])],
@@ -1162,6 +1172,7 @@ AM_CONDITIONAL([USE_LCOV],[test x$use_lcov = xyes])
11621172
AM_CONDITIONAL([GLIBC_BACK_COMPAT],[test x$use_glibc_compat = xyes])
11631173
AM_CONDITIONAL([HARDEN],[test x$use_hardening = xyes])
11641174
AM_CONDITIONAL([ENABLE_HWCRC32],[test x$enable_hwcrc32 = xyes])
1175+
AM_CONDITIONAL([EXPERIMENTAL_ASM],[test x$experimental_asm = xyes])
11651176

11661177
AC_DEFINE(CLIENT_VERSION_MAJOR, _CLIENT_VERSION_MAJOR, [Major version])
11671178
AC_DEFINE(CLIENT_VERSION_MINOR, _CLIENT_VERSION_MINOR, [Minor version])

src/Makefile.am

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,14 @@ crypto_libbitcoin_crypto_a_SOURCES = \
263263
crypto/sha1.cpp \
264264
crypto/sha1.h \
265265
crypto/sha256.cpp \
266-
crypto/sha256_sse4.cpp \
267266
crypto/sha256.h \
268267
crypto/sha512.cpp \
269268
crypto/sha512.h
270269

270+
if EXPERIMENTAL_ASM
271+
crypto_libbitcoin_crypto_a_SOURCES += crypto/sha256_sse4.cpp
272+
endif
273+
271274
# consensus: shared between all executables that validate any consensus rules.
272275
libbitcoin_consensus_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
273276
libbitcoin_consensus_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)

src/crypto/sha256.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
#include <atomic>
1111

1212
#if defined(__x86_64__) || defined(__amd64__)
13+
#if defined(EXPERIMENTAL_ASM)
1314
#include <cpuid.h>
1415
namespace sha256_sse4
1516
{
1617
void Transform(uint32_t* s, const unsigned char* chunk, size_t blocks);
1718
}
1819
#endif
20+
#endif
1921

2022
// Internal implementation code.
2123
namespace
@@ -176,7 +178,7 @@ TransformType Transform = sha256::Transform;
176178

177179
std::string SHA256AutoDetect()
178180
{
179-
#if defined(__x86_64__) || defined(__amd64__)
181+
#if defined(EXPERIMENTAL_ASM) && (defined(__x86_64__) || defined(__amd64__))
180182
uint32_t eax, ebx, ecx, edx;
181183
if (__get_cpuid(1, &eax, &ebx, &ecx, &edx) && (ecx >> 19) & 1) {
182184
Transform = sha256_sse4::Transform;

0 commit comments

Comments
 (0)