Skip to content

Commit

Permalink
Merge pull request #1445 from evoskuil/master
Browse files Browse the repository at this point in the history
Update msvc system .props and import.props for intrinsics.
  • Loading branch information
evoskuil authored Apr 29, 2024
2 parents e45cea0 + 9fa614a commit 2e886ee
Show file tree
Hide file tree
Showing 15 changed files with 145 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
<!--<Optimization>Disabled</Optimization>-->
<DisableSpecificWarnings>%(DisableSpecificWarnings)</DisableSpecificWarnings>
<EnablePREfast>false</EnablePREfast>
<PreprocessorDefinitions Condition="'$(Option-datagen)' == 'true'">ENABLE_DATAGEN;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(DefaultLinkage)' == 'dynamic'">BOOST_TEST_DYN_LINK;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<PostBuildEvent Condition="'$(DebugOrRelease)' == 'release'">
Expand Down Expand Up @@ -57,7 +56,6 @@
<Target Name="LinkageInfo" BeforeTargets="PrepareForBuild">
<Message Text="Linkage-secp256k1 : $(Linkage-secp256k1)" Importance="high"/>
<Message Text="Linkage-_system : $(Linkage-libbitcoin-system)" Importance="high"/>
<!--<Message Text="Linkage-openssl : $(Linkage-openssl)" Importance="high" Condition="'$(Option-datagen)' == 'true'"/>-->
</Target>

</Project>
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<ProjectSchemaDefinitions xmlns="clr-namespace:Microsoft.Build.Framework.XamlTypes;assembly=Microsoft.Build.Framework">
<Rule Name="libbitcoin-system-test-uiextension" PageTemplate="tool" DisplayName="Bitcoin System Test Options" SwitchPrefix="/" Order="1">
<Rule.Categories>
<Category Name="datagen" DisplayName="datagen" />
</Rule.Categories>
<Rule.DataSource>
<DataSource Persistence="ProjectFile" ItemType="" />
</Rule.DataSource>
<EnumProperty Name="Option-datagen" DisplayName="Enable Test Data Generation" Description="Enable the Test Data Generation build option" Category="datagen">
<EnumValue Name="" DisplayName="No" />
<EnumValue Name="true" DisplayName="Yes" />
</EnumProperty>
</Rule>
</ProjectSchemaDefinitions>
43 changes: 42 additions & 1 deletion builds/msvc/vs2022/libbitcoin-system.import.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,36 @@
<ItemGroup Label="BuildOptionsExtension">
<PropertyPageSchema Include="$(MSBuildThisFileDirectory)libbitcoin-system.import.xml" />
</ItemGroup>

<!-- Options -->

<!-- These create non-portability. -->
<!-- These will compile to the target regardless of the compiling platform. -->
<!-- That will result in a crash of test/executable execution if mismatched. -->
<PropertyGroup>
<Option-avx512>false</Option-avx512>
<Option-avx2>true</Option-avx2>
<Option-sse41>true</Option-sse41>
<Option-shani>false</Option-shani>
<Option-neon>false</Option-neon>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<!-- order matters -->
<EnableEnhancedInstructionSet Condition="'$(Option-avx2)' == 'true'">AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
<EnableEnhancedInstructionSet Condition="'$(Option-avx512)' == 'true'">AdvancedVectorExtensions512</EnableEnhancedInstructionSet>
</ClCompile>
</ItemDefinitionGroup>

<!-- Messages -->

<Target Name="OptionInfo" BeforeTargets="PrepareForBuild">
<Message Text="Option-avx512 : $(Option-avx512)" Importance="high"/>
<Message Text="Option-avx2 : $(Option-avx2)" Importance="high"/>
<Message Text="Option-sse41 : $(Option-sse41)" Importance="high"/>
<Message Text="Option-shani : $(Option-shani)" Importance="high"/>
<Message Text="Option-neon : $(Option-neon)" Importance="high"/>
</Target>

<!-- Linkage -->

