1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
#include "cpu_features.h"
#include <volk/volk.h>
#include <string>
namespace cpu_features
{
cpu_features_t get_cpu_features()
{
std::string machine_string(volk_get_machine());
cpu_features_t f;
// X86 SSE
if (machine_string.find("sse2") != std::string::npos)
f.CPU_X86_SSE2 = true;
if (machine_string.find("sse3") != std::string::npos)
f.CPU_X86_SSE3 = f.CPU_X86_SSE2 = true;
if (machine_string.find("sse4_a") != std::string::npos)
f.CPU_X86_SSE4A = f.CPU_X86_SSE3 = f.CPU_X86_SSE2 = true;
if (machine_string.find("sse4_1") != std::string::npos)
f.CPU_X86_SSE41 = f.CPU_X86_SSE4A = f.CPU_X86_SSE3 = f.CPU_X86_SSE2 = true;
if (machine_string.find("sse4_2") != std::string::npos)
f.CPU_X86_SSE42 = f.CPU_X86_SSE41 = f.CPU_X86_SSE4A = f.CPU_X86_SSE3 = f.CPU_X86_SSE2 = true;
// X86 AVX
if (machine_string.find("avx") != std::string::npos)
f.CPU_X86_AVX = f.CPU_X86_SSE42 = f.CPU_X86_SSE41 = f.CPU_X86_SSE4A = f.CPU_X86_SSE3 = f.CPU_X86_SSE2 = true;
if (machine_string.find("avx2") != std::string::npos)
f.CPU_X86_AVX2 = f.CPU_X86_AVX = f.CPU_X86_SSE42 = f.CPU_X86_SSE41 = f.CPU_X86_SSE4A = f.CPU_X86_SSE3 = f.CPU_X86_SSE2 = true;
// ARM NEON
if (machine_string.find("neon") != std::string::npos)
f.CPU_ARM_NEON = true;
if (machine_string.find("neonv7") != std::string::npos)
f.CPU_ARM_NEON7 = f.CPU_ARM_NEON = true;
if (machine_string.find("neonv8") != std::string::npos)
f.CPU_ARM_NEON8 = f.CPU_ARM_NEON = true;
return f;
}
void print_features(cpu_features_t f)
{
printf("Found CPU Features :\n");
if (f.CPU_X86_SSE2)
printf("- SSE2\n");
if (f.CPU_X86_SSE3)
printf("- SSE3\n");
if (f.CPU_X86_SSE4A)
printf("- SSE4_A\n");
if (f.CPU_X86_SSE41)
printf("- SSE4_1\n");
if (f.CPU_X86_SSE42)
printf("- SSE4_2\n");
if (f.CPU_X86_AVX)
printf("- AVX\n");
if (f.CPU_X86_AVX2)
printf("- AVX2\n");
if (f.CPU_ARM_NEON)
printf("- NEON\n");
if (f.CPU_ARM_NEON7)
printf("- NEONv7\n");
if (f.CPU_ARM_NEON8)
printf("- NEONv8\n");
}
}
|