OSDN Git Service

Enable the GUI to use the "AVX2" binary, if supported on the current machine.
authorLoRd_MuldeR <mulder2@gmx.de>
Mon, 18 Apr 2022 16:52:55 +0000 (18:52 +0200)
committerLoRd_MuldeR <mulder2@gmx.de>
Mon, 18 Apr 2022 16:52:55 +0000 (18:52 +0200)
Slunk.sln
frontend/SlunkCrypt.vcxproj
gui/Process/ExecutableHelper.cs
gui/SlunkCryptGUI.xaml.cs
gui/Utilities/CPUFeatures.cs
libslunkcrypt/libSlunkCrypt.vcxproj
mk-release.cmd

index dfc6e18..2bac0ad 100644 (file)
--- 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
index 457d49b..8c33d19 100644 (file)
     <LinkIncremental>false</LinkIncremental>
     <OutDir>$(SolutionDir)bin\static\</OutDir>
     <IntDir>$(SolutionDir)obj\$(Configuration)\$(PlatformShortName)\$(ProjectName)\</IntDir>
-    <TargetName>slunkcrypt-cli-x64-sse2</TargetName>
+    <TargetName>slunkcrypt-cli-avx2</TargetName>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_DLL|x64'">
     <LinkIncremental>false</LinkIncremental>
       <FloatingPointModel>Fast</FloatingPointModel>
       <DisableSpecificWarnings>4706;4204</DisableSpecificWarnings>
       <CreateHotpatchableImage>false</CreateHotpatchableImage>
-      <EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
+      <EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
     </ClCompile>
     <Link>
       <SubSystem>Console</SubSystem>
index 11e4d2b..a318e1d 100644 (file)
@@ -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)
             {
-                Trace.Assert(executableFile != null);
-                return executableFile;
+                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.sse2 && CheckExecutableFile(ref executableFile, appBaseDirectory, "sse2"))
+            if (cpuFeatures.hasSSE2 && 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;
index 5d8249f..44039db 100644 (file)
@@ -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();
index bdf035e..59870ee 100644 (file)
@@ -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> cpuFeatures = new Lazy<CPUFeatures>(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*/
             }
         }
     }
index 95095aa..01746df 100644 (file)
     <LinkIncremental>false</LinkIncremental>
     <OutDir>$(SolutionDir)bin\static\</OutDir>
     <IntDir>$(SolutionDir)obj\$(Configuration)\$(PlatformShortName)\$(ProjectName)\</IntDir>
-    <TargetName>libslunkcrypt-1-x64-sse2</TargetName>
+    <TargetName>libslunkcrypt-1-avx2</TargetName>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_DLL|x64'">
     <LinkIncremental>false</LinkIncremental>
       <FloatingPointModel>Fast</FloatingPointModel>
       <DisableSpecificWarnings>4706;4204</DisableSpecificWarnings>
       <CreateHotpatchableImage>false</CreateHotpatchableImage>
-      <EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
+      <EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
     </ClCompile>
     <Link>
       <SubSystem>
index a232499..019cecc 100644 (file)
@@ -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
        )
 )