From e78b1444139f499264fa6619ddee57e6a2203651 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Mon, 18 Apr 2022 18:52:55 +0200 Subject: [PATCH] Enable the GUI to use the "AVX2" binary, if supported on the current machine. --- Slunk.sln | 6 ++++-- frontend/SlunkCrypt.vcxproj | 4 ++-- gui/Process/ExecutableHelper.cs | 22 +++++++++++++++------- gui/SlunkCryptGUI.xaml.cs | 2 +- gui/Utilities/CPUFeatures.cs | 15 ++++++++++----- libslunkcrypt/libSlunkCrypt.vcxproj | 4 ++-- mk-release.cmd | 22 ++++++++++------------ 7 files changed, 44 insertions(+), 31 deletions(-) diff --git a/Slunk.sln b/Slunk.sln index dfc6e18..2bac0ad 100644 --- a/Slunk.sln +++ b/Slunk.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30523.141 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.1913 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SlunkCrypt", "frontend\SlunkCrypt.vcxproj", "{86D28793-713E-4CEC-9686-335514AC5EF0}" EndProject @@ -34,6 +34,7 @@ Global {86D28793-713E-4CEC-9686-335514AC5EF0}.Release_DLL|x86.ActiveCfg = Release_DLL|Win32 {86D28793-713E-4CEC-9686-335514AC5EF0}.Release_DLL|x86.Build.0 = Release_DLL|Win32 {86D28793-713E-4CEC-9686-335514AC5EF0}.Release_SSE2|x64.ActiveCfg = Release_SSE2|x64 + {86D28793-713E-4CEC-9686-335514AC5EF0}.Release_SSE2|x64.Build.0 = Release_SSE2|x64 {86D28793-713E-4CEC-9686-335514AC5EF0}.Release_SSE2|x86.ActiveCfg = Release_SSE2|Win32 {86D28793-713E-4CEC-9686-335514AC5EF0}.Release_SSE2|x86.Build.0 = Release_SSE2|Win32 {86D28793-713E-4CEC-9686-335514AC5EF0}.Release|x64.ActiveCfg = Release|x64 @@ -49,6 +50,7 @@ Global {A4A3879C-BD2C-4304-AF66-7349CEF7E4C0}.Release_DLL|x86.ActiveCfg = Release_DLL|Win32 {A4A3879C-BD2C-4304-AF66-7349CEF7E4C0}.Release_DLL|x86.Build.0 = Release_DLL|Win32 {A4A3879C-BD2C-4304-AF66-7349CEF7E4C0}.Release_SSE2|x64.ActiveCfg = Release_SSE2|x64 + {A4A3879C-BD2C-4304-AF66-7349CEF7E4C0}.Release_SSE2|x64.Build.0 = Release_SSE2|x64 {A4A3879C-BD2C-4304-AF66-7349CEF7E4C0}.Release_SSE2|x86.ActiveCfg = Release_SSE2|Win32 {A4A3879C-BD2C-4304-AF66-7349CEF7E4C0}.Release_SSE2|x86.Build.0 = Release_SSE2|Win32 {A4A3879C-BD2C-4304-AF66-7349CEF7E4C0}.Release|x64.ActiveCfg = Release|x64 diff --git a/frontend/SlunkCrypt.vcxproj b/frontend/SlunkCrypt.vcxproj index 457d49b..8c33d19 100644 --- a/frontend/SlunkCrypt.vcxproj +++ b/frontend/SlunkCrypt.vcxproj @@ -203,7 +203,7 @@ false $(SolutionDir)bin\static\ $(SolutionDir)obj\$(Configuration)\$(PlatformShortName)\$(ProjectName)\ - slunkcrypt-cli-x64-sse2 + slunkcrypt-cli-avx2 false @@ -389,7 +389,7 @@ Fast 4706;4204 false - StreamingSIMDExtensions2 + AdvancedVectorExtensions2 Console diff --git a/gui/Process/ExecutableHelper.cs b/gui/Process/ExecutableHelper.cs index 11e4d2b..a318e1d 100644 --- a/gui/Process/ExecutableHelper.cs +++ b/gui/Process/ExecutableHelper.cs @@ -35,17 +35,25 @@ namespace com.muldersoft.slunkcrypt.gui.process FileStream executableFile = null; string appBaseDirectory = AppDomain.CurrentDomain.BaseDirectory; CPUFeatures cpuFeatures = CPUFeatures.Features; - if (cpuFeatures.x64 && CheckExecutableFile(ref executableFile, appBaseDirectory, "x64")) + if (cpuFeatures.x64) + { + if (cpuFeatures.hasAVX2 && CheckExecutableFile(ref executableFile, appBaseDirectory, "avx2")) + { + Trace.Assert(executableFile != null); + return executableFile; + } + else if (CheckExecutableFile(ref executableFile, appBaseDirectory, "x64")) + { + Trace.Assert(executableFile != null); + return executableFile; + } + } + if (cpuFeatures.hasSSE2 && CheckExecutableFile(ref executableFile, appBaseDirectory, "sse2")) { Trace.Assert(executableFile != null); return executableFile; } - if (cpuFeatures.sse2 && CheckExecutableFile(ref executableFile, appBaseDirectory, "sse2")) - { - Trace.Assert(executableFile != null); - return executableFile; - } - if (CheckExecutableFile(ref executableFile, appBaseDirectory, "i686")) + else if (CheckExecutableFile(ref executableFile, appBaseDirectory, "i686")) { Trace.Assert(executableFile != null); return executableFile; diff --git a/gui/SlunkCryptGUI.xaml.cs b/gui/SlunkCryptGUI.xaml.cs index 5d8249f..44039db 100644 --- a/gui/SlunkCryptGUI.xaml.cs +++ b/gui/SlunkCryptGUI.xaml.cs @@ -860,7 +860,7 @@ namespace com.muldersoft.slunkcrypt.gui .AppendLine(Environment.OSVersion.VersionString) .AppendLine(string.Format("Operating System Bitness: {0:D}, Process Bitness: {1:D}", Environment.Is64BitOperatingSystem ? 64 : 32, Environment.Is64BitProcess ? 64 : 32)) .AppendLine(".NET Runtime Version: " + Environment.Version) - .AppendLine(string.Format("CPU Count: {0:D}, Architecture: {1}, SSE2 Support: {2}", Environment.ProcessorCount, cpuFeatures.x64 ? "x64" : "x86", cpuFeatures.sse2 ? "Yes" : "No")) + .AppendLine(string.Format("CPU Count: {0:D}, Architecture: {1}, SSE2: {2}, AVX2: {3}", Environment.ProcessorCount, cpuFeatures.x64 ? "x64" : "x86", cpuFeatures.hasSSE2 ? "Yes" : "No", cpuFeatures.hasAVX2 ? "Yes" : "No")) .AppendLine() .AppendLine("Using “Silk” icons, by Mark James") .ToString(); diff --git a/gui/Utilities/CPUFeatures.cs b/gui/Utilities/CPUFeatures.cs index bdf035e..59870ee 100644 --- a/gui/Utilities/CPUFeatures.cs +++ b/gui/Utilities/CPUFeatures.cs @@ -11,7 +11,8 @@ namespace com.muldersoft.slunkcrypt.gui.process struct CPUFeatures { public readonly bool x64; - public readonly bool sse2; + public readonly bool hasSSE2; + public readonly bool hasAVX2; private static readonly Lazy cpuFeatures = new Lazy(DetectFeatures); @@ -20,21 +21,25 @@ namespace com.muldersoft.slunkcrypt.gui.process get { return cpuFeatures.Value; } } - public CPUFeatures(bool x64, bool sse2) + public CPUFeatures(bool x64, bool sse2, bool avx2) { this.x64 = x64; - this.sse2 = sse2; + this.hasSSE2 = sse2; + this.hasAVX2 = avx2; } private static CPUFeatures DetectFeatures() { try { - return new CPUFeatures(CPU.Architecture.Equals(CPUArchitecture.CPU_ARCH_X64), CPU.Capabilities.HasFlag(CPUCapabilities.CPU_SSE2)); + return new CPUFeatures( + CPU.Architecture.Equals(CPUArchitecture.CPU_ARCH_X64), + CPU.Capabilities.HasFlag(CPUCapabilities.CPU_SSE2), + CPU.Capabilities.HasFlag(CPUCapabilities.CPU_AVX2)); } catch { - return new CPUFeatures(false, false); /*fallback*/ + return new CPUFeatures(false, false, false); /*fallback*/ } } } diff --git a/libslunkcrypt/libSlunkCrypt.vcxproj b/libslunkcrypt/libSlunkCrypt.vcxproj index 95095aa..01746df 100644 --- a/libslunkcrypt/libSlunkCrypt.vcxproj +++ b/libslunkcrypt/libSlunkCrypt.vcxproj @@ -188,7 +188,7 @@ false $(SolutionDir)bin\static\ $(SolutionDir)obj\$(Configuration)\$(PlatformShortName)\$(ProjectName)\ - libslunkcrypt-1-x64-sse2 + libslunkcrypt-1-avx2 false @@ -382,7 +382,7 @@ Fast 4706;4204 false - StreamingSIMDExtensions2 + AdvancedVectorExtensions2 diff --git a/mk-release.cmd b/mk-release.cmd index a232499..019cecc 100644 --- a/mk-release.cmd +++ b/mk-release.cmd @@ -15,18 +15,16 @@ if not exist "%MSVC_PATH%\Auxiliary\Build\vcvarsall.bat" ( for %%p in (x86,x64) do ( call "%MSVC_PATH%\Auxiliary\Build\vcvarsall.bat" %%p for %%c in (Release,Release_SSE2) do ( - if not "%%p::%%c" == "x64::Release_SSE2" ( - %ECHO% white "\n------------------------------------------------------------------------------" - %ECHO% white "Clean [%%p:%%c]" - %ECHO% white "------------------------------------------------------------------------------\n" - MSBuild.exe /property:Configuration=%%c /property:Platform=%%p /target:Clean /verbosity:normal "%~dp0\Slunk.sln" - if not "!ERRORLEVEL!"=="0" goto:BuildFailed - %ECHO% white "\n------------------------------------------------------------------------------" - %ECHO% white "Compile [%%p:%%c]" - %ECHO% white "------------------------------------------------------------------------------\n" - MSBuild.exe /property:Configuration=%%c /property:Platform=%%p /target:Build /verbosity:normal "%~dp0\Slunk.sln" - if not "!ERRORLEVEL!"=="0" goto:BuildFailed - ) + %ECHO% white "\n------------------------------------------------------------------------------" + %ECHO% white "Clean [%%p:%%c]" + %ECHO% white "------------------------------------------------------------------------------\n" + MSBuild.exe /property:Configuration=%%c /property:Platform=%%p /target:Clean /verbosity:normal "%~dp0\Slunk.sln" + if not "!ERRORLEVEL!"=="0" goto:BuildFailed + %ECHO% white "\n------------------------------------------------------------------------------" + %ECHO% white "Compile [%%p:%%c]" + %ECHO% white "------------------------------------------------------------------------------\n" + MSBuild.exe /property:Configuration=%%c /property:Platform=%%p /target:Build /verbosity:normal "%~dp0\Slunk.sln" + if not "!ERRORLEVEL!"=="0" goto:BuildFailed ) )