Skip to content

Commit

Permalink
Merge #268: cmake: Port PR28893 from the master branch
Browse files Browse the repository at this point in the history
07e7fdc fixup! cmake: Build `bitcoin_crypto` library (Hennadii Stepanov)
6e9c0c6 crypto: Guard code with `ENABLE_SSE41` macro (Hennadii Stepanov)
7db01e1 build: Fix test for SSE4.1 intrinsics (Hennadii Stepanov)

Pull request description:

  This PR ports bitcoin#28893. All commits from there are picked here to avoid conflicts and CI failures.

ACKs for top commit:
  theuni:
    utACK 07e7fdc

Tree-SHA512: 58b5167d644e47f4e5d499f21a11acc66f9c8c2d23ee76ec1886d701d4f34965069af25a0a86d5c40ccbc3e064346bbe68f1e7451e7653419ad68a13ccc1492b
  • Loading branch information
hebasto committed Jul 18, 2024
2 parents 945d5c6 + 07e7fdc commit 9b4aa92
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
7 changes: 4 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,12 @@ TEMP_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$SSE41_CXXFLAGS $CXXFLAGS"
AC_MSG_CHECKING([for SSE4.1 intrinsics])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <stdint.h>
#include <immintrin.h>
]],[[
__m128i l = _mm_set1_epi32(0);
return _mm_extract_epi32(l, 3);
__m128i a = _mm_set1_epi32(0);
__m128i b = _mm_set1_epi32(1);
__m128i r = _mm_blend_epi16(a, b, 0xFF);
return _mm_extract_epi32(r, 3);
]])],
[ AC_MSG_RESULT([yes]); enable_sse41=yes; AC_DEFINE([ENABLE_SSE41], [1], [Define this symbol to build code that uses SSE4.1 intrinsics]) ],
[ AC_MSG_RESULT([no])]
Expand Down
10 changes: 5 additions & 5 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ LIBBITCOIN_CRYPTO = $(LIBBITCOIN_CRYPTO_BASE)
if ENABLE_SSE41
LIBBITCOIN_CRYPTO_SSE41 = crypto/libbitcoin_crypto_sse41.la
LIBBITCOIN_CRYPTO += $(LIBBITCOIN_CRYPTO_SSE41)
if ENABLE_X86_SHANI
LIBBITCOIN_CRYPTO_X86_SHANI = crypto/libbitcoin_crypto_x86_shani.la
LIBBITCOIN_CRYPTO += $(LIBBITCOIN_CRYPTO_X86_SHANI)
endif
endif
if ENABLE_AVX2
LIBBITCOIN_CRYPTO_AVX2 = crypto/libbitcoin_crypto_avx2.la
LIBBITCOIN_CRYPTO += $(LIBBITCOIN_CRYPTO_AVX2)
endif
if ENABLE_X86_SHANI
LIBBITCOIN_CRYPTO_X86_SHANI = crypto/libbitcoin_crypto_x86_shani.la
LIBBITCOIN_CRYPTO += $(LIBBITCOIN_CRYPTO_X86_SHANI)
endif
if ENABLE_ARM_SHANI
LIBBITCOIN_CRYPTO_ARM_SHANI = crypto/libbitcoin_crypto_arm_shani.la
LIBBITCOIN_CRYPTO += $(LIBBITCOIN_CRYPTO_ARM_SHANI)
Expand Down Expand Up @@ -622,7 +622,7 @@ crypto_libbitcoin_crypto_x86_shani_la_LDFLAGS = $(AM_LDFLAGS) -static
crypto_libbitcoin_crypto_x86_shani_la_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) -static
crypto_libbitcoin_crypto_x86_shani_la_CPPFLAGS = $(AM_CPPFLAGS)
crypto_libbitcoin_crypto_x86_shani_la_CXXFLAGS += $(X86_SHANI_CXXFLAGS)
crypto_libbitcoin_crypto_x86_shani_la_CPPFLAGS += -DENABLE_X86_SHANI
crypto_libbitcoin_crypto_x86_shani_la_CPPFLAGS += -DENABLE_SSE41 -DENABLE_X86_SHANI
crypto_libbitcoin_crypto_x86_shani_la_SOURCES = crypto/sha256_x86_shani.cpp

# See explanation for -static in crypto_libbitcoin_crypto_base_la's LDFLAGS and
Expand Down
10 changes: 6 additions & 4 deletions src/crypto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ if(NOT MSVC)
int main()
{
__m128i l = _mm_set1_epi32(0);
return _mm_extract_epi32(l, 3);
__m128i a = _mm_set1_epi32(0);
__m128i b = _mm_set1_epi32(1);
__m128i r = _mm_blend_epi16(a, b, 0xFF);
return _mm_extract_epi32(r, 3);
}
" HAVE_SSE41
)
Expand Down Expand Up @@ -108,11 +110,11 @@ if(HAVE_AVX2)
target_link_libraries(bitcoin_crypto PRIVATE bitcoin_crypto_avx2)
endif()

if(HAVE_X86_SHANI)
if(HAVE_SSE41 AND HAVE_X86_SHANI)
add_library(bitcoin_crypto_x86_shani STATIC EXCLUDE_FROM_ALL
sha256_x86_shani.cpp
)
target_compile_definitions(bitcoin_crypto_x86_shani PUBLIC ENABLE_X86_SHANI)
target_compile_definitions(bitcoin_crypto_x86_shani PUBLIC ENABLE_SSE41 ENABLE_X86_SHANI)
target_compile_options(bitcoin_crypto_x86_shani PRIVATE ${X86_SHANI_CXXFLAGS})
target_link_libraries(bitcoin_crypto_x86_shani PRIVATE core_interface)
target_link_libraries(bitcoin_crypto PRIVATE bitcoin_crypto_x86_shani)
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/sha256.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ std::string SHA256AutoDetect(sha256_implementation::UseImplementation use_implem
}
}

#if defined(ENABLE_X86_SHANI)
#if defined(ENABLE_SSE41) && defined(ENABLE_X86_SHANI)
if (have_x86_shani) {
Transform = sha256_x86_shani::Transform;
TransformD64 = TransformD64Wrapper<sha256_x86_shani::Transform>;
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/sha256_x86_shani.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Written and placed in public domain by Jeffrey Walton.
// Based on code from Intel, and by Sean Gulley for the miTLS project.

#ifdef ENABLE_X86_SHANI
#if defined(ENABLE_SSE41) && defined(ENABLE_X86_SHANI)

#include <stdint.h>
#include <immintrin.h>
Expand Down

0 comments on commit 9b4aa92

Please sign in to comment.