public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, i386-driver]: Ignore -march and -mtune for native target when   not compiled with gcc
@ 2009-06-02 11:16 Uros Bizjak
  2009-06-02 14:09 ` Ian Lance Taylor
  0 siblings, 1 reply; 2+ messages in thread
From: Uros Bizjak @ 2009-06-02 11:16 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 710 bytes --]

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.

[-- Attachment #2: p.diff.txt --]
[-- Type: text/plain, Size: 3146 bytes --]

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__ */

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH, i386-driver]: Ignore -march and -mtune for native target when   not compiled with gcc
  2009-06-02 11:16 [PATCH, i386-driver]: Ignore -march and -mtune for native target when not compiled with gcc Uros Bizjak
@ 2009-06-02 14:09 ` Ian Lance Taylor
  0 siblings, 0 replies; 2+ messages in thread
From: Ian Lance Taylor @ 2009-06-02 14:09 UTC (permalink / raw)
  To: Uros Bizjak; +Cc: gcc-patches

Uros Bizjak <ubizjak@gmail.com> writes:

> 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.

That seems fine to me.

> -  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);

As long as you're touching these lines can you change the sprintf to
snprintf?  Thanks.

Ian

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-06-02 14:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-02 11:16 [PATCH, i386-driver]: Ignore -march and -mtune for native target when not compiled with gcc Uros Bizjak
2009-06-02 14:09 ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).