[PATCH, i386-driver]: Ignore -march and -mtune for native target when not compiled with gcc

Uros Bizjak ubizjak@gmail.com
Tue Jun 2 11:16:00 GMT 2009


Hello!

Attached patch teaches i386 driver to ignore -march and -mtune
switches for native target when the driver is not compiled with gcc.
By ignoring the switches, the compiler generates code for its default
target, which is max that we can do in this case (*). The driver also
optimizes concatenation of options a bit.

2009-06-02  Uros Bizjak  <ubizjak@gmail.com>

	* config/i386/driver-i386.c (describe_cache): Optimize
	concatenation of strings.
	(host_detect_local_cpu): Ditto.
	(host_detect_local_cpu): Ignore -march and -mtune for native
	target when not compiling with GCC.

Any comments on this approach?

(*) driver uses gcc specific asm to use cpuid insn, so it must be
compiled using gcc.

Uros.
-------------- next part --------------
Index: driver-i386.c
===================================================================
--- driver-i386.c	(revision 148080)
+++ driver-i386.c	(working copy)
@@ -46,12 +46,12 @@ describe_cache (struct cache_desc level1
   /* At the moment, gcc does not use the information
      about the associativity of the cache.  */
 
-  sprintf (size, "--param l1-cache-size=%u", level1.sizekb);
-  sprintf (line, "--param l1-cache-line-size=%u", level1.line);
+  sprintf (size, "--param l1-cache-size=%u ", level1.sizekb);
+  sprintf (line, "--param l1-cache-line-size=%u ", level1.line);
 
-  sprintf (size2, "--param l2-cache-size=%u", level2.sizekb);
+  sprintf (size2, "--param l2-cache-size=%u ", level2.sizekb);
 
-  return concat (size, " ", line, " ", size2, " ", NULL);
+  return concat (size, line, size2, NULL);
 }
 
 /* Detect L2 cache parameters using CPUID extended function 0x80000006.  */
@@ -608,55 +608,38 @@ const char *host_detect_local_cpu (int a
   if (arch)
     {
       if (has_cmpxchg16b)
-	options = concat (options, "-mcx16 ", NULL);
+	options = concat (options, " -mcx16", NULL);
       if (has_lahf_lm)
-	options = concat (options, "-msahf ", NULL);
+	options = concat (options, " -msahf", NULL);
       if (has_movbe)
-	options = concat (options, "-mmovbe ", NULL);
+	options = concat (options, " -mmovbe", NULL);
       if (has_aes)
-	options = concat (options, "-maes ", NULL);
+	options = concat (options, " -maes", NULL);
       if (has_pclmul)
-	options = concat (options, "-mpclmul ", NULL);
+	options = concat (options, " -mpclmul", NULL);
       if (has_popcnt)
-	options = concat (options, "-mpopcnt ", NULL);
+	options = concat (options, " -mpopcnt", NULL);
+
       if (has_avx)
-	options = concat (options, "-mavx ", NULL);
+	options = concat (options, " -mavx", NULL);
       else if (has_sse4_2)
-	options = concat (options, "-msse4.2 ", NULL);
+	options = concat (options, " -msse4.2", NULL);
       else if (has_sse4_1)
-	options = concat (options, "-msse4.1 ", NULL);
+	options = concat (options, " -msse4.1", NULL);
     }
 
 done:
-  return concat (cache, "-m", argv[0], "=", cpu, " ", options, NULL);
+  return concat (cache, "-m", argv[0], "=", cpu, options, NULL);
 }
 #else
 
-/* If we aren't compiling with GCC we just provide a minimal
-   default value.  */
+/* If we aren't compiling with GCC then the driver will just ignore
+   -march and -mtune "native" target and will leave to the newly
+   built compiler to generate code for its default target.  */
 
-const char *host_detect_local_cpu (int argc, const char **argv)
+const char *host_detect_local_cpu (int argc ATTRIBUTE_UNUSED,
+				   const char **argv ATTRIBUTE_UNUSED)
 {
-  const char *cpu;
-  bool arch;
-
-  if (argc < 1)
-    return NULL;
-
-  arch = !strcmp (argv[0], "arch");
-
-  if (!arch && strcmp (argv[0], "tune"))
-    return NULL;
-  
-  if (arch)
-    {
-      /* FIXME: i386 is wrong for 64bit compiler.  How can we tell if
-	 we are generating 64bit or 32bit code?  */
-      cpu = "i386";
-    }
-  else
-    cpu = "generic";
-
-  return concat ("-m", argv[0], "=", cpu, NULL);
+  return NULL;
 }
 #endif /* __GNUC__ */


More information about the Gcc-patches mailing list