Arch detection

This commit is contained in:
Dmitrii Kovalkov 2020-04-06 09:31:26 +02:00
parent 09bb9041ec
commit 9d875d8adb
2 changed files with 32 additions and 7 deletions

View File

@ -1,12 +1,37 @@
#include <Functions/TargetSpecific.h> #include <Functions/TargetSpecific.h>
#if defined(__GNUC__) || defined(__clang__)
# include <cpuid.h>
#else
# error "Only CLANG and GCC compilers are supported for dynamic dispatch"
#endif
namespace DB namespace DB
{ {
int GetSupportedArches() {
unsigned int eax, ebx, ecx, edx;
if (!__get_cpuid(1, &eax, &ebx, &ecx, &edx)) {
return 0;
}
int res = 0;
if (ecx & bit_SSE4_2)
res |= static_cast<int>(TargetArch::SSE4);
if ((ecx & bit_OSXSAVE) && (ecx & bit_AVX)) {
// TODO(dakovalkov): check XGETBV.
res |= static_cast<int>(TargetArch::AVX);
if (__get_cpuid(7, &eax, &ebx, &ecx, &edx) && (ebx & bit_AVX2)) {
res |= static_cast<int>(TargetArch::AVX2);
}
// TODO(dakovalkov): check AVX512 support.
}
return res;
}
bool IsArchSupported(TargetArch arch) bool IsArchSupported(TargetArch arch)
{ {
// TODO(dakovalkov): use cpuid static int arches = GetSupportedArches();
return arch != TargetArch::AVX512; return arch == TargetArch::Default || (arches & static_cast<int>(arch));
} }
} // namespace DB } // namespace DB

View File

@ -58,11 +58,11 @@ namespace DB
{ {
enum class TargetArch : int { enum class TargetArch : int {
Default, // Without any additional compiler options. Default = 0, // Without any additional compiler options.
SSE4, SSE4 = (1 << 0),
AVX, AVX = (1 << 1),
AVX2, AVX2 = (1 << 2),
AVX512, AVX512 = (1 << 3),
}; };
// Runtime detection. // Runtime detection.