Expand All @@ -18,11 +48,22 @@
<AdditionalIncludeDirectories>$(ProjectDir)..\..\..\..\..\libbitcoin-system\include\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<!-- WITH_ICU always defined in Visual Studio builds. -->
<!-- NOMINMAX enables use of std::min/max without conflict. -->
<!-- BOOST_EXCEPTION_DISABLE must be set here to be captured by all includes. -->
<!-- WIN32_LEAN_AND_MEAN avoids inclusion of certain headers, winsock.h conflicts with boost and protocol use of winsock2.h. -->
<PreprocessorDefinitions>WITH_ICU;WIN32_LEAN_AND_MEAN;NOMINMAX;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Linkage-libbitcoin-system)' == 'static' Or '$(Linkage-libbitcoin-system)' == 'ltcg'">BC_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile>
<!-- Enable use of CPU intrinsics. -->
<PreprocessorDefinitions Condition="'$(Option-avx512)' == 'true'">WITH_AVX512;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Option-avx2)' == 'true'">WITH_AVX2;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Option-sse41)' == 'true'">WITH_SSE41;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Option-shani)' == 'true'">WITH_SHANI;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Option-neon)' == 'true'">WITH_NEON;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<!-- 4099: warns about missing PDB files. -->
<AdditionalOptions>/ignore:4099 %(AdditionalOptions)</AdditionalOptions>
</Link>
<Link>
<AdditionalDependencies Condition="'$(Linkage-libbitcoin-system)' != ''">libbitcoin-system.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
Expand Down
32 changes: 32 additions & 0 deletions builds/msvc/vs2022/libbitcoin-system.import.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,36 @@
<EnumValue Name="ltcg" DisplayName="Static using link time compile generation (LTCG)" />
</EnumProperty>
</Rule>
<Rule Name="libbitcoin-system-options-uiextension" PageTemplate="tool" DisplayName="Bitcoin System Options" SwitchPrefix="/" Order="1">
<Rule.Categories>
<Category Name="avx512" DisplayName="avx512" />
<Category Name="avx2" DisplayName="avx2" />
<Category Name="sse41" DisplayName="sse41" />
<Category Name="shani" DisplayName="shani" />
<Category Name="neon" DisplayName="neon" />
</Rule.Categories>
<Rule.DataSource>
<DataSource Persistence="ProjectFile" ItemType="" />
</Rule.DataSource>
<EnumProperty Name="Option-avx512" DisplayName="Enable AVX512 Intrinsics" Description="Use AVX512 intrinsics." Category="avx512">
<EnumValue Name="false" DisplayName="No" />
<EnumValue Name="true" DisplayName="Yes" />
</EnumProperty>
<EnumProperty Name="Option-avx2" DisplayName="Enable AVX2 Intrinsics" Description="Use AVX2 intrinsics." Category="avx2">
<EnumValue Name="false" DisplayName="No" />
<EnumValue Name="true" DisplayName="Yes" />
</EnumProperty>
<EnumProperty Name="Option-sse41" DisplayName="Enable SSE4.1 Intrinsics" Description="Use SSE4.1 intrinsics." Category="sse41">
<EnumValue Name="false" DisplayName="No" />
<EnumValue Name="true" DisplayName="Yes" />
</EnumProperty>
<EnumProperty Name="Option-shani" DisplayName="Enable SHA Native Intrinsics" Description="Use SHA native intrinsics." Category="shani">
<EnumValue Name="false" DisplayName="No" />
<EnumValue Name="true" DisplayName="Yes" />
</EnumProperty>
<EnumProperty Name="Option-neon" DisplayName="Enable ARM Neon Intrinsics" Description="Use ARM Neon intrinsics." Category="neon">
<EnumValue Name="false" DisplayName="No" />
<EnumValue Name="true" DisplayName="Yes" />
</EnumProperty>
</Rule>
</ProjectSchemaDefinitions>
36 changes: 30 additions & 6 deletions builds/msvc/vs2022/libbitcoin-system/libbitcoin-system.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,16 @@
<EnablePREfast>false</EnablePREfast>
<!-- WITH_ICU always defined in Visual Studio builds. -->
<!-- NOMINMAX enables use of std::min/max without conflict. -->
<!-- BOOST_EXCEPTION_DISABLE must be set here to be captured by all includes. -->
<!-- WIN32_LEAN_AND_MEAN avoids inclusion of certain headers, winsock.h conflicts with boost and protocol use of winsock2.h. -->
<PreprocessorDefinitions>WITH_ICU;WIN32_LEAN_AND_MEAN;NOMINMAX;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(ConfigurationType)' == 'DynamicLibrary'">BC_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(ConfigurationType)' == 'StaticLibrary'">BC_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<!-- Enable use of CPU intrinsics. -->
<PreprocessorDefinitions Condition="'$(Option-avx2)' == 'true'">WITH_AVX2;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Option-sse41)' == 'true'">WITH_SSE41;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Option-shani)' == 'true'">WITH_SHANI;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Option-sse4)' == 'true'">WITH_SSE4;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Option-neon)' == 'true'">WITH_NEON;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Option-avx512)' == 'true'">WITH_AVX512;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Option-avx2)' == 'true'">WITH_AVX2;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Option-sse41)' == 'true'">WITH_SSE41;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Option-shani)' == 'true'">WITH_SHANI;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Option-neon)' == 'true'">WITH_NEON;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>

Expand All @@ -50,10 +49,35 @@
<PropertyGroup Condition="'$(DefaultLinkage)' == 'static'">
<Linkage-secp256k1>static</Linkage-secp256k1>
</PropertyGroup>

<!-- Options -->

