diff mbox

Support -mcpu=native on Tru64 UNIX

Message ID ydd4o28djgw.fsf@manam.CeBiTec.Uni-Bielefeld.DE
State New
Headers show

Commit Message

Rainer Orth July 27, 2011, 11:57 a.m. UTC
I had long meant to support -mcpu=native on my targets.  Now I finally
got around to implementing it.

The following patch does so for -mcpu=native/-mtune=native on Tru64
UNIX, using getsysinfo(2).  A non-bootstrap C-only build is currently
running, the options above work as expected.

Ok for mainline if it passes?

Thanks.
	Rainer


2011-07-26  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	* config/alpha/driver-alpha.c [__osf__]: Include <sys/sysinfo.h>,
	<machine/hal_sysinfo.h>.
	(host_detect_local_cpu) [__osf__]: Define cpu_types[], ret, cpu_type.
	Use getsysinfo to detect processor type.
	* config.host: Also use driver-alpha.o, alpha/x-alpha on
	alpha*-dec-osf*.
	* config/alpha/osf5.h [__alpha__ || __alpha]
	(host_detect_local_cpu): Declare.
	(EXTRA_SPEC_FUNCTIONS, MCPU_MTUNE_NATIVE_SPECS)
	(DRIVER_SELF_SPECS): Define.

Comments

Richard Henderson July 27, 2011, 2:54 p.m. UTC | #1
On 07/27/2011 04:57 AM, Rainer Orth wrote:
> The following patch does so for -mcpu=native/-mtune=native on Tru64
> UNIX, using getsysinfo(2).  A non-bootstrap C-only build is currently
> running, the options above work as expected.

I hadn't realized that the =native detection wasn't being done
via __builtin_implver and __builtin_amask.  Seems to me that
we should just use that and eliminate all the OS-specific stuff.


r~
diff mbox

Patch

diff --git a/gcc/config.host b/gcc/config.host
--- a/gcc/config.host
+++ b/gcc/config.host
@@ -100,9 +100,9 @@  case ${host} in
 esac
 
 case ${host} in
-  alpha*-*-linux*)
+  alpha*-*-linux* | alpha*-dec-osf*)
     case ${target} in
-      alpha*-*-linux*)
+      alpha*-*-linux* | alpha*-dec-osf*)
 	host_extra_gcc_objs="driver-alpha.o"
 	host_xmake_file="${host_xmake_file} alpha/x-alpha"
 	;;
diff --git a/gcc/config/alpha/driver-alpha.c b/gcc/config/alpha/driver-alpha.c
--- a/gcc/config/alpha/driver-alpha.c
+++ b/gcc/config/alpha/driver-alpha.c
@@ -1,5 +1,5 @@ 
 /* Subroutines for the gcc driver.
-   Copyright (C) 2009 Free Software Foundation, Inc.
+   Copyright (C) 2009, 2011 Free Software Foundation, Inc.
    Contributed by Arthur Loiret <aloiret@debian.org>
 
 This file is part of GCC.
@@ -23,6 +23,11 @@  along with GCC; see the file COPYING3.  
 #include "coretypes.h"
 #include "tm.h"
 
+#ifdef __osf__
+#include <sys/sysinfo.h>
+#include <machine/hal_sysinfo.h>
+#endif
+
 /* This will be called by the spec parser in gcc.c when it sees
    a %:local_cpu_detect(args) construct.  Currently it will be called
    with either "cpu" or "tune" as argument depending on if -mcpu=native
@@ -40,9 +45,31 @@  const char *
 host_detect_local_cpu (int argc, const char **argv)
 {
   const char *cpu = NULL;
-  char buf[128];
-  FILE *f;
 
+#ifdef __osf__
+  static const char *const cpu_types[] = {
+    0,
+    "ev3",	/* EV3_CPU */
+    "ev4",	/* EV4_CPU */
+    0,
+    "ev4",	/* LCA4_CPU */
+    "ev5",	/* EV5_CPU */
+    "ev45",	/* EV45_CPU */
+    "ev56",	/* EV56_CPU */
+    "ev6",	/* EV6_CPU */
+    "pca56",	/* PCA56_CPU */
+    "pca56",	/* PCA57_CPU */
+    "ev67",	/* EV67_CPU */
+    "ev67",	/* EV68CB_CPU */
+    "ev67",	/* EV68AL_CPU */
+    "ev67",	/* EV68CX_CPU */
+    "ev67",	/* EV7_CPU */
+    "ev67"	/* EV79_CPU */
+    "ev67",	/* EV69A_CPU */
+  };
+  int ret;
+  long cpu_type;
+#else
   static const struct cpu_names {
    const char *const name;
    const char *const cpu;
@@ -66,6 +93,9 @@  host_detect_local_cpu (int argc, const c
 /*  { "EV3",	"ev3" },  */
     { 0, 0 }
   };
+  char buf[128];
+  FILE *f;
+#endif
 
   int i;
 
@@ -75,6 +105,17 @@  host_detect_local_cpu (int argc, const c
   if (strcmp (argv[0], "cpu") && strcmp (argv[0], "tune"))
     return NULL;
 
+#ifdef __osf__
+  ret = getsysinfo (GSI_PROC_TYPE, (caddr_t) &cpu_type, sizeof (cpu_type),
+		    NULL, NULL, NULL);
+
+  if (ret == 1)
+    /* Processor type is only returned in the lower 32 bits of cpu_type.  */
+    cpu_type &= 0xffff;
+
+  if (cpu_type > 0 && cpu_type <= sizeof (cpu_types) / sizeof (cpu_types[0]))
+    cpu = cpu_types[cpu_type];
+#else
   f = fopen ("/proc/cpuinfo", "r");
   if (f == NULL)
     return NULL;
@@ -92,6 +133,7 @@  host_detect_local_cpu (int argc, const c
       }
 
   fclose (f);
+#endif
 
   if (cpu == NULL)
     return NULL;
diff --git a/gcc/config/alpha/osf5.h b/gcc/config/alpha/osf5.h
--- a/gcc/config/alpha/osf5.h
+++ b/gcc/config/alpha/osf5.h
@@ -80,6 +80,22 @@  along with GCC; see the file COPYING3.  
 #define CPP_SPEC \
 "%{pthread|threads:-D_REENTRANT} %{threads:-D_PTHREAD_USE_D4}"
 
+/* -mcpu=native handling only makes sense with compiler running on
+   an Alpha chip.  */
+#if defined(__alpha__) || defined(__alpha)
+extern const char *host_detect_local_cpu (int argc, const char **argv);
+# define EXTRA_SPEC_FUNCTIONS						\
+  { "local_cpu_detect", host_detect_local_cpu },
+
+# define MCPU_MTUNE_NATIVE_SPECS					\
+   " %{mcpu=native:%<mcpu=native %:local_cpu_detect(cpu)}"		\
+   " %{mtune=native:%<mtune=native %:local_cpu_detect(tune)}"
+#else
+# define MCPU_MTUNE_NATIVE_SPECS ""
+#endif
+
+#define DRIVER_SELF_SPECS MCPU_MTUNE_NATIVE_SPECS
+
 /* Under DEC OSF/1 V4, -p and -pg require -lprof1, and -lprof1 requires 
    -lpdf.  */