Protect SSE4 code behind a compile-time flag

This commit is contained in:
Pieter Wuille 2017-07-18 01:06:11 -07:00
parent fa9be909c9
commit 6b8d872e5e
3 changed files with 18 additions and 2 deletions

View file

@ -177,6 +177,16 @@ AC_ARG_ENABLE([glibc-back-compat],
[use_glibc_compat=$enableval], [use_glibc_compat=$enableval],
[use_glibc_compat=no]) [use_glibc_compat=no])
AC_ARG_ENABLE([experimental-asm],
[AS_HELP_STRING([--enable-experimental-asm],
[Enable experimental assembly routines (default is no)])],
[experimental_asm=$enableval],
[experimental_asm=no])
if test "x$experimental_asm" = xyes; then
AC_DEFINE(EXPERIMENTAL_ASM, 1, [Define this symbol to build in experimental assembly routines])
fi
AC_ARG_WITH([system-univalue], AC_ARG_WITH([system-univalue],
[AS_HELP_STRING([--with-system-univalue], [AS_HELP_STRING([--with-system-univalue],
[Build with system UniValue (default is no)])], [Build with system UniValue (default is no)])],
@ -1162,6 +1172,7 @@ 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])
AM_CONDITIONAL([ENABLE_HWCRC32],[test x$enable_hwcrc32 = xyes]) AM_CONDITIONAL([ENABLE_HWCRC32],[test x$enable_hwcrc32 = xyes])
AM_CONDITIONAL([EXPERIMENTAL_ASM],[test x$experimental_asm = xyes])
AC_DEFINE(CLIENT_VERSION_MAJOR, _CLIENT_VERSION_MAJOR, [Major version]) AC_DEFINE(CLIENT_VERSION_MAJOR, _CLIENT_VERSION_MAJOR, [Major version])
AC_DEFINE(CLIENT_VERSION_MINOR, _CLIENT_VERSION_MINOR, [Minor version]) AC_DEFINE(CLIENT_VERSION_MINOR, _CLIENT_VERSION_MINOR, [Minor version])

View file

@ -263,11 +263,14 @@ crypto_libbitcoin_crypto_a_SOURCES = \
crypto/sha1.cpp \ crypto/sha1.cpp \
crypto/sha1.h \ crypto/sha1.h \
crypto/sha256.cpp \ crypto/sha256.cpp \
crypto/sha256_sse4.cpp \
crypto/sha256.h \ crypto/sha256.h \
crypto/sha512.cpp \ crypto/sha512.cpp \
crypto/sha512.h crypto/sha512.h
if EXPERIMENTAL_ASM
crypto_libbitcoin_crypto_a_SOURCES += crypto/sha256_sse4.cpp
endif
# consensus: shared between all executables that validate any consensus rules. # consensus: shared between all executables that validate any consensus rules.
libbitcoin_consensus_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) libbitcoin_consensus_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
libbitcoin_consensus_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) libbitcoin_consensus_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)

View file

@ -10,12 +10,14 @@
#include <atomic> #include <atomic>
#if defined(__x86_64__) || defined(__amd64__) #if defined(__x86_64__) || defined(__amd64__)
#if defined(EXPERIMENTAL_ASM)
#include <cpuid.h> #include <cpuid.h>
namespace sha256_sse4 namespace sha256_sse4
{ {
void Transform(uint32_t* s, const unsigned char* chunk, size_t blocks); void Transform(uint32_t* s, const unsigned char* chunk, size_t blocks);
} }
#endif #endif
#endif
// Internal implementation code. // Internal implementation code.
namespace namespace
@ -176,7 +178,7 @@ TransformType Transform = sha256::Transform;
std::string SHA256AutoDetect() std::string SHA256AutoDetect()
{ {
#if defined(__x86_64__) || defined(__amd64__) #if defined(EXPERIMENTAL_ASM) && (defined(__x86_64__) || defined(__amd64__))
uint32_t eax, ebx, ecx, edx; uint32_t eax, ebx, ecx, edx;
if (__get_cpuid(1, &eax, &ebx, &ecx, &edx) && (ecx >> 19) & 1) { if (__get_cpuid(1, &eax, &ebx, &ecx, &edx) && (ecx >> 19) & 1) {
Transform = sha256_sse4::Transform; Transform = sha256_sse4::Transform;