ClickHouse/src/Common/TargetSpecific.cpp

46 lines
1.2 KiB
C++
Raw Normal View History

2022-04-04 12:07:05 +00:00
#include <Common/TargetSpecific.h>
2020-04-02 13:48:14 +00:00
#include <Common/CpuId.h>
2020-04-06 07:31:26 +00:00
namespace DB
2020-04-02 13:48:14 +00:00
{
2020-06-21 18:47:16 +00:00
UInt32 getSupportedArchs()
2020-05-16 06:59:08 +00:00
{
UInt32 result = 0;
if (Cpu::CpuFlagsCache::have_SSE42)
result |= static_cast<UInt32>(TargetArch::SSE42);
if (Cpu::CpuFlagsCache::have_AVX)
result |= static_cast<UInt32>(TargetArch::AVX);
if (Cpu::CpuFlagsCache::have_AVX2)
result |= static_cast<UInt32>(TargetArch::AVX2);
if (Cpu::CpuFlagsCache::have_AVX512F)
result |= static_cast<UInt32>(TargetArch::AVX512F);
2022-05-27 17:54:11 +00:00
if (Cpu::CpuFlagsCache::have_AVX512BW)
2022-05-31 19:41:10 +00:00
result |= static_cast<UInt32>(TargetArch::AVX512BW);
return result;
2020-04-06 07:31:26 +00:00
}
2020-06-21 18:47:16 +00:00
bool isArchSupported(TargetArch arch)
2020-04-02 13:48:14 +00:00
{
2020-06-21 18:47:16 +00:00
static UInt32 arches = getSupportedArchs();
2020-05-16 06:59:08 +00:00
return arch == TargetArch::Default || (arches & static_cast<UInt32>(arch));
2020-04-02 13:48:14 +00:00
}
2020-06-21 18:47:16 +00:00
String toString(TargetArch arch)
2020-05-15 10:10:34 +00:00
{
2020-05-16 06:59:08 +00:00
switch (arch)
{
2020-05-15 10:10:34 +00:00
case TargetArch::Default: return "default";
case TargetArch::SSE42: return "sse42";
2020-05-15 10:10:34 +00:00
case TargetArch::AVX: return "avx";
case TargetArch::AVX2: return "avx2";
2020-05-15 12:00:20 +00:00
case TargetArch::AVX512F: return "avx512f";
2022-05-27 17:54:11 +00:00
case TargetArch::AVX512BW: return "avx512bw";
2020-05-15 10:10:34 +00:00
}
__builtin_unreachable();
}
2020-05-16 06:59:08 +00:00
}