From 283b6e911517313597756a9c3acd966c2dfe77e4 Mon Sep 17 00:00:00 2001
From: Josh Blum <josh@joshknows.com>
Date: Wed, 18 Apr 2012 11:16:59 -0700
Subject: volk: added gcc version check to xgetbv

Reference
https://code.google.com/p/pcsx2/issues/detail?id=1195
---
 volk/tmpl/volk_cpu.tmpl.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

(limited to 'volk')

diff --git a/volk/tmpl/volk_cpu.tmpl.c b/volk/tmpl/volk_cpu.tmpl.c
index e0a0e91ded..b312c44853 100644
--- a/volk/tmpl/volk_cpu.tmpl.c
+++ b/volk/tmpl/volk_cpu.tmpl.c
@@ -44,12 +44,16 @@ struct VOLK_CPU volk_cpu;
      * This function will bomb on non-AVX-capable machines, so
      * check for AVX capability before executing.
      */
-    static inline unsigned int __xgetbv(void)
-    {
-        unsigned int index, __eax, __edx;
-        __asm__ ("xgetbv" : "=a"(__eax), "=d"(__edx) : "c" (index));
-        return __eax;
+    #if defined(__GNUC_PREREQ) && __GNUC_PREREQ(4, 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) && defined(HAVE_INTRIN_H)
-- 
cgit v1.2.3