summaryrefslogtreecommitdiff
path: root/volk/gen/make_cpuid_c.py
diff options
context:
space:
mode:
Diffstat (limited to 'volk/gen/make_cpuid_c.py')
-rw-r--r--volk/gen/make_cpuid_c.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/volk/gen/make_cpuid_c.py b/volk/gen/make_cpuid_c.py
index a8939fb90..005fc2b19 100644
--- a/volk/gen/make_cpuid_c.py
+++ b/volk/gen/make_cpuid_c.py
@@ -41,11 +41,32 @@ struct VOLK_CPU volk_cpu;
#include <gcc_x86_cpuid.h>
#define cpuid_x86(op, r) __get_cpuid(op, (unsigned int *)r+0, (unsigned int *)r+1, (unsigned int *)r+2, (unsigned int *)r+3)
+ /* Return Intel AVX extended CPU capabilities register.
+ * This function will bomb on non-AVX-capable machines, so
+ * check for AVX capability before executing.
+ */
+ #if __GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 4
+ static inline unsigned long long _xgetbv(unsigned int index){
+ unsigned int eax, edx;
+ __asm__ __volatile__("xgetbv" : "=a"(eax), "=d"(edx) : "c"(index));
+ return ((unsigned long long)edx << 32) | eax;
+ }
+ #define __xgetbv() _xgetbv(0)
+ #else
+ #define __xgetbv() 0
+ #endif
+
//implement get cpuid for MSVC compilers using __cpuid intrinsic
#elif defined(_MSC_VER)
#include <intrin.h>
#define cpuid_x86(op, r) __cpuid(r, op)
+ #if defined(_XCR_XFEATURE_ENABLED_MASK)
+ #define __xgetbv() _xgetbv(_XCR_XFEATURE_ENABLED_MASK)
+ #else
+ #define __xgetbv() 0
+ #endif
+
#else
#error "A get cpuid for volk is not available on this compiler..."
#endif