From patchwork Mon Jan 8 13:47:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kito Cheng X-Patchwork-Id: 186006 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:37c1:b0:101:2151:f287 with SMTP id y1csp1028005dyq; Mon, 8 Jan 2024 05:48:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IEuMrzzWssonzVQUIxN/lV0ITtEU4X5OCz6H91T7QdbWEGAugwLT+GbHrcZ91y5OnSK0nnq X-Received: by 2002:ac8:58c2:0:b0:427:ebd9:215b with SMTP id u2-20020ac858c2000000b00427ebd9215bmr5469440qta.135.1704721726187; Mon, 08 Jan 2024 05:48:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704721726; cv=pass; d=google.com; s=arc-20160816; b=MfGTKHomNsmSoFuIwV3OuKbTegRG3+nnOl2LRUtm/WkwB0rV8v2QzhuYYYD1/HOzXk PQ4CXXnVtKh9HfC0XidSgAOzhenPXIjLnz6yZDgXHuUDkTHf9xa/mPc99+VKOM0iF9sh /KVqTY3P6ngriPEUWrKcK37LxI/4z6OIRPmSIr4eFZrsKa0z8Z6258hcl+H4sbnyTPws T9zWR5QYASq1VLcU+u/vJl+VYD0LcjvVX0+0oT4NMMW3jLcuHSAhkf2WFJY0fh7ZPjQ+ TL4QJJe3sX7FM+CBZz5LkZX+b0Tr5s7d5WrM5E3U6SdDPXYbPG38Nxg12ecl1/sRibfx ex5Q== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=D/0+e0XHYwUoo+ZUcUk5RYifTfQWY2+4ucstYkojjVk=; fh=3Ck16crQUxNabL1wC/NAUZY2nAVZpSKeVH/lwIj1XIE=; b=Xugi9epLytE6Y79blJcKl4NC6v/94gYlXVdWUYuIMVz6U54unvMBUtceCqK6F43hqT qlx2ZyGer1I4SIHxig2NVbrlaHptAFh9lYEz0350/XNtvU/JkHUssD9qJlooicdZFCRg X5qHm5A7aCxTxcdHq1ur2yFU06mJsG1nX96VGYObTjo/s4TCN9G4V6Ke1N/aAsrLZd0Z weUbZ4tEAV+FIPndXHgbc7vyup/WP3Hb9nEeHs9YPQzHEWjpeNXKQRgpwLP3PYW7dNEi Ot64XYwDVdTiF0LTskMe56x6bNiy+y8h0g9a2ETXZ5k1FCCplWTT9zvqz5J9jh+JbbSL UtIA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=frq9Oczw; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.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 e10-20020ac84e4a000000b004299a319646si1076301qtw.277.2024.01.08.05.48.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 05:48:46 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.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=frq9Oczw; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.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 E0B62385E44F for ; Mon, 8 Jan 2024 13:48:45 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id C5D0A3858292 for ; Mon, 8 Jan 2024 13:47:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C5D0A3858292 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 C5D0A3858292 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704721676; cv=none; b=tbpN9lRwRSqsGb3woQWwYxSUKp++Eoircuu/4IdtFTp7BdktnKUqrCjiiKD86/Z6pjyKhuGKk5cagO58jH4xTw40ibjJMHbe9wwJ2M6WKErm2pOnOVzEPUqqDs0cQcHL22Aa4gFIArMYbVwFQyxZRAoHujCN+Pea4FbPSFTgUys= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704721676; c=relaxed/simple; bh=Y1+N7pfH2152+A/3ZwJxYJaO3fj+hxQisOpS9XXHfBA=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=GYfmZXclRT/yRXUZtn1cQz6+I5jof0o7Zo+rcaPbqngjCd8biuwy+wgiL6LYzYsTsNQFZgvEcvPx9PyTz31Y32jTylm8ug5JtYq9Qgv/L6M1+9xAY04BcMP9HC5GC4on3xjF9vSs92c6Bn7Y4kUUoBRuUgK8zHPQ5AP/iNGOmI0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1d542701796so3008185ad.1 for ; Mon, 08 Jan 2024 05:47:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1704721672; x=1705326472; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=D/0+e0XHYwUoo+ZUcUk5RYifTfQWY2+4ucstYkojjVk=; b=frq9OczwMvxBrQ9JogbBIFprAYaSAjHhJwHXuTNab3t0pWTOELbQfBelz4fUEw1Onf rl5DYLXHs8Cn7T1ap3Z6vJVdlL7bgf6ReFR95T06e0q+0d4jamRSnFM6jrrtFEx+rCXQ 9WgIYO02RvqJsDMa/e+I04SfPGX+15FoZUp0P5WwhDZeRol+cYLlxkjXFw0rMfRla8MR Th5j0jVSZmdA7As3Vz65gVj4Jqt5TB5PcpwiCoiwbaLbHsRgVPV5bresgc/xP8ED2af8 sbaAjtJUrcJIa+Z64BS36P9nBvcYzmjE3U1ck6twOung9dvCFNQdWgQ7dvQprP0TKEPk huhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704721672; x=1705326472; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=D/0+e0XHYwUoo+ZUcUk5RYifTfQWY2+4ucstYkojjVk=; b=HKhaobBmqO+LSzSUvJQ9TY5n8/Ho7rcNtgL3p2DY7opLHMZiylJCb4gbUL1Ea20MTE 2xf7bfkamk7u1ZxSYp6HRYLOPyFi3BVpYqv+d564RHabNCOqZcFrxxz/cEP9lEixuRN2 nYbMmJbwBwvYIX58KawAFh6FtXPOG7Q0LCbjG942YkIRoN0SCei+x5O6+JfehJwgnDi/ ZIGQBkVHzWoVFRbvundZVS3X2xTrvPSHDSeZkJ297wOwIeEaY7Qe66DZNh1J2pUGkv3d G6yOFRouOG2PPd2PapLPTEVe3grNXlNCrTz4mVahtX+VnTpteNqpkrZbwSRqo/dHEcvM BSqQ== X-Gm-Message-State: AOJu0YxESehRPUA6vKGBQ1UKahklnVd4ExdUSQ7f4IwBeAHhXYZOIxHS DCn6bryU7arkB+RkP2CvA+KV08DfXS9q8/1sezRt9mwNDe8KvRyaurVytCdK27iiUYbV5JCEXvK CKfnBraLsLZl64Gej2EANPpaHl2txVeBFtdtwxNaI+DuR8k6XOlWZoY4Q/5jEKy5TR2mSb5nnOL VnLw05EQLSsMA= X-Received: by 2002:a17:902:e74f:b0:1d0:8a8c:56b6 with SMTP id p15-20020a170902e74f00b001d08a8c56b6mr1526165plf.103.1704721672240; Mon, 08 Jan 2024 05:47:52 -0800 (PST) Received: from hsinchu18.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id jc20-20020a17090325d400b001d403969b65sm4588056plb.187.2024.01.08.05.47.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 05:47:51 -0800 (PST) From: Kito Cheng To: gcc-patches@gcc.gnu.org, kito.cheng@gmail.com, jim.wilson.gcc@gmail.com, palmer@dabbelt.com, andrew@sifive.com, jeffreyalaw@gmail.com, christoph.muellner@vrull.eu Cc: Kito Cheng Subject: [PATCH 1/5] RISC-V: Extract part parsing base ISA logic into a standalone function [NFC] Date: Mon, 8 Jan 2024 21:47:34 +0800 Message-Id: <20240108134738.998804-2-kito.cheng@sifive.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240108134738.998804-1-kito.cheng@sifive.com> References: <20240108134738.998804-1-kito.cheng@sifive.com> 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787530288630127365 X-GMAIL-MSGID: 1787530288630127365 Minor refactor, preparation for further change. gcc/ChangeLog: * common/config/riscv/riscv-common.cc (riscv_subset_list::parse_base_ext): New. (riscv_subset_list::parse): Extract part of logic into riscv_subset_list::parse_base_ext. * config/riscv/riscv-subset.h (riscv_subset_list::parse_base_ext): New. --- gcc/common/config/riscv/riscv-common.cc | 68 ++++++++++++++++--------- gcc/config/riscv/riscv-subset.h | 2 + 2 files changed, 47 insertions(+), 23 deletions(-) diff --git a/gcc/common/config/riscv/riscv-common.cc b/gcc/common/config/riscv/riscv-common.cc index 0301d170a41..f0359380451 100644 --- a/gcc/common/config/riscv/riscv-common.cc +++ b/gcc/common/config/riscv/riscv-common.cc @@ -970,25 +970,38 @@ riscv_subset_list::parsing_subset_version (const char *ext, return p; } -/* Parsing function for standard extensions. +/* Parsing function for base extensions, rv[32|64][i|e|g] Return Value: - Points to the end of extensions. + Points to the end of extensions, return NULL if any error. Arguments: `p`: Current parsing position. */ - const char * -riscv_subset_list::parse_std_ext (const char *p) +riscv_subset_list::parse_base_ext (const char *p) { - const char *all_std_exts = riscv_supported_std_ext (); - const char *std_exts = all_std_exts; - unsigned major_version = 0; unsigned minor_version = 0; char std_ext = '\0'; bool explicit_version_p = false; + if (startswith (p, "rv32")) + { + m_xlen = 32; + p += 4; + } + else if (startswith (p, "rv64")) + { + m_xlen = 64; + p += 4; + } + else + { + error_at (m_loc, "%<-march=%s%>: ISA string must begin with rv32 or rv64", + m_arch); + return NULL; + } + /* First letter must start with i, e or g. */ switch (*p) { @@ -1043,6 +1056,28 @@ riscv_subset_list::parse_std_ext (const char *p) "% or %", m_arch); return NULL; } + return p; +} + + +/* Parsing function for standard extensions. + + Return Value: + Points to the end of extensions. + + Arguments: + `p`: Current parsing position. */ + +const char * +riscv_subset_list::parse_std_ext (const char *p) +{ + const char *all_std_exts = riscv_supported_std_ext (); + const char *std_exts = all_std_exts; + + unsigned major_version = 0; + unsigned minor_version = 0; + char std_ext = '\0'; + bool explicit_version_p = false; while (p != NULL && *p) { @@ -1499,22 +1534,9 @@ riscv_subset_list::parse (const char *arch, location_t loc) riscv_subset_list *subset_list = new riscv_subset_list (arch, loc); riscv_subset_t *itr; const char *p = arch; - if (startswith (p, "rv32")) - { - subset_list->m_xlen = 32; - p += 4; - } - else if (startswith (p, "rv64")) - { - subset_list->m_xlen = 64; - p += 4; - } - else - { - error_at (loc, "%<-march=%s%>: ISA string must begin with rv32 or rv64", - arch); - goto fail; - } + p = subset_list->parse_base_ext (p); + if (p == NULL) + goto fail; /* Parsing standard extension. */ p = subset_list->parse_std_ext (p); diff --git a/gcc/config/riscv/riscv-subset.h b/gcc/config/riscv/riscv-subset.h index 14461838db5..c8117d8daf2 100644 --- a/gcc/config/riscv/riscv-subset.h +++ b/gcc/config/riscv/riscv-subset.h @@ -67,6 +67,8 @@ private: const char *parsing_subset_version (const char *, const char *, unsigned *, unsigned *, bool, bool *); + const char *parse_base_ext (const char *); + const char *parse_std_ext (const char *); const char *parse_single_std_ext (const char *);