From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id 83C933858C56 for ; Wed, 21 Feb 2024 03:37:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 83C933858C56 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 83C933858C56 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::435 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708486656; cv=none; b=mpSMkTjhgtnDFgMtaF6Iv601npguQumvSwgc1r8dSE+aq8f0kzonjvyIcwjSxiShN3iWvJ8Y6tpc2sPyJNS+YwtGMrbezOWgvJcH70R6lySfL8Ni61/puBOM+CeTPsuC0hsR35C4E/iBedoCFi4R+nmcMcxMoCS9YpTQWe0Yw1c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708486656; c=relaxed/simple; bh=WzToJRYPYSlA5BwAFohnoHJ/5UOlsUIz2wwwbfj41TM=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=mmHCdnyNm01552xaqND1BGwn88leqVPw75ATW5kkHzqJvEzG4BsyZr1q8ffM6dQRNIplbTieEpFwCqzT/HhBX8eSLRfchC9BNwVocEcopRdQOBecTstftHu/V7DPd6nnrZtZG/6m4qbEEcAL1Bh/+kCek8+hATwPoW794UpcsFo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-6e457fab0e2so1610980b3a.0 for ; Tue, 20 Feb 2024 19:37:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1708486652; x=1709091452; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=RqMDcNXgkv/98edrkwXRNNnFLypCILKHWzUCwrnWtAg=; b=aivK4nNS9HenPOZ7t1L8jc4lt9+maj5XuPBtGYJzb1+rGOUFWl2H3kwFUG/wWz4jAM ff7rWKPbyVaVR/1VkJnsOU/BaYPQb8w7STh8sjcGigvcCWXlPmKrV2dZe+A6j7dBmoKH ztVQAh0WdIEWA088t2brRzkL86d7dR6Q4rcerln7qTKSbRrXJrOfu2nLaqRtx0qlfTJZ n6hxXVdE8/7vgR3h8LkIWtwkNK0ppTgMTV6v6zLbiQpcloVtjF9YRGdwuMAWYr5HEbp8 mHmBHMFRt7Sq8n9nRyotf1n5Fada8n85Fi0TH/H2tBIZkAAkgFS31fsDImLYq5XJGMLT HqtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708486652; x=1709091452; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RqMDcNXgkv/98edrkwXRNNnFLypCILKHWzUCwrnWtAg=; b=lculjiJ0Vo/ORmkGZufTffSE15BxsAgfBeVsNkL4GuP8ED1XufFjUGu3U9V745vrqF 1J1DmRsYTEyru3Aq64wGZGVnsrIojm9+6tKHz9Le3ZnW9tm2ANs1JeC1+/MXysODq+pl ZMcr+W9U8Q70w0eG3RZl6WXeZh8uH9k7Xxw6eqo0SocKcd/ecZ+7m399ycUbHVfat0NP oNGfsozJmGLcHVSMC52tmDloj/redaScCy0/M6Ft6ITze0QZt2vO6ZYW7ACqcj4HN3ok u1rZ+xWNb9wywVrov8OtcWlbDbC5f9h9LC+A0axSIE22CiNzUsrdIXm27KxPto0M70TM fj6Q== X-Gm-Message-State: AOJu0YyljoWF41+Jbr3dNnHHkENQQKtQBTGLVlaU2VDNqbgbJhkdOTl0 jk6cXxdFmHCuzX6hGpSzg3bXMQs6qUhBc5DWrxDrVyN7EeCte+LWTD0VFzjlRzoB3fZ7afHM96k MeqBmbhvsLtQbemeTytmJTyStne4i/aiajzTrUBfgspw4VxOE3IPM1j07krsuMg0BKGtEHY0zsw +J3H+LH85x6X/LOENOHCV9/g66N1SSGqsO1aAnvlw= X-Google-Smtp-Source: AGHT+IE11xGB3Skac4fBTM+XjyLKe0N4viySF0LZg5i72rUOinznCberJ+9N3vNTmFp4LyXpGwUG8g== X-Received: by 2002:a05:6a00:9282:b0:6e4:6048:75fd with SMTP id jw2-20020a056a00928200b006e4604875fdmr11210647pfb.4.1708486651983; Tue, 20 Feb 2024 19:37:31 -0800 (PST) Received: from sw05.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id y19-20020a056a00191300b006e118d2db9dsm7926714pfi.97.2024.02.20.19.37.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 19:37:31 -0800 (PST) From: Hau Hsu To: binutils@sourceware.org, kito.cheng@gmail.com, hau.hsu@sifive.com Subject: [PATCH 1/1] RISC-V: Add --march=help Date: Wed, 21 Feb 2024 11:37:10 +0800 Message-Id: <20240221033710.3611098-2-hau.hsu@sifive.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240221033710.3611098-1-hau.hsu@sifive.com> References: <20240221033710.3611098-1-hau.hsu@sifive.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.5 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 List-Id: Use --march=help 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; -- 2.31.1