public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 0/4] S390 -march=native related fixes
@ 2015-07-17 16:03 Dominik Vogt
  2015-07-17 16:04 ` [PATCH 1/4] " Dominik Vogt
                   ` (4 more replies)
  0 siblings, 5 replies; 16+ messages in thread
From: Dominik Vogt @ 2015-07-17 16:03 UTC (permalink / raw)
  To: gcc-patches

The following series of patches contains fixes, and cleanup work
related to -march=native (and -mtune=native) for S390.

* 0001 Fix cross compilation for S390 targets that was broken with
       the original -march=native aptch.

* 0002 Fix handling of -march=z9_ec in old code.  This bug has been
       in the code since z9-ec support was added.

* 0003 -march=native now detects various cpu features and passes
       that as options from the driver to the compiler.

* 0004 Non-mandatory cleanup of the S390 code handling the various
       cpu types.

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany

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

* [PATCH 1/4] S390 -march=native related fixes
  2015-07-17 16:03 [PATCH 0/4] S390 -march=native related fixes Dominik Vogt
@ 2015-07-17 16:04 ` Dominik Vogt
  2015-07-17 16:05 ` [PATCH 2/4] " Dominik Vogt
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 16+ messages in thread
From: Dominik Vogt @ 2015-07-17 16:04 UTC (permalink / raw)
  To: gcc-patches

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

> The following series of patches contains fixes, and cleanup work
> related to -march=native (and -mtune=native) for S390.
> 
> * 0001 Fix cross compilation for S390 targets that was broken with
>        the original -march=native aptch.

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany

[-- Attachment #2: 0001-ChangeLog --]
[-- Type: text/plain, Size: 103 bytes --]

gcc/ChangeLog:

	* config/s390/s390.h: S390: Do not define EXTRA_SPEC_FUNCTIONS when
	cross compiling.

[-- Attachment #3: 0001-S390-Do-not-define-EXTRA_SPEC_FUNCTIONS-when-cross-c.patch --]
[-- Type: text/x-diff, Size: 1164 bytes --]

From 7ce17cd9b53959a70a9d30cb33acf62ef43ea418 Mon Sep 17 00:00:00 2001
From: Dominik Vogt <vogt@linux.vnet.ibm.com>
Date: Thu, 9 Jul 2015 07:31:42 +0100
Subject: [PATCH 1/4] S390: Do not define EXTRA_SPEC_FUNCTIONS when cross
 compiling.

---
 gcc/config/s390/s390.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/gcc/config/s390/s390.h b/gcc/config/s390/s390.h
index 85a0d1a..f18b973 100644
--- a/gcc/config/s390/s390.h
+++ b/gcc/config/s390/s390.h
@@ -126,6 +126,7 @@ enum processor_flags
   { "arch", "%{!march=*:-march=%(VALUE)}" },			\
   { "tune", "%{!mtune=*:-mtune=%(VALUE)}" }
 
+#ifdef __s390__
 extern const char *s390_host_detect_local_cpu (int argc, const char **argv);
 # define EXTRA_SPEC_FUNCTIONS \
   { "local_cpu_detect", s390_host_detect_local_cpu },
@@ -133,6 +134,9 @@ extern const char *s390_host_detect_local_cpu (int argc, const char **argv);
 # define MARCH_MTUNE_NATIVE_SPECS				\
   " %{march=native:%<march=native %:local_cpu_detect(arch)}"	\
   " %{mtune=native:%<mtune=native %:local_cpu_detect(tune)}"
+#else
+# define MARCH_MTUNE_NATIVE_SPECS ""
+#endif
 
 /* Defaulting rules.  */
 #ifdef DEFAULT_TARGET_64BIT
-- 
2.3.0


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

* [PATCH 2/4] S390 -march=native related fixes
  2015-07-17 16:03 [PATCH 0/4] S390 -march=native related fixes Dominik Vogt
  2015-07-17 16:04 ` [PATCH 1/4] " Dominik Vogt
@ 2015-07-17 16:05 ` Dominik Vogt
  2015-07-17 16:08 ` [PATCH 3/4] " Dominik Vogt
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 16+ messages in thread
From: Dominik Vogt @ 2015-07-17 16:05 UTC (permalink / raw)
  To: gcc-patches

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

> The following series of patches contains fixes, and cleanup work
> related to -march=native (and -mtune=native) for S390.
> 
> * 0002 Fix handling of -march=z9_ec in old code.  This bug has been
>        in the code since z9-ec support was added.

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany

[-- Attachment #2: 0002-ChangeLog --]
[-- Type: text/plain, Size: 155 bytes --]

gcc/ChangeLog

	* config/s390/s390.c (s390_issue_rate): Handle PROCESSOR_2094_Z9_EC.
	(s390_option_override): Likewise.
	(s390_adjust_priority): Likewise.

[-- Attachment #3: 0002-S390-Add-handling-of-PROCESSOR_2094_Z9_EC.patch --]
[-- Type: text/x-diff, Size: 1420 bytes --]

From d7fda8d5dbb006bffef36323921efa081bfdfa57 Mon Sep 17 00:00:00 2001
From: Dominik Vogt <vogt@linux.vnet.ibm.com>
Date: Tue, 7 Jul 2015 07:57:26 +0100
Subject: [PATCH 2/4] S390: Add handling of PROCESSOR_2094_Z9_EC.

---
 gcc/config/s390/s390.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c
index 861dfb2..27e1c35 100644
--- a/gcc/config/s390/s390.c
+++ b/gcc/config/s390/s390.c
@@ -7270,12 +7270,7 @@ s390_adjust_priority (rtx_insn *insn, int priority)
   if (! INSN_P (insn))
     return priority;
 
-  if (s390_tune != PROCESSOR_2084_Z990
-      && s390_tune != PROCESSOR_2094_Z9_109
-      && s390_tune != PROCESSOR_2097_Z10
-      && s390_tune != PROCESSOR_2817_Z196
-      && s390_tune != PROCESSOR_2827_ZEC12
-      && s390_tune != PROCESSOR_2964_Z13)
+  if (s390_tune <= PROCESSOR_2064_Z900)
     return priority;
 
   switch (s390_safe_attr_type (insn))
@@ -7304,6 +7299,7 @@ s390_issue_rate (void)
     {
     case PROCESSOR_2084_Z990:
     case PROCESSOR_2094_Z9_109:
+    case PROCESSOR_2094_Z9_EC:
     case PROCESSOR_2817_Z196:
       return 3;
     case PROCESSOR_2097_Z10:
@@ -13521,6 +13517,7 @@ s390_option_override (void)
       s390_cost = &z990_cost;
       break;
     case PROCESSOR_2094_Z9_109:
+    case PROCESSOR_2094_Z9_EC:
       s390_cost = &z9_109_cost;
       break;
     case PROCESSOR_2097_Z10:
-- 
2.3.0


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

* [PATCH 3/4] S390 -march=native related fixes
  2015-07-17 16:03 [PATCH 0/4] S390 -march=native related fixes Dominik Vogt
  2015-07-17 16:04 ` [PATCH 1/4] " Dominik Vogt
  2015-07-17 16:05 ` [PATCH 2/4] " Dominik Vogt
@ 2015-07-17 16:08 ` Dominik Vogt
  2015-07-17 16:43   ` Dominik Vogt
  2015-07-17 16:09 ` [PATCH 4/4] " Dominik Vogt
  2015-07-24 11:38 ` [PATCH 0/4] " Andreas Krebbel
  4 siblings, 1 reply; 16+ messages in thread
From: Dominik Vogt @ 2015-07-17 16:08 UTC (permalink / raw)
  To: gcc-patches

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

On Fri, Jul 17, 2015 at 05:00:50PM +0100, Dominik Vogt wrote:
> The following series of patches contains fixes, and cleanup work
> related to -march=native (and -mtune=native) for S390.
> 
> * 0003 -march=native now detects various cpu features and passes
>        that as options from the driver to the compiler.

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany

[-- Attachment #2: 0003-ChangeLog --]
[-- Type: text/plain, Size: 438 bytes --]

gcc/ChangeLog

	* config/s390/driver-native.c (s390_host_detect_local_cpu): Handle
	processor capabilities with -march=native.
	* config/s390/s390.h (MARCH_MTUNE_NATIVE_SPECS): Likewise.
	(DRIVER_SELF_SPECS): Likewise.  Join specs for 31 and 64 bit.
	* (S390_TARGET_BITS_STRING): Macro to simplify specs.  Use
	CC1_CPU_SPEC, EXTRA_SPECS and CC1_SPEC instead.
	(CC1_CPU_SPEC): New macro.
	(EXTRA_SPECS): New macro.
	(CC1_SPEC): New macro.

[-- Attachment #3: 0003-S390-Handle-processor-capabilities-with-march-native.patch --]
[-- Type: text/x-diff, Size: 6637 bytes --]

From 0b6de7baee54ce964ff4d0be1380dd03ab69bb93 Mon Sep 17 00:00:00 2001
From: Dominik Vogt <vogt@linux.vnet.ibm.com>
Date: Mon, 6 Jul 2015 16:28:32 +0100
Subject: [PATCH 3/4] S390: Handle processor capabilities with -march=native.

---
 gcc/config/s390/driver-native.c | 143 ++++++++++++++++++++++++++++++++--------
 gcc/config/s390/s390.h          |  32 +++++----
 2 files changed, 133 insertions(+), 42 deletions(-)

diff --git a/gcc/config/s390/driver-native.c b/gcc/config/s390/driver-native.c
index 88c76bd..ebce79f 100644
--- a/gcc/config/s390/driver-native.c
+++ b/gcc/config/s390/driver-native.c
@@ -42,6 +42,17 @@ s390_host_detect_local_cpu (int argc, const char **argv)
   char buf[256];
   FILE *f;
   bool arch;
+  const char *options = "";
+  unsigned int has_features;
+  unsigned int has_processor;
+  unsigned int is_cpu_z9_109 = 0;
+  unsigned int has_highgprs = 0;
+  unsigned int has_dfp = 0;
+  unsigned int has_te = 0;
+  unsigned int has_vx = 0;
+  unsigned int has_opt_te = 0;
+  unsigned int has_opt_vx = 0;
+  unsigned int has_opt_esa_zarch = 0;
 
   if (argc < 1)
     return NULL;
@@ -49,43 +60,119 @@ s390_host_detect_local_cpu (int argc, const char **argv)
   arch = strcmp (argv[0], "arch") == 0;
   if (!arch && strcmp (argv[0], "tune"))
     return NULL;
+  if (argc == 4)
+    {
+      /* The extra arguments are only used for "arch" mode.  */
+      has_opt_esa_zarch = atoi (argv[1]);
+      has_opt_te = atoi (argv[2]);
+      has_opt_vx = atoi (argv[3]);
+    }
 
   f = fopen ("/proc/cpuinfo", "r");
   if (f == NULL)
     return NULL;
 
-  while (fgets (buf, sizeof (buf), f) != NULL)
-    if (strncmp (buf, "processor", sizeof ("processor") - 1) == 0)
-      {
-	if (strstr (buf, "machine = 9672") != NULL)
-	  cpu = "g5";
-	else if (strstr (buf, "machine = 2064") != NULL
-		 || strstr (buf, "machine = 2066") != NULL)
-	  cpu = "z900";
-	else if (strstr (buf, "machine = 2084") != NULL
-		 || strstr (buf, "machine = 2086") != NULL)
-	  cpu = "z990";
-	else if (strstr (buf, "machine = 2094") != NULL
-		 || strstr (buf, "machine = 2096") != NULL)
-	  cpu = "z9-109";
-	else if (strstr (buf, "machine = 2097") != NULL
-		 || strstr (buf, "machine = 2098") != NULL)
-	  cpu = "z10";
-	else if (strstr (buf, "machine = 2817") != NULL
-		 || strstr (buf, "machine = 2818") != NULL)
-	  cpu = "z196";
-	else if (strstr (buf, "machine = 2827") != NULL
-		 || strstr (buf, "machine = 2828") != NULL)
-	  cpu = "zEC12";
-	else if (strstr (buf, "machine = 2964") != NULL)
-	  cpu = "z13";
-	break;
-      }
+  for (has_features = 0, has_processor = 0;
+       (has_features == 0 || has_processor == 0)
+	 && fgets (buf, sizeof (buf), f) != NULL; )
+    {
+      if (has_processor == 0 && strncmp (buf, "processor", 9) == 0)
+	{
+	  const char *p;
+	  long machine_id;
+
+	  p = strstr (buf, "machine = ");
+	  if (p == NULL)
+	    continue;
+	  p += 10;
+	  has_processor = 1;
+	  machine_id = strtol (p, NULL, 16);
+	  switch (machine_id)
+	    {
+	    case 0x9672:
+	      cpu = "g5";
+	      break;
+	    case 0x2064:
+	    case 0x2066:
+	      cpu = "z900";
+	      break;
+	    case 0x2084:
+	    case 0x2086:
+	      cpu = "z990";
+	      break;
+	    case 0x2094:
+	    case 0x2096:
+	      cpu = "z9-109";
+	      is_cpu_z9_109 = 1;
+	      break;
+	    case 0x2097:
+	    case 0x2098:
+	      cpu = "z10";
+	      break;
+	    case 0x2817:
+	    case 0x2818:
+	      cpu = "z196";
+	      break;
+	    case 0x2827:
+	    case 0x2828:
+	      cpu = "zEC12";
+	      break;
+	    case 0x2964:
+	      cpu = "z13";
+	      break;
+	    }
+	}
+      if (has_features == 0 && strncmp (buf, "features", 8) == 0)
+	{
+	  const char *p;
+
+	  p = strchr (buf, ':');
+	  if (p == NULL)
+	    continue;
+	  p++;
+	  while (*p != 0)
+	    {
+	      int i;
+
+	      while (ISSPACE (*p))
+		p++;
+	      for (i = 0; !ISSPACE (p[i]) && p[i] != 0; i++)
+		;
+	      if (i == 3 && strncmp (p, "dfp", 3) == 0)
+		has_dfp = 1;
+	      else if (i == 2 && strncmp (p, "te", 2) == 0)
+		has_te = 1;
+	      else if (i == 2 && strncmp (p, "vx", 2) == 0)
+		has_vx = 1;
+	      else if (i == 8 && strncmp (p, "highgprs", 8) == 0)
+		has_highgprs = 1;
+	      p += i;
+	    }
+	  has_features = 1;
+	}
+    }
 
   fclose (f);
 
   if (cpu == NULL)
     return NULL;
 
-  return concat ("-m", argv[0], "=", cpu, NULL);
+  if (arch)
+    {
+      const char *opt_htm = "";
+      const char *opt_vx = "";
+      const char *opt_esa_zarch = "";
+
+      if (!has_opt_te)
+	opt_htm = (has_te) ? " -mhtm" : " -mno-htm";
+      if (!has_opt_vx)
+	opt_vx = (has_vx) ? " -mvx" : " -mno-vx";
+      if (!has_opt_esa_zarch)
+	opt_esa_zarch = (has_highgprs) ? " -mzarch" : " -mesa";
+      options = concat (options, opt_htm, opt_vx, opt_esa_zarch, NULL);
+    }
+  if (has_dfp && is_cpu_z9_109)
+    cpu = "z9-ec";
+
+  return concat ("-m", argv[0], "=", cpu, options, NULL);
 }
diff --git a/gcc/config/s390/s390.h b/gcc/config/s390/s390.h
index f18b973..cfe23d4 100644
--- a/gcc/config/s390/s390.h
+++ b/gcc/config/s390/s390.h
@@ -131,26 +131,30 @@ extern const char *s390_host_detect_local_cpu (int argc, const char **argv);
 # define EXTRA_SPEC_FUNCTIONS \
   { "local_cpu_detect", s390_host_detect_local_cpu },
 
-# define MARCH_MTUNE_NATIVE_SPECS				\
-  " %{march=native:%<march=native %:local_cpu_detect(arch)}"	\
-  " %{mtune=native:%<mtune=native %:local_cpu_detect(tune)}"
+#define MARCH_MTUNE_NATIVE_SPECS			\
+  "%{mtune=native:%<mtune=native %:local_cpu_detect(tune)} "	\
+  "%{march=native:%<march=native %:local_cpu_detect(arch)} "
 #else
 # define MARCH_MTUNE_NATIVE_SPECS ""
 #endif
 
-/* Defaulting rules.  */
 #ifdef DEFAULT_TARGET_64BIT
-#define DRIVER_SELF_SPECS					\
-  "%{!m31:%{!m64:-m64}}",					\
-  "%{!mesa:%{!mzarch:%{m31:-mesa}%{m64:-mzarch}}}",		\
-  "%{!march=*:%{mesa:-march=g5}%{mzarch:-march=z900}}",		\
-  MARCH_MTUNE_NATIVE_SPECS
+#define S390_TARGET_BITS_STRING "64"
 #else
-#define DRIVER_SELF_SPECS					\
-  "%{!m31:%{!m64:-m31}}",					\
-  "%{!mesa:%{!mzarch:%{m31:-mesa}%{m64:-mzarch}}}",		\
-  "%{!march=*:%{mesa:-march=g5}%{mzarch:-march=z900}}",		\
-  MARCH_MTUNE_NATIVE_SPECS
+#define S390_TARGET_BITS_STRING "31"
+#endif
+
+/* Defaulting rules.  */
+#define CC1_CPU_SPEC						\
+  "%{!m31:%{!m64:-m" S390_TARGET_BITS_STRING "}} "		\
+  "%{!march=*:%{mesa:-march=g5}%{mzarch:-march=z900}} "		\
+  MARCH_MTUNE_NATIVE_SPECS					\
+  "%{!mesa:%{!mzarch:%{m31:-mesa}%{m64:-mzarch}}} "
+
+#define EXTRA_SPECS { "cc1_cpu",  CC1_CPU_SPEC },
+
+#ifndef CC1_SPEC
+#define CC1_SPEC "%(cc1_cpu) "
 #endif
 
 /* Constants needed to control the TEST DATA CLASS (TDC) instruction.  */
-- 
2.3.0


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

* [PATCH 4/4] S390 -march=native related fixes
  2015-07-17 16:03 [PATCH 0/4] S390 -march=native related fixes Dominik Vogt
                   ` (2 preceding siblings ...)
  2015-07-17 16:08 ` [PATCH 3/4] " Dominik Vogt
@ 2015-07-17 16:09 ` Dominik Vogt
  2015-07-24 11:38 ` [PATCH 0/4] " Andreas Krebbel
  4 siblings, 0 replies; 16+ messages in thread
From: Dominik Vogt @ 2015-07-17 16:09 UTC (permalink / raw)
  To: gcc-patches

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

On Fri, Jul 17, 2015 at 05:00:50PM +0100, Dominik Vogt wrote:
> The following series of patches contains fixes, and cleanup work
> related to -march=native (and -mtune=native) for S390.
> 
> * 0004 Non-mandatory cleanup of the S390 code handling the various
>        cpu types.

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany

[-- Attachment #2: 0004-ChangeLog --]
[-- Type: text/plain, Size: 274 bytes --]

gcc/ChangeLog

	* config/s390/s390.c (s390_reorg): Clean up handling of processors with
	-mtune=
	(s390_issue_rate): Likewise.
	(s390_sched_reorder): Likewise.
	(s390_sched_variable_issue): Likewise.
	(s390_loop_unroll_adjust): Likewise.
	(s390_option_override):  Likewise.

[-- Attachment #3: 0004-S390-Clean-up-handling-of-various-PROCESSOR_-values-.patch --]
[-- Type: text/x-diff, Size: 3293 bytes --]

From 1d52b5534a728c9625b64bb702f3adcb2fc35ed0 Mon Sep 17 00:00:00 2001
From: Dominik Vogt <vogt@linux.vnet.ibm.com>
Date: Wed, 8 Jul 2015 13:20:41 +0100
Subject: [PATCH 4/4] S390: Clean up handling of various PROCESSOR_* values
 with -mtune=.

---
 gcc/config/s390/s390.c | 32 +++++++++++++-------------------
 1 file changed, 13 insertions(+), 19 deletions(-)

diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c
index 27e1c35..1764243 100644
--- a/gcc/config/s390/s390.c
+++ b/gcc/config/s390/s390.c
@@ -7304,11 +7304,15 @@ s390_issue_rate (void)
       return 3;
     case PROCESSOR_2097_Z10:
       return 2;
+    case PROCESSOR_9672_G5:
+    case PROCESSOR_9672_G6:
+    case PROCESSOR_2064_Z900:
       /* Starting with EC12 we use the sched_reorder hook to take care
 	 of instruction dispatch constraints.  The algorithm only
 	 picks the best instruction and assumes only a single
 	 instruction gets issued per cycle.  */
     case PROCESSOR_2827_ZEC12:
+    case PROCESSOR_2964_Z13:
     default:
       return 1;
     }
@@ -12914,10 +12918,7 @@ s390_reorg (void)
   s390_optimize_prologue ();
 
   /* Walk over the insns and do some >=z10 specific changes.  */
-  if (s390_tune == PROCESSOR_2097_Z10
-      || s390_tune == PROCESSOR_2817_Z196
-      || s390_tune == PROCESSOR_2827_ZEC12
-      || s390_tune == PROCESSOR_2964_Z13)
+  if (s390_tune >= PROCESSOR_2097_Z10)
     {
       rtx_insn *insn;
       bool insn_added_p = false;
@@ -13168,12 +13169,12 @@ static int
 s390_sched_reorder (FILE *file, int verbose,
 		    rtx_insn **ready, int *nreadyp, int clock ATTRIBUTE_UNUSED)
 {
-  if (s390_tune == PROCESSOR_2097_Z10)
-    if (reload_completed && *nreadyp > 1)
-      s390_z10_prevent_earlyload_conflicts (ready, nreadyp);
+  if (s390_tune == PROCESSOR_2097_Z10
+      && reload_completed
+      && *nreadyp > 1)
+    s390_z10_prevent_earlyload_conflicts (ready, nreadyp);
 
-  if ((s390_tune == PROCESSOR_2827_ZEC12
-       || s390_tune == PROCESSOR_2964_Z13)
+  if (s390_tune >= PROCESSOR_2827_ZEC12
       && reload_completed
       && *nreadyp > 1)
     {
@@ -13256,8 +13257,7 @@ s390_sched_variable_issue (FILE *file, int verbose, rtx_insn *insn, int more)
 {
   last_scheduled_insn = insn;
 
-  if ((s390_tune == PROCESSOR_2827_ZEC12
-       || s390_tune == PROCESSOR_2964_Z13)
+  if (s390_tune >= PROCESSOR_2827_ZEC12
       && reload_completed
       && recog_memoized (insn) >= 0)
     {
@@ -13335,10 +13335,7 @@ s390_loop_unroll_adjust (unsigned nunroll, struct loop *loop)
   unsigned i;
   unsigned mem_count = 0;
 
-  if (s390_tune != PROCESSOR_2097_Z10
-      && s390_tune != PROCESSOR_2817_Z196
-      && s390_tune != PROCESSOR_2827_ZEC12
-      && s390_tune != PROCESSOR_2964_Z13)
+  if (s390_tune < PROCESSOR_2097_Z10)
     return nunroll;
 
   /* Count the number of memory references within the loop body.  */
@@ -13553,10 +13550,7 @@ s390_option_override (void)
     target_flags |= MASK_LONG_DOUBLE_128;
 #endif
 
-  if (s390_tune == PROCESSOR_2097_Z10
-      || s390_tune == PROCESSOR_2817_Z196
-      || s390_tune == PROCESSOR_2827_ZEC12
-      || s390_tune == PROCESSOR_2964_Z13)
+  if (s390_tune >= PROCESSOR_2097_Z10)
     {
       maybe_set_param_value (PARAM_MAX_UNROLLED_INSNS, 100,
 			     global_options.x_param_values,
-- 
2.3.0


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

* Re: [PATCH 3/4] S390 -march=native related fixes
  2015-07-17 16:08 ` [PATCH 3/4] " Dominik Vogt
@ 2015-07-17 16:43   ` Dominik Vogt
  2015-07-18  0:22     ` Ulrich Weigand
  0 siblings, 1 reply; 16+ messages in thread
From: Dominik Vogt @ 2015-07-17 16:43 UTC (permalink / raw)
  To: gcc-patches

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

> > The following series of patches contains fixes, and cleanup work
> > related to -march=native (and -mtune=native) for S390.
> > 
> > * 0003 -march=native now detects various cpu features and passes
> >        that as options from the driver to the compiler.

Sorry, some old code sneaked into the patch.  Updated version
without the dead code attached.  The ChangeLog ist still the same.

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany

[-- Attachment #2: 0003-S390-Handle-processor-capabilities-with-march-native.patch --]
[-- Type: text/x-diff, Size: 6119 bytes --]

From b7942651a85761dcd9cf1f1c0c01074b9c327e43 Mon Sep 17 00:00:00 2001
From: Dominik Vogt <vogt@linux.vnet.ibm.com>
Date: Mon, 6 Jul 2015 16:28:32 +0100
Subject: [PATCH 3/4] S390: Handle processor capabilities with -march=native.

---
 gcc/config/s390/driver-native.c | 130 +++++++++++++++++++++++++++++++---------
 gcc/config/s390/s390.h          |  32 +++++-----
 2 files changed, 120 insertions(+), 42 deletions(-)

diff --git a/gcc/config/s390/driver-native.c b/gcc/config/s390/driver-native.c
index 88c76bd..ff897cc 100644
--- a/gcc/config/s390/driver-native.c
+++ b/gcc/config/s390/driver-native.c
@@ -42,6 +42,14 @@ s390_host_detect_local_cpu (int argc, const char **argv)
   char buf[256];
   FILE *f;
   bool arch;
+  const char *options = "";
+  unsigned int has_features;
+  unsigned int has_processor;
+  unsigned int is_cpu_z9_109 = 0;
+  unsigned int has_highgprs = 0;
+  unsigned int has_dfp = 0;
+  unsigned int has_te = 0;
+  unsigned int has_vx = 0;
 
   if (argc < 1)
     return NULL;
@@ -54,38 +62,104 @@ s390_host_detect_local_cpu (int argc, const char **argv)
   if (f == NULL)
     return NULL;
 
-  while (fgets (buf, sizeof (buf), f) != NULL)
-    if (strncmp (buf, "processor", sizeof ("processor") - 1) == 0)
-      {
-	if (strstr (buf, "machine = 9672") != NULL)
-	  cpu = "g5";
-	else if (strstr (buf, "machine = 2064") != NULL
-		 || strstr (buf, "machine = 2066") != NULL)
-	  cpu = "z900";
-	else if (strstr (buf, "machine = 2084") != NULL
-		 || strstr (buf, "machine = 2086") != NULL)
-	  cpu = "z990";
-	else if (strstr (buf, "machine = 2094") != NULL
-		 || strstr (buf, "machine = 2096") != NULL)
-	  cpu = "z9-109";
-	else if (strstr (buf, "machine = 2097") != NULL
-		 || strstr (buf, "machine = 2098") != NULL)
-	  cpu = "z10";
-	else if (strstr (buf, "machine = 2817") != NULL
-		 || strstr (buf, "machine = 2818") != NULL)
-	  cpu = "z196";
-	else if (strstr (buf, "machine = 2827") != NULL
-		 || strstr (buf, "machine = 2828") != NULL)
-	  cpu = "zEC12";
-	else if (strstr (buf, "machine = 2964") != NULL)
-	  cpu = "z13";
-	break;
-      }
+  for (has_features = 0, has_processor = 0;
+       (has_features == 0 || has_processor == 0)
+	 && fgets (buf, sizeof (buf), f) != NULL; )
+    {
+      if (has_processor == 0 && strncmp (buf, "processor", 9) == 0)
+	{
+	  const char *p;
+	  long machine_id;
+
+	  p = strstr (buf, "machine = ");
+	  if (p == NULL)
+	    continue;
+	  p += 10;
+	  has_processor = 1;
+	  machine_id = strtol (p, NULL, 16);
+	  switch (machine_id)
+	    {
+	    case 0x9672:
+	      cpu = "g5";
+	      break;
+	    case 0x2064:
+	    case 0x2066:
+	      cpu = "z900";
+	      break;
+	    case 0x2084:
+	    case 0x2086:
+	      cpu = "z990";
+	      break;
+	    case 0x2094:
+	    case 0x2096:
+	      cpu = "z9-109";
+	      is_cpu_z9_109 = 1;
+	      break;
+	    case 0x2097:
+	    case 0x2098:
+	      cpu = "z10";
+	      break;
+	    case 0x2817:
+	    case 0x2818:
+	      cpu = "z196";
+	      break;
+	    case 0x2827:
+	    case 0x2828:
+	      cpu = "zEC12";
+	      break;
+	    case 0x2964:
+	      cpu = "z13";
+	      break;
+	    }
+	}
+      if (has_features == 0 && strncmp (buf, "features", 8) == 0)
+	{
+	  const char *p;
+
+	  p = strchr (buf, ':');
+	  if (p == NULL)
+	    continue;
+	  p++;
+	  while (*p != 0)
+	    {
+	      int i;
+
+	      while (ISSPACE (*p))
+		p++;
+	      for (i = 0; !ISSPACE (p[i]) && p[i] != 0; i++)
+		;
+	      if (i == 3 && strncmp (p, "dfp", 3) == 0)
+		has_dfp = 1;
+	      else if (i == 2 && strncmp (p, "te", 2) == 0)
+		has_te = 1;
+	      else if (i == 2 && strncmp (p, "vx", 2) == 0)
+		has_vx = 1;
+	      else if (i == 8 && strncmp (p, "highgprs", 8) == 0)
+		has_highgprs = 1;
+	      p += i;
+	    }
+	  has_features = 1;
+	}
+    }
 
   fclose (f);
 
   if (cpu == NULL)
     return NULL;
 
-  return concat ("-m", argv[0], "=", cpu, NULL);
+  if (arch)
+    {
+      const char *opt_htm = "";
+      const char *opt_vx = "";
+      const char *opt_esa_zarch = "";
+
+      opt_htm = (has_te) ? " -mhtm" : " -mno-htm";
+      opt_vx = (has_vx) ? " -mvx" : " -mno-vx";
+      opt_esa_zarch = (has_highgprs) ? " -mzarch" : " -mesa";
+      options = concat (options, opt_htm, opt_vx, opt_esa_zarch, NULL);
+    }
+  if (has_dfp && is_cpu_z9_109)
+    cpu = "z9-ec";
+
+  return concat ("-m", argv[0], "=", cpu, options, NULL);
 }
diff --git a/gcc/config/s390/s390.h b/gcc/config/s390/s390.h
index f18b973..cfe23d4 100644
--- a/gcc/config/s390/s390.h
+++ b/gcc/config/s390/s390.h
@@ -131,26 +131,30 @@ extern const char *s390_host_detect_local_cpu (int argc, const char **argv);
 # define EXTRA_SPEC_FUNCTIONS \
   { "local_cpu_detect", s390_host_detect_local_cpu },
 
-# define MARCH_MTUNE_NATIVE_SPECS				\
-  " %{march=native:%<march=native %:local_cpu_detect(arch)}"	\
-  " %{mtune=native:%<mtune=native %:local_cpu_detect(tune)}"
+#define MARCH_MTUNE_NATIVE_SPECS			\
+  "%{mtune=native:%<mtune=native %:local_cpu_detect(tune)} "	\
+  "%{march=native:%<march=native %:local_cpu_detect(arch)} "
 #else
 # define MARCH_MTUNE_NATIVE_SPECS ""
 #endif
 
-/* Defaulting rules.  */
 #ifdef DEFAULT_TARGET_64BIT
-#define DRIVER_SELF_SPECS					\
-  "%{!m31:%{!m64:-m64}}",					\
-  "%{!mesa:%{!mzarch:%{m31:-mesa}%{m64:-mzarch}}}",		\
-  "%{!march=*:%{mesa:-march=g5}%{mzarch:-march=z900}}",		\
-  MARCH_MTUNE_NATIVE_SPECS
+#define S390_TARGET_BITS_STRING "64"
 #else
-#define DRIVER_SELF_SPECS					\
-  "%{!m31:%{!m64:-m31}}",					\
-  "%{!mesa:%{!mzarch:%{m31:-mesa}%{m64:-mzarch}}}",		\
-  "%{!march=*:%{mesa:-march=g5}%{mzarch:-march=z900}}",		\
-  MARCH_MTUNE_NATIVE_SPECS
+#define S390_TARGET_BITS_STRING "31"
+#endif
+
+/* Defaulting rules.  */
+#define CC1_CPU_SPEC						\
+  "%{!m31:%{!m64:-m" S390_TARGET_BITS_STRING "}} "		\
+  "%{!march=*:%{mesa:-march=g5}%{mzarch:-march=z900}} "		\
+  MARCH_MTUNE_NATIVE_SPECS					\
+  "%{!mesa:%{!mzarch:%{m31:-mesa}%{m64:-mzarch}}} "
+
+#define EXTRA_SPECS { "cc1_cpu",  CC1_CPU_SPEC },
+
+#ifndef CC1_SPEC
+#define CC1_SPEC "%(cc1_cpu) "
 #endif
 
 /* Constants needed to control the TEST DATA CLASS (TDC) instruction.  */
-- 
2.3.0


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

* Re: [PATCH 3/4] S390 -march=native related fixes
  2015-07-17 16:43   ` Dominik Vogt
@ 2015-07-18  0:22     ` Ulrich Weigand
  2015-07-20 16:10       ` Dominik Vogt
  0 siblings, 1 reply; 16+ messages in thread
From: Ulrich Weigand @ 2015-07-18  0:22 UTC (permalink / raw)
  To: vogt; +Cc: gcc-patches, krebbel

Dominik Vogt wrote:

> +      opt_esa_zarch = (has_highgprs) ? " -mzarch" : " -mesa";

This will force -mesa on old machines *even in -m64 mode*,
which is wrong and will cause compilation to fail.


> -/* Defaulting rules.  */
>  #ifdef DEFAULT_TARGET_64BIT
> -#define DRIVER_SELF_SPECS					\

This completely removes use of DRIVER_SELF_SPECS for defaulting,
which I introduced back here:
https://gcc.gnu.org/ml/gcc-patches/2003-06/msg03369.html

The reason for using DRIVER_SELF_SPECS as described there is to
make sure we use compatible flags for compiler, assembler and
linker in all cases, even if some of those flags result from
defaulting rules.

If we don't do that, we rely on those components agreeing exactly
in how to default for unspecified options; for example, we want
to give the correct -march flag to the assembler as an additional
verification to detect compiler bugs where the compiler erroneously
generates an incorrect instruction for that architecture.

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU/Linux compilers and toolchain
  Ulrich.Weigand@de.ibm.com

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

* Re: [PATCH 3/4] S390 -march=native related fixes
  2015-07-18  0:22     ` Ulrich Weigand
@ 2015-07-20 16:10       ` Dominik Vogt
  2015-07-21 11:23         ` Ulrich Weigand
  0 siblings, 1 reply; 16+ messages in thread
From: Dominik Vogt @ 2015-07-20 16:10 UTC (permalink / raw)
  To: gcc-patches

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

On Sat, Jul 18, 2015 at 01:09:26AM +0200, Ulrich Weigand wrote:
> Dominik Vogt wrote:
> 
> > +      opt_esa_zarch = (has_highgprs) ? " -mzarch" : " -mesa";
> 
> This will force -mesa on old machines *even in -m64 mode*,
> which is wrong and will cause compilation to fail.
> 
> 
> > -/* Defaulting rules.  */
> >  #ifdef DEFAULT_TARGET_64BIT
> > -#define DRIVER_SELF_SPECS					\
> 
> This completely removes use of DRIVER_SELF_SPECS for defaulting,
> which I introduced back here:
> https://gcc.gnu.org/ml/gcc-patches/2003-06/msg03369.html
>...

New version of the patch and ChangeLog attached, as discussed
internally:

 * -march=native never setzt -mvx or -mhtm but disables these
   features if the cpu does not support them.  This always wins
   against any options set on the command line.

 * -march=native never sets -mesa, and appends -mzarch to the
   command line if the highgprs cpu flag is present and the command
   line does not specify -mesa (or -mzarch).

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany

[-- Attachment #2: 0003-v3-ChangeLog --]
[-- Type: text/plain, Size: 305 bytes --]

gcc/ChangeLog

	* config/s390/driver-native.c (s390_host_detect_local_cpu): Handle
	processor capabilities with -march=native.
	* config/s390/s390.h (MARCH_MTUNE_NATIVE_SPECS): Likewise.
	(DRIVER_SELF_SPECS): Likewise.  Join specs for 31 and 64 bit.
	* (S390_TARGET_BITS_STRING): Macro to simplify specs.

[-- Attachment #3: 0003-v3-S390-Handle-processor-capabilities-with-march-native.patch --]
[-- Type: text/x-diff, Size: 6776 bytes --]

From 2120164854639bee14053d7cd418fdbb7ebfc8b7 Mon Sep 17 00:00:00 2001
From: Dominik Vogt <vogt@linux.vnet.ibm.com>
Date: Mon, 6 Jul 2015 16:28:32 +0100
Subject: [PATCH 3/4] S390: Handle processor capabilities with -march=native.

---
 gcc/config/s390/driver-native.c | 143 ++++++++++++++++++++++++++++++++--------
 gcc/config/s390/s390.h          |  28 ++++----
 2 files changed, 129 insertions(+), 42 deletions(-)

diff --git a/gcc/config/s390/driver-native.c b/gcc/config/s390/driver-native.c
index 88c76bd..5f7fe0a 100644
--- a/gcc/config/s390/driver-native.c
+++ b/gcc/config/s390/driver-native.c
@@ -42,6 +42,16 @@ s390_host_detect_local_cpu (int argc, const char **argv)
   char buf[256];
   FILE *f;
   bool arch;
+  const char *options = "";
+  unsigned int has_features;
+  unsigned int has_processor;
+  unsigned int is_cpu_z9_109 = 0;
+  unsigned int has_highgprs = 0;
+  unsigned int has_dfp = 0;
+  unsigned int has_te = 0;
+  unsigned int has_vx = 0;
+  unsigned int has_opt_esa_zarch = 0;
+  int i;
 
   if (argc < 1)
     return NULL;
@@ -49,43 +59,120 @@ s390_host_detect_local_cpu (int argc, const char **argv)
   arch = strcmp (argv[0], "arch") == 0;
   if (!arch && strcmp (argv[0], "tune"))
     return NULL;
+  for (i = 1; i < argc; i++)
+    if (strcmp (argv[i], "mesa_mzarch") == 0)
+      has_opt_esa_zarch = 1;
 
   f = fopen ("/proc/cpuinfo", "r");
   if (f == NULL)
     return NULL;
 
-  while (fgets (buf, sizeof (buf), f) != NULL)
-    if (strncmp (buf, "processor", sizeof ("processor") - 1) == 0)
-      {
-	if (strstr (buf, "machine = 9672") != NULL)
-	  cpu = "g5";
-	else if (strstr (buf, "machine = 2064") != NULL
-		 || strstr (buf, "machine = 2066") != NULL)
-	  cpu = "z900";
-	else if (strstr (buf, "machine = 2084") != NULL
-		 || strstr (buf, "machine = 2086") != NULL)
-	  cpu = "z990";
-	else if (strstr (buf, "machine = 2094") != NULL
-		 || strstr (buf, "machine = 2096") != NULL)
-	  cpu = "z9-109";
-	else if (strstr (buf, "machine = 2097") != NULL
-		 || strstr (buf, "machine = 2098") != NULL)
-	  cpu = "z10";
-	else if (strstr (buf, "machine = 2817") != NULL
-		 || strstr (buf, "machine = 2818") != NULL)
-	  cpu = "z196";
-	else if (strstr (buf, "machine = 2827") != NULL
-		 || strstr (buf, "machine = 2828") != NULL)
-	  cpu = "zEC12";
-	else if (strstr (buf, "machine = 2964") != NULL)
-	  cpu = "z13";
-	break;
-      }
+  for (has_features = 0, has_processor = 0;
+       (has_features == 0 || has_processor == 0)
+	 && fgets (buf, sizeof (buf), f) != NULL; )
+    {
+      if (has_processor == 0 && strncmp (buf, "processor", 9) == 0)
+	{
+	  const char *p;
+	  long machine_id;
+
+	  p = strstr (buf, "machine = ");
+	  if (p == NULL)
+	    continue;
+	  p += 10;
+	  has_processor = 1;
+	  machine_id = strtol (p, NULL, 16);
+	  switch (machine_id)
+	    {
+	    case 0x9672:
+	      cpu = "g5";
+	      break;
+	    case 0x2064:
+	    case 0x2066:
+	      cpu = "z900";
+	      break;
+	    case 0x2084:
+	    case 0x2086:
+	      cpu = "z990";
+	      break;
+	    case 0x2094:
+	    case 0x2096:
+	      cpu = "z9-109";
+	      is_cpu_z9_109 = 1;
+	      break;
+	    case 0x2097:
+	    case 0x2098:
+	      cpu = "z10";
+	      break;
+	    case 0x2817:
+	    case 0x2818:
+	      cpu = "z196";
+	      break;
+	    case 0x2827:
+	    case 0x2828:
+	      cpu = "zEC12";
+	      break;
+	    case 0x2964:
+	      cpu = "z13";
+	      break;
+	    }
+	}
+      if (has_features == 0 && strncmp (buf, "features", 8) == 0)
+	{
+	  const char *p;
+
+	  p = strchr (buf, ':');
+	  if (p == NULL)
+	    continue;
+	  p++;
+	  while (*p != 0)
+	    {
+	      int i;
+
+	      while (ISSPACE (*p))
+		p++;
+	      for (i = 0; !ISSPACE (p[i]) && p[i] != 0; i++)
+		;
+	      if (i == 3 && strncmp (p, "dfp", 3) == 0)
+		has_dfp = 1;
+	      else if (i == 2 && strncmp (p, "te", 2) == 0)
+		has_te = 1;
+	      else if (i == 2 && strncmp (p, "vx", 2) == 0)
+		has_vx = 1;
+	      else if (i == 8 && strncmp (p, "highgprs", 8) == 0)
+		has_highgprs = 1;
+	      p += i;
+	    }
+	  has_features = 1;
+	}
+    }
 
   fclose (f);
 
   if (cpu == NULL)
     return NULL;
 
-  return concat ("-m", argv[0], "=", cpu, NULL);
+  if (arch)
+    {
+      const char *opt_htm = "";
+      const char *opt_vx = "";
+      const char *opt_esa_zarch = "";
+
+      /* We may switch off these cpu features but never switch the on
+	 explicitly.  This overrides options specified on the command line.  */
+      if (!has_te)
+	opt_htm = " -mno-htm";
+      if (!has_vx)
+	opt_vx = " -mno-vx";
+      /* However, we set -mzarch only if neither -mzarch nor -mesa are used on
+	 the command line.  This allows the user to switch to -mesa manually.
+      */
+      if (!has_opt_esa_zarch && has_highgprs)
+	opt_esa_zarch = " -mzarch";
+      options = concat (options, opt_htm, opt_vx, opt_esa_zarch, NULL);
+    }
+  if (has_dfp && is_cpu_z9_109)
+    cpu = "z9-ec";
+
+  return concat ("-m", argv[0], "=", cpu, options, NULL);
 }
diff --git a/gcc/config/s390/s390.h b/gcc/config/s390/s390.h
index f18b973..5882d04 100644
--- a/gcc/config/s390/s390.h
+++ b/gcc/config/s390/s390.h
@@ -131,28 +131,28 @@ extern const char *s390_host_detect_local_cpu (int argc, const char **argv);
 # define EXTRA_SPEC_FUNCTIONS \
   { "local_cpu_detect", s390_host_detect_local_cpu },
 
-# define MARCH_MTUNE_NATIVE_SPECS				\
-  " %{march=native:%<march=native %:local_cpu_detect(arch)}"	\
-  " %{mtune=native:%<mtune=native %:local_cpu_detect(tune)}"
+#define MARCH_MTUNE_NATIVE_SPECS				\
+  "%{mtune=native:%<mtune=native %:local_cpu_detect(tune)} "	\
+  "%{march=native:%<march=native"				\
+  " %:local_cpu_detect(arch %{mesa|mzarch:mesa_mzarch})}"
 #else
 # define MARCH_MTUNE_NATIVE_SPECS ""
 #endif
 
-/* Defaulting rules.  */
 #ifdef DEFAULT_TARGET_64BIT
-#define DRIVER_SELF_SPECS					\
-  "%{!m31:%{!m64:-m64}}",					\
-  "%{!mesa:%{!mzarch:%{m31:-mesa}%{m64:-mzarch}}}",		\
-  "%{!march=*:%{mesa:-march=g5}%{mzarch:-march=z900}}",		\
-  MARCH_MTUNE_NATIVE_SPECS
+#define S390_TARGET_BITS_STRING "64"
 #else
-#define DRIVER_SELF_SPECS					\
-  "%{!m31:%{!m64:-m31}}",					\
-  "%{!mesa:%{!mzarch:%{m31:-mesa}%{m64:-mzarch}}}",		\
-  "%{!march=*:%{mesa:-march=g5}%{mzarch:-march=z900}}",		\
-  MARCH_MTUNE_NATIVE_SPECS
+#define S390_TARGET_BITS_STRING "31"
 #endif
 
+/* Defaulting rules.  */
+#define DRIVER_SELF_SPECS					\
+  "%{!m31:%{!m64:-m" S390_TARGET_BITS_STRING "}} "		\
+  "%{!march=*:%{mesa:-march=g5}%{mzarch:-march=z900}} "		\
+  MARCH_MTUNE_NATIVE_SPECS					\
+  "%{!mesa:%{!mzarch:%{m31:-mesa}%{m64:-mzarch}}} "
+
+
 /* Constants needed to control the TEST DATA CLASS (TDC) instruction.  */
 #define S390_TDC_POSITIVE_ZERO                     (1 << 11)
 #define S390_TDC_NEGATIVE_ZERO                     (1 << 10)
-- 
2.3.0


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

* Re: [PATCH 3/4] S390 -march=native related fixes
  2015-07-20 16:10       ` Dominik Vogt
@ 2015-07-21 11:23         ` Ulrich Weigand
  2015-07-21 12:53           ` Dominik Vogt
  0 siblings, 1 reply; 16+ messages in thread
From: Ulrich Weigand @ 2015-07-21 11:23 UTC (permalink / raw)
  To: vogt; +Cc: gcc-patches

Dominik Vogt wrote:

> 	* config/s390/driver-native.c (s390_host_detect_local_cpu): Handle
> 	processor capabilities with -march=native.
> 	* config/s390/s390.h (MARCH_MTUNE_NATIVE_SPECS): Likewise.
> 	(DRIVER_SELF_SPECS): Likewise.  Join specs for 31 and 64 bit.
> 	* (S390_TARGET_BITS_STRING): Macro to simplify specs.

This version is looking good, except for one problem:

> -  "%{!m31:%{!m64:-m64}}",					\
> -  "%{!mesa:%{!mzarch:%{m31:-mesa}%{m64:-mzarch}}}",		\
> -  "%{!march=*:%{mesa:-march=g5}%{mzarch:-march=z900}}",		\

There's a reason for this particular sequence.  The first line ensures
that one of -m64 or -m31 is present.  The second line ensures that one
of -mesa or -mzarch is present, but this works only if already one of
-m64 or -m31 is present, so it needs to come *after* the first line.
The third line ensures that some -march= switch is present, but this
works only if already one of -mesa or -mzarch is present, so it needs
to comer *after* the second line.

> +#define DRIVER_SELF_SPECS					\
> +  "%{!m31:%{!m64:-m" S390_TARGET_BITS_STRING "}} "		\
> +  "%{!march=*:%{mesa:-march=g5}%{mzarch:-march=z900}} "		\
> +  MARCH_MTUNE_NATIVE_SPECS					\
> +  "%{!mesa:%{!mzarch:%{m31:-mesa}%{m64:-mzarch}}} "

This inverts the order of the second and third lines, so it is now
no longer guaranteed that at least one -march= switch is present.

I understand that you need to move MARCH_MTUNE_NATIVE_SPECS ahead
of the -mesa/-mzarch defaulting rule, but it should be possible
to do that without changing the sequence of the three existing
rules.  Why not just move MARCH_MTUNE_NATIVE_SPECS first?

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU/Linux compilers and toolchain
  Ulrich.Weigand@de.ibm.com

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

* Re: [PATCH 3/4] S390 -march=native related fixes
  2015-07-21 11:23         ` Ulrich Weigand
@ 2015-07-21 12:53           ` Dominik Vogt
  2015-07-21 17:15             ` Ulrich Weigand
  0 siblings, 1 reply; 16+ messages in thread
From: Dominik Vogt @ 2015-07-21 12:53 UTC (permalink / raw)
  To: gcc-patches

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

On Tue, Jul 21, 2015 at 01:14:44PM +0200, Ulrich Weigand wrote:
> Dominik Vogt wrote:
> This version is looking good, except for one problem:
> 
> > -  "%{!m31:%{!m64:-m64}}",					\
> > -  "%{!mesa:%{!mzarch:%{m31:-mesa}%{m64:-mzarch}}}",		\
> > -  "%{!march=*:%{mesa:-march=g5}%{mzarch:-march=z900}}",		\
> 
> There's a reason for this particular sequence.  The first line ensures
> that one of -m64 or -m31 is present.  The second line ensures that one
> of -mesa or -mzarch is present, but this works only if already one of
> -m64 or -m31 is present, so it needs to come *after* the first line.
> The third line ensures that some -march= switch is present, but this
> works only if already one of -mesa or -mzarch is present, so it needs
> to comer *after* the second line.
> 
> > +#define DRIVER_SELF_SPECS					\
> > +  "%{!m31:%{!m64:-m" S390_TARGET_BITS_STRING "}} "		\
> > +  "%{!march=*:%{mesa:-march=g5}%{mzarch:-march=z900}} "		\
> > +  MARCH_MTUNE_NATIVE_SPECS					\
> > +  "%{!mesa:%{!mzarch:%{m31:-mesa}%{m64:-mzarch}}} "
> 
> This inverts the order of the second and third lines, so it is now
> no longer guaranteed that at least one -march= switch is present.
> 
> I understand that you need to move MARCH_MTUNE_NATIVE_SPECS ahead
> of the -mesa/-mzarch defaulting rule, but it should be possible
> to do that without changing the sequence of the three existing
> rules.  Why not just move MARCH_MTUNE_NATIVE_SPECS first?

Okay, good point.  Since this is a bit complicated, let's consider
which effect this change would have on the following two cases in
conjunction with -march=native:

1. local_cpu_detect returns -march=<something>

   Before suggested change: -march=<something> takes effect
   After change: -march=<something> takes effect

   => Correct behaviour in both cases, the second line never does
   anything.

2. local_cpu_detect returns nothing (empty string)

   Before change: No architecture string is used at all -> Bad!
   After change: The default defined by the second line kicks in.

   So the current code has even another bug, apart from the issue
   you have mentioned.

Given the above line numbering (1, 2, 3, 4), the order of
activation of the spec rules should be

 * 1, 4        with -march=<something> (<something> != native)
 * 1, 4, 2     without -march=<something>
 * 1, 3, 4     with -march=native (if local_cpu_detect returns a string)
 * 1, 3, 4, 2  with -march=native (if local_cpu_detect returns nothing)

So, the suggested order 1, 3, 4, 2 should cover all these cases.

Also, there's another bug.  The spec lines need to be separated by
commas.  This change is also contained in the attached new patch
(v4).

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany

[-- Attachment #2: 0003-v4-ChangeLog.patch --]
[-- Type: text/x-diff, Size: 305 bytes --]

gcc/ChangeLog

	* config/s390/driver-native.c (s390_host_detect_local_cpu): Handle
	processor capabilities with -march=native.
	* config/s390/s390.h (MARCH_MTUNE_NATIVE_SPECS): Likewise.
	(DRIVER_SELF_SPECS): Likewise.  Join specs for 31 and 64 bit.
	* (S390_TARGET_BITS_STRING): Macro to simplify specs.

[-- Attachment #3: 0003-v4-S390-Handle-processor-capabilities-with-march-native.patch --]
[-- Type: text/x-diff, Size: 6779 bytes --]

From 1fc834c4d5d3ac9e26cad101b8a16900a83f4ca0 Mon Sep 17 00:00:00 2001
From: Dominik Vogt <vogt@linux.vnet.ibm.com>
Date: Mon, 6 Jul 2015 16:28:32 +0100
Subject: [PATCH 3/4] S390: Handle processor capabilities with -march=native.

---
 gcc/config/s390/driver-native.c | 143 ++++++++++++++++++++++++++++++++--------
 gcc/config/s390/s390.h          |  28 ++++----
 2 files changed, 129 insertions(+), 42 deletions(-)

diff --git a/gcc/config/s390/driver-native.c b/gcc/config/s390/driver-native.c
index 88c76bd..5f7fe0a 100644
--- a/gcc/config/s390/driver-native.c
+++ b/gcc/config/s390/driver-native.c
@@ -42,6 +42,16 @@ s390_host_detect_local_cpu (int argc, const char **argv)
   char buf[256];
   FILE *f;
   bool arch;
+  const char *options = "";
+  unsigned int has_features;
+  unsigned int has_processor;
+  unsigned int is_cpu_z9_109 = 0;
+  unsigned int has_highgprs = 0;
+  unsigned int has_dfp = 0;
+  unsigned int has_te = 0;
+  unsigned int has_vx = 0;
+  unsigned int has_opt_esa_zarch = 0;
+  int i;
 
   if (argc < 1)
     return NULL;
@@ -49,43 +59,120 @@ s390_host_detect_local_cpu (int argc, const char **argv)
   arch = strcmp (argv[0], "arch") == 0;
   if (!arch && strcmp (argv[0], "tune"))
     return NULL;
+  for (i = 1; i < argc; i++)
+    if (strcmp (argv[i], "mesa_mzarch") == 0)
+      has_opt_esa_zarch = 1;
 
   f = fopen ("/proc/cpuinfo", "r");
   if (f == NULL)
     return NULL;
 
-  while (fgets (buf, sizeof (buf), f) != NULL)
-    if (strncmp (buf, "processor", sizeof ("processor") - 1) == 0)
-      {
-	if (strstr (buf, "machine = 9672") != NULL)
-	  cpu = "g5";
-	else if (strstr (buf, "machine = 2064") != NULL
-		 || strstr (buf, "machine = 2066") != NULL)
-	  cpu = "z900";
-	else if (strstr (buf, "machine = 2084") != NULL
-		 || strstr (buf, "machine = 2086") != NULL)
-	  cpu = "z990";
-	else if (strstr (buf, "machine = 2094") != NULL
-		 || strstr (buf, "machine = 2096") != NULL)
-	  cpu = "z9-109";
-	else if (strstr (buf, "machine = 2097") != NULL
-		 || strstr (buf, "machine = 2098") != NULL)
-	  cpu = "z10";
-	else if (strstr (buf, "machine = 2817") != NULL
-		 || strstr (buf, "machine = 2818") != NULL)
-	  cpu = "z196";
-	else if (strstr (buf, "machine = 2827") != NULL
-		 || strstr (buf, "machine = 2828") != NULL)
-	  cpu = "zEC12";
-	else if (strstr (buf, "machine = 2964") != NULL)
-	  cpu = "z13";
-	break;
-      }
+  for (has_features = 0, has_processor = 0;
+       (has_features == 0 || has_processor == 0)
+	 && fgets (buf, sizeof (buf), f) != NULL; )
+    {
+      if (has_processor == 0 && strncmp (buf, "processor", 9) == 0)
+	{
+	  const char *p;
+	  long machine_id;
+
+	  p = strstr (buf, "machine = ");
+	  if (p == NULL)
+	    continue;
+	  p += 10;
+	  has_processor = 1;
+	  machine_id = strtol (p, NULL, 16);
+	  switch (machine_id)
+	    {
+	    case 0x9672:
+	      cpu = "g5";
+	      break;
+	    case 0x2064:
+	    case 0x2066:
+	      cpu = "z900";
+	      break;
+	    case 0x2084:
+	    case 0x2086:
+	      cpu = "z990";
+	      break;
+	    case 0x2094:
+	    case 0x2096:
+	      cpu = "z9-109";
+	      is_cpu_z9_109 = 1;
+	      break;
+	    case 0x2097:
+	    case 0x2098:
+	      cpu = "z10";
+	      break;
+	    case 0x2817:
+	    case 0x2818:
+	      cpu = "z196";
+	      break;
+	    case 0x2827:
+	    case 0x2828:
+	      cpu = "zEC12";
+	      break;
+	    case 0x2964:
+	      cpu = "z13";
+	      break;
+	    }
+	}
+      if (has_features == 0 && strncmp (buf, "features", 8) == 0)
+	{
+	  const char *p;
+
+	  p = strchr (buf, ':');
+	  if (p == NULL)
+	    continue;
+	  p++;
+	  while (*p != 0)
+	    {
+	      int i;
+
+	      while (ISSPACE (*p))
+		p++;
+	      for (i = 0; !ISSPACE (p[i]) && p[i] != 0; i++)
+		;
+	      if (i == 3 && strncmp (p, "dfp", 3) == 0)
+		has_dfp = 1;
+	      else if (i == 2 && strncmp (p, "te", 2) == 0)
+		has_te = 1;
+	      else if (i == 2 && strncmp (p, "vx", 2) == 0)
+		has_vx = 1;
+	      else if (i == 8 && strncmp (p, "highgprs", 8) == 0)
+		has_highgprs = 1;
+	      p += i;
+	    }
+	  has_features = 1;
+	}
+    }
 
   fclose (f);
 
   if (cpu == NULL)
     return NULL;
 
-  return concat ("-m", argv[0], "=", cpu, NULL);
+  if (arch)
+    {
+      const char *opt_htm = "";
+      const char *opt_vx = "";
+      const char *opt_esa_zarch = "";
+
+      /* We may switch off these cpu features but never switch the on
+	 explicitly.  This overrides options specified on the command line.  */
+      if (!has_te)
+	opt_htm = " -mno-htm";
+      if (!has_vx)
+	opt_vx = " -mno-vx";
+      /* However, we set -mzarch only if neither -mzarch nor -mesa are used on
+	 the command line.  This allows the user to switch to -mesa manually.
+      */
+      if (!has_opt_esa_zarch && has_highgprs)
+	opt_esa_zarch = " -mzarch";
+      options = concat (options, opt_htm, opt_vx, opt_esa_zarch, NULL);
+    }
+  if (has_dfp && is_cpu_z9_109)
+    cpu = "z9-ec";
+
+  return concat ("-m", argv[0], "=", cpu, options, NULL);
 }
diff --git a/gcc/config/s390/s390.h b/gcc/config/s390/s390.h
index f18b973..66d6702 100644
--- a/gcc/config/s390/s390.h
+++ b/gcc/config/s390/s390.h
@@ -131,28 +131,28 @@ extern const char *s390_host_detect_local_cpu (int argc, const char **argv);
 # define EXTRA_SPEC_FUNCTIONS \
   { "local_cpu_detect", s390_host_detect_local_cpu },
 
-# define MARCH_MTUNE_NATIVE_SPECS				\
-  " %{march=native:%<march=native %:local_cpu_detect(arch)}"	\
-  " %{mtune=native:%<mtune=native %:local_cpu_detect(tune)}"
+#define MARCH_MTUNE_NATIVE_SPECS				\
+  "%{mtune=native:%<mtune=native %:local_cpu_detect(tune)} "	\
+  "%{march=native:%<march=native"				\
+  " %:local_cpu_detect(arch %{mesa|mzarch:mesa_mzarch})}"
 #else
 # define MARCH_MTUNE_NATIVE_SPECS ""
 #endif
 
-/* Defaulting rules.  */
 #ifdef DEFAULT_TARGET_64BIT
-#define DRIVER_SELF_SPECS					\
-  "%{!m31:%{!m64:-m64}}",					\
-  "%{!mesa:%{!mzarch:%{m31:-mesa}%{m64:-mzarch}}}",		\
-  "%{!march=*:%{mesa:-march=g5}%{mzarch:-march=z900}}",		\
-  MARCH_MTUNE_NATIVE_SPECS
+#define S390_TARGET_BITS_STRING "64"
 #else
-#define DRIVER_SELF_SPECS					\
-  "%{!m31:%{!m64:-m31}}",					\
-  "%{!mesa:%{!mzarch:%{m31:-mesa}%{m64:-mzarch}}}",		\
-  "%{!march=*:%{mesa:-march=g5}%{mzarch:-march=z900}}",		\
-  MARCH_MTUNE_NATIVE_SPECS
+#define S390_TARGET_BITS_STRING "31"
 #endif
 
+/* Defaulting rules.  */
+#define DRIVER_SELF_SPECS					\
+  "%{!m31:%{!m64:-m" S390_TARGET_BITS_STRING "}} ",		\
+  MARCH_MTUNE_NATIVE_SPECS,					\
+  "%{!mesa:%{!mzarch:%{m31:-mesa}%{m64:-mzarch}}} ",		\
+  "%{!march=*:%{mesa:-march=g5}%{mzarch:-march=z900}} "
+
+
 /* Constants needed to control the TEST DATA CLASS (TDC) instruction.  */
 #define S390_TDC_POSITIVE_ZERO                     (1 << 11)
 #define S390_TDC_NEGATIVE_ZERO                     (1 << 10)
-- 
2.3.0


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

* Re: [PATCH 3/4] S390 -march=native related fixes
  2015-07-21 12:53           ` Dominik Vogt
@ 2015-07-21 17:15             ` Ulrich Weigand
  2015-07-22 10:54               ` Dominik Vogt
  0 siblings, 1 reply; 16+ messages in thread
From: Ulrich Weigand @ 2015-07-21 17:15 UTC (permalink / raw)
  To: vogt; +Cc: gcc-patches

Dominik Vogt wrote:

> 	* config/s390/driver-native.c (s390_host_detect_local_cpu): Handle
> 	processor capabilities with -march=native.
> 	* config/s390/s390.h (MARCH_MTUNE_NATIVE_SPECS): Likewise.
> 	(DRIVER_SELF_SPECS): Likewise.  Join specs for 31 and 64 bit.
> 	* (S390_TARGET_BITS_STRING): Macro to simplify specs.
(That last "*" is superfluous.)

This looks correct to me now, just a cosmetic comment:

> +/* Defaulting rules.  */
> +#define DRIVER_SELF_SPECS					\
> +  "%{!m31:%{!m64:-m" S390_TARGET_BITS_STRING "}} ",		\
> +  MARCH_MTUNE_NATIVE_SPECS,					\
> +  "%{!mesa:%{!mzarch:%{m31:-mesa}%{m64:-mzarch}}} ",		\
> +  "%{!march=*:%{mesa:-march=g5}%{mzarch:-march=z900}} "

There's no need to add those spaces at the end -- the self specs
are all independent string, they don't need to end in a space.

Also, I had thought to put MARCH_MTUNE_NATIVE_SPECS right at the
top of list, like so:

#define DRIVER_SELF_SPECS					\
  MARCH_MTUNE_NATIVE_SPECS,					\
  "%{!m31:%{!m64:-m" S390_TARGET_BITS_STRING "}}",		\
  "%{!mesa:%{!mzarch:%{m31:-mesa}%{m64:-mzarch}}}",		\
  "%{!march=*:%{mesa:-march=g5}%{mzarch:-march=z900}}"

But there should not be any functional difference between the two,
it just looks a bit nicer maybe.

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU/Linux compilers and toolchain
  Ulrich.Weigand@de.ibm.com

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

* Re: [PATCH 3/4] S390 -march=native related fixes
  2015-07-21 17:15             ` Ulrich Weigand
@ 2015-07-22 10:54               ` Dominik Vogt
  2015-07-23 13:03                 ` Ulrich Weigand
  0 siblings, 1 reply; 16+ messages in thread
From: Dominik Vogt @ 2015-07-22 10:54 UTC (permalink / raw)
  To: gcc-patches

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

On Tue, Jul 21, 2015 at 07:05:27PM +0200, Ulrich Weigand wrote:
> Dominik Vogt wrote:
> > 	* config/s390/driver-native.c (s390_host_detect_local_cpu): Handle
> > 	processor capabilities with -march=native.
> > 	* config/s390/s390.h (MARCH_MTUNE_NATIVE_SPECS): Likewise.
> > 	(DRIVER_SELF_SPECS): Likewise.  Join specs for 31 and 64 bit.
> > 	* (S390_TARGET_BITS_STRING): Macro to simplify specs.
> (That last "*" is superfluous.)
> 
> This looks correct to me now, just a cosmetic comment:
> 
> > +/* Defaulting rules.  */
> > +#define DRIVER_SELF_SPECS					\
> > +  "%{!m31:%{!m64:-m" S390_TARGET_BITS_STRING "}} ",		\
> > +  MARCH_MTUNE_NATIVE_SPECS,					\
> > +  "%{!mesa:%{!mzarch:%{m31:-mesa}%{m64:-mzarch}}} ",		\
> > +  "%{!march=*:%{mesa:-march=g5}%{mzarch:-march=z900}} "
> 
> There's no need to add those spaces at the end -- the self specs
> are all independent string, they don't need to end in a space.
> 
> Also, I had thought to put MARCH_MTUNE_NATIVE_SPECS right at the
> top of list, like so:
> 
> #define DRIVER_SELF_SPECS					\
>   MARCH_MTUNE_NATIVE_SPECS,					\
>   "%{!m31:%{!m64:-m" S390_TARGET_BITS_STRING "}}",		\
>   "%{!mesa:%{!mzarch:%{m31:-mesa}%{m64:-mzarch}}}",		\
>   "%{!march=*:%{mesa:-march=g5}%{mzarch:-march=z900}}"
> 
> But there should not be any functional difference between the two,
> it just looks a bit nicer maybe.

The order was important in an earlier version of the patch, so
That's why I missed that.  Version 5 of the patch cleans up all
the things you've mentioned and also removes a superfluous newline.

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany

[-- Attachment #2: 0003-v5-ChangeLog.patch --]
[-- Type: text/x-diff, Size: 304 bytes --]

gcc/ChangeLog
 
	* config/s390/driver-native.c (s390_host_detect_local_cpu): Handle
	processor capabilities with -march=native.
	* config/s390/s390.h (MARCH_MTUNE_NATIVE_SPECS): Likewise.
	(DRIVER_SELF_SPECS): Likewise.  Join specs for 31 and 64 bit.
	(S390_TARGET_BITS_STRING): Macro to simplify specs.

[-- Attachment #3: 0003-v5-S390-Handle-processor-capabilities-with-march-native.patch --]
[-- Type: text/x-diff, Size: 6630 bytes --]

From 34a28f0cee71af2ec46cdc6f37485746750b2874 Mon Sep 17 00:00:00 2001
From: Dominik Vogt <vogt@linux.vnet.ibm.com>
Date: Mon, 6 Jul 2015 16:28:32 +0100
Subject: [PATCH 3/4] S390: Handle processor capabilities with -march=native.

---
 gcc/config/s390/driver-native.c | 143 ++++++++++++++++++++++++++++++++--------
 gcc/config/s390/s390.h          |  25 ++++---
 2 files changed, 127 insertions(+), 41 deletions(-)

diff --git a/gcc/config/s390/driver-native.c b/gcc/config/s390/driver-native.c
index 88c76bd..5f7fe0a 100644
--- a/gcc/config/s390/driver-native.c
+++ b/gcc/config/s390/driver-native.c
@@ -42,6 +42,16 @@ s390_host_detect_local_cpu (int argc, const char **argv)
   char buf[256];
   FILE *f;
   bool arch;
+  const char *options = "";
+  unsigned int has_features;
+  unsigned int has_processor;
+  unsigned int is_cpu_z9_109 = 0;
+  unsigned int has_highgprs = 0;
+  unsigned int has_dfp = 0;
+  unsigned int has_te = 0;
+  unsigned int has_vx = 0;
+  unsigned int has_opt_esa_zarch = 0;
+  int i;
 
   if (argc < 1)
     return NULL;
@@ -49,43 +59,120 @@ s390_host_detect_local_cpu (int argc, const char **argv)
   arch = strcmp (argv[0], "arch") == 0;
   if (!arch && strcmp (argv[0], "tune"))
     return NULL;
+  for (i = 1; i < argc; i++)
+    if (strcmp (argv[i], "mesa_mzarch") == 0)
+      has_opt_esa_zarch = 1;
 
   f = fopen ("/proc/cpuinfo", "r");
   if (f == NULL)
     return NULL;
 
-  while (fgets (buf, sizeof (buf), f) != NULL)
-    if (strncmp (buf, "processor", sizeof ("processor") - 1) == 0)
-      {
-	if (strstr (buf, "machine = 9672") != NULL)
-	  cpu = "g5";
-	else if (strstr (buf, "machine = 2064") != NULL
-		 || strstr (buf, "machine = 2066") != NULL)
-	  cpu = "z900";
-	else if (strstr (buf, "machine = 2084") != NULL
-		 || strstr (buf, "machine = 2086") != NULL)
-	  cpu = "z990";
-	else if (strstr (buf, "machine = 2094") != NULL
-		 || strstr (buf, "machine = 2096") != NULL)
-	  cpu = "z9-109";
-	else if (strstr (buf, "machine = 2097") != NULL
-		 || strstr (buf, "machine = 2098") != NULL)
-	  cpu = "z10";
-	else if (strstr (buf, "machine = 2817") != NULL
-		 || strstr (buf, "machine = 2818") != NULL)
-	  cpu = "z196";
-	else if (strstr (buf, "machine = 2827") != NULL
-		 || strstr (buf, "machine = 2828") != NULL)
-	  cpu = "zEC12";
-	else if (strstr (buf, "machine = 2964") != NULL)
-	  cpu = "z13";
-	break;
-      }
+  for (has_features = 0, has_processor = 0;
+       (has_features == 0 || has_processor == 0)
+	 && fgets (buf, sizeof (buf), f) != NULL; )
+    {
+      if (has_processor == 0 && strncmp (buf, "processor", 9) == 0)
+	{
+	  const char *p;
+	  long machine_id;
+
+	  p = strstr (buf, "machine = ");
+	  if (p == NULL)
+	    continue;
+	  p += 10;
+	  has_processor = 1;
+	  machine_id = strtol (p, NULL, 16);
+	  switch (machine_id)
+	    {
+	    case 0x9672:
+	      cpu = "g5";
+	      break;
+	    case 0x2064:
+	    case 0x2066:
+	      cpu = "z900";
+	      break;
+	    case 0x2084:
+	    case 0x2086:
+	      cpu = "z990";
+	      break;
+	    case 0x2094:
+	    case 0x2096:
+	      cpu = "z9-109";
+	      is_cpu_z9_109 = 1;
+	      break;
+	    case 0x2097:
+	    case 0x2098:
+	      cpu = "z10";
+	      break;
+	    case 0x2817:
+	    case 0x2818:
+	      cpu = "z196";
+	      break;
+	    case 0x2827:
+	    case 0x2828:
+	      cpu = "zEC12";
+	      break;
+	    case 0x2964:
+	      cpu = "z13";
+	      break;
+	    }
+	}
+      if (has_features == 0 && strncmp (buf, "features", 8) == 0)
+	{
+	  const char *p;
+
+	  p = strchr (buf, ':');
+	  if (p == NULL)
+	    continue;
+	  p++;
+	  while (*p != 0)
+	    {
+	      int i;
+
+	      while (ISSPACE (*p))
+		p++;
+	      for (i = 0; !ISSPACE (p[i]) && p[i] != 0; i++)
+		;
+	      if (i == 3 && strncmp (p, "dfp", 3) == 0)
+		has_dfp = 1;
+	      else if (i == 2 && strncmp (p, "te", 2) == 0)
+		has_te = 1;
+	      else if (i == 2 && strncmp (p, "vx", 2) == 0)
+		has_vx = 1;
+	      else if (i == 8 && strncmp (p, "highgprs", 8) == 0)
+		has_highgprs = 1;
+	      p += i;
+	    }
+	  has_features = 1;
+	}
+    }
 
   fclose (f);
 
   if (cpu == NULL)
     return NULL;
 
-  return concat ("-m", argv[0], "=", cpu, NULL);
+  if (arch)
+    {
+      const char *opt_htm = "";
+      const char *opt_vx = "";
+      const char *opt_esa_zarch = "";
+
+      /* We may switch off these cpu features but never switch the on
+	 explicitly.  This overrides options specified on the command line.  */
+      if (!has_te)
+	opt_htm = " -mno-htm";
+      if (!has_vx)
+	opt_vx = " -mno-vx";
+      /* However, we set -mzarch only if neither -mzarch nor -mesa are used on
+	 the command line.  This allows the user to switch to -mesa manually.
+      */
+      if (!has_opt_esa_zarch && has_highgprs)
+	opt_esa_zarch = " -mzarch";
+      options = concat (options, opt_htm, opt_vx, opt_esa_zarch, NULL);
+    }
+  if (has_dfp && is_cpu_z9_109)
+    cpu = "z9-ec";
+
+  return concat ("-m", argv[0], "=", cpu, options, NULL);
 }
diff --git a/gcc/config/s390/s390.h b/gcc/config/s390/s390.h
index f18b973..a0faf13 100644
--- a/gcc/config/s390/s390.h
+++ b/gcc/config/s390/s390.h
@@ -131,27 +131,26 @@ extern const char *s390_host_detect_local_cpu (int argc, const char **argv);
 # define EXTRA_SPEC_FUNCTIONS \
   { "local_cpu_detect", s390_host_detect_local_cpu },
 
-# define MARCH_MTUNE_NATIVE_SPECS				\
-  " %{march=native:%<march=native %:local_cpu_detect(arch)}"	\
-  " %{mtune=native:%<mtune=native %:local_cpu_detect(tune)}"
+#define MARCH_MTUNE_NATIVE_SPECS				\
+  "%{mtune=native:%<mtune=native %:local_cpu_detect(tune)} "	\
+  "%{march=native:%<march=native"				\
+  " %:local_cpu_detect(arch %{mesa|mzarch:mesa_mzarch})}"
 #else
 # define MARCH_MTUNE_NATIVE_SPECS ""
 #endif
 
-/* Defaulting rules.  */
 #ifdef DEFAULT_TARGET_64BIT
-#define DRIVER_SELF_SPECS					\
-  "%{!m31:%{!m64:-m64}}",					\
-  "%{!mesa:%{!mzarch:%{m31:-mesa}%{m64:-mzarch}}}",		\
-  "%{!march=*:%{mesa:-march=g5}%{mzarch:-march=z900}}",		\
-  MARCH_MTUNE_NATIVE_SPECS
+#define S390_TARGET_BITS_STRING "64"
 #else
+#define S390_TARGET_BITS_STRING "31"
+#endif
+
+/* Defaulting rules.  */
 #define DRIVER_SELF_SPECS					\
-  "%{!m31:%{!m64:-m31}}",					\
+  MARCH_MTUNE_NATIVE_SPECS,					\
+  "%{!m31:%{!m64:-m" S390_TARGET_BITS_STRING "}}",		\
   "%{!mesa:%{!mzarch:%{m31:-mesa}%{m64:-mzarch}}}",		\
-  "%{!march=*:%{mesa:-march=g5}%{mzarch:-march=z900}}",		\
-  MARCH_MTUNE_NATIVE_SPECS
-#endif
+  "%{!march=*:%{mesa:-march=g5}%{mzarch:-march=z900}}"
 
 /* Constants needed to control the TEST DATA CLASS (TDC) instruction.  */
 #define S390_TDC_POSITIVE_ZERO                     (1 << 11)
-- 
2.3.0


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

* Re: [PATCH 3/4] S390 -march=native related fixes
  2015-07-22 10:54               ` Dominik Vogt
@ 2015-07-23 13:03                 ` Ulrich Weigand
  0 siblings, 0 replies; 16+ messages in thread
From: Ulrich Weigand @ 2015-07-23 13:03 UTC (permalink / raw)
  To: vogt; +Cc: gcc-patches

Dominik Vogt wrote:
> 
> gcc/ChangeLog
>  
> 	* config/s390/driver-native.c (s390_host_detect_local_cpu): Handle
> 	processor capabilities with -march=native.
> 	* config/s390/s390.h (MARCH_MTUNE_NATIVE_SPECS): Likewise.
> 	(DRIVER_SELF_SPECS): Likewise.  Join specs for 31 and 64 bit.
> 	(S390_TARGET_BITS_STRING): Macro to simplify specs.

This is OK.

Thanks,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU/Linux compilers and toolchain
  Ulrich.Weigand@de.ibm.com

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

* Re: [PATCH 0/4] S390 -march=native related fixes
  2015-07-17 16:03 [PATCH 0/4] S390 -march=native related fixes Dominik Vogt
                   ` (3 preceding siblings ...)
  2015-07-17 16:09 ` [PATCH 4/4] " Dominik Vogt
@ 2015-07-24 11:38 ` Andreas Krebbel
  2015-07-24 14:39   ` Dominik Vogt
  4 siblings, 1 reply; 16+ messages in thread
From: Andreas Krebbel @ 2015-07-24 11:38 UTC (permalink / raw)
  To: gcc-patches; +Cc: vogt

On 07/17/2015 06:00 PM, Dominik Vogt wrote:
> The following series of patches contains fixes, and cleanup work
> related to -march=native (and -mtune=native) for S390.
> 
> * 0001 Fix cross compilation for S390 targets that was broken with
>        the original -march=native aptch.
> 
> * 0002 Fix handling of -march=z9_ec in old code.  This bug has been
>        in the code since z9-ec support was added.
> 
> * 0003 -march=native now detects various cpu features and passes
>        that as options from the driver to the compiler.
> 
> * 0004 Non-mandatory cleanup of the S390 code handling the various
>        cpu types.

I've just applied them.  For 0003 I've picked the last iteration.

Thanks!

-Andreas-

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

* Re: [PATCH 0/4] S390 -march=native related fixes
  2015-07-24 11:38 ` [PATCH 0/4] " Andreas Krebbel
@ 2015-07-24 14:39   ` Dominik Vogt
  2015-07-29 21:19     ` Richard Sandiford
  0 siblings, 1 reply; 16+ messages in thread
From: Dominik Vogt @ 2015-07-24 14:39 UTC (permalink / raw)
  To: gcc-patches

With that problem fixed I still see one minor glitch.  Maybe
someone knows how to fix the following:

* With a cross compiler that generates i686 binaries on s390x:

   $ i686-elf-gcc -c ~/foo.c -march=native
   /home/vogt/foo.c:1:0: error: bad value (native) for -march= switch

  This is all right because the x86 compiler just emits a brief
  error message because the argument to -march= is a string.

* The other way round, generating s390x binaries on i686:

   $ s390x-linux-gcc -c ~/foo.c -march=native
   cc1: error: unrecognized argument in option '-march=native'
   cc1: note: valid arguments to '-march=' are: g5 g6 native z10 z13 z196 z9-109 z9-ec z900 z990 zEC12

  So, the error message complains about "native" not being a valid
  argument to -march=, and then lists it as valid in the next line.
  This is because s390x uses an Enum option, and "native" is one
  of the allowed values.

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany

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

* Re: [PATCH 0/4] S390 -march=native related fixes
  2015-07-24 14:39   ` Dominik Vogt
@ 2015-07-29 21:19     ` Richard Sandiford
  0 siblings, 0 replies; 16+ messages in thread
From: Richard Sandiford @ 2015-07-29 21:19 UTC (permalink / raw)
  To: gcc-patches

Dominik Vogt <vogt@linux.vnet.ibm.com> writes:
> With that problem fixed I still see one minor glitch.  Maybe
> someone knows how to fix the following:
>
> * With a cross compiler that generates i686 binaries on s390x:
>
>    $ i686-elf-gcc -c ~/foo.c -march=native
>    /home/vogt/foo.c:1:0: error: bad value (native) for -march= switch
>
>   This is all right because the x86 compiler just emits a brief
>   error message because the argument to -march= is a string.
>
> * The other way round, generating s390x binaries on i686:
>
>    $ s390x-linux-gcc -c ~/foo.c -march=native
>    cc1: error: unrecognized argument in option '-march=native'
>    cc1: note: valid arguments to '-march=' are: g5 g6 native z10 z13 z196 z9-109 z9-ec z900 z990 zEC12
>
>   So, the error message complains about "native" not being a valid
>   argument to -march=, and then lists it as valid in the next line.
>   This is because s390x uses an Enum option, and "native" is one
>   of the allowed values.

Nice spot :-)  One way would be to have:

  %{mtune=native:%e-mtune=native is only supported for native configurations}

in the non-native MARCH_MTUNE_NATIVE_SPECS, and similarly for -march.
The problem is that that won't quote -mtune=native in the canonical
way and I don't know how well it would handle intl (probably not very well).
Maybe we should have a new .opt tag for native-only enum options.

Thanks,
Richard

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

end of thread, other threads:[~2015-07-29 20:52 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-17 16:03 [PATCH 0/4] S390 -march=native related fixes Dominik Vogt
2015-07-17 16:04 ` [PATCH 1/4] " Dominik Vogt
2015-07-17 16:05 ` [PATCH 2/4] " Dominik Vogt
2015-07-17 16:08 ` [PATCH 3/4] " Dominik Vogt
2015-07-17 16:43   ` Dominik Vogt
2015-07-18  0:22     ` Ulrich Weigand
2015-07-20 16:10       ` Dominik Vogt
2015-07-21 11:23         ` Ulrich Weigand
2015-07-21 12:53           ` Dominik Vogt
2015-07-21 17:15             ` Ulrich Weigand
2015-07-22 10:54               ` Dominik Vogt
2015-07-23 13:03                 ` Ulrich Weigand
2015-07-17 16:09 ` [PATCH 4/4] " Dominik Vogt
2015-07-24 11:38 ` [PATCH 0/4] " Andreas Krebbel
2015-07-24 14:39   ` Dominik Vogt
2015-07-29 21:19     ` Richard Sandiford

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