1
0

mptCPU.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * mptCPU.h
  3. * --------
  4. * Purpose: CPU feature detection.
  5. * Notes : (currently none)
  6. * Authors: OpenMPT Devs
  7. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  8. */
  9. #pragma once
  10. #include "openmpt/all/BuildSettings.hpp"
  11. OPENMPT_NAMESPACE_BEGIN
  12. namespace CPU
  13. {
  14. namespace feature {
  15. inline constexpr uint32 lm = 0x00004; // Processor supports long mode (amd64)
  16. inline constexpr uint32 mmx = 0x00010; // Processor supports MMX instructions
  17. inline constexpr uint32 sse = 0x00100; // Processor supports SSE instructions
  18. inline constexpr uint32 sse2 = 0x00200; // Processor supports SSE2 instructions
  19. inline constexpr uint32 sse3 = 0x00400; // Processor supports SSE3 instructions
  20. inline constexpr uint32 ssse3 = 0x00800; // Processor supports SSSE3 instructions
  21. inline constexpr uint32 sse4_1 = 0x01000; // Processor supports SSE4.1 instructions
  22. inline constexpr uint32 sse4_2 = 0x02000; // Processor supports SSE4.2 instructions
  23. inline constexpr uint32 avx = 0x10000; // Processor supports AVX instructions
  24. inline constexpr uint32 avx2 = 0x20000; // Processor supports AVX2 instructions
  25. } // namespace feature
  26. #ifdef MPT_ENABLE_ARCH_INTRINSICS
  27. extern uint32 EnabledFeatures;
  28. struct Info
  29. {
  30. public:
  31. uint32 AvailableFeatures = 0;
  32. uint32 CPUID = 0;
  33. char VendorID[16+1] = {};
  34. char BrandID[4*4*3+1] = {};
  35. uint16 Family = 0;
  36. uint8 Model = 0;
  37. uint8 Stepping = 0;
  38. private:
  39. Info();
  40. public:
  41. static const Info & Get();
  42. };
  43. void EnableAvailableFeatures();
  44. struct AvailableFeaturesEnabler
  45. {
  46. AvailableFeaturesEnabler()
  47. {
  48. EnableAvailableFeatures();
  49. }
  50. };
  51. // enabled processor features for inline asm and intrinsics
  52. MPT_FORCEINLINE uint32 GetEnabledFeatures()
  53. {
  54. return EnabledFeatures;
  55. }
  56. MPT_FORCEINLINE bool HasFeatureSet(uint32 features)
  57. {
  58. return features == (GetEnabledFeatures() & features);
  59. }
  60. #endif // MPT_ENABLE_ARCH_INTRINSICS
  61. uint32 GetMinimumFeatures();
  62. } // namespace CPU
  63. OPENMPT_NAMESPACE_END