/ src / ARMeilleure / Optimizations.cs
Optimizations.cs
 1  namespace ARMeilleure
 2  {
 3      using Arm64HardwareCapabilities = ARMeilleure.CodeGen.Arm64.HardwareCapabilities;
 4      using X86HardwareCapabilities = ARMeilleure.CodeGen.X86.HardwareCapabilities;
 5  
 6      public static class Optimizations
 7      {
 8          public static bool FastFP { get; set; } = true;
 9  
10          public static bool AllowLcqInFunctionTable { get; set; } = true;
11          public static bool UseUnmanagedDispatchLoop { get; set; } = true;
12  
13          public static bool UseAdvSimdIfAvailable { get; set; } = true;
14          public static bool UseArm64AesIfAvailable { get; set; } = true;
15          public static bool UseArm64PmullIfAvailable { get; set; } = true;
16  
17          public static bool UseSseIfAvailable { get; set; } = true;
18          public static bool UseSse2IfAvailable { get; set; } = true;
19          public static bool UseSse3IfAvailable { get; set; } = true;
20          public static bool UseSsse3IfAvailable { get; set; } = true;
21          public static bool UseSse41IfAvailable { get; set; } = true;
22          public static bool UseSse42IfAvailable { get; set; } = true;
23          public static bool UsePopCntIfAvailable { get; set; } = true;
24          public static bool UseAvxIfAvailable { get; set; } = true;
25          public static bool UseAvx512FIfAvailable { get; set; } = true;
26          public static bool UseAvx512VlIfAvailable { get; set; } = true;
27          public static bool UseAvx512BwIfAvailable { get; set; } = true;
28          public static bool UseAvx512DqIfAvailable { get; set; } = true;
29          public static bool UseF16cIfAvailable { get; set; } = true;
30          public static bool UseFmaIfAvailable { get; set; } = true;
31          public static bool UseAesniIfAvailable { get; set; } = true;
32          public static bool UsePclmulqdqIfAvailable { get; set; } = true;
33          public static bool UseShaIfAvailable { get; set; } = true;
34          public static bool UseGfniIfAvailable { get; set; } = true;
35  
36          public static bool ForceLegacySse
37          {
38              get => X86HardwareCapabilities.ForceLegacySse;
39              set => X86HardwareCapabilities.ForceLegacySse = value;
40          }
41  
42  #pragma warning disable IDE0055 // Disable formatting
43          internal static bool UseAdvSimd    => UseAdvSimdIfAvailable    && Arm64HardwareCapabilities.SupportsAdvSimd;
44          internal static bool UseArm64Aes   => UseArm64AesIfAvailable   && Arm64HardwareCapabilities.SupportsAes;
45          internal static bool UseArm64Pmull => UseArm64PmullIfAvailable && Arm64HardwareCapabilities.SupportsPmull;
46  
47          internal static bool UseSse       => UseSseIfAvailable       && X86HardwareCapabilities.SupportsSse;
48          internal static bool UseSse2      => UseSse2IfAvailable      && X86HardwareCapabilities.SupportsSse2;
49          internal static bool UseSse3      => UseSse3IfAvailable      && X86HardwareCapabilities.SupportsSse3;
50          internal static bool UseSsse3     => UseSsse3IfAvailable     && X86HardwareCapabilities.SupportsSsse3;
51          internal static bool UseSse41     => UseSse41IfAvailable     && X86HardwareCapabilities.SupportsSse41;
52          internal static bool UseSse42     => UseSse42IfAvailable     && X86HardwareCapabilities.SupportsSse42;
53          internal static bool UsePopCnt    => UsePopCntIfAvailable    && X86HardwareCapabilities.SupportsPopcnt;
54          internal static bool UseAvx       => UseAvxIfAvailable       && X86HardwareCapabilities.SupportsAvx && !ForceLegacySse;
55          internal static bool UseAvx512F   => UseAvx512FIfAvailable   && X86HardwareCapabilities.SupportsAvx512F && !ForceLegacySse;
56          internal static bool UseAvx512Vl  => UseAvx512VlIfAvailable  && X86HardwareCapabilities.SupportsAvx512Vl && !ForceLegacySse;
57          internal static bool UseAvx512Bw  => UseAvx512BwIfAvailable  && X86HardwareCapabilities.SupportsAvx512Bw && !ForceLegacySse;
58          internal static bool UseAvx512Dq  => UseAvx512DqIfAvailable  && X86HardwareCapabilities.SupportsAvx512Dq && !ForceLegacySse;
59          internal static bool UseF16c      => UseF16cIfAvailable      && X86HardwareCapabilities.SupportsF16c;
60          internal static bool UseFma       => UseFmaIfAvailable       && X86HardwareCapabilities.SupportsFma;
61          internal static bool UseAesni     => UseAesniIfAvailable     && X86HardwareCapabilities.SupportsAesni;
62          internal static bool UsePclmulqdq => UsePclmulqdqIfAvailable && X86HardwareCapabilities.SupportsPclmulqdq;
63          internal static bool UseSha       => UseShaIfAvailable       && X86HardwareCapabilities.SupportsSha;
64          internal static bool UseGfni      => UseGfniIfAvailable      && X86HardwareCapabilities.SupportsGfni;
65  #pragma warning restore IDE0055
66  
67          internal static bool UseAvx512Ortho => UseAvx512F && UseAvx512Vl;
68          internal static bool UseAvx512OrthoFloat => UseAvx512Ortho && UseAvx512Dq;
69      }
70  }