From patchwork Tue Jan 30 06:36:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hau Hsu X-Patchwork-Id: 193860 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1035190dyb; Mon, 29 Jan 2024 22:36:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IFpBmdHWCbRrnjybVYEH5xaPr9rX/pOhhje5LQQqGsxlqmfxV+na/qcrJAdgx1d2Kpyv4E7 X-Received: by 2002:ae9:f406:0:b0:783:fdc2:51e8 with SMTP id y6-20020ae9f406000000b00783fdc251e8mr3458657qkl.6.1706596606342; Mon, 29 Jan 2024 22:36:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706596606; cv=pass; d=google.com; s=arc-20160816; b=sx55/qlSupZXTEwSm3MSN9BMLS7fM0e+66u+JPdH7pkX1ZyBLLrrIenUYQ8mFxjn/S yxR3skEzUI3un5q3gKjww+apt4sJriUgiZ5NA9adLqNyKokxKJmFNKYUUvY/qFGNbFNm iHDPOw9QynKviRZdvsysV/2ruH6D+NNA0TgAq2dMSPrCc7dV4eXaCEmyrlJyvSVVAWVa GcpK4zluy5rO+0bBBZoITyeRkFG4Pex0w92IcJc7Xapn9eefnD92Vy59418amMeiD5ba vNd1PNmfJvZaAun9An+bjcQWcIJ3iAzaYKohmI2QfBQt+Rog+Wtjpxtyf08pRKA7uwuV clBw== 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=H/AnKGSAeIzRQDzSH4WpZdnVEd2zQEX3iIsg2LMAEzQ=; fh=6OrReRbb9HLCfFlmOD+dckeiHpBhs1x4fMzFSuSWhg0=; b=jxxW7/yJ4I/+735BBMUtTGg20ZovSUs7lnCb9kw5A7kuLBGTw02+QmvSQ0DbbGFJz1 y5JCHFnWXvYIifsB9Dvs7ia8us/UWk29H5KzCtRLY8MUG7lTY6a9U9vfHk4dFAk0siFN ua/PRmVrjZDJjg3Rjw3old+jzmFGjRMxtSDpM5u+TouU57lvljQ3a0Nk4EITmOGzMPWQ 8kAeCr48Fi2kMbHuJRbI17ZW3bBBlqlRt2Zg84VbNpz3OiGVh1QQcZojnTK9Kd4/dKXe 3wJEQ9KpdUYXS5UAM6UUYfOa0m+JyHTorX6NUg/PBiaiG+yP0RgPUJced8h4w6HOru98 GDow== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=fI3bqMLB; 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 h8-20020ae9ec08000000b0078314a8b5b8si9156994qkg.497.2024.01.29.22.36.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 22:36: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=fI3bqMLB; 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 0E8273858433 for ; Tue, 30 Jan 2024 06:36:46 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by sourceware.org (Postfix) with ESMTPS id 2F3F33858C30 for ; Tue, 30 Jan 2024 06:36:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2F3F33858C30 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 2F3F33858C30 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706596598; cv=none; b=U27bSOZ5pm93VDnnjLOiYKe7QakLqFSnF+38GMkTtZs8YmgCR3MTez4CrFJwX8TVgeHI/KqR170ZXsSlxBfC7elXRzPfFn/2m11RF/RUCQ9lFx96Qmct4K+amX6lgBQKH5+tXbjm3e6q7ZlgAKP9ZPhPkLN6nUEEUzw0VsfqNLk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706596598; c=relaxed/simple; bh=U3UUrPqZ2cgTSasmS9Q3/lpsHI167uu3o0TO8XS6j+Q=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=KhGPahxpiMB5L/PzKcOdLXKb5pKSjzS42CQrrzvC/FZD7WcvhAlQgd8hXvky7LUdhCEGuVorrJobOcLXL6w+60OSz9zMGuBPUxVbJnZMpFm3nCZufO+tP3HY5kZSRPdflsMgEElmVQOe6aBOzGH5HjK3BvE9KLbQh3Gi2ZmKB4E= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1d8dd580f3dso7529315ad.3 for ; Mon, 29 Jan 2024 22:36:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1706596594; x=1707201394; 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=H/AnKGSAeIzRQDzSH4WpZdnVEd2zQEX3iIsg2LMAEzQ=; b=fI3bqMLBJPYJ95zAHLSl8/8/ANqjpDebFDCg7PetDE1PL4/sv121QH9lCvSUQmt/Yj 7azQa8V951KtKk+LM+7LB44CSjxwv7YWXD4hm7Wb9WodmvUnXDoAe6RSEOgjpnUD8gw6 VZ7M8/WeofF4NxYLmQ93FjCqMMzrPOQ2NwgkZvnAd13x9x1esEtyvrMyJkJdj13wX3kM oOLEtqbHzacExgJIJHVKz6hhvwmYyHaFkoza3pmozqM8GARLCbte4hxYck6ESdOssr6G TjNIP0nSzbj80XIYYkpr5RS6euI3BVnd2xelnGJOWfgNMj7sBgP/+jf8Vv1DF1UMbKqx r4aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706596594; x=1707201394; 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=H/AnKGSAeIzRQDzSH4WpZdnVEd2zQEX3iIsg2LMAEzQ=; b=YLXTHXb9uBJrwBvm1vHjmSMooEtvmoHZJ5JU6COtRIn8Lh9wkVvR2tTUIJmWkF/zFh sAIcN8gacbSFr+QAeQNV5g+mlEEKnoDebBfSXBMnQybqoo/hG1PIZXNqoZUie8skc62U Gjv926Su9qXip3HQlHZ6uFLjOM4jwFHEXNlNjnqFs1fESaJ6N8zm1nQhNcVsmlkF5EWe 2YTvaqWfzLCBV5dQ2UunNhoSvjovEokXgmmHf9j8vJB+g1zuN+VKv0ro6sQCd4Tbe8Ja xMpatVjHHqVtvr1fbly8Lc32AXepkCFNG9ovJgQiCMg3rgusz6kiIFnjPYjoycjXVBla vhTg== X-Gm-Message-State: AOJu0Yx2pjUrEtF7IVPapAle9Z1Gk9Nu3X8Gz8kNQGN6EVofgA8PjJuR Ac8FqNlhstITKNHxAKSa+lPjemMaJf9/c2RS6h0TCQ8MN76WL7FceTb3Qq4MUxUB0IJbk1GE4yW pGKSZUQYHA07KuTQCSVXgMoK2aRwoM/G6K9barvxeSbLLlRrbtqy9z+EKbllwPfXCNS6t0PVIin BHcAHWTLjJy4vMMW7CUwpajYINpFCgkqf8Te53qxQ= X-Received: by 2002:a17:902:d2c2:b0:1d9:fbe:466e with SMTP id n2-20020a170902d2c200b001d90fbe466emr371751plc.66.1706596593550; Mon, 29 Jan 2024 22:36:33 -0800 (PST) Received: from sw05.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id jj9-20020a170903048900b001d8c9f23518sm3915468plb.206.2024.01.29.22.36.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 22:36:33 -0800 (PST) From: Hau Hsu To: binutils@sourceware.org, kito.cheng@gmail.com, hau.hsu@sifive.com Subject: [PATCH v2] RISC-V: Add --march=help Date: Tue, 30 Jan 2024 14:36:30 +0800 Message-Id: <20240130063630.2931301-1-hau.hsu@sifive.com> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.8 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: 1789496242975029571 X-GMAIL-MSGID: 1789496242975029571 Use --march=help to print all supported extensions and versions. 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 "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. 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 Signed-off-by: Hau Hsu --- bfd/ChangeLog | 9 ++++++ bfd/elfxx-riscv.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 97d0c585a56..0807a2e0bcb 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,12 @@ +2024-01-17 Hau Hsu + + * elfxx-riscv.c (riscv_parse_subset): Parse 'help' keyword to print + available extension and versions. + (riscv_print_extensions): New function. + (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..bb394a589b1 100644 --- a/bfd/elfxx-riscv.c +++ b/bfd/elfxx-riscv.c @@ -2051,6 +2051,71 @@ 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); +} + +static +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: @@ -2089,6 +2154,13 @@ riscv_parse_subset (riscv_parse_subset_t *rps, } p = arch; + /* List all avaiable archs. */ + if (strcmp (p, "help") == 0) + { + riscv_print_extensions(); + exit (EXIT_SUCCESS); + } + if (startswith (p, "rv32")) { *rps->xlen = 32;