From patchwork Tue Sep 6 12:22:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christoph_M=C3=BCllner?= X-Patchwork-Id: 12967523 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BBAF8C6FA83 for ; Tue, 6 Sep 2022 13:47:01 +0000 (UTC) Received: from localhost ([::1]:54514 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVYuq-00021b-Ln for qemu-devel@archiver.kernel.org; Tue, 06 Sep 2022 09:47:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42296) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVXbh-0005gD-QZ for qemu-devel@nongnu.org; Tue, 06 Sep 2022 08:23:11 -0400 Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631]:38806) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oVXbV-0003rT-3D for qemu-devel@nongnu.org; Tue, 06 Sep 2022 08:23:04 -0400 Received: by mail-ej1-x631.google.com with SMTP id u9so22823849ejy.5 for ; Tue, 06 Sep 2022 05:22:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=aOh7zsauraP9R+VJcwE2IKulzqyQTi8hmp+P1Bbj1v8=; b=X8Bhk+zGm0SurfMSG/2whlaE+11OEG8+E39qPS4Wg4/F8nUgNaZInDb8uJzjwSEklR 6/YeVn8KXXsLr1m3/Hzt7ijS7ZcCC3U69pWecCRtEPmAEh+YbbNgsnIYKDR0PliEpL5Y An5dlVbw5d+QbyW2hAllcDbw/YrRbsT5G2KyLGk8FlQNO/22MXSS+4h0bA6PCidqtAgd Lm6+Y0lJ7IwLcDPWavaBPwPqIR1pLLIjZ/57uXz226MKK6eO5CW01K+Te+MAfVqOZT8T rWxzrW03Nbn8cIv/b7EPumigrVFPcngh2okh0FuNPWWh67gZNYRxBRBprZN/bshE338r By3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=aOh7zsauraP9R+VJcwE2IKulzqyQTi8hmp+P1Bbj1v8=; b=L0FJ/iJLcHKS6Qhlb4qGchlGTGw8bynDCgH2IXcdQvLcfpkpEulS3Ron6PnX02EEYw ltiU8JiHhCzsNC6EpiWnMPFhJC5/ZC8dRP2To31N+13gIZJmevIzK9hCiM5p8ssMzPPw hVplYas4Ci6K3x+4EUKn+qI0M9a34RUWtWlpaarc918MFRaxh8leUNstl0mcSkTUomSJ EVFJd/BCe0gQEFEh4O0jxpgPiiGwTJmFOxHdp3TUUdCo/0Ib4lCRvFy/JLvFXFF7TsB9 EV31txlmM2CfzLYXDrzaG782EFPeoqvNYNB1ins4G3l4IfcryJbH5e2z3TgNLzuQUJBA bntw== X-Gm-Message-State: ACgBeo3xuu8iaZswEZO505WPRkbS6nk9MWtvKIbYGm41BZ1Z+ppU4KkS Gw9xVPNVX6HubuViLmxQ4GrtZw== X-Google-Smtp-Source: AA6agR4x6aHQtS3I+QxXgWppTmliap7/p0eVHDqcGs694rgyLrAfOZkhvKly3SpsF79ZmOff4RQKaA== X-Received: by 2002:a17:906:9c82:b0:6e1:1d6c:914c with SMTP id fj2-20020a1709069c8200b006e11d6c914cmr1616044ejc.769.1662466974878; Tue, 06 Sep 2022 05:22:54 -0700 (PDT) Received: from beast.fritz.box (62-178-148-172.cable.dynamic.surfer.at. [62.178.148.172]) by smtp.gmail.com with ESMTPSA id d21-20020a170906305500b0073d6ab5bcaasm6479034ejd.212.2022.09.06.05.22.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 05:22:54 -0700 (PDT) From: Christoph Muellner To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org, Alistair Francis , Bin Meng , Philipp Tomsich , =?utf-8?q?Heiko_St=C3=BCbner?= , Palmer Dabbelt , Richard Henderson , Nelson Chu , Kito Cheng , Cooper Qu , Lifang Xia , Yunhai Shang , Zhiwei Liu Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [PATCH 05/11] RISC-V: Adding T-Head CondMov instructions Date: Tue, 6 Sep 2022 14:22:37 +0200 Message-Id: <20220906122243.1243354-6-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220906122243.1243354-1-christoph.muellner@vrull.eu> References: <20220906122243.1243354-1-christoph.muellner@vrull.eu> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::631; envelope-from=christoph.muellner@vrull.eu; helo=mail-ej1-x631.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Christoph Müllner This patch adds support for the T-Head CondMov instructions. The patch uses the T-Head specific decoder and translation. Signed-off-by: Christoph Müllner --- target/riscv/cpu.c | 1 + target/riscv/cpu.h | 1 + target/riscv/insn_trans/trans_xthead.c.inc | 23 +++++++++++++++ target/riscv/meson.build | 1 + target/riscv/translate.c | 3 ++ target/riscv/xtheadcondmov.decode | 33 ++++++++++++++++++++++ 6 files changed, 62 insertions(+) create mode 100644 target/riscv/xtheadcondmov.decode diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index d129a6112a..b7d6dbd28e 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -924,6 +924,7 @@ static Property riscv_cpu_extensions[] = { DEFINE_PROP_BOOL("xtheadbb", RISCVCPU, cfg.ext_xtheadbb, false), DEFINE_PROP_BOOL("xtheadbs", RISCVCPU, cfg.ext_xtheadbs, false), DEFINE_PROP_BOOL("xtheadcmo", RISCVCPU, cfg.ext_xtheadcmo, false), + DEFINE_PROP_BOOL("xtheadcondmov", RISCVCPU, cfg.ext_xtheadcondmov, false), DEFINE_PROP_BOOL("xtheadsync", RISCVCPU, cfg.ext_xtheadsync, false), DEFINE_PROP_BOOL("xventanacondops", RISCVCPU, cfg.ext_XVentanaCondOps, false), diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 9e2b3d6f56..0b58b38335 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -444,6 +444,7 @@ struct RISCVCPUConfig { bool ext_xtheadbb; bool ext_xtheadbs; bool ext_xtheadcmo; + bool ext_xtheadcondmov; bool ext_xtheadsync; bool ext_XVentanaCondOps; diff --git a/target/riscv/insn_trans/trans_xthead.c.inc b/target/riscv/insn_trans/trans_xthead.c.inc index b2d523b905..da3a538400 100644 --- a/target/riscv/insn_trans/trans_xthead.c.inc +++ b/target/riscv/insn_trans/trans_xthead.c.inc @@ -194,3 +194,26 @@ static bool trans_th_tst(DisasContext *ctx, arg_th_tst *a) return gen_shift_imm_tl(ctx, a, EXT_NONE, gen_bext); } +static bool gen_th_condmove(DisasContext *ctx, arg_r *a, TCGCond cond) +{ + TCGv dest = dest_gpr(ctx, a->rd); + TCGv src1 = get_gpr(ctx, a->rs1, EXT_NONE); + TCGv src2 = get_gpr(ctx, a->rs2, EXT_NONE); + + tcg_gen_movcond_tl(cond, dest, src2, ctx->zero, src1, dest); + + gen_set_gpr(ctx, a->rd, dest); + return true; +} + +/* th.mveqz: "if (rs2 == 0) rd = rs1;" */ +static bool trans_th_mveqz(DisasContext *ctx, arg_th_mveqz *a) +{ + return gen_th_condmove(ctx, a, TCG_COND_EQ); +} + +/* th.mvnez: "if (rs2 != 0) rd = rs1;" */ +static bool trans_th_mvnez(DisasContext *ctx, arg_th_mveqz *a) +{ + return gen_th_condmove(ctx, a, TCG_COND_NE); +} diff --git a/target/riscv/meson.build b/target/riscv/meson.build index 5ee37683cb..496ae37f26 100644 --- a/target/riscv/meson.build +++ b/target/riscv/meson.build @@ -6,6 +6,7 @@ gen = [ decodetree.process('xtheadbb.decode', extra_args: '--static-decode=decode_xtheadbb'), decodetree.process('xtheadbs.decode', extra_args: '--static-decode=decode_xtheadbs'), decodetree.process('xtheadcmo.decode', extra_args: '--static-decode=decode_xtheadcmo'), + decodetree.process('xtheadcondmov.decode', extra_args: '--static-decode=decode_xtheadcondmov'), decodetree.process('xtheadsync.decode', extra_args: '--static-decode=decode_xtheadsync'), decodetree.process('XVentanaCondOps.decode', extra_args: '--static-decode=decode_XVentanaCodeOps'), ] diff --git a/target/riscv/translate.c b/target/riscv/translate.c index f662e403f8..986243df99 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -136,6 +136,7 @@ MATERIALISE_EXT_PREDICATE(xtheadba) MATERIALISE_EXT_PREDICATE(xtheadbb) MATERIALISE_EXT_PREDICATE(xtheadbs) MATERIALISE_EXT_PREDICATE(xtheadcmo) +MATERIALISE_EXT_PREDICATE(xtheadcondmov); MATERIALISE_EXT_PREDICATE(xtheadsync) MATERIALISE_EXT_PREDICATE(XVentanaCondOps) @@ -727,6 +728,7 @@ static int ex_rvc_shifti(DisasContext *ctx, int imm) #include "decode-xtheadbb.c.inc" #include "decode-xtheadbs.c.inc" #include "decode-xtheadcmo.c.inc" +#include "decode-xtheadcondmov.c.inc" #include "decode-xtheadsync.c.inc" #include "decode-XVentanaCondOps.c.inc" @@ -1052,6 +1054,7 @@ static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode) { has_xtheadbb_p, decode_xtheadbb }, { has_xtheadbs_p, decode_xtheadbs }, { has_xtheadcmo_p, decode_xtheadcmo }, + { has_xtheadcondmov_p, decode_xtheadcondmov }, { has_xtheadsync_p, decode_xtheadsync }, { has_XVentanaCondOps_p, decode_XVentanaCodeOps }, }; diff --git a/target/riscv/xtheadcondmov.decode b/target/riscv/xtheadcondmov.decode new file mode 100644 index 0000000000..00f9ca96c6 --- /dev/null +++ b/target/riscv/xtheadcondmov.decode @@ -0,0 +1,33 @@ +# +# RISC-V instruction decode for the XTheadCondMov extension +# +# Copyright (c) 2022 Dr. Philipp Tomsich, philipp.tomsich@vrull.eu +# Christoph Muellner, christoph.muellner@vrull.eu +# +# SPDX-License-Identifier: LGPL-2.1-or-later +# +# The XTheadCondMov extension provides conditional move instructions. +# +# It is documented in +# https://github.com/T-head-Semi/thead-extension-spec/releases/download/2.0.0/xthead-2022-09-05-2.0.0.pdf +# +# The instructions contained in XTheadCondMov are: +# - th.mveqz move to register, if condition is zero +# - th.mvnez move to register, if condition is non-zero +# +# These instructions reuse existing instruction formats. + +# Fields +%rs2 20:5 +%rs1 15:5 +%rd 7:5 + +# Argument sets +&r rd rs1 rs2 !extern + +# Formats: +@r ....... ..... ..... ... ..... ....... &r %rs2 %rs1 %rd + +# T-Head conditional move instructions +th_mveqz 0100000 ..... ..... 001 ..... 0001011 @r +th_mvnez 0100001 ..... ..... 001 ..... 0001011 @r