<!-- These create non-portability. -->
<!-- These will compile to the target regardless of the compiling platform. -->
<!-- That will result in a crash of test/executable execution if mismatched. -->
<PropertyGroup>
<Option-avx512>false</Option-avx512>
<Option-avx2>true</Option-avx2>
<Option-sse41>true</Option-sse41>
<Option-shani>false</Option-shani>
<Option-neon>false</Option-neon>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<!-- order matters -->
<EnableEnhancedInstructionSet Condition="'$(Option-avx2)' == 'true'">AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
<EnableEnhancedInstructionSet Condition="'$(Option-avx512)' == 'true'">AdvancedVectorExtensions512</EnableEnhancedInstructionSet>
</ClCompile>
</ItemDefinitionGroup>

<!-- Messages -->

<Target Name="OptionInfo" BeforeTargets="PrepareForBuild">
<Message Text="Option-avx512 : $(Option-avx512)" Importance="high"/>
<Message Text="Option-avx2 : $(Option-avx2)" Importance="high"/>
<Message Text="Option-sse41 : $(Option-sse41)" Importance="high"/>
<Message Text="Option-shani : $(Option-shani)" Importance="high"/>
<Message Text="Option-neon : $(Option-neon)" Importance="high"/>
</Target>

<Target Name="LinkageInfo" BeforeTargets="PrepareForBuild">
Expand Down
18 changes: 9 additions & 9 deletions builds/msvc/vs2022/libbitcoin-system/libbitcoin-system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@
<ProjectSchemaDefinitions xmlns="clr-namespace:Microsoft.Build.Framework.XamlTypes;assembly=Microsoft.Build.Framework">
<Rule Name="libbitcoin-system-uiextension" PageTemplate="tool" DisplayName="Bitcoin System Options" SwitchPrefix="/" Order="1">
<Rule.Categories>
<Category Name="avx512" DisplayName="avx512" />
<Category Name="avx2" DisplayName="avx2" />
<Category Name="sse41" DisplayName="sse41" />
<Category Name="shani" DisplayName="shani" />
<Category Name="sse4" DisplayName="sse4" />
<Category Name="neon" DisplayName="neon" />
</Rule.Categories>
<Rule.DataSource>
<DataSource Persistence="ProjectFile" ItemType="" />
</Rule.DataSource>
<EnumProperty Name="Option-avx512" DisplayName="Enable AVX512 Intrinsics" Description="Use AVX512 intrinsics." Category="avx512">
<EnumValue Name="false" DisplayName="No" />
<EnumValue Name="true" DisplayName="Yes" />
</EnumProperty>
<EnumProperty Name="Option-avx2" DisplayName="Enable AVX2 Intrinsics" Description="Use AVX2 intrinsics." Category="avx2">
<EnumValue Name="" DisplayName="No" />
<EnumValue Name="false" DisplayName="No" />
<EnumValue Name="true" DisplayName="Yes" />
</EnumProperty>
<EnumProperty Name="Option-sse41" DisplayName="Enable SSE4.1 Intrinsics" Description="Use SSE4.1 intrinsics." Category="sse41">
<EnumValue Name="" DisplayName="No" />
<EnumValue Name="false" DisplayName="No" />
<EnumValue Name="true" DisplayName="Yes" />
</EnumProperty>
<EnumProperty Name="Option-shani" DisplayName="Enable SHA Native Intrinsics" Description="Use SHA native intrinsics." Category="shani">
<EnumValue Name="" DisplayName="No" />
<EnumValue Name="false" DisplayName="No" />
<EnumValue Name="true" DisplayName="Yes" />
</EnumProperty>
<EnumProperty Name="Option-neon" DisplayName="Enable ARM Neon Intrinsics" Description="Use ARM Neon intrinsics." Category="neon">
<EnumValue Name="" DisplayName="No" />
<EnumValue Name="true" DisplayName="Yes" />
</EnumProperty>
<EnumProperty Name="Option-sse4" DisplayName="Enable SSE4" Description="Use SSE4 intrinsics." Category="sse4">
<EnumValue Name="" DisplayName="No" />
<EnumValue Name="false" DisplayName="No" />
<EnumValue Name="true" DisplayName="Yes" />
</EnumProperty>
</Rule>
Expand Down
26 changes: 8 additions & 18 deletions include/bitcoin/system/have.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,26 +132,16 @@
/// All require runtime evaluation, as the binary is portable across XCPUs.
#if defined(HAVE_XCPU)
// TODO: CLANG/GCC compile test and set -msse4 -mavx2 -mavx512f -msha.
// TODO: if set also set these WITH_ symbols, picked up here.
#if defined(HAVE_CLANG) || defined(HAVE_GNUC)
#if defined (WITH_SSE4)
#define HAVE_SSE4
#endif
#if defined (WITH_AVX2)
#define HAVE_AVX2
#endif
#if defined (WITH_AVX512)
#define HAVE_AVX512
#endif
#if defined (WITH_SHANI)
#define HAVE_SHANI
#endif
#if defined (WITH_AVX512)
#define HAVE_AVX512
#endif
// Always available without platform test or build configuration.
#if defined(HAVE_MSC)
#define HAVE_SSE4
#if defined (WITH_AVX2)
#define HAVE_AVX2
#define HAVE_AVX512
#endif
#if defined (WITH_SSE41)
#define HAVE_SSE41
#endif
#if defined (WITH_SHANI)
#define HAVE_SHANI
#endif
#endif
Expand Down
46 changes: 8 additions & 38 deletions include/bitcoin/system/intrinsics/haves.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,9 @@ BC_PUSH_WARNING(USE_CONSTEXPR_FOR_FUNCTION)

