diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/cpuid_check/cpu_id_check.cpp | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/cpuid_check/cpu_id_check.cpp')
-rw-r--r-- | library/cpp/cpuid_check/cpu_id_check.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/library/cpp/cpuid_check/cpu_id_check.cpp b/library/cpp/cpuid_check/cpu_id_check.cpp new file mode 100644 index 0000000000..f19a573567 --- /dev/null +++ b/library/cpp/cpuid_check/cpu_id_check.cpp @@ -0,0 +1,64 @@ +#include <util/system/compat.h> +#include <util/system/compiler.h> +#include <util/system/cpu_id.h> +#include <util/system/platform.h> + +#define Y_CPU_ID_ENUMERATE_STARTUP_CHECKS(F) \ + F(SSE42) \ + F(PCLMUL) \ + F(AES) \ + F(AVX) \ + F(AVX2) \ + F(FMA) + +namespace { + [[noreturn]] void ReportISAError(const char* isa) { + err(-1, "This program was compiled for %s which is not supported on your system, exiting...", isa); + } + +#define Y_DEF_NAME(X) \ + void Assert##X() noexcept { \ + if (!NX86::Have##X()) { \ + ReportISAError(#X); \ + } \ + } + + Y_CPU_ID_ENUMERATE_STARTUP_CHECKS(Y_DEF_NAME) +#undef Y_DEF_NAME + + class TBuildCpuChecker { + public: + TBuildCpuChecker() { + Check(); + } + + private: + void Check() const noexcept { +#if defined(_fma_) + AssertFMA(); +#elif defined(_avx2_) + AssertAVX2(); +#elif defined(_avx_) + AssertAVX(); +#elif defined(_aes_) + AssertAES(); +#elif defined(_pclmul_) + AssertPCLMUL(); +#elif defined(_sse4_2_) + AssertSSE42(); +#endif + +#define Y_DEF_NAME(X) Y_UNUSED(Assert##X); + Y_CPU_ID_ENUMERATE_STARTUP_CHECKS(Y_DEF_NAME) +#undef Y_DEF_NAME + } + }; +} + +#if defined(_x86_) && !defined(_MSC_VER) +#define INIT_PRIORITY(x) __attribute__((init_priority(x))) +#else +#define INIT_PRIORITY(x) +#endif + +const static TBuildCpuChecker CheckCpuWeAreRunningOn INIT_PRIORITY(101) ; |