OSDN Git Service

PR target/50740
[pf3gnuchains/gcc-fork.git] / gcc / config / i386 / driver-i386.c
index 17694ef..5f14c76 100644 (file)
@@ -1,5 +1,5 @@
 /* Subroutines for the gcc driver.
-   Copyright (C) 2006, 2007, 2008 Free Software Foundation, Inc.
+   Copyright (C) 2006, 2007, 2008, 2010 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -21,7 +21,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "system.h"
 #include "coretypes.h"
 #include "tm.h"
-#include <stdlib.h>
 
 const char *host_detect_local_cpu (int argc, const char **argv);
 
@@ -394,8 +393,10 @@ const char *host_detect_local_cpu (int argc, const char **argv)
   unsigned int has_lahf_lm = 0, has_sse4a = 0;
   unsigned int has_longmode = 0, has_3dnowp = 0, has_3dnow = 0;
   unsigned int has_movbe = 0, has_sse4_1 = 0, has_sse4_2 = 0;
-  unsigned int has_popcnt = 0, has_aes = 0, has_avx = 0;
+  unsigned int has_popcnt = 0, has_aes = 0, has_avx = 0, has_avx2 = 0;
   unsigned int has_pclmul = 0, has_abm = 0, has_lwp = 0;
+  unsigned int has_fma = 0, has_fma4 = 0, has_xop = 0;
+  unsigned int has_bmi = 0, has_bmi2 = 0, has_tbm = 0, has_lzcnt = 0;
 
   bool arch;
 
@@ -442,6 +443,7 @@ const char *host_detect_local_cpu (int argc, const char **argv)
   has_popcnt = ecx & bit_POPCNT;
   has_aes = ecx & bit_AES;
   has_pclmul = ecx & bit_PCLMUL;
+  has_fma = ecx & bit_FMA;
 
   has_cmpxchg8b = edx & bit_CMPXCHG8B;
   has_cmov = edx & bit_CMOV;
@@ -449,6 +451,15 @@ const char *host_detect_local_cpu (int argc, const char **argv)
   has_sse = edx & bit_SSE;
   has_sse2 = edx & bit_SSE2;
 
+  if (max_level >= 7)
+    {
+      __cpuid_count (7, 0, eax, ebx, ecx, edx);
+
+      has_bmi = ebx & bit_BMI;
+      has_avx2 = ebx & bit_AVX2;
+      has_bmi2 = ebx & bit_BMI2;
+    }
+
   /* Check cpuid level of extended features.  */
   __cpuid (0x80000000, ext_level, ebx, ecx, edx);
 
@@ -460,6 +471,10 @@ const char *host_detect_local_cpu (int argc, const char **argv)
       has_sse4a = ecx & bit_SSE4a;
       has_abm = ecx & bit_ABM;
       has_lwp = ecx & bit_LWP;
+      has_fma4 = ecx & bit_FMA4;
+      has_xop = ecx & bit_XOP;
+      has_tbm = ecx & bit_TBM;
+      has_lzcnt = ecx & bit_LZCNT;
 
       has_longmode = edx & bit_LM;
       has_3dnowp = edx & bit_3DNOWP;
@@ -490,6 +505,12 @@ const char *host_detect_local_cpu (int argc, const char **argv)
 
       if (name == SIG_GEODE)
        processor = PROCESSOR_GEODE;
+      else if (has_bmi)
+        processor = PROCESSOR_BDVER2;
+      else if (has_xop)
+       processor = PROCESSOR_BDVER1;
+      else if (has_sse4a && has_ssse3)
+        processor = PROCESSOR_BTVER1;
       else if (has_sse4a)
        processor = PROCESSOR_AMDFAM10;
       else if (has_sse2 || has_longmode)
@@ -538,34 +559,80 @@ const char *host_detect_local_cpu (int argc, const char **argv)
        cpu = "pentium";
       break;
     case PROCESSOR_PENTIUMPRO:
-      if (model == 28)
-       cpu = "atom";
-      else if (model >= 28 && l2sizekb < 2048)
-       /* Assume it's a small core if there's less than 2MB cache */
-       cpu = "atom";
-      else if (has_longmode)
-       cpu = "core2";
-      else if (arch)
+      switch (model)
        {
-         if (has_sse3)
-           /* It is Core Duo.  */
-           cpu = "pentium-m";
-         else if (has_sse2)
-           /* It is Pentium M.  */
-           cpu = "pentium-m";
-         else if (has_sse)
-           /* It is Pentium III.  */
-           cpu = "pentium3";
-         else if (has_mmx)
-           /* It is Pentium II.  */
-           cpu = "pentium2";
+       case 0x1c:
+       case 0x26:
+         /* Atom.  */
+         cpu = "atom";
+         break;
+       case 0x1a:
+       case 0x1e:
+       case 0x1f:
+       case 0x2e:
+         /* Nehalem.  */
+         cpu = "corei7";
+         break;
+       case 0x25:
+       case 0x2c:
+       case 0x2f:
+         /* Westmere.  */
+         cpu = "corei7";
+         break;
+       case 0x2a:
+       case 0x2d:
+         /* Sandy Bridge.  */
+         cpu = "corei7-avx";
+         break;
+       case 0x17:
+       case 0x1d:
+         /* Penryn.  */
+         cpu = "core2";
+         break;
+       case 0x0f:
+         /* Merom.  */
+         cpu = "core2";
+         break;
+       default:
+         if (arch)
+           {
+             /* This is unknown family 0x6 CPU.  */
+             if (has_avx)
+               /* Assume Sandy Bridge.  */
+               cpu = "corei7-avx";
+             else if (has_sse4_2)
+               /* Assume Core i7.  */
+               cpu = "corei7";
+             else if (has_ssse3)
+               {
+                 if (has_movbe)
+                   /* Assume Atom.  */
+                   cpu = "atom";
+                 else
+                   /* Assume Core 2.  */
+                   cpu = "core2";
+               }
+             else if (has_sse3)
+               /* It is Core Duo.  */
+               cpu = "pentium-m";
+             else if (has_sse2)
+               /* It is Pentium M.  */
+               cpu = "pentium-m";
+             else if (has_sse)
+               /* It is Pentium III.  */
+               cpu = "pentium3";
+             else if (has_mmx)
+               /* It is Pentium II.  */
+               cpu = "pentium2";
+             else
+               /* Default to Pentium Pro.  */
+               cpu = "pentiumpro";
+           }
          else
-           /* Default to Pentium Pro.  */
-           cpu = "pentiumpro";
+           /* For -mtune, we default to -mtune=generic.  */
+           cpu = "generic";
+         break;
        }
-      else
-       /* For -mtune, we default to -mtune=generic.  */
-       cpu = "generic";
       break;
     case PROCESSOR_PENTIUM4:
       if (has_sse3)
@@ -602,6 +669,15 @@ const char *host_detect_local_cpu (int argc, const char **argv)
     case PROCESSOR_AMDFAM10:
       cpu = "amdfam10";
       break;
+    case PROCESSOR_BDVER1:
+      cpu = "bdver1";
+      break;
+    case PROCESSOR_BDVER2:
+      cpu = "bdver2";
+      break;
+    case PROCESSOR_BTVER1:
+      cpu = "btver1";
+      break;
 
     default:
       /* Use something reasonable.  */
@@ -631,29 +707,29 @@ const char *host_detect_local_cpu (int argc, const char **argv)
 
   if (arch)
     {
-      if (has_cmpxchg16b)
-       options = concat (options, " -mcx16", NULL);
-      if (has_lahf_lm)
-       options = concat (options, " -msahf", NULL);
-      if (has_movbe)
-       options = concat (options, " -mmovbe", NULL);
-      if (has_aes)
-       options = concat (options, " -maes", NULL);
-      if (has_pclmul)
-       options = concat (options, " -mpclmul", NULL);
-      if (has_popcnt)
-       options = concat (options, " -mpopcnt", NULL);
-      if (has_abm)
-       options = concat (options, " -mabm", NULL);
-      if (has_lwp)
-       options = concat (options, " -mlwp", NULL);
-
-      if (has_avx)
-       options = concat (options, " -mavx", NULL);
-      else if (has_sse4_2)
-       options = concat (options, " -msse4.2", NULL);
-      else if (has_sse4_1)
-       options = concat (options, " -msse4.1", NULL);
+      const char *cx16 = has_cmpxchg16b ? " -mcx16" : " -mno-cx16";
+      const char *sahf = has_lahf_lm ? " -msahf" : " -mno-sahf";
+      const char *movbe = has_movbe ? " -mmovbe" : " -mno-movbe";
+      const char *ase = has_aes ? " -maes" : " -mno-aes";
+      const char *pclmul = has_pclmul ? " -mpclmul" : " -mno-pclmul";
+      const char *popcnt = has_popcnt ? " -mpopcnt" : " -mno-popcnt";
+      const char *abm = has_abm ? " -mabm" : " -mno-abm";
+      const char *lwp = has_lwp ? " -mlwp" : " -mno-lwp";
+      const char *fma = has_fma ? " -mfma" : " -mno-fma";
+      const char *fma4 = has_fma4 ? " -mfma4" : " -mno-fma4";
+      const char *xop = has_xop ? " -mxop" : " -mno-xop";
+      const char *bmi = has_bmi ? " -mbmi" : " -mno-bmi";
+      const char *bmi2 = has_bmi2 ? " -mbmi2" : " -mno-bmi2";
+      const char *tbm = has_tbm ? " -mtbm" : " -mno-tbm";
+      const char *avx = has_avx ? " -mavx" : " -mno-avx";
+      const char *avx2 = has_avx2 ? " -mavx2" : " -mno-avx2";
+      const char *sse4_2 = has_sse4_2 ? " -msse4.2" : " -mno-sse4.2";
+      const char *sse4_1 = has_sse4_1 ? " -msse4.1" : " -mno-sse4.1";
+      const char *lzcnt = has_lzcnt ? " -mlzcnt" : " -mno-lzcnt";
+
+      options = concat (options, cx16, sahf, movbe, ase, pclmul,
+                       popcnt, abm, lwp, fma, fma4, xop, bmi, bmi2,
+                       tbm, avx, avx2, sse4_2, sse4_1, lzcnt, NULL);
     }
 
 done: