]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Check SSE and YMM state support for -march=native
authorH.J. Lu <hongjiu.lu@intel.com>
Tue, 2 Oct 2012 20:31:40 +0000 (20:31 +0000)
committerH.J. Lu <hjl@gcc.gnu.org>
Tue, 2 Oct 2012 20:31:40 +0000 (13:31 -0700)
Backported from mainline
PR target/54741
*  config/i386/driver-i386.c (XCR_XFEATURE_ENABLED_MASK): New.
(XSTATE_FP): Likewise.
(XSTATE_SSE): Likewise.
(XSTATE_YMM): Likewise.
(host_detect_local_cpu): Disable AVX, FMA, FMA4 and XOP if SSE
and YMM states aren't supported.

From-SVN: r192004

gcc/ChangeLog
gcc/config/i386/driver-i386.c

index 29065b818b1bf4cc41960f2ac7e0ce91f475a20a..3bdfda68265afc9b6c14804c403e97a675b8b345 100644 (file)
@@ -1,3 +1,16 @@
+2012-10-02  H.J. Lu  <hongjiu.lu@intel.com>
+
+       Backported from mainline
+       2012-10-02  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR target/54741
+       *  config/i386/driver-i386.c (XCR_XFEATURE_ENABLED_MASK): New.
+       (XSTATE_FP): Likewise.
+       (XSTATE_SSE): Likewise.
+       (XSTATE_YMM): Likewise.
+       (host_detect_local_cpu): Disable AVX, FMA, FMA4 and XOP if SSE
+       and YMM states aren't supported.
+
 2012-09-21  Richard Guenther  <rguenther@suse.de>
 
        PR middle-end/54638
index 1871ae485044f081ff9bfe22ccac4495a1d9902f..3e25a72f63d5b2322952e41351fbc90d2e62efe0 100644 (file)
@@ -1,5 +1,5 @@
 /* Subroutines for the gcc driver.
-   Copyright (C) 2006, 2007, 2008, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2006-2012 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -398,6 +398,7 @@ const char *host_detect_local_cpu (int argc, const char **argv)
   unsigned int has_fma = 0, has_fma4 = 0, has_xop = 0;
   unsigned int has_bmi = 0, has_tbm = 0;
   unsigned int has_rdrnd = 0, has_f16c = 0, has_fsgsbase = 0;
+  unsigned int has_osxsave = 0;
 
   bool arch;
 
@@ -439,6 +440,7 @@ const char *host_detect_local_cpu (int argc, const char **argv)
   has_sse4_1 = ecx & bit_SSE4_1;
   has_sse4_2 = ecx & bit_SSE4_2;
   has_avx = ecx & bit_AVX;
+  has_osxsave = ecx & bit_OSXSAVE;
   has_cmpxchg16b = ecx & bit_CMPXCHG16B;
   has_movbe = ecx & bit_MOVBE;
   has_popcnt = ecx & bit_POPCNT;
@@ -461,6 +463,25 @@ const char *host_detect_local_cpu (int argc, const char **argv)
       has_fsgsbase = ebx & bit_FSGSBASE;
     }
 
+  /* Get XCR_XFEATURE_ENABLED_MASK register with xgetbv.  */
+#define XCR_XFEATURE_ENABLED_MASK      0x0
+#define XSTATE_FP                      0x1
+#define XSTATE_SSE                     0x2
+#define XSTATE_YMM                     0x4
+  if (has_osxsave)
+    asm (".byte 0x0f; .byte 0x01; .byte 0xd0"
+        : "=a" (eax), "=d" (edx)
+        : "c" (XCR_XFEATURE_ENABLED_MASK));
+
+  /* Check if SSE and YMM states are supported.  */
+  if ((eax & (XSTATE_SSE | XSTATE_YMM)) == (XSTATE_SSE | XSTATE_YMM))
+    {
+      has_avx = 0;
+      has_fma = 0;
+      has_fma4 = 0;
+      has_xop = 0;
+    }
+
   /* Check cpuid level of extended features.  */
   __cpuid (0x80000000, ext_level, ebx, ecx, edx);