From patchwork Fri Feb 23 06:17:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hau Hsu X-Patchwork-Id: 205202 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp410769dyb; Thu, 22 Feb 2024 22:17:46 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVeSZKrNCnplAmH7kAl/0R51yJuVQr7wbRH5TOkMu5I+bn+lApe5JxGT1ilXqwN7gUwoKq84H/ukWzlRMSxGuccXWk7Jw== X-Google-Smtp-Source: AGHT+IFUFsz0P1fp4kP7xzCZ+7N9F8OmDZwmY1igNhXNVT00hKaDUTz6IOBICkojMD9c37lIi6Os X-Received: by 2002:a05:620a:1d90:b0:787:7272:a1bf with SMTP id pj16-20020a05620a1d9000b007877272a1bfmr1083559qkn.45.1708669066315; Thu, 22 Feb 2024 22:17:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708669066; cv=pass; d=google.com; s=arc-20160816; b=asEaM85+kP+9kfY4U/PNckxepu1i5aC0yYzt5PbIpoT7HMjGCXT2bUnfEHzre6mqCR C/D2fq3VjDgDeUVI5vMyQ4//Kk9yiAprIorGHNIV5AC/lI6kuqh5mbmLmWt0apP4RWZA yxu/bnFM4IAmIKuBDz4RLk8T4TlfTPTVEpSu9z0jECvrhYGuu10Is+kEllLXQu2ZICcx If8DC9imzG5ldiUT1DzljQRtPFugDZHTcrR2zYfE0luN9cqw/LR/9KgHoGOYbB63aVQ2 10mtDoUM2vPBJFbA774laSubfAmeOLMfVDwQJHYxkhyL3dAmGx/QBYLvLtdQYIE1PoeQ r7Cw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=sZze7KPhdJa3XHam8mMhNb0iLlLd4DIy4H1s0+YhbKM=; fh=6OrReRbb9HLCfFlmOD+dckeiHpBhs1x4fMzFSuSWhg0=; b=OM5ijUyKQ7jQsjLzGL3s/vMVsfHTeebRTS2SW4wjENRD3NlQE/hpb84z9r8LECPGCc 3aIMgBPHFmvEcBHDj/1/6N9gRANGmDXGCfRBM5qkGG70FQQVzOnWcpWgDagnf3kW58Bn 3fMV4uFrA+udwXPFk8c0O6UHU0lmWJXSUAKChy+zIOppJezeS3ltrCQdmR2kQbBUNjq3 sdgVLD5lvgPXkBqfgXhRh0+FVU8pLYAV7LmwfxFi8Ykn9U8ONhnumKPD/1KeMZ7ppfPW bNoVmSZKJ+5qv7wMMx7KbYsY9w+BBJ2WxtKgMVTaenitYl0+TwWS3ZAD/1IXy5sQc6J+ b+wg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=eUkZGdhU; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id d26-20020a05620a159a00b007858b831cd1si14917554qkk.176.2024.02.22.22.17.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 22:17:46 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=eUkZGdhU; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8E75B3858416 for ; Fri, 23 Feb 2024 06:17:45 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by sourceware.org (Postfix) with ESMTPS id 87702385840C for ; Fri, 23 Feb 2024 06:17:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 87702385840C Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=sifive.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 87702385840C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::635 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708669055; cv=none; b=iDPtO9LSg2yi+oR62MnVLmmDqNKjHlAC5yrJWOtHc4bbdurrw9wrelHtDiEKqmig4+0fQ84OQq+h7vSGkp7eJXHhEibeEpgjbvJiKZHZZE/aU1j+jVOLkPIAVh0G1tiGZt1JSiqCzvnNEpf1L/oBYiQBGJ4nqLOkNhW4FitG2xA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708669055; c=relaxed/simple; bh=xG1NXgSqg3C7ONB6rNG2hZDSVD4S1VVAf22/e+RAu+o=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=giDVEt3avN8nqPhVGSED2h4wtwxeAn88DJ2ikmaIECjRlEfMtfHhOUxKJeOozBOpYh7Xd/yhLX7VYR9QYYNR+roXUKTMQK3L5MBEsPLcbEbxh5iMGYOdQioHjig/z3eW1WG8hyRWlgwpjDmREiObdvZhSh43ww3qnA8Pk/AxDEM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1dc1ff58fe4so5773895ad.1 for ; Thu, 22 Feb 2024 22:17:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1708669051; x=1709273851; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=sZze7KPhdJa3XHam8mMhNb0iLlLd4DIy4H1s0+YhbKM=; b=eUkZGdhUxS2uz9lVmLee780VjLLCKBkkqQz0ajB17L5yQXv9+hYTqfuM96DIeJgcB2 iHqG2TDFA8WwwVI9iR3jWM3zVuxJulSxG5tuHozHWSIj4UcDKDksHDJTHecSst+pw1xp 3FU0a7ISYbT6k6jI07n7G4cMm3g7HHjt/cqSUPbb+iLXg4x6lcmw4vOAXV+f1iY3SNCi PIkK31oHNmjPJeA2ANdN9gIs3kfnZwMX+Nxz+dhl73vrhoY5OJICPquqOmQgNFPQQw6R bELneCWLPFVnmXoexq1/plWlnit+T58aVpWfsmgJRvdr/dmZsLm+e1hINEQUXIy/fDX0 miwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708669051; x=1709273851; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=sZze7KPhdJa3XHam8mMhNb0iLlLd4DIy4H1s0+YhbKM=; b=oAY5ISFjhiwBJdddg7fgVu2y8R+9TgRJL/MOiuJZzQGvbZUO8NhFY79iHTBvcuuaeX LEZdWdtwpiqlztFdmXYotdJTk26VvQ/VnBN7dWbkfjlPtEOTYW0wkrCF/QrIZkKIOuEq bJ9RcMaJWEQJBe+YzzdemL1wawgPPWzZ2ypbuIcQ3l/MfZJpvXGj6BF3+kiNLQXkhrmk C3UOrftIFeKZji4caIimYxpp0dzty7/KpA4o6Q5nTr6uQ92OiFc9RkF9R4oNN/XnHngh 4q/DoMqlrQswJR1fNFMUINi/taF1++CMDobmlx9vyg6Qh39xwl/6XZ549dEJ9c7bWUoQ YRgg== X-Gm-Message-State: AOJu0Yz1gui0vD8+Z01CuU1YbXyDTcOmIk7zG+KR6vPDwYp1jq3L27Z+ w7kKRyRszHJ8/MmQapQFs8l/FV9Zyszb/56PB/gqBdZCPi9INKWN3OhHCMnfkY1/zXeSq5+yK66 eRlXuRbixNqGCPV5nP8wdf3xa2xKNUrrMnvOisMqDsJa38FGqN5CCZ3udTbOFX6NkHzkp46/68K KJjb5A2kjeunwrO7FciurWsJvQBCj/tjpdmq6WEb4= X-Received: by 2002:a17:902:e807:b0:1dc:1f47:ef6d with SMTP id u7-20020a170902e80700b001dc1f47ef6dmr1225536plg.30.1708669051265; Thu, 22 Feb 2024 22:17:31 -0800 (PST) Received: from sw05.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id b14-20020a170902650e00b001db2ff16acasm11260806plk.128.2024.02.22.22.17.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 22:17:30 -0800 (PST) From: Hau Hsu To: binutils@sourceware.org, kito.cheng@gmail.com, hau.hsu@sifive.com Subject: [PATCH v4] RISC-V: Add -march=help for gas Date: Fri, 23 Feb 2024 14:17:28 +0800 Message-Id: <20240223061728.1422484-1-hau.hsu@sifive.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791669375246554211 X-GMAIL-MSGID: 1791669375246554211 Use -march=help for gas to print all supported extensions and versions. Here is part of the output of `as -march=help`: All available -march extensions for RISC-V: e 1.9 i 2.1, 2.0 m 2.0 a 2.1, 2.0 f 2.2, 2.0 d 2.2, 2.0 q 2.2, 2.0 c 2.0 v 1.0 h 1.0 zicbom 1.0 zicbop 1.0 ... This patch assumes that the supported extensions with the same versions are listed together. For example: static struct riscv_supported_ext riscv_supported_std_ext[] = { ... {"i", ISA_SPEC_CLASS_20191213, 2, 1, 0 }, {"i", ISA_SPEC_CLASS_20190608, 2, 1, 0 }, {"i", ISA_SPEC_CLASS_2P2, 2, 0, 0 }, ... }; For the "i" extension, 2.1.0 with different spec class are listed together. This patch records the previous printed extension and version. If the current extension and version are the same as the previous one, skip printing. --- bfd/ChangeLog | 9 ++++++ bfd/elfxx-riscv.c | 64 +++++++++++++++++++++++++++++++++++++++++++ bfd/elfxx-riscv.h | 3 ++ gas/ChangeLog | 4 +++ gas/config/tc-riscv.c | 6 ++++ 5 files changed, 86 insertions(+) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 97d0c585a56..66572927998 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,12 @@ +2024-02-21 Hau Hsu + + * elfxx-riscv.h (riscv_print_extensions): New declaration. + * elfxx-riscv.c (riscv_print_extensions): New function. Print + available extensions and versions. + (riscv_same_extension_version): New function. + (riscv_same_extension_diff_version): New function. + (riscv_valid_ext): New function. + 2024-01-15 Nick Clifton * 2.42 branch point. diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c index 9a121b47121..108e26d5b30 100644 --- a/bfd/elfxx-riscv.c +++ b/bfd/elfxx-riscv.c @@ -2051,6 +2051,70 @@ riscv_set_default_arch (riscv_parse_subset_t *rps) } } +static +bool riscv_same_extension_version( + const struct riscv_supported_ext* ext1, + const struct riscv_supported_ext* ext2) +{ + return (strcmp(ext1->name, ext2->name) == 0 + && ext1->major_version == ext2->major_version + && ext1->minor_version == ext2->minor_version); +} + +static +bool riscv_same_extension_diff_version( + const struct riscv_supported_ext* ext1, + const struct riscv_supported_ext* ext2) +{ + return (strcmp(ext1->name, ext2->name) == 0 + && !(ext1->major_version == ext2->major_version + && ext1->minor_version == ext2->minor_version)); +} + +static +bool riscv_valid_ext(const struct riscv_supported_ext *ext) +{ + return (ext->isa_spec_class != ISA_SPEC_CLASS_NONE + && ext->major_version != RISCV_UNKNOWN_VERSION + && ext->minor_version != RISCV_UNKNOWN_VERSION); +} + +void riscv_print_extensions(void) +{ + /* Record the previous pritned extension. + Print the current one if they are not the same. */ + const struct riscv_supported_ext *cur = NULL, *prev = NULL; + + int i, j; + printf ("All available -march extensions for RISC-V:"); + for (i = 0; riscv_all_supported_ext[i] != NULL; i++) + { + const struct riscv_supported_ext *exts = riscv_all_supported_ext[i]; + prev = NULL; + for (j = 0; exts[j].name != NULL; j++) + { + cur = &exts[j]; + if (!riscv_valid_ext (cur)) + continue; + + if (prev && riscv_same_extension_version (prev, cur)) + continue; + + if (!prev || !riscv_same_extension_diff_version (prev, cur)) + { + printf("\n\t%-40s%d.%d", cur->name, cur->major_version, cur->minor_version); + prev = &exts[j]; + } + else + { + printf(", %d.%d", cur->major_version, cur->minor_version); + prev = &exts[j]; + } + } + } + printf ("\n"); +} + /* Function for parsing ISA string. Return Value: diff --git a/bfd/elfxx-riscv.h b/bfd/elfxx-riscv.h index ae4cbee7bc3..f3710ec7fab 100644 --- a/bfd/elfxx-riscv.h +++ b/bfd/elfxx-riscv.h @@ -121,6 +121,9 @@ riscv_multi_subset_supports (riscv_parse_subset_t *, enum riscv_insn_class); extern const char * riscv_multi_subset_supports_ext (riscv_parse_subset_t *, enum riscv_insn_class); +extern void +riscv_print_extensions(void); + extern void bfd_elf32_riscv_set_data_segment_info (struct bfd_link_info *, int *); extern void diff --git a/gas/ChangeLog b/gas/ChangeLog index 88e61083c44..cebd9d94ae5 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,7 @@ +2024-02-21 Hau Hsu + * gas/config/tc-riscv.c (md_parse_option): Parse 'help' keyword in + march to print available extensions and versions. + 2024-02-19 Will Hawkins * config/tc-bpf.c (parse_expression): Change switch to if so that diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c index a4161420128..e0910f59157 100644 --- a/gas/config/tc-riscv.c +++ b/gas/config/tc-riscv.c @@ -4034,6 +4034,12 @@ md_parse_option (int c, const char *arg) switch (c) { case OPTION_MARCH: + /* List all avaiable archs. */ + if (strcmp (arg, "help") == 0) + { + riscv_print_extensions(); + exit (EXIT_SUCCESS); + } default_arch_with_ext = arg; break;