From patchwork Wed Jan 3 07:55:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: joshua X-Patchwork-Id: 1881870 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4T4hrD0r0Hz1ygb for ; Wed, 3 Jan 2024 18:56:44 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 04E2F3858016 for ; Wed, 3 Jan 2024 07:56:40 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) by sourceware.org (Postfix) with ESMTPS id 5FF733858421 for ; Wed, 3 Jan 2024 07:56:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5FF733858421 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.alibaba.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5FF733858421 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=115.124.30.132 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704268578; cv=none; b=Yied8ZlkIP+d800n4EbAIVCQ+volvFGPmbZWAI3g/zurj2rp7AYmI4UgwNREdMvTaR2nHro76dOisBfigooTWNeL/5SnpHv295OlbRDT8O1r1vuZhPjkkOj7U8R33zLs2pBUFrGadEqNAu/IHojmSG91x7b0w8grSTBEr8bk+SQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704268578; c=relaxed/simple; bh=YVo6PhiIzmTbx0R66ob0rLz6yFNILd1Gd+91Xis5zyw=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=Kil/TATL6Xdp93RFvISxmrIIvEZKiD14ayCXaCwzPbPeh62EpAO7WxqNW36F3Jlh7Qm0tY+U815LM2wJ7II6a7SqUimENm5S/2vbwJcT03T+rnHHmjYtBn7N/vZAFz6wqtI4HBnuPKn+7d+vYUYZ3NCnWolHBabptrZUINrc5tE= ARC-Authentication-Results: i=1; server2.sourceware.org X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R171e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=ay29a033018046056; MF=cooper.joshua@linux.alibaba.com; NM=1; PH=DS; RN=11; SR=0; TI=SMTPD_---0VztEi1J_1704268568; Received: from localhost.localdomain(mailfrom:cooper.joshua@linux.alibaba.com fp:SMTPD_---0VztEi1J_1704268568) by smtp.aliyun-inc.com; Wed, 03 Jan 2024 15:56:10 +0800 From: "Jun Sha (Joshua)" To: gcc-patches@gcc.gnu.org Cc: jim.wilson.gcc@gmail.com, palmer@dabbelt.com, andrew@sifive.com, philipp.tomsich@vrull.eu, jeffreyalaw@gmail.com, christoph.muellner@vrull.eu, juzhe.zhong@rivai.ai, "Jun Sha (Joshua)" , Jin Ma , Xianmiao Qu Subject: [PATCH v4] RISC-V: Rewrite some instructions using ASM targethook Date: Wed, 3 Jan 2024 15:55:58 +0800 Message-Id: <20240103075558.1843-1-cooper.joshua@linux.alibaba.com> X-Mailer: git-send-email 2.27.0.windows.1 In-Reply-To: <20240103023901.1631-1-cooper.joshua@linux.alibaba.com> References: <20240103023901.1631-1-cooper.joshua@linux.alibaba.com> MIME-Version: 1.0 X-Spam-Status: No, score=-20.5 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY, USER_IN_DEF_SPF_WL 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+incoming=patchwork.ozlabs.org@gcc.gnu.org There are some xtheadvector instructions that differ from RVV1.0 apart from simply adding "th." prefix. For example, RVV1.0 load/store instructions will have SEW while xtheadvector not; RVV1.0 will have "o" for indexed-ordered store instructions while xtheadvecotr not; xtheadvector and RVV1.0 have different vnsrl/vnsra/vfncvt suffix (vv/vx/vi vs wv/wx/wi). To address this issue without duplicating patterns, we use ASM targethook to rewrite the whole string of the instructions. We identify different instructions from the corresponding attribute. gcc/ChangeLog: * config/riscv/thead.cc (th_asm_output_opcode): Rewrite some instructions. Co-authored-by: Jin Ma Co-authored-by: Xianmiao Qu Co-authored-by: Christoph Müllner --- gcc/config/riscv/thead.cc | 215 +++++++++++++++++++++++++++++++++++++- 1 file changed, 213 insertions(+), 2 deletions(-) diff --git a/gcc/config/riscv/thead.cc b/gcc/config/riscv/thead.cc index dc3aed3904d..fb088ebff02 100644 --- a/gcc/config/riscv/thead.cc +++ b/gcc/config/riscv/thead.cc @@ -27,6 +27,7 @@ #include "backend.h" #include "tree.h" #include "rtl.h" +#include "insn-attr.h" #include "explow.h" #include "memmodel.h" #include "emit-rtl.h" @@ -890,8 +891,218 @@ th_asm_output_opcode (FILE *asm_out_file, const char *p) { /* We need to add th. prefix to all the xtheadvector instructions here.*/ - if (current_output_insn != NULL && p[0] == 'v') - fputs ("th.", asm_out_file); + if (current_output_insn != NULL) + { + if (get_attr_type (current_output_insn) == TYPE_VLDE || + get_attr_type (current_output_insn) == TYPE_VSTE || + get_attr_type (current_output_insn) == TYPE_VLDFF) + { + if (strstr (p, "e8") || strstr (p, "e16") || + strstr (p, "e32") || strstr (p, "e64")) + { + get_attr_type (current_output_insn) == TYPE_VSTE + ? fputs ("th.vse", asm_out_file) + : fputs ("th.vle", asm_out_file); + if (strstr (p, "e8")) + return p+4; + else + return p+5; + } + } + + if (get_attr_type (current_output_insn) == TYPE_VLDS || + get_attr_type (current_output_insn) == TYPE_VSTS) + { + if (strstr (p, "vle8") || strstr (p, "vse8") || + strstr (p, "vle16") || strstr (p, "vse16") || + strstr (p, "vle32") || strstr (p, "vse32") || + strstr (p, "vle64") || strstr (p, "vse64")) + { + get_attr_type (current_output_insn) == TYPE_VSTS + ? fputs ("th.vse", asm_out_file) + : fputs ("th.vle", asm_out_file); + if (strstr (p, "e8")) + return p+4; + else + return p+5; + } + else if (strstr (p, "vlse8") || strstr (p, "vsse8") || + strstr (p, "vlse16") || strstr (p, "vsse16") || + strstr (p, "vlse32") || strstr (p, "vsse32") || + strstr (p, "vlse64") || strstr (p, "vsse64")) + { + get_attr_type (current_output_insn) == TYPE_VSTS + ? fputs ("th.vsse", asm_out_file) + : fputs ("th.vlse", asm_out_file); + if (strstr (p, "e8")) + return p+5; + else + return p+6; + } + } + + if (get_attr_type (current_output_insn) == TYPE_VLDUX || + get_attr_type (current_output_insn) == TYPE_VLDOX) + { + if (strstr (p, "ei")) + { + fputs ("th.vlxe", asm_out_file); + if (strstr (p, "ei8")) + return p+7; + else + return p+8; + } + } + + if (get_attr_type (current_output_insn) == TYPE_VSTUX || + get_attr_type (current_output_insn) == TYPE_VSTOX) + { + if (strstr (p, "ei")) + { + get_attr_type (current_output_insn) == TYPE_VSTUX + ? fputs ("th.vsuxe", asm_out_file) + : fputs ("th.vsxe", asm_out_file); + if (strstr (p, "ei8")) + return p+7; + else + return p+8; + } + } + + if (get_attr_type (current_output_insn) == TYPE_VLSEGDE || + get_attr_type (current_output_insn) == TYPE_VSSEGTE || + get_attr_type (current_output_insn) == TYPE_VLSEGDFF) + { + get_attr_type (current_output_insn) == TYPE_VSSEGTE + ? fputs ("th.vsseg", asm_out_file) + : fputs ("th.vlseg", asm_out_file); + asm_fprintf (asm_out_file, "%c", p[5]); + fputs ("e", asm_out_file); + if (strstr (p, "e8")) + return p+8; + else + return p+9; + } + + if (get_attr_type (current_output_insn) == TYPE_VLSEGDS || + get_attr_type (current_output_insn) == TYPE_VSSEGTS) + { + get_attr_type (current_output_insn) == TYPE_VSSEGTS + ? fputs ("th.vssseg", asm_out_file) + : fputs ("th.vlsseg", asm_out_file); + asm_fprintf (asm_out_file, "%c", p[6]); + fputs ("e", asm_out_file); + if (strstr (p, "e8")) + return p+9; + else + return p+10; + } + + if (get_attr_type (current_output_insn) == TYPE_VLSEGDUX || + get_attr_type (current_output_insn) == TYPE_VLSEGDOX) + { + fputs ("th.vlxseg", asm_out_file); + asm_fprintf (asm_out_file, "%c", p[7]); + fputs ("e", asm_out_file); + if (strstr (p, "ei8")) + return p+11; + else + return p+12; + } + + if (get_attr_type (current_output_insn) == TYPE_VSSEGTUX || + get_attr_type (current_output_insn) == TYPE_VSSEGTOX) + { + fputs ("th.vsxseg", asm_out_file); + asm_fprintf (asm_out_file, "%c", p[7]); + fputs ("e", asm_out_file); + if (strstr (p, "ei8")) + return p+11; + else + return p+12; + } + + if (get_attr_type (current_output_insn) == TYPE_VNSHIFT) + { + if (strstr (p, "vncvt")) + { + fputs ("th.vncvt.x.x.v", asm_out_file); + return p+11; + } + + strstr (p, "vnsrl") ? fputs ("th.vnsrl.v", asm_out_file) + : fputs ("th.vnsra.v", asm_out_file); + return p+7; + } + + if (get_attr_type (current_output_insn) == TYPE_VNCLIP) + { + if (strstr (p, "vnclipu")) + { + fputs ("th.vnclipu.v", asm_out_file); + return p+9; + } + else + { + fputs ("th.vnclip.v", asm_out_file); + return p+8; + } + } + + if (get_attr_type (current_output_insn) == TYPE_VMPOP) + { + fputs ("th.vmpopc", asm_out_file); + return p+5; + } + + if (get_attr_type (current_output_insn) == TYPE_VMFFS) + { + fputs ("th.vmfirst", asm_out_file); + return p+6; + } + + if (get_attr_type (current_output_insn) == TYPE_VFNCVTFTOI || + get_attr_type (current_output_insn) == TYPE_VFNCVTITOF) + { + if (strstr (p, "xu")) + { + get_attr_type (current_output_insn) == TYPE_VFNCVTFTOI + ? fputs ("th.vfncvt.xu.f.v", asm_out_file) + : fputs ("th.vfncvt.f.xu.v", asm_out_file); + return p+13; + } + else + { + get_attr_type (current_output_insn) == TYPE_VFNCVTFTOI + ? fputs ("th.vfncvt.x.f.v", asm_out_file) + : fputs ("th.vfncvt.f.x.v", asm_out_file); + return p+12; + } + } + + if (get_attr_type (current_output_insn) == TYPE_VFNCVTFTOF) + { + fputs ("th.vfncvt.f.f.v", asm_out_file); + return p+12; + } + + if (get_attr_type (current_output_insn) == TYPE_VFREDU + && strstr (p, "sum")) + { + fputs ("th.vfredsum", asm_out_file); + return p+9; + } + + if (get_attr_type (current_output_insn) == TYPE_VFWREDU + && strstr (p, "sum")) + { + fputs ("th.vfwredsum", asm_out_file); + return p+10; + } + + if (p[0] == 'v') + fputs ("th.", asm_out_file); + } return p; }