mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 01:22:04 +00:00
Arch detection
This commit is contained in:
parent
09bb9041ec
commit
9d875d8adb
@ -1,12 +1,37 @@
|
||||
#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
|
||||
{
|
||||
|
||||
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)
|
||||
{
|
||||
// TODO(dakovalkov): use cpuid
|
||||
return arch != TargetArch::AVX512;
|
||||
static int arches = GetSupportedArches();
|
||||
return arch == TargetArch::Default || (arches & static_cast<int>(arch));
|
||||
}
|
||||
|
||||
} // namespace DB
|
||||
|
@ -58,11 +58,11 @@ namespace DB
|
||||
{
|
||||
|
||||
enum class TargetArch : int {
|
||||
Default, // Without any additional compiler options.
|
||||
SSE4,
|
||||
AVX,
|
||||
AVX2,
|
||||
AVX512,
|
||||
Default = 0, // Without any additional compiler options.
|
||||
SSE4 = (1 << 0),
|
||||
AVX = (1 << 1),
|
||||
AVX2 = (1 << 2),
|
||||
AVX512 = (1 << 3),
|
||||
};
|
||||
|
||||
// Runtime detection.
|
||||
|
Loading…
Reference in New Issue
Block a user