/// Constant symbols for compiled intrinsics interfaces.
/// ---------------------------------------------------------------------------
// sse41a (assembly) optimization is implemented without assembly.

// TODO: unclear if there is a necessary x64 limitation.
#if defined(HAVE_X64) && defined(HAVE_XASSEMBLY)
constexpr auto with_sse41a = true;
#else
constexpr auto with_sse41a = false;
#endif
#if defined(HAVE_SSE4)
#if defined(HAVE_SSE41)
constexpr auto with_sse41 = true;
#else
constexpr auto with_sse41 = false;
Expand Down Expand Up @@ -173,19 +168,6 @@ inline bool try_sse41() NOEXCEPT
return false;
}

inline bool try_sse41a() NOEXCEPT
{
// SSE41a implies assembly, with no need for SSE41 intrinsics.
if constexpr (with_sse41a)
{
uint32_t eax{}, ebx{}, ecx{}, edx{};
return get_cpu(eax, ebx, ecx, edx, cpu1_0::leaf, cpu1_0::subleaf)
&& get_bit<cpu1_0::sse41_ecx_bit>(ecx); // SSE4.1
}
else
return false;
}

constexpr bool try_neon() NOEXCEPT
{
if constexpr (with_neon)
Expand All @@ -199,44 +181,32 @@ constexpr bool try_neon() NOEXCEPT

/// Runtime tests for Intel SIMD, and ARM SIMD (Neon) availability.
/// ---------------------------------------------------------------------------
/// Thread local statics introduce a guard, not ideal for excessive iteration.
/// But no performance impact measured in sha except minor impact to merkle.
/// These keep binary portable, otherwise can reply on "with" symbols.
/// TODO: evaluate performance impact of removing the thread statics.

inline bool have_shani() NOEXCEPT
{
static auto enable = try_shani();
return enable;
return try_shani();
}

inline bool have_avx512() NOEXCEPT
{
static auto enable = try_avx512();
return enable;
return try_avx512();
}

inline bool have_avx2() NOEXCEPT
{
static auto enable = try_avx2();
return enable;
return try_avx2();
}

inline bool have_sse41() NOEXCEPT
{
static auto enable = try_sse41();
return enable;
}

inline bool have_sse41a() NOEXCEPT
{
static auto enable = try_sse41a();
return enable;
return try_sse41();
}

inline bool have_neon() NOEXCEPT
{
static auto enable = try_neon();
return enable;
return try_neon();
}

/// ---------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/system/intrinsics/xcpu/defines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
// These are not defined for 32 bit bit builds.
// This presently precludes sha512 vectorization on x32 builds.
#if defined(HAVE_X32)
#if defined(HAVE_SSE4)
#if defined(HAVE_SSE41)
inline uint64_t _mm_extract_epi64(auto, auto) NOEXCEPT
{
return {};
Expand Down Expand Up @@ -111,7 +111,7 @@ inline uint64_t _mm512_extract_epi64(auto a, auto Lane) NOEXCEPT
BC_POP_WARNING()
#endif

#if !defined(HAVE_SSE4)
#if !defined(HAVE_SSE41)
#define mm_and_si128(a, b) (a)
#define mm_or_si128(a, b) (a)
#define mm_xor_si128(a, b) (a)
Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/system/intrinsics/xcpu/functional_128.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
namespace libbitcoin {
namespace system {

#if defined(HAVE_SSE4)
#if defined(HAVE_SSE41)

using xint128_t = __m128i;

Expand Down Expand Up @@ -277,7 +277,7 @@ INLINE xint128_t byteswap(xint128_t a) NOEXCEPT
// Symbol is defined but not usable as an integer.
using xint128_t = std_array<uint8_t, bytes<128>>;

#endif // HAVE_SSE4
#endif // HAVE_SSE41

} // namespace system
} // namespace libbitcoin
Expand Down
Loading

0 comments on commit 2e886ee

Please sign in to comment.