cpu_id_check.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include <util/system/compat.h>
  2. #include <util/system/compiler.h>
  3. #include <util/system/cpu_id.h>
  4. #include <util/system/platform.h>
  5. #define Y_CPU_ID_ENUMERATE_STARTUP_CHECKS(F) \
  6. F(SSE42) \
  7. F(PCLMUL) \
  8. F(AES) \
  9. F(AVX) \
  10. F(AVX2) \
  11. F(FMA)
  12. namespace {
  13. [[noreturn]] void ReportISAError(const char* isa) {
  14. err(-1, "This program was compiled for %s which is not supported on your system, exiting...", isa);
  15. }
  16. #define Y_DEF_NAME(X) \
  17. void Assert##X() noexcept { \
  18. if (!NX86::Have##X()) { \
  19. ReportISAError(#X); \
  20. } \
  21. }
  22. Y_CPU_ID_ENUMERATE_STARTUP_CHECKS(Y_DEF_NAME)
  23. #undef Y_DEF_NAME
  24. class TBuildCpuChecker {
  25. public:
  26. TBuildCpuChecker() {
  27. Check();
  28. }
  29. private:
  30. void Check() const noexcept {
  31. #if defined(_fma_)
  32. AssertFMA();
  33. #elif defined(_avx2_)
  34. AssertAVX2();
  35. #elif defined(_avx_)
  36. AssertAVX();
  37. #elif defined(_aes_)
  38. AssertAES();
  39. #elif defined(_pclmul_)
  40. AssertPCLMUL();
  41. #elif defined(_sse4_2_)
  42. AssertSSE42();
  43. #endif
  44. #define Y_DEF_NAME(X) Y_UNUSED(Assert##X);
  45. Y_CPU_ID_ENUMERATE_STARTUP_CHECKS(Y_DEF_NAME)
  46. #undef Y_DEF_NAME
  47. }
  48. };
  49. }
  50. #if defined(_x86_) && !defined(_MSC_VER)
  51. #define INIT_PRIORITY(x) __attribute__((init_priority(x)))
  52. #else
  53. #define INIT_PRIORITY(x)
  54. #endif
  55. const static TBuildCpuChecker CheckCpuWeAreRunningOn INIT_PRIORITY(101) ;