HardwareCapabilities.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using ARMeilleure.IntermediateRepresentation;
  2. using ARMeilleure.Translation;
  3. namespace ARMeilleure.CodeGen.X86
  4. {
  5. static class HardwareCapabilities
  6. {
  7. private delegate ulong GetFeatureInfo();
  8. private static ulong _featureInfo;
  9. public static bool SupportsSse3 => (_featureInfo & (1UL << 0)) != 0;
  10. public static bool SupportsPclmulqdq => (_featureInfo & (1UL << 1)) != 0;
  11. public static bool SupportsSsse3 => (_featureInfo & (1UL << 9)) != 0;
  12. public static bool SupportsFma => (_featureInfo & (1UL << 12)) != 0;
  13. public static bool SupportsCx16 => (_featureInfo & (1UL << 13)) != 0;
  14. public static bool SupportsSse41 => (_featureInfo & (1UL << 19)) != 0;
  15. public static bool SupportsSse42 => (_featureInfo & (1UL << 20)) != 0;
  16. public static bool SupportsPopcnt => (_featureInfo & (1UL << 23)) != 0;
  17. public static bool SupportsAesni => (_featureInfo & (1UL << 25)) != 0;
  18. public static bool SupportsAvx => (_featureInfo & (1UL << 28)) != 0;
  19. public static bool SupportsF16c => (_featureInfo & (1UL << 29)) != 0;
  20. public static bool SupportsSse => (_featureInfo & (1UL << 32 + 25)) != 0;
  21. public static bool SupportsSse2 => (_featureInfo & (1UL << 32 + 26)) != 0;
  22. public static bool ForceLegacySse { get; set; }
  23. public static bool SupportsVexEncoding => SupportsAvx && !ForceLegacySse;
  24. static HardwareCapabilities()
  25. {
  26. EmitterContext context = new EmitterContext();
  27. Operand featureInfo = context.CpuId();
  28. context.Return(featureInfo);
  29. ControlFlowGraph cfg = context.GetControlFlowGraph();
  30. OperandType[] argTypes = new OperandType[0];
  31. GetFeatureInfo getFeatureInfo = Compiler.Compile<GetFeatureInfo>(
  32. cfg,
  33. argTypes,
  34. OperandType.I64,
  35. CompilerOptions.HighCq);
  36. _featureInfo = getFeatureInfo();
  37. }
  38. }
  39. }