mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-29 11:02:08 +00:00
Arch detection
This commit is contained in:
parent
09bb9041ec
commit
9d875d8adb
@ -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
|
||||||
|
@ -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.
|
||||||
|
Loading…
Reference in New Issue
Block a user