Skip to content

Commit

Permalink
Merge 13203 via dsha256_power8-27
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-jr committed Feb 14, 2025
2 parents 30b18af + 5fa767a commit cc4b680
Show file tree
Hide file tree
Showing 4 changed files with 451 additions and 1 deletion.
20 changes: 20 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ enable_sse42=no
enable_sse41=no
enable_avx2=no
enable_x86_shani=no
enable_power8=no

dnl Check for optional instruction set support. Enabling these does _not_ imply that all code will
dnl be compiled with them, rather that specific objects/libs may use them after checking for runtime
Expand All @@ -445,6 +446,7 @@ AX_CHECK_COMPILE_FLAG([-msse4.2], [SSE42_CXXFLAGS="-msse4.2"], [], [$CXXFLAG_WER
AX_CHECK_COMPILE_FLAG([-msse4.1], [SSE41_CXXFLAGS="-msse4.1"], [], [$CXXFLAG_WERROR])
AX_CHECK_COMPILE_FLAG([-mavx -mavx2], [AVX2_CXXFLAGS="-mavx -mavx2"], [], [$CXXFLAG_WERROR])
AX_CHECK_COMPILE_FLAG([-msse4 -msha], [X86_SHANI_CXXFLAGS="-msse4 -msha"], [], [$CXXFLAG_WERROR])
AX_CHECK_COMPILE_FLAG([-mpower8-vector], [POWER8_CXXFLAGS="-mpower8-vector"], [], [$CXXFLAG_WERROR])

enable_clmul=
AX_CHECK_COMPILE_FLAG([-mpclmul], [enable_clmul=yes], [], [$CXXFLAG_WERROR], [AC_LANG_PROGRAM([
Expand Down Expand Up @@ -593,6 +595,22 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
)
CXXFLAGS="$TEMP_CXXFLAGS"

TEMP_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$TEMP_CXXFLAGS $POWER8_CXXFLAGS"
AC_MSG_CHECKING(for POWER8 compiler support)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <altivec.h>
#include <stdint.h>
]], [[
unsigned char src[16];
__builtin_crypto_vshasigmaw((__vector uint32_t)vec_vsx_ld(0, src), 1, 0xf);
return 0;
]])],
[ AC_MSG_RESULT(yes); enable_power8=yes; AC_DEFINE(ENABLE_POWER8, 1, [Define if compiler supports POWER8 instructions.]) ],
[ AC_MSG_RESULT(no) ]
)
CXXFLAGS="$TEMP_CXXFLAGS"

CORE_CPPFLAGS="$CORE_CPPFLAGS -DHAVE_BUILD_INFO"

AC_ARG_WITH([utils],
Expand Down Expand Up @@ -1829,6 +1847,7 @@ AM_CONDITIONAL([ENABLE_AVX2], [test "$enable_avx2" = "yes"])
AM_CONDITIONAL([ENABLE_X86_SHANI], [test "$enable_x86_shani" = "yes"])
AM_CONDITIONAL([ENABLE_ARM_CRC], [test "$enable_arm_crc" = "yes"])
AM_CONDITIONAL([ENABLE_ARM_SHANI], [test "$enable_arm_shani" = "yes"])
AM_CONDITIONAL([ENABLE_POWER8], [test "$enable_power8" = "yes"])
AM_CONDITIONAL([WORDS_BIGENDIAN], [test "$ac_cv_c_bigendian" = "yes"])
AM_CONDITIONAL([USE_NATPMP], [test "$use_natpmp" = "yes"])
AM_CONDITIONAL([USE_UPNP], [test "$use_upnp" = "yes"])
Expand Down Expand Up @@ -1887,6 +1906,7 @@ AC_SUBST(AVX2_CXXFLAGS)
AC_SUBST(X86_SHANI_CXXFLAGS)
AC_SUBST(ARM_CRC_CXXFLAGS)
AC_SUBST(ARM_SHANI_CXXFLAGS)
AC_SUBST(POWER8_CXXFLAGS)
AC_SUBST(LIBTOOL_APP_LDFLAGS)
AC_SUBST(USE_SQLITE)
AC_SUBST(USE_BDB)
Expand Down
14 changes: 14 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ if ENABLE_ARM_SHANI
LIBBITCOIN_CRYPTO_ARM_SHANI = crypto/libbitcoin_crypto_arm_shani.la
LIBBITCOIN_CRYPTO += $(LIBBITCOIN_CRYPTO_ARM_SHANI)
endif
if ENABLE_POWER8
LIBBITCOIN_CRYPTO_POWER8 = crypto/libbitcoin_crypto_power8.la
LIBBITCOIN_CRYPTO += $(LIBBITCOIN_CRYPTO_POWER8)
endif
noinst_LTLIBRARIES += $(LIBBITCOIN_CRYPTO)

if EMBEDDED_LIBSECP256K1
Expand Down Expand Up @@ -645,6 +649,16 @@ crypto_libbitcoin_crypto_arm_shani_la_CPPFLAGS += -DENABLE_ARM_SHANI
crypto_libbitcoin_crypto_arm_shani_la_SOURCES = crypto/sha256_arm_shani.cpp
#

# See explanation for -static in crypto_libbitcoin_crypto_base_la's LDFLAGS and
# CXXFLAGS above
crypto_libbitcoin_crypto_power8_la_LDFLAGS = $(AM_LDFLAGS) -static
crypto_libbitcoin_crypto_power8_la_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) -static
crypto_libbitcoin_crypto_power8_la_CPPFLAGS = $(AM_CPPFLAGS)
crypto_libbitcoin_crypto_power8_la_CXXFLAGS += $(POWER8_CXXFLAGS)
crypto_libbitcoin_crypto_power8_la_CPPFLAGS += -DENABLE_POWER8
crypto_libbitcoin_crypto_power8_la_SOURCES = crypto/sha256_power8.cpp
#

# consensus #
libbitcoin_consensus_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
libbitcoin_consensus_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
Expand Down
17 changes: 16 additions & 1 deletion src/crypto/sha256.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ void Transform_2way(unsigned char* out, const unsigned char* in);
}
#endif // DISABLE_OPTIMIZED_SHA256

#if defined(__linux__) && defined(ENABLE_POWER8)
#include <sys/auxv.h>
namespace sha256_power8
{
void Transform_4way(unsigned char* out, const unsigned char* in);
}
#endif


// Internal implementation code.
namespace
{
Expand Down Expand Up @@ -651,7 +660,13 @@ std::string SHA256AutoDetect(sha256_implementation::UseImplementation use_implem
ret += ",avx2(8way)";
}
#endif
#endif // defined(HAVE_GETCPUID)
#elif (defined(__linux__)) && defined(ENABLE_POWER8)
if (getauxval(AT_HWCAP2) & 0x02000000) {
TransformD64_4way = sha256_power8::Transform_4way;
assert(SelfTest());
return "power8(4way),C(1way)";
}
#endif

#if defined(ENABLE_ARM_SHANI)
bool have_arm_shani = false;
Expand Down
Loading

0 comments on commit cc4b680

Please sign in to comment.