From df99a023ee1ae62a86a510a2c7c6e3f7a2f259f3 Mon Sep 17 00:00:00 2001 From: LDj3SNuD Date: Sat, 31 Oct 2020 05:43:05 +0100 Subject: [PATCH] Address comment. --- .../CodeGen/X86/HardwareCapabilities.cs | 60 ++++++++++++++----- ARMeilleure/Translation/PTC/Ptc.cs | 19 +----- appveyor.yml | 2 +- 3 files changed, 49 insertions(+), 32 deletions(-) diff --git a/ARMeilleure/CodeGen/X86/HardwareCapabilities.cs b/ARMeilleure/CodeGen/X86/HardwareCapabilities.cs index 6fac871d8..1c5f5702d 100644 --- a/ARMeilleure/CodeGen/X86/HardwareCapabilities.cs +++ b/ARMeilleure/CodeGen/X86/HardwareCapabilities.cs @@ -1,3 +1,4 @@ +using System; using System.Runtime.Intrinsics.X86; namespace ARMeilleure.CodeGen.X86 @@ -6,23 +7,54 @@ namespace ARMeilleure.CodeGen.X86 { static HardwareCapabilities() { - (_, _, int ecx, _) = X86Base.CpuId(0x00000001, 0x00000000); + if (!X86Base.IsSupported) + { + throw new Exception(); + } - SupportsF16c = ((ecx >> 29) & 1) != 0; + (_, _, int ecx, int edx) = X86Base.CpuId(0x00000001, 0x00000000); + + FeatureInfoEdx = (FeatureFlagsEdx)edx; + FeatureInfoEcx = (FeatureFlagsEcx)ecx; } - public static bool SupportsSse => Sse.IsSupported; - public static bool SupportsSse2 => Sse2.IsSupported; - public static bool SupportsSse3 => Sse3.IsSupported; - public static bool SupportsSsse3 => Ssse3.IsSupported; - public static bool SupportsSse41 => Sse41.IsSupported; - public static bool SupportsSse42 => Sse42.IsSupported; - public static bool SupportsPclmulqdq => Pclmulqdq.IsSupported; - public static bool SupportsFma => Fma.IsSupported; - public static bool SupportsPopcnt => Popcnt.IsSupported; - public static bool SupportsAesni => Aes.IsSupported; - public static bool SupportsAvx => Avx.IsSupported; - public static bool SupportsF16c; + [Flags] + public enum FeatureFlagsEdx + { + Sse = 1 << 25, + Sse2 = 1 << 26 + } + + [Flags] + public enum FeatureFlagsEcx + { + Sse3 = 1 << 0, + Pclmulqdq = 1 << 1, + Ssse3 = 1 << 9, + Fma = 1 << 12, + Sse41 = 1 << 19, + Sse42 = 1 << 20, + Popcnt = 1 << 23, + Aes = 1 << 25, + Avx = 1 << 28, + F16c = 1 << 29 + } + + public static FeatureFlagsEdx FeatureInfoEdx { get; } + public static FeatureFlagsEcx FeatureInfoEcx { get; } + + public static bool SupportsSse => FeatureInfoEdx.HasFlag(FeatureFlagsEdx.Sse); + public static bool SupportsSse2 => FeatureInfoEdx.HasFlag(FeatureFlagsEdx.Sse2); + public static bool SupportsSse3 => FeatureInfoEcx.HasFlag(FeatureFlagsEcx.Sse3); + public static bool SupportsPclmulqdq => FeatureInfoEcx.HasFlag(FeatureFlagsEcx.Pclmulqdq); + public static bool SupportsSsse3 => FeatureInfoEcx.HasFlag(FeatureFlagsEcx.Ssse3); + public static bool SupportsFma => FeatureInfoEcx.HasFlag(FeatureFlagsEcx.Fma); + public static bool SupportsSse41 => FeatureInfoEcx.HasFlag(FeatureFlagsEcx.Sse41); + public static bool SupportsSse42 => FeatureInfoEcx.HasFlag(FeatureFlagsEcx.Sse42); + public static bool SupportsPopcnt => FeatureInfoEcx.HasFlag(FeatureFlagsEcx.Popcnt); + public static bool SupportsAesni => FeatureInfoEcx.HasFlag(FeatureFlagsEcx.Aes); + public static bool SupportsAvx => FeatureInfoEcx.HasFlag(FeatureFlagsEcx.Avx); + public static bool SupportsF16c => FeatureInfoEcx.HasFlag(FeatureFlagsEcx.F16c); public static bool ForceLegacySse { get; set; } diff --git a/ARMeilleure/Translation/PTC/Ptc.cs b/ARMeilleure/Translation/PTC/Ptc.cs index 283cbd06f..3baef401a 100644 --- a/ARMeilleure/Translation/PTC/Ptc.cs +++ b/ARMeilleure/Translation/PTC/Ptc.cs @@ -21,7 +21,7 @@ namespace ARMeilleure.Translation.PTC { private const string HeaderMagic = "PTChd"; - private const int InternalVersion = 1273; //! To be incremented manually for each change to the ARMeilleure project. + private const int InternalVersion = 1650; //! To be incremented manually for each change to the ARMeilleure project. private const string ActualDir = "0"; private const string BackupDir = "1"; @@ -646,22 +646,7 @@ namespace ARMeilleure.Translation.PTC private static ulong GetFeatureInfo() { - ulong featureInfo = 0ul; - - featureInfo |= (HardwareCapabilities.SupportsSse3 ? 1ul : 0ul) << 0; - featureInfo |= (HardwareCapabilities.SupportsPclmulqdq ? 1ul : 0ul) << 1; - featureInfo |= (HardwareCapabilities.SupportsSsse3 ? 1ul : 0ul) << 9; - featureInfo |= (HardwareCapabilities.SupportsFma ? 1ul : 0ul) << 12; - featureInfo |= (HardwareCapabilities.SupportsSse41 ? 1ul : 0ul) << 19; - featureInfo |= (HardwareCapabilities.SupportsSse42 ? 1ul : 0ul) << 20; - featureInfo |= (HardwareCapabilities.SupportsPopcnt ? 1ul : 0ul) << 23; - featureInfo |= (HardwareCapabilities.SupportsAesni ? 1ul : 0ul) << 25; - featureInfo |= (HardwareCapabilities.SupportsAvx ? 1ul : 0ul) << 28; - featureInfo |= (HardwareCapabilities.SupportsF16c ? 1ul : 0ul) << 29; - featureInfo |= (HardwareCapabilities.SupportsSse ? 1ul : 0ul) << 57; - featureInfo |= (HardwareCapabilities.SupportsSse2 ? 1ul : 0ul) << 58; - - return featureInfo; + return (ulong)HardwareCapabilities.FeatureInfoEdx << 32 | (uint)HardwareCapabilities.FeatureInfoEcx; } private struct Header diff --git a/appveyor.yml b/appveyor.yml index 1bf99a049..67d923b55 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,7 +2,7 @@ version: 1.0.{build} branches: only: - master -image: Visual Studio 2019 +image: Visual Studio 2019 Preview environment: appveyor_dotnet_runtime: net5.0 matrix: