From patchwork Thu Jul 28 13:29:35 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rainer Orth X-Patchwork-Id: 107252 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id E2D2CB6F68 for ; Thu, 28 Jul 2011 23:30:12 +1000 (EST) Received: (qmail 17959 invoked by alias); 28 Jul 2011 13:30:07 -0000 Received: (qmail 17918 invoked by uid 22791); 28 Jul 2011 13:30:03 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, TW_PL X-Spam-Check-By: sourceware.org Received: from snape.CeBiTec.Uni-Bielefeld.DE (HELO smtp-relay.CeBiTec.Uni-Bielefeld.DE) (129.70.160.84) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 28 Jul 2011 13:29:48 +0000 Received: from localhost (localhost.CeBiTec.Uni-Bielefeld.DE [127.0.0.1]) by smtp-relay.CeBiTec.Uni-Bielefeld.DE (Postfix) with ESMTP id 4954D7B5; Thu, 28 Jul 2011 15:29:46 +0200 (CEST) Received: from smtp-relay.CeBiTec.Uni-Bielefeld.DE ([127.0.0.1]) by localhost (malfoy.CeBiTec.Uni-Bielefeld.DE [127.0.0.1]) (amavisd-new, port 10024) with LMTP id KQhVTD17MNVp; Thu, 28 Jul 2011 15:29:42 +0200 (CEST) Received: from manam.CeBiTec.Uni-Bielefeld.DE (manam.CeBiTec.Uni-Bielefeld.DE [129.70.161.120]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-relay.CeBiTec.Uni-Bielefeld.DE (Postfix) with ESMTPS id 149617B4; Thu, 28 Jul 2011 15:29:42 +0200 (CEST) Received: (from ro@localhost) by manam.CeBiTec.Uni-Bielefeld.DE (8.14.5+Sun/8.14.5/Submit) id p6SDTZHL007384; Thu, 28 Jul 2011 15:29:35 +0200 (MEST) From: Rainer Orth To: Richard Henderson Cc: gcc-patches@gcc.gnu.org Subject: Re: Support -mcpu=native on Tru64 UNIX References: <4E30269C.10007@redhat.com> Date: Thu, 28 Jul 2011 15:29:35 +0200 In-Reply-To: <4E30269C.10007@redhat.com> (Richard Henderson's message of "Wed, 27 Jul 2011 07:54:20 -0700") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (usg-unix-v) MIME-Version: 1.0 X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Richard Henderson writes: > 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. I wasn't aware of that, especially given that similar instructions on MIPS and SPARC are privileged. The following code has been tested in a minimal program and seems to work fine, a full alpha-dec-osf5.1b bootstrap is currently running. Ok for mainline if that passes? Thanks. Rainer 2011-07-26 Rainer Orth * config/alpha/driver-alpha.c (IMPLVER_EV4_FAMILY, IMPLVER_EV5_FAMILY, IMPLVER_EV6_FAMILY, IMPLVER_EV7_FAMILY): Define. (AMASK_BWX, AMASK_FIX, AMASK_CIX, AMASK_MVI, AMASK_PRECISE, AMASK_LOCKPFTCHOK): Define. (host_detect_local_cpu): Remove buf, f, cpu_names. Define cpu_types, implver, amask. Use __builtin_alpha_implver, __builtin_alpha_amask to determine native CPU. * 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. 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 This file is part of GCC. @@ -23,6 +23,22 @@ along with GCC; see the file COPYING3. #include "coretypes.h" #include "tm.h" +/* Chip family type IDs, returned by implver instruction. */ +#define IMPLVER_EV4_FAMILY 0 /* LCA/EV4/EV45 */ +#define IMPLVER_EV5_FAMILY 1 /* EV5/EV56/PCA56 */ +#define IMPLVER_EV6_FAMILY 2 /* EV6 */ +#define IMPLVER_EV7_FAMILY 3 /* EV7 */ + +/* Bit defines for amask instruction. */ +#define AMASK_BWX 0x1 /* byte/word extension. */ +#define AMASK_FIX 0x2 /* sqrt and f <-> i conversions + extension. */ +#define AMASK_CIX 0x4 /* count extension. */ +#define AMASK_MVI 0x100 /* multimedia extension. */ +#define AMASK_PRECISE 0x200 /* Precise arithmetic traps. */ +#define AMASK_LOCKPFTCHOK 0x1000 /* Safe to prefetch lock cache + block. */ + /* 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 @@ -39,34 +55,22 @@ along with GCC; see the file COPYING3. const char * host_detect_local_cpu (int argc, const char **argv) { - const char *cpu = NULL; - char buf[128]; - FILE *f; - - static const struct cpu_names { - const char *const name; - const char *const cpu; - } cpu_names[] = { - { "EV79", "ev67" }, - { "EV7", "ev67" }, - { "EV69", "ev67" }, - { "EV68CX", "ev67" }, - { "EV68CB", "ev67" }, - { "EV68AL", "ev67" }, - { "EV67", "ev67" }, - { "EV6", "ev6" }, - { "PCA57", "pca56" }, - { "PCA56", "pca56" }, - { "EV56", "ev56" }, - { "EV5", "ev5" }, - { "LCA45", "ev45" }, - { "EV45", "ev45" }, - { "LCA4", "ev4" }, - { "EV4", "ev4" }, -/* { "EV3", "ev3" }, */ - { 0, 0 } + static const struct cpu_types { + long implver; + long amask; + const char *const cpu; + } cpu_types[] = { + { IMPLVER_EV7_FAMILY, AMASK_BWX|AMASK_MVI|AMASK_FIX|AMASK_CIX, "ev67" }, + { IMPLVER_EV6_FAMILY, AMASK_BWX|AMASK_MVI|AMASK_FIX|AMASK_CIX, "ev67" }, + { IMPLVER_EV6_FAMILY, AMASK_BWX|AMASK_MVI|AMASK_FIX, "ev6" }, + { IMPLVER_EV5_FAMILY, AMASK_BWX, "ev56" }, + { IMPLVER_EV5_FAMILY, 0, "ev5" }, + { IMPLVER_EV4_FAMILY, 0, "ev4" }, + { 0, 0, NULL } }; - + long implver; + long amask; + const char *cpu; int i; if (argc < 1) @@ -75,24 +79,18 @@ host_detect_local_cpu (int argc, const c if (strcmp (argv[0], "cpu") && strcmp (argv[0], "tune")) return NULL; - f = fopen ("/proc/cpuinfo", "r"); - if (f == NULL) - return NULL; + implver = __builtin_alpha_implver (); + amask = __builtin_alpha_amask (~0L); + cpu = NULL; - while (fgets (buf, sizeof (buf), f) != NULL) - if (strncmp (buf, "cpu model", sizeof ("cpu model") - 1) == 0) + for (i = 0; cpu_types[i].cpu != NULL; i++) + if (implver == cpu_types[i].implver + && (~amask & cpu_types[i].amask) == cpu_types[i].amask) { - for (i = 0; cpu_names [i].name; i++) - if (strstr (buf, cpu_names [i].name) != NULL) - { - cpu = cpu_names [i].cpu; - break; - } + cpu = cpu_types[i].cpu; break; } - fclose (f); - 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:%