Skip to content

Instantly share code, notes, and snippets.

@Youka
Created June 28, 2015 15:54
Show Gist options
  • Select an option

  • Save Youka/eb4d2c2142921a1b4dbc to your computer and use it in GitHub Desktop.

Select an option

Save Youka/eb4d2c2142921a1b4dbc to your computer and use it in GitHub Desktop.
#pragma once
#ifdef _MSC_VER
#include <intrin.h>
#define bit_SSE2 (1 << 26)
#define bit_SSE3 (1 << 0)
#define bit_AVX (1 << 28)
#else
#include <cpuid.h>
#endif // _MSC_VER
struct vector_features{
int sse2, sse3, avx;
};
inline struct vector_features detect_vector_features(void){
#ifdef _MSC_VER
int cpu_info[4];
__cpuid(cpu_info, 1);
return {cpu_info[3] & bit_SSE2, cpu_info[2] & bit_SSE3, cpu_info[2] & bit_AVX};
#else
int eax, ebx, ecx, edx;
__cpuid (1, eax, ebx, ecx, edx);
return {edx & bit_SSE2, ecx & bit_SSE3, ecx & bit_AVX};
#endif // _MSC_VER
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment