From patchwork Wed Apr 6 10:10:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Greenhalgh X-Patchwork-Id: 65157 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp957032lbc; Wed, 6 Apr 2016 03:11:26 -0700 (PDT) X-Received: by 10.98.32.218 with SMTP id m87mr37070695pfj.48.1459937486746; Wed, 06 Apr 2016 03:11:26 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id eh2si3672878pac.155.2016.04.06.03.11.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Apr 2016 03:11:26 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-424444-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-424444-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-424444-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; q=dns; s=default; b=kKtqWv+HoGDKiTkB Nwj1uf3ES8zKQfcxV1Mxysdhp/wt5p+tCteNw4zGta7cm+kJoQhPFkNCLYsRIWsv bihgE4twG0fC73bjMtzkKgbvMyCNtZxmiEXU5VY5nMF+CBJ0Jbb2qWXhc2lIjfAg s8dATow6XUfnV31pz9htXLtn2q4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=default; bh=SKl0C4A39Yrc/HwJmAY3ep B9M/s=; b=PlgDRG7wTy8hzaVMd+bdQTdvikFupoZzXizD8p/IH8kJSaIjHXQNx6 f/wEDRVgT137WNuGn9CH2lVD/16T6Y2RvWZ/sQAxMc7bS6ko3XWrOBN+1j1ThQND k/uqnh3BQtlc2qblBkyKWHCFCMbTpAdhfv3B43wZnIpdjswQXWNws= Received: (qmail 81602 invoked by alias); 6 Apr 2016 10:10:48 -0000 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 Received: (qmail 81479 invoked by uid 89); 6 Apr 2016 10:10:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.4 required=5.0 tests=AWL, BAYES_50, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_SOFTFAIL autolearn=no version=3.3.2 spammy=HAuthentication-Results:gcc.gnu.org, HAuthentication-Results:pass, crc, 64 X-HELO: emea01-db3-obe.outbound.protection.outlook.com Received: from mail-db3on0100.outbound.protection.outlook.com (HELO emea01-db3-obe.outbound.protection.outlook.com) (157.55.234.100) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA256 encrypted) ESMTPS; Wed, 06 Apr 2016 10:10:37 +0000 Received: from AMXPR07CA0049.eurprd07.prod.outlook.com (10.242.64.49) by VI1PR07MB1693.eurprd07.prod.outlook.com (10.166.143.13) with Microsoft SMTP Server (TLS) id 15.1.453.11; Wed, 6 Apr 2016 10:10:32 +0000 Received: from DB3FFO11FD015.protection.gbl (2a01:111:f400:7e04::160) by AMXPR07CA0049.outlook.office365.com (2a01:111:e400:1000::49) with Microsoft SMTP Server (TLS) id 15.1.453.11 via Frontend Transport; Wed, 6 Apr 2016 10:10:32 +0000 Authentication-Results: spf=pass (sender IP is 217.140.96.140) smtp.mailfrom=arm.com; gcc.gnu.org; dkim=none (message not signed) header.d=none; gcc.gnu.org; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 217.140.96.140 as permitted sender) receiver=protection.outlook.com; client-ip=217.140.96.140; helo=nebula.arm.com; Received: from nebula.arm.com (217.140.96.140) by DB3FFO11FD015.mail.protection.outlook.com (10.47.216.189) with Microsoft SMTP Server (TLS) id 15.1.453.6 via Frontend Transport; Wed, 6 Apr 2016 10:10:31 +0000 Received: from e107456-lin.cambridge.arm.com (10.1.2.79) by mail.arm.com (10.1.105.66) with Microsoft SMTP Server id 14.3.279.2; Wed, 6 Apr 2016 11:10:29 +0100 From: James Greenhalgh To: CC: , , Subject: [Patch AArch64 2/3] Rework the code to print extension strings (pr70133) Date: Wed, 6 Apr 2016 11:10:02 +0100 Message-ID: <1459937403-22657-3-git-send-email-james.greenhalgh@arm.com> In-Reply-To: <1459937403-22657-1-git-send-email-james.greenhalgh@arm.com> References: <1459937403-22657-1-git-send-email-james.greenhalgh@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-Matching-Connectors: 131044110320349421; (7f4fb8e1-17aa-4746-8602-08d27e8c8cd0); () X-Forefront-Antispam-Report: CIP:217.140.96.140; IPV:NLI; CTRY:GB; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(438002)(189002)(377424004)(199003)(4326007)(77096005)(6806005)(104016004)(5003600100002)(19580395003)(19580405001)(1096002)(76176999)(1220700001)(2476003)(110136002)(2906002)(50226001)(450100001)(164054004)(512874002)(5008740100001)(84326002)(33646002)(92566002)(2950100001)(50986999)(4610100001)(2351001)(229853001)(86362001)(11100500001)(5890100001)(568964002)(106466001)(586003)(36756003)(87936001)(189998001); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR07MB1693; H:nebula.arm.com; FPR:; SPF:Pass; MLV:sfv; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; DB3FFO11FD015; 1:oTOLZO3SeS0LAc0gMVQPERz5gMGVtWv1zmFNutQzAiUT+whaL3FFdwRhN7T/Jv/a9MBAlSy7AniIdgZ597+liKQ9DHxkz4PWfbn3vFp7gOw/Gos0mEQA5R5XDVHO5IwMawmOqQP621j1HCFJWAU7bODtIbeRwVsMVUAaXIsa91BL5xEUxYbBH86L/gL8WV19sH0diELTyFaUnp7nMyHrpgNLPD1kECRz5K4DnlQ3f7yA9tGBk14lnFBsFHr3PaUmiskBqbAqH857UvZleNi5DGmKkQV9ZIg0hgXyJCdbJBAebfQ5WFCy0QUEzBplgpaxMx/iQNmMv3xNdo3tKPYd+evWAnJh1ZMTHXXRkroabbhBQFj96BJqRQiujCo76QSDp3TeASu7urwv7FXviMANNoW5C4Kt3vfazgbXt/hFikGQL8nwRuQebuRvX0Rwk3Zk0+MmdKUtY9l9+9io7LzzaCDqeEgvPkZOKsacVDXqU8Fk1wxbI/XEYkt9ZcPXENvov/rdSub7hEHEQY4QhBocU89JKpo2L2scZ4Vqi49IdGE= X-MS-Office365-Filtering-Correlation-Id: e5c45c9e-ffb0-49b9-cf8c-08d35e03b001 X-Microsoft-Exchange-Diagnostics: 1; VI1PR07MB1693; 2:SVdibEw6iPS6oTW0pTAB+Uh9ACjC2TE+Mq2/ZtIjG6y8TfS4lYhR861JKp7Fjaf5caWuMfcVDW2iFte3wajCupY78dyA3dfnSLwxUHX9bY/x18Z9wOzQLA7hpGfuUAosGYYwC/3ngFjcDDmWK4RxcutJTq2Jx6iin2SyAGKsK+IE1TyP2zLmiiFklclEbmrX; 3:SUXgBzHf4ctbevt0VNg85HjGHYsJxrUy9zczOw4HTkPsGGzpjeDV6hs5H5B91OZGcEv47TLNekXnCFhgE9dmVDI9xahVlRlrXreemXmcRfYNUxxpb0MbsItjuST5Ho3BaKnU+0z/RxpC1p1fDHDd/rsRNg46xc4mqcHX6y2qrwOzW3OXuWs6STIkG4ntBPM9IUbALp6FOt8vCGIkfYdqL9q/9JkN7jq71M0dL8b/Vqu1+m6y2wRv+jkbBxjKWcv+W0v0Y20w0IVADwtgGerxxg==; 25:IzTZRnvTj7tn1jPESXKOYyJMj45BtTzJn9AS0eYdq1o76CQLbuGEtnbkDzDeCgnuX9+F1Up+A5JlM7IQ4Kj3umebd4q7kX5mnMeHkYE5C/K9Dk16eFzBl1CgwWF5PmR8Tzh1aNzTHJU9rpGWS4qoMZZRpnJ59W9tQZb8MYq3+zJs7mQ0DpPdc5qlwcZv6Sl2Mf1Dh/S8sNmu2+M9pcvtcPqvVPuro7RgP/WRQaAURhbwznwiRhOegM7v5q3xY1QllrEvizCNNB4dzSqEkCkw6OBXMRHRwTK39uHKBKUdWHW15Fn5ON0w4unRTCk0lU/LcDi4Wmv0KnZelVYJOXJUVA== X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(8251501002); SRVR:VI1PR07MB1693; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(102415293)(102615271)(601004)(2401047)(13018025)(13016025)(8121501046)(13024025)(5005006)(13023025)(3002001)(10201501046)(6055026); SRVR:VI1PR07MB1693; BCL:0; PCL:0; RULEID:(400006); SRVR:VI1PR07MB1693; X-Microsoft-Exchange-Diagnostics: 1; VI1PR07MB1693; 4:MBEbyLWdpOIrIJm9wKAT96UdSObmId+itcr/XxVUPBW5IapNtSTxiFXIWy76KKVWeas4G/Z6uL4YXoVTAoAPWA4xJIqPtqDMF11zJyyzDS+zEweXCoQw2JXb+4Jqf4iwVQf2SMpgS11WBUl/OtTxqfc4JKFOKbHtzOD4b4iixDuLaeefzk5Q6BnuXeUzh3EE153jogW+btbFIRJtp1Rz99Kbt89XXEVwDBhY7EOWV/9KSELB9rfzoadhnSiJPVpBJ5x74l4S+yK+LbVaNPnQNP5GMuZgg8gh5Co2l85rblNtAZEbUg5cdEEDY9V0ToFoQ5BEe+pTj8I6xMK1JEIrqcspki9rPPQh+PSMaQ/DK6eKU1x0QA8D9GOfZJ5pcnB3A+tSBt0xcM3YTjjofzL2R80+HspLwiylBUhzIeHUL2m3EttJXeFgVLKu64i8MbK9Sbyrg+63JipNmbPmC70LGBN2b7FEEbjLW6PEmm3ihdBM1zQY9frukzhJxWPUaAuF X-Forefront-PRVS: 0904004ECB X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR07MB1693; 23:t4fY9JpNMu13xUWLae3hEZqvcshZoqqXyeuffixh6?= =?us-ascii?Q?80zFd8jC42Q9l8d3SXblcD3hF1r029aC0ikdUZFn2jiFvds3acljzh1F77rS?= =?us-ascii?Q?Uwl1ijz/hC/0PxhrBXBCZ+T+RA8DD8371HPhmwx1G68HtYVNJXPNIzSDMLnx?= =?us-ascii?Q?5T5faKh+/QnnQfTStNE6iyv+FpPE/KDrEPmKtSteFtBpSjpObZaAgdOm2F1K?= =?us-ascii?Q?K1KrRfI2jVS6tv4eg9+XmnRlpp7vdDCIUTJL7cvGHTEJAuGiCLE0OjoeU/1F?= =?us-ascii?Q?O4AvBs3PkshrSFbBRCXkFVmH7B0yx1/o0x8MPLSMkXvYIFJzzw/SZl2RL+gb?= =?us-ascii?Q?Smd9BvSmqU7a+M+pWcuQU83r/Jqok9kgKRKus7ran00gBxR5kn3OBGnVepIV?= =?us-ascii?Q?wpRh0D2mkIqEGMU+D+hrkFuzfLw5Ckwdc7i+bSSAwjJ3fYTBkv94rZaO9CWH?= =?us-ascii?Q?LHt8zMcAjHBhJmZnNN06QEHiE1h0+dOKJJTgVOA2UF3x0AuNHQcJGISyJo8n?= =?us-ascii?Q?HorD3u8lyiiWmDQRlMrboZ8yOV5jRjSNZvI79Xeid2bMgo0Ly26cDh9eNzJN?= =?us-ascii?Q?MpBpqKCmXMtg20ZKE7Fpts0omSPCp2kq4qdDZb0KH13dTF5Vo7+nBiQwTXLH?= =?us-ascii?Q?IuvGjLaBX9SKQ83NmfgNvjdh+8TrQ5t9goksEzijVxDr/hCwNmsiPEgJiWOj?= =?us-ascii?Q?EU3IT5YWcQAyc4bwDJ6iOWIZErL1PwwYwS6VBkU4+h7cs2ptsIDOfCLbW35x?= =?us-ascii?Q?g0/Inr4nZkWTO4EtvpGSDbHE/3ZmjbZcB7+BuJTXj8ApDyK70YM4cGDwuKQm?= =?us-ascii?Q?c8O/TQU+vETrmuOp9uafaMEQnz7+CUuAPc59GiJA15SFHvToaQQROhgT6iJJ?= =?us-ascii?Q?KFzTdbWl/ZTYcbuZ6k08wMEBcyiDLkxWV19Zzei7ck4VXHpPQRVA9Y7X+JTM?= =?us-ascii?Q?ldemsx4pLjV0EMHNRIMkf4WnaNesayEyvJp9oH9b4aYXiaxaPRl6/wVYFE1e?= =?us-ascii?Q?3VUM7hCVGJ47MnSX19n3mtnmHvBwFweQZBjJAuMK4BBjvL2qlRi1LW1zyJ9h?= =?us-ascii?Q?24KZKifTr41UV46mdzM7XUF4PQ+?= X-Microsoft-Exchange-Diagnostics: 1; VI1PR07MB1693; 5:6o6BT0EWtpvkKk8kKvM5+aGwc7qWPgvERm/T6Lv18OQpTw5UhbS32hwdS942I7BcaGZjBl/CqM8qouCfjO2mNQviKfFb6MCzSKYWziQkIwgdPWTuqEbKlKgcXlEPOfhbZ0Vq++m5fgRrjHU+lxvFsis8cJuiOM/1XS5dQmiSqjI=; 24:belSfjZFKc7Xh5KDb5P+6jSKmtFxpUzua9HNDzFbVMYKVPkLuFTcjOXDjg2K9YFGn5+EmjLIjsn9tqMrISU0Apjq1IptemlAt05+MSL/EkE= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2016 10:10:31.7853 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[217.140.96.140]; Helo=[nebula.arm.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR07MB1693 X-IsSubscribed: yes Hi, This patch aims to ensure that when we say: -march=armv8-a+nosimd We communicate that to the assembler in a way it understands. On trunk, we'll put out a directive that says .march armv8-a+fp Which has two issues; it is not enough to disable the simd extensions, and it adds a +fp that is already implied by the .march. Rather, we should be emitting: .march armv8-a+nosimd Fixing this is reasonably easy. The size of this patch comes from some refactoring to move aarch64_parse_extension from config/aarch64/aarch64.c to common/config/aarch64/aarch64-common.c . we also need to modify config/aarch64/aarch64-option-extensions.def to start keeping track of a canonical name for each flag. Doing this means updating config.gcc with a new regex. We also need to fixup two testcases that look for an incorrect .arch directive in the assembler output. We need this to rationalise the way we put out .arch strings in preparation for the next patch in the series, and to fix the existing bugs and deficiencies in our .arch handling. As an exception +crc is only sometimes guaranteed to be enabled by default for ARMv8.1-A, so we always have to put this out. Bootstrapped on aarch64-none-linux-gnu and tested for the defaults, and with an explicit -march=native passed to dejagnu. OK? Thanks, James --- gcc/ 2016-04-06 James Greenhalgh PR target/70133 * config/aarch64/aarch64-common.c (aarch64_option_extension): Keep track of a canonical flag name. (all_extensions): Likewise. (arch_to_arch_name): Also track extension flags enabled by the arch. (all_architectures): Likewise. (aarch64_parse_extension): Move to here. (aarch64_get_extension_string_for_isa_flags): Take a new argument, rework. (aarch64_rewrite_selected_cpu): Update for above change. * config/aarch64/aarch64-option-extensions.def: Rework the way flags are handled, such that the single explicit value enabled by an extension is kept seperate from the implicit values it also enables. * config/aarch64/aarch64-protos.h (aarch64_parse_opt_result): Move to here. (aarch64_parse_extension): New. * config/aarch64/aarch64.c (aarch64_parse_opt_result): Move from here to config/aarch64/aarch64-protos.h. (aarch64_parse_extension): Move from here to common/config/aarch64/aarch64-common.c. (aarch64_option_print): Update. (aarch64_declare_function_name): Likewise. (aarch64_start_file): Likewise. * config/aarch64/driver-aarch64.c (arch_extension): Keep track of the canonical flag for extensions. * config.gcc (aarch64*-*-*): Extend regex for capturing extension flags. gcc/testsuite/ 2016-04-06 James Greenhalgh PR target/70133 * gcc.target/aarch64/mgeneral-regs_4.c: Fix expected output. * gcc.target/aarch64/target_attr_15.c: Likewise. diff --git a/gcc/common/config/aarch64/aarch64-common.c b/gcc/common/config/aarch64/aarch64-common.c index 4969f07..08e7959 100644 --- a/gcc/common/config/aarch64/aarch64-common.c +++ b/gcc/common/config/aarch64/aarch64-common.c @@ -112,6 +112,7 @@ struct gcc_targetm_common targetm_common = TARGETM_COMMON_INITIALIZER; struct aarch64_option_extension { const char *const name; + const unsigned long flag_canonical; const unsigned long flags_on; const unsigned long flags_off; }; @@ -119,11 +120,11 @@ struct aarch64_option_extension /* ISA extensions in AArch64. */ static const struct aarch64_option_extension all_extensions[] = { -#define AARCH64_OPT_EXTENSION(NAME, FLAGS_ON, FLAGS_OFF, FEATURE_STRING) \ - {NAME, FLAGS_ON, FLAGS_OFF}, +#define AARCH64_OPT_EXTENSION(NAME, FLAG_CANONICAL, FLAGS_ON, FLAGS_OFF, Z) \ + {NAME, FLAG_CANONICAL, FLAGS_ON, FLAGS_OFF}, #include "config/aarch64/aarch64-option-extensions.def" #undef AARCH64_OPT_EXTENSION - {NULL, 0, 0} + {NULL, 0, 0, 0} }; struct processor_name_to_arch @@ -137,6 +138,7 @@ struct arch_to_arch_name { const enum aarch64_arch arch; const std::string arch_name; + const unsigned long flags; }; /* Map processor names to the architecture revision they implement and @@ -155,26 +157,111 @@ static const struct processor_name_to_arch all_cores[] = static const struct arch_to_arch_name all_architectures[] = { #define AARCH64_ARCH(NAME, CORE, ARCH_IDENT, ARCH, FLAGS) \ - {AARCH64_ARCH_##ARCH_IDENT, NAME}, + {AARCH64_ARCH_##ARCH_IDENT, NAME, FLAGS}, #include "config/aarch64/aarch64-arches.def" #undef AARCH64_ARCH - {aarch64_no_arch, ""} + {aarch64_no_arch, "", 0} }; -/* Return a string representation of ISA_FLAGS. */ +/* Parse the architecture extension string STR and update ISA_FLAGS + with the architecture features turned on or off. Return a + aarch64_parse_opt_result describing the result. */ + +enum aarch64_parse_opt_result +aarch64_parse_extension (const char *str, unsigned long *isa_flags) +{ + /* The extension string is parsed left to right. */ + const struct aarch64_option_extension *opt = NULL; + + /* Flag to say whether we are adding or removing an extension. */ + int adding_ext = -1; + + while (str != NULL && *str != 0) + { + const char *ext; + size_t len; + + str++; + ext = strchr (str, '+'); + + if (ext != NULL) + len = ext - str; + else + len = strlen (str); + + if (len >= 2 && strncmp (str, "no", 2) == 0) + { + adding_ext = 0; + len -= 2; + str += 2; + } + else if (len > 0) + adding_ext = 1; + + if (len == 0) + return AARCH64_PARSE_MISSING_ARG; + + + /* Scan over the extensions table trying to find an exact match. */ + for (opt = all_extensions; opt->name != NULL; opt++) + { + if (strlen (opt->name) == len && strncmp (opt->name, str, len) == 0) + { + /* Add or remove the extension. */ + if (adding_ext) + *isa_flags |= (opt->flags_on | opt->flag_canonical); + else + *isa_flags &= ~(opt->flags_off | opt->flag_canonical); + break; + } + } + + if (opt->name == NULL) + { + /* Extension not found in list. */ + return AARCH64_PARSE_INVALID_FEATURE; + } + + str = ext; + }; + + return AARCH64_PARSE_OK; +} + +/* Return a string representation of ISA_FLAGS. DEFAULT_ARCH_FLAGS + gives the default set of flags which are implied by whatever -march + we'd put out. Our job is to figure out the minimal set of "+" and + "+no" feature flags to put out, and to put them out grouped such + that all the "+" flags come before the "+no" flags. */ std::string -aarch64_get_extension_string_for_isa_flags (unsigned long isa_flags) +aarch64_get_extension_string_for_isa_flags (unsigned long isa_flags, + unsigned long default_arch_flags) { const struct aarch64_option_extension *opt = NULL; std::string outstr = ""; + /* Pass one: Find all the things we need to turn on. As a special case, + we always want to put out +crc if it is enabled. */ for (opt = all_extensions; opt->name != NULL; opt++) - if ((isa_flags & opt->flags_on) == opt->flags_on) + if ((isa_flags & opt->flag_canonical + && !(default_arch_flags & opt->flag_canonical)) + || (default_arch_flags & opt->flag_canonical + && opt->flag_canonical == AARCH64_ISA_CRC)) { outstr += "+"; outstr += opt->name; } + + /* Pass two: Find all the things we need to turn off. */ + for (opt = all_extensions; opt->name != NULL; opt++) + if ((~isa_flags) & opt->flag_canonical + && !((~default_arch_flags) & opt->flag_canonical)) + { + outstr += "+no"; + outstr += opt->name; + } + return outstr; } @@ -186,7 +273,7 @@ const char * aarch64_rewrite_selected_cpu (const char *name) { std::string original_string (name); - std::string extensions; + std::string extension_str; std::string processor; size_t extension_pos = original_string.find_first_of ('+'); @@ -194,8 +281,8 @@ aarch64_rewrite_selected_cpu (const char *name) if (extension_pos != std::string::npos) { processor = original_string.substr (0, extension_pos); - extensions = original_string.substr (extension_pos, - std::string::npos); + extension_str = original_string.substr (extension_pos, + std::string::npos); } else { @@ -227,9 +314,12 @@ aarch64_rewrite_selected_cpu (const char *name) || a_to_an->arch == aarch64_no_arch) fatal_error (input_location, "unknown value %qs for -mcpu", name); + unsigned long extensions = p_to_a->flags; + aarch64_parse_extension (extension_str.c_str (), &extensions); + std::string outstr = a_to_an->arch_name - + aarch64_get_extension_string_for_isa_flags (p_to_a->flags) - + extensions; + + aarch64_get_extension_string_for_isa_flags (extensions, + a_to_an->flags); /* We are going to memory leak here, nobody elsewhere in the callchain is going to clean up after us. The alternative is diff --git a/gcc/config.gcc b/gcc/config.gcc index 6722260..f66e48c 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc @@ -3620,22 +3620,28 @@ case "${target}" in ${srcdir}/config/aarch64/aarch64-option-extensions.def \ > /dev/null; then - ext_on=`grep "^AARCH64_OPT_EXTENSION(\"$base_ext\"," \ + ext_canon=`grep "^AARCH64_OPT_EXTENSION(\"$base_ext\"," \ ${srcdir}/config/aarch64/aarch64-option-extensions.def | \ sed -e 's/^[^,]*,[ ]*//' | \ sed -e 's/,.*$//'` - ext_off=`grep "^AARCH64_OPT_EXTENSION(\"$base_ext\"," \ + ext_on=`grep "^AARCH64_OPT_EXTENSION(\"$base_ext\"," \ ${srcdir}/config/aarch64/aarch64-option-extensions.def | \ sed -e 's/^[^,]*,[ ]*[^,]*,[ ]*//' | \ sed -e 's/,.*$//' | \ sed -e 's/).*$//'` + ext_off=`grep "^AARCH64_OPT_EXTENSION(\"$base_ext\"," \ + ${srcdir}/config/aarch64/aarch64-option-extensions.def | \ + sed -e 's/^[^,]*,[ ]*[^,]*,[ ]*[^,]*,[ ]*//' | \ + sed -e 's/,.*$//' | \ + sed -e 's/).*$//'` + if [ $ext = $base_ext ]; then # Adding extension - ext_mask="("$ext_mask") | ("$ext_on")" + ext_mask="("$ext_mask") | ("$ext_on" | "$ext_canon")" else # Removing extension - ext_mask="("$ext_mask") & ~("$ext_off")" + ext_mask="("$ext_mask") & ~("$ext_off" | "$ext_canon")" fi true diff --git a/gcc/config/aarch64/aarch64-option-extensions.def b/gcc/config/aarch64/aarch64-option-extensions.def index fbf9a53..e8706d1 100644 --- a/gcc/config/aarch64/aarch64-option-extensions.def +++ b/gcc/config/aarch64/aarch64-option-extensions.def @@ -21,23 +21,37 @@ Before using #include to read this file, define a macro: - AARCH64_OPT_EXTENSION(EXT_NAME, FLAGS_ON, FLAGS_OFF, FEATURE_STRING) + AARCH64_OPT_EXTENSION(EXT_NAME, FLAG_CANONICAL, FLAGS_ON, FLAGS_OFF, FEATURE_STRING) EXT_NAME is the name of the extension, represented as a string constant. - FLAGS_ON are the bitwise-or of the features that the extension adds. - FLAGS_OFF are the bitwise-or of the features that the extension removes. + FLAGS_CANONICAL is the canonical internal name for this flag. + FLAGS_ON are the bitwise-or of the features that enabling the extension + adds, or zero if enabling this extension has no effect on other features. + FLAGS_OFF are the bitwise-or of the features that disabling the extension + removes, or zero if disabling this extension has no effect on other + features. FEAT_STRING is a string containing the entries in the 'Features' field of /proc/cpuinfo on a GNU/Linux system that correspond to this architecture extension being available. Sometimes multiple entries are needed to enable the extension (for example, the 'crypto' extension depends on four entries: aes, pmull, sha1, sha2 being present). In that case this field - should contain a whitespace-separated list of the strings in 'Features' + should contain a space (" ") separated list of the strings in 'Features' that are required. Their order is not important. */ -AARCH64_OPT_EXTENSION ("fp", AARCH64_FL_FP, - AARCH64_FL_FPSIMD | AARCH64_FL_CRYPTO, "fp") -AARCH64_OPT_EXTENSION ("simd", AARCH64_FL_FPSIMD, - AARCH64_FL_SIMD | AARCH64_FL_CRYPTO, "asimd") -AARCH64_OPT_EXTENSION("crypto", AARCH64_FL_CRYPTO | AARCH64_FL_FPSIMD, AARCH64_FL_CRYPTO, "aes pmull sha1 sha2") -AARCH64_OPT_EXTENSION("crc", AARCH64_FL_CRC, AARCH64_FL_CRC, "crc32") -AARCH64_OPT_EXTENSION("lse", AARCH64_FL_LSE, AARCH64_FL_LSE, "atomics") +/* Enabling "fp" just enables "fp". + Disabling "fp" also disables "simd", "crypto". */ +AARCH64_OPT_EXTENSION("fp", AARCH64_FL_FP, 0, AARCH64_FL_SIMD | AARCH64_FL_CRYPTO, "fp") + +/* Enabling "simd" also enables "fp". + Disabling "simd" also disables "crypto". */ +AARCH64_OPT_EXTENSION("simd", AARCH64_FL_SIMD, AARCH64_FL_FP, AARCH64_FL_CRYPTO, "asimd") + +/* Enabling "crypto" also enables "fp", "simd". + Disabling "crypto" just disables "crypto". */ +AARCH64_OPT_EXTENSION("crypto", AARCH64_FL_CRYPTO, AARCH64_FL_FP | AARCH64_FL_SIMD, 0, "aes pmull sha1 sha2") + +/* Enabling or disabling "crc" only changes "crc". */ +AARCH64_OPT_EXTENSION("crc", AARCH64_FL_CRC, 0, 0, "crc32") + +/* Enabling or disabling "lse" only changes "lse". */ +AARCH64_OPT_EXTENSION("lse", AARCH64_FL_LSE, 0, 0, "atomics") diff --git a/gcc/config/aarch64/aarch64-protos.h b/gcc/config/aarch64/aarch64-protos.h index 58c9d0d..f22a31c 100644 --- a/gcc/config/aarch64/aarch64-protos.h +++ b/gcc/config/aarch64/aarch64-protos.h @@ -263,6 +263,18 @@ enum aarch64_extra_tuning_flags }; #undef AARCH64_EXTRA_TUNING_OPTION +/* Enum describing the various ways that the + aarch64_parse_{arch,tune,cpu,extension} functions can fail. + This way their callers can choose what kind of error to give. */ + +enum aarch64_parse_opt_result +{ + AARCH64_PARSE_OK, /* Parsing was successful. */ + AARCH64_PARSE_MISSING_ARG, /* Missing argument. */ + AARCH64_PARSE_INVALID_FEATURE, /* Invalid feature modifier. */ + AARCH64_PARSE_INVALID_ARG /* Invalid arch, tune, cpu arg. */ +}; + extern struct tune_params aarch64_tune_params; HOST_WIDE_INT aarch64_initial_elimination_offset (unsigned, unsigned); @@ -280,8 +292,6 @@ bool aarch64_float_const_zero_rtx_p (rtx); bool aarch64_function_arg_regno_p (unsigned); bool aarch64_gen_movmemqi (rtx *); bool aarch64_gimple_fold_builtin (gimple_stmt_iterator *); -bool aarch64_handle_option (struct gcc_options *, struct gcc_options *, - const struct cl_decoded_option *, location_t); bool aarch64_is_extend_from_extract (machine_mode, rtx, rtx); bool aarch64_is_long_call_p (rtx); bool aarch64_is_noplt_call_p (rtx); @@ -315,7 +325,6 @@ bool aarch64_uimm12_shift (HOST_WIDE_INT); bool aarch64_use_return_insn_p (void); const char *aarch64_mangle_builtin_type (const_tree); const char *aarch64_output_casesi (rtx *); -const char *aarch64_rewrite_selected_cpu (const char *name); enum aarch64_symbol_type aarch64_classify_symbol (rtx, rtx); enum aarch64_symbol_type aarch64_classify_tls_symbol (rtx); @@ -338,7 +347,6 @@ rtx aarch64_simd_gen_const_vector_dup (machine_mode, int); bool aarch64_simd_mem_operand_p (rtx); rtx aarch64_simd_vect_par_cnst_half (machine_mode, bool); rtx aarch64_tls_get_addr (void); -std::string aarch64_get_extension_string_for_isa_flags (unsigned long); tree aarch64_fold_builtin (tree, int, tree *, bool); unsigned aarch64_dbx_register_number (unsigned); unsigned aarch64_trampoline_size (void); @@ -433,4 +441,13 @@ extern bool aarch64_nopcrelative_literal_loads; extern void aarch64_asm_output_pool_epilogue (FILE *, const char *, tree, HOST_WIDE_INT); +/* Defined in common/config/aarch64-common.c. */ +bool aarch64_handle_option (struct gcc_options *, struct gcc_options *, + const struct cl_decoded_option *, location_t); +const char *aarch64_rewrite_selected_cpu (const char *name); +enum aarch64_parse_opt_result aarch64_parse_extension (const char *, + unsigned long *); +std::string aarch64_get_extension_string_for_isa_flags (unsigned long, + unsigned long); + #endif /* GCC_AARCH64_PROTOS_H */ diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index b7086dd..9995494 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -666,7 +666,7 @@ struct aarch64_option_extension /* ISA extensions in AArch64. */ static const struct aarch64_option_extension all_extensions[] = { -#define AARCH64_OPT_EXTENSION(NAME, FLAGS_ON, FLAGS_OFF, FEATURE_STRING) \ +#define AARCH64_OPT_EXTENSION(NAME, X, FLAGS_ON, FLAGS_OFF, FEATURE_STRING) \ {NAME, FLAGS_ON, FLAGS_OFF}, #include "aarch64-option-extensions.def" #undef AARCH64_OPT_EXTENSION @@ -7673,83 +7673,6 @@ aarch64_add_stmt_cost (void *data, int count, enum vect_cost_for_stmt kind, static void initialize_aarch64_code_model (struct gcc_options *); -/* Enum describing the various ways that the - aarch64_parse_{arch,tune,cpu,extension} functions can fail. - This way their callers can choose what kind of error to give. */ - -enum aarch64_parse_opt_result -{ - AARCH64_PARSE_OK, /* Parsing was successful. */ - AARCH64_PARSE_MISSING_ARG, /* Missing argument. */ - AARCH64_PARSE_INVALID_FEATURE, /* Invalid feature modifier. */ - AARCH64_PARSE_INVALID_ARG /* Invalid arch, tune, cpu arg. */ -}; - -/* Parse the architecture extension string STR and update ISA_FLAGS - with the architecture features turned on or off. Return a - aarch64_parse_opt_result describing the result. */ - -static enum aarch64_parse_opt_result -aarch64_parse_extension (char *str, unsigned long *isa_flags) -{ - /* The extension string is parsed left to right. */ - const struct aarch64_option_extension *opt = NULL; - - /* Flag to say whether we are adding or removing an extension. */ - int adding_ext = -1; - - while (str != NULL && *str != 0) - { - char *ext; - size_t len; - - str++; - ext = strchr (str, '+'); - - if (ext != NULL) - len = ext - str; - else - len = strlen (str); - - if (len >= 2 && strncmp (str, "no", 2) == 0) - { - adding_ext = 0; - len -= 2; - str += 2; - } - else if (len > 0) - adding_ext = 1; - - if (len == 0) - return AARCH64_PARSE_MISSING_ARG; - - - /* Scan over the extensions table trying to find an exact match. */ - for (opt = all_extensions; opt->name != NULL; opt++) - { - if (strlen (opt->name) == len && strncmp (opt->name, str, len) == 0) - { - /* Add or remove the extension. */ - if (adding_ext) - *isa_flags |= opt->flags_on; - else - *isa_flags &= ~(opt->flags_off); - break; - } - } - - if (opt->name == NULL) - { - /* Extension not found in list. */ - return AARCH64_PARSE_INVALID_FEATURE; - } - - str = ext; - }; - - return AARCH64_PARSE_OK; -} - /* Parse the TO_PARSE string and put the architecture struct that it selects into RES and the architectural features into ISA_FLAGS. Return an aarch64_parse_opt_result describing the parse result. @@ -8550,7 +8473,7 @@ aarch64_option_print (FILE *file, int indent, struct cl_target_option *ptr) unsigned long isa_flags = ptr->x_aarch64_isa_flags; const struct processor *arch = aarch64_get_arch (ptr->x_explicit_arch); std::string extension - = aarch64_get_extension_string_for_isa_flags (isa_flags); + = aarch64_get_extension_string_for_isa_flags (isa_flags, arch->flags); fprintf (file, "%*sselected tune = %s\n", indent, "", cpu->name); fprintf (file, "%*sselected arch = %s%s\n", indent, "", @@ -11213,7 +11136,8 @@ aarch64_declare_function_name (FILE *stream, const char* name, unsigned long isa_flags = targ_options->x_aarch64_isa_flags; std::string extension - = aarch64_get_extension_string_for_isa_flags (isa_flags); + = aarch64_get_extension_string_for_isa_flags (isa_flags, + this_arch->flags); /* Only update the assembler .arch string if it is distinct from the last such string we printed. */ std::string to_print = this_arch->name + extension; @@ -11253,7 +11177,8 @@ aarch64_start_file (void) = aarch64_get_arch (default_options->x_explicit_arch); unsigned long default_isa_flags = default_options->x_aarch64_isa_flags; std::string extension - = aarch64_get_extension_string_for_isa_flags (default_isa_flags); + = aarch64_get_extension_string_for_isa_flags (default_isa_flags, + default_arch->flags); aarch64_last_printed_arch_string = default_arch->name + extension; aarch64_last_printed_tune_string = ""; diff --git a/gcc/config/aarch64/driver-aarch64.c b/gcc/config/aarch64/driver-aarch64.c index 317a8a9..8925ec1 100644 --- a/gcc/config/aarch64/driver-aarch64.c +++ b/gcc/config/aarch64/driver-aarch64.c @@ -23,11 +23,12 @@ struct arch_extension { const char *ext; + unsigned int flag; const char *feat_string; }; -#define AARCH64_OPT_EXTENSION(EXT_NAME, FLAGS_ON, FLAGS_OFF, FEATURE_STRING) \ - { EXT_NAME, FEATURE_STRING }, +#define AARCH64_OPT_EXTENSION(EXT_NAME, FLAG_CANONICAL, FLAGS_ON, FLAGS_OFF, FEATURE_STRING) \ + { EXT_NAME, FLAG_CANONICAL, FEATURE_STRING }, static struct arch_extension ext_to_feat_string[] = { #include "aarch64-option-extensions.def" diff --git a/gcc/testsuite/gcc.target/aarch64/mgeneral-regs_4.c b/gcc/testsuite/gcc.target/aarch64/mgeneral-regs_4.c index 8eb50aa..49b74d9 100644 --- a/gcc/testsuite/gcc.target/aarch64/mgeneral-regs_4.c +++ b/gcc/testsuite/gcc.target/aarch64/mgeneral-regs_4.c @@ -6,4 +6,4 @@ test (void) return 1; } -/* { dg-final { scan-assembler "\.arch.*fp.*simd" } } */ +/* { dg-final { scan-assembler-times "\\.arch armv8-a\n" 1 } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/target_attr_15.c b/gcc/testsuite/gcc.target/aarch64/target_attr_15.c index f72bec8..2d8c7b9 100644 --- a/gcc/testsuite/gcc.target/aarch64/target_attr_15.c +++ b/gcc/testsuite/gcc.target/aarch64/target_attr_15.c @@ -10,4 +10,4 @@ foo (int a) return a + 1; } -/* { dg-final { scan-assembler-times "\\.arch armv8-a\n" 1 } } */ +/* { dg-final { scan-assembler-times "\\.arch armv8-a\\+nofp\\+nosimd\n" 1 } } */