Optimizations.cs 4.5 KB

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