mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 03:47:29 -03:00
Add sha256_arm_shani to build system
Also rename AArch64 intrinsics to ARMv8 intrinsics as these are not necessarily limited to 64-bit
This commit is contained in:
parent
c2b7934250
commit
48a72fa81f
4 changed files with 100 additions and 1 deletions
23
configure.ac
23
configure.ac
|
@ -569,10 +569,11 @@ CXXFLAGS="$TEMP_CXXFLAGS"
|
|||
|
||||
# ARM
|
||||
AX_CHECK_COMPILE_FLAG([-march=armv8-a+crc+crypto], [ARM_CRC_CXXFLAGS="-march=armv8-a+crc+crypto"], [], [$CXXFLAG_WERROR])
|
||||
AX_CHECK_COMPILE_FLAG([-march=armv8-a+crc+crypto], [ARM_SHANI_CXXFLAGS="-march=armv8-a+crc+crypto"], [], [$CXXFLAG_WERROR])
|
||||
|
||||
TEMP_CXXFLAGS="$CXXFLAGS"
|
||||
CXXFLAGS="$CXXFLAGS $ARM_CRC_CXXFLAGS"
|
||||
AC_MSG_CHECKING([for AArch64 CRC32 intrinsics])
|
||||
AC_MSG_CHECKING([for ARMv8 CRC32 intrinsics])
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
|
||||
#include <arm_acle.h>
|
||||
#include <arm_neon.h>
|
||||
|
@ -589,6 +590,24 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
|
|||
)
|
||||
CXXFLAGS="$TEMP_CXXFLAGS"
|
||||
|
||||
TEMP_CXXFLAGS="$CXXFLAGS"
|
||||
CXXFLAGS="$CXXFLAGS $ARM_SHANI_CXXFLAGS"
|
||||
AC_MSG_CHECKING([for ARMv8 SHA-NI intrinsics])
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
|
||||
#include <arm_acle.h>
|
||||
#include <arm_neon.h>
|
||||
]],[[
|
||||
uint32x4_t a, b, c;
|
||||
vsha256h2q_u32(a, b, c);
|
||||
vsha256hq_u32(a, b, c);
|
||||
vsha256su0q_u32(a, b);
|
||||
vsha256su1q_u32(a, b, c);
|
||||
]])],
|
||||
[ AC_MSG_RESULT([yes]); enable_arm_shani=yes; AC_DEFINE([ENABLE_ARM_SHANI], [1], [Define this symbol to build code that uses ARMv8 SHA-NI intrinsics]) ],
|
||||
[ AC_MSG_RESULT([no])]
|
||||
)
|
||||
CXXFLAGS="$TEMP_CXXFLAGS"
|
||||
|
||||
fi
|
||||
|
||||
CPPFLAGS="$CPPFLAGS -DHAVE_BUILD_INFO"
|
||||
|
@ -1808,6 +1827,7 @@ AM_CONDITIONAL([ENABLE_SSE41], [test "$enable_sse41" = "yes"])
|
|||
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([USE_ASM], [test "$use_asm" = "yes"])
|
||||
AM_CONDITIONAL([WORDS_BIGENDIAN], [test "$ac_cv_c_bigendian" = "yes"])
|
||||
AM_CONDITIONAL([USE_NATPMP], [test "$use_natpmp" = "yes"])
|
||||
|
@ -1866,6 +1886,7 @@ AC_SUBST(CLMUL_CXXFLAGS)
|
|||
AC_SUBST(AVX2_CXXFLAGS)
|
||||
AC_SUBST(X86_SHANI_CXXFLAGS)
|
||||
AC_SUBST(ARM_CRC_CXXFLAGS)
|
||||
AC_SUBST(ARM_SHANI_CXXFLAGS)
|
||||
AC_SUBST(LIBTOOL_APP_LDFLAGS)
|
||||
AC_SUBST(USE_SQLITE)
|
||||
AC_SUBST(USE_BDB)
|
||||
|
|
|
@ -50,6 +50,10 @@ if ENABLE_X86_SHANI
|
|||
LIBBITCOIN_CRYPTO_X86_SHANI = crypto/libbitcoin_crypto_x86_shani.a
|
||||
LIBBITCOIN_CRYPTO += $(LIBBITCOIN_CRYPTO_X86_SHANI)
|
||||
endif
|
||||
if ENABLE_ARM_SHANI
|
||||
LIBBITCOIN_CRYPTO_ARM_SHANI = crypto/libbitcoin_crypto_arm_shani.a
|
||||
LIBBITCOIN_CRYPTO += $(LIBBITCOIN_CRYPTO_ARM_SHANI)
|
||||
endif
|
||||
|
||||
$(LIBSECP256K1): $(wildcard secp256k1/src/*.h) $(wildcard secp256k1/src/*.c) $(wildcard secp256k1/include/*)
|
||||
$(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C $(@D) $(@F)
|
||||
|
@ -504,6 +508,12 @@ crypto_libbitcoin_crypto_x86_shani_a_CXXFLAGS += $(X86_SHANI_CXXFLAGS)
|
|||
crypto_libbitcoin_crypto_x86_shani_a_CPPFLAGS += -DENABLE_X86_SHANI
|
||||
crypto_libbitcoin_crypto_x86_shani_a_SOURCES = crypto/sha256_x86_shani.cpp
|
||||
|
||||
crypto_libbitcoin_crypto_arm_shani_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
crypto_libbitcoin_crypto_arm_shani_a_CPPFLAGS = $(AM_CPPFLAGS)
|
||||
crypto_libbitcoin_crypto_arm_shani_a_CXXFLAGS += $(ARM_SHANI_CXXFLAGS)
|
||||
crypto_libbitcoin_crypto_arm_shani_a_CPPFLAGS += -DENABLE_ARM_SHANI
|
||||
crypto_libbitcoin_crypto_arm_shani_a_SOURCES = crypto/sha256_arm_shani.cpp
|
||||
|
||||
# consensus: shared between all executables that validate any consensus rules.
|
||||
libbitcoin_consensus_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
|
||||
libbitcoin_consensus_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
|
|
|
@ -10,6 +10,16 @@
|
|||
|
||||
#include <compat/cpuid.h>
|
||||
|
||||
#if defined(__linux__) && defined(ENABLE_ARM_SHANI) && !defined(BUILD_BITCOIN_INTERNAL)
|
||||
#include <sys/auxv.h>
|
||||
#include <asm/hwcap.h>
|
||||
#endif
|
||||
|
||||
#if defined(MAC_OSX) && defined(ENABLE_ARM_SHANI) && !defined(BUILD_BITCOIN_INTERNAL)
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
|
||||
#if defined(__x86_64__) || defined(__amd64__) || defined(__i386__)
|
||||
#if defined(USE_ASM)
|
||||
namespace sha256_sse4
|
||||
|
@ -39,6 +49,11 @@ namespace sha256_x86_shani
|
|||
void Transform(uint32_t* s, const unsigned char* chunk, size_t blocks);
|
||||
}
|
||||
|
||||
namespace sha256_arm_shani
|
||||
{
|
||||
void Transform(uint32_t* s, const unsigned char* chunk, size_t blocks);
|
||||
}
|
||||
|
||||
// Internal implementation code.
|
||||
namespace
|
||||
{
|
||||
|
@ -623,6 +638,37 @@ std::string SHA256AutoDetect()
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(ENABLE_ARM_SHANI) && !defined(BUILD_BITCOIN_INTERNAL)
|
||||
bool have_arm_shani = false;
|
||||
|
||||
#if defined(__linux__)
|
||||
#if defined(__arm__) // 32-bit
|
||||
if (getauxval(AT_HWCAP2) & HWCAP2_SHA2) {
|
||||
have_arm_shani = true;
|
||||
}
|
||||
#endif
|
||||
#if defined(__aarch64__) // 64-bit
|
||||
if (getauxval(AT_HWCAP) & HWCAP_SHA2) {
|
||||
have_arm_shani = true;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(MAC_OSX)
|
||||
int val = 0;
|
||||
size_t len = sizeof(val);
|
||||
if (sysctlbyname("hw.optional.arm.FEAT_SHA256", &val, &len, nullptr, 0) == 0) {
|
||||
have_arm_shani = val != 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (have_arm_shani) {
|
||||
Transform = sha256_arm_shani::Transform;
|
||||
TransformD64 = TransformD64Wrapper<sha256_arm_shani::Transform>;
|
||||
ret = "arm_shani(1way)";
|
||||
}
|
||||
#endif
|
||||
|
||||
assert(SelfTest());
|
||||
return ret;
|
||||
}
|
||||
|
|
22
src/crypto/sha256_arm_shani.cpp
Normal file
22
src/crypto/sha256_arm_shani.cpp
Normal file
|
@ -0,0 +1,22 @@
|
|||
// Copyright (c) 2022 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
//
|
||||
// Based on https://github.com/noloader/SHA-Intrinsics/blob/master/sha256-arm.c,
|
||||
// Written and placed in public domain by Jeffrey Walton.
|
||||
// Based on code from ARM, and by Johannes Schneiders, Skip Hovsmith and
|
||||
// Barry O'Rourke for the mbedTLS project.
|
||||
|
||||
#ifdef ENABLE_ARM_SHANI
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
|
||||
namespace sha256_arm_shani {
|
||||
void Transform(uint32_t* s, const unsigned char* chunk, size_t blocks)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue