From patchwork Wed Sep 1 02:09:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 504983 Delivered-To: patch@linaro.org Received: by 2002:a02:8629:0:0:0:0:0 with SMTP id e38csp3336381jai; Tue, 31 Aug 2021 19:25:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8vCss19EJjkWnx04aA/0Pl2K5mZaN3ovUh9doYV3Dm+Tv/xTeh7jpI+Jf3nP5Lo8wcwCY X-Received: by 2002:ac8:5442:: with SMTP id d2mr5901311qtq.176.1630463140517; Tue, 31 Aug 2021 19:25:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630463140; cv=none; d=google.com; s=arc-20160816; b=IAbWs9QyKM3dx5pc8/3KQoSr0vZBVuDklg7eCFXWpB3aEjTOh2nPZPOrhXJOsxBfFj j6tTDXKABdnYjpFFKa8iFHDV7Y90GKvlAvaABdetV68zFnCKDPNe1r1ru+JRhiPOxnar tUEWIMeZkHGuKRF182+KzmkGErIOMkVqP5LxQhUTobUAsUXxvVUX4vwBiOpgPi8QAnTZ isBq8Yr1puk3Nh60pQBoZwWauhRZBQBOaIvsJTzLE2I4GpX2eVgyhkMxqmY4Ii6/w+D7 G1Ze+fbfSzA1ybNbtUTylPvuYNW2fyle+6R6PztvpdhBzJLdfNGkPBUfVh70h8y722W1 x9aQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender: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:wdcironportexception:ironport-sdr:ironport-sdr :dkim-signature; bh=2LnRrqDJsseq6OEUNFTmiZf0eakc+3ddxIs4KUNFmFI=; b=TdGQtyvv/PKl602A7/EnjCh972ShCM73w8KA9oWbe/hdVVxW9Jg4esa0G6v6ekSeJH QpuzNEUL1ZFzfDvy+j29uc2WscONkQgXwJgSK8fzibmV1ceDs7Noe/NlV87JjpPnm5KG qO0LD4xY5Wot3IpsKdidcuHFoGc36L2/XO1oDiWMYXJywD1V232jJo5qoG7U00gMBKWg cUsN5V3hEyqfVOBYWxQrOXg4MK8khajg6IvKReLPuXTdhBTTE3YD32HYYnxPIyvsLwhV L9U5GgXeP2+0KgrbsZ1otjj2btsIYCEobHNjV1QbxXm7MxEYMX4ADSHBaEA8KMsiSHz8 BmXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=dLnbRusl; dkim=pass header.i=@opensource.wdc.com header.s=dkim header.b=SmO1eJai; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=opensource.wdc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id h25si11984679qkl.126.2021.08.31.19.25.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 31 Aug 2021 19:25:40 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=dLnbRusl; dkim=pass header.i=@opensource.wdc.com header.s=dkim header.b=SmO1eJai; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=opensource.wdc.com Received: from localhost ([::1]:53172 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLFwY-0002QM-Tz for patch@linaro.org; Tue, 31 Aug 2021 22:25:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47014) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLFjD-0006aO-Ma for qemu-devel@nongnu.org; Tue, 31 Aug 2021 22:11:51 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:34281) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLFj9-0008Vd-HB for qemu-devel@nongnu.org; Tue, 31 Aug 2021 22:11:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1630462308; x=1661998308; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=I0syDRJtV2wn16n8wBMLqUksv37eMsmpSz/469s9+9A=; b=dLnbRuslEOJf41vd5DDmRKYCYgS3cyjniXa3Td1tuQDeVG3WGvuzKG/o dYJa+VsqBWMd8Tq4aCzdHyJtGDNb5X1JxAy895ERoPmCEhXr8JStEplmj dbx40M2/05NMSFPUpIgtjiTAcZUrU2oOKTxYGL0qyyrEWOCmv+ReVtUJP zv4fBH7CwZwoV8TwQDgOnZdHmNIheGjBwOl4nYxqdMDBJGb/7mmeFTYYR D3Pig2gUtHcqctmYloRWPVHqSrr5kBFV60R72La3P0q0d7evBhB/VVyLu kGkXzaX/Cz0fKa1ZdYkbEhot+pQB8Eysbw1wrBSFmgMoeBV4pZGJ75LF4 w==; X-IronPort-AV: E=Sophos;i="5.84,368,1620662400"; d="scan'208";a="179452404" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 01 Sep 2021 10:11:30 +0800 IronPort-SDR: exhL6G8o6U0CVu3JknEe5oE2qNtTs3c+cITiKH49oFerK8grxZuvk35ehXd4gxpzBzxPG7mEig gbGClbcvfqbhkEjk740KRTAnZ8XVv/GGBTUkzMpf0+y+l8grpHF3AVjnLDMnexmflxmmIXUufS r9wpr/ZpxHG1mkipGXKQnLnsx7KnAww6mLrD06ckVTtGqnKUSbSia37YcExsTVprN0Pa4+69T4 dMY3m2J6jEqG96ZvZnULbTFa6/EAEnhu692GLyYCnZrBlCeuBAgH5s1kLMm8iiG0gRPXhla+qp PVVo+wUx5hSYy+BdBvGGrOAK Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Aug 2021 18:46:36 -0700 IronPort-SDR: k7LdePXGTdzqEEIH2Nb3QxjPfTZSZ2jefJGh87fKIpb+SH7qYuAO+JAjFeOI/+OuMaETGnwdpo DtsrHxIFCz6pHdGyLhiCy42mV5y6UeME80lx1IyRgajHVI4YK+UXhdynfAFvnT7aie47G4wbcZ yHFWqUavJyMPwTNYENBkExJcjNTHsi5mnHcc0M3YXqAtCDUZ9okDhG7fnFVkhaQlHwYgvBAv+a 8UV5RsfSJIt6w6fsC9IWgECIQTL2I4EAmxaTF6DEd+f2WI5uZ5rJ4U2+qLby30YBkJ/InNAoXk hlA= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Aug 2021 19:11:30 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Gznc22s2Cz1RvlY for ; Tue, 31 Aug 2021 19:11:30 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1630462289; x=1633054290; bh=I0syDRJtV2wn16n8wB MLqUksv37eMsmpSz/469s9+9A=; b=SmO1eJaijaBsGRjdjigK5Y0IlOVDG05/pn zL6cA6w1jKnaVZC58bc2CnNtiG1AQsxXshZ9qweOCnMsZgSmcBiD3QbgXiddsxb5 7OSB8hBxKK9mBnEjITYigWuq8DF4hvq5EQX40z1VTyHWxjGfN5wNORPm2HGZF2Bs 7wscUmauc96mfPXrKv+H7SkPPJaUVtR6QjG+ZK72zyVTlPJKCvwX5szGPwpoipyF xUQKnWpAn2rc8KZO4dNVoq9lP7xkc9iR5mt/d6ILa/POLd/vd2ZzZkM8ImQFfzYT II6Apo30c71QJGG9SGN42N0E4q2MmZ8nBVM4YUaFGT6nWsiGvVUw== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id oykBLk7MnniN for ; Tue, 31 Aug 2021 19:11:29 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.165.16]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Gznbx1xynz1Rvl9; Tue, 31 Aug 2021 19:11:24 -0700 (PDT) From: Alistair Francis To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: alistair23@gmail.com, Richard Henderson , Bin Meng , Alistair Francis Subject: [PULL 14/33] target/riscv: Introduce DisasExtend and new helpers Date: Wed, 1 Sep 2021 12:09:39 +1000 Message-Id: <20210901020958.458454-15-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210901020958.458454-1-alistair.francis@opensource.wdc.com> References: <20210901020958.458454-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Received-SPF: pass client-ip=216.71.154.45; envelope-from=prvs=871df42ed=alistair.francis@opensource.wdc.com; helo=esa6.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Introduce get_gpr, dest_gpr, temp_new -- new helpers that do not force tcg globals into temps, returning a constant 0 for $zero as source and a new temp for $zero as destination. Introduce ctx->w for simplifying word operations, such as addw. Reviewed-by: Bin Meng Reviewed-by: Alistair Francis Signed-off-by: Richard Henderson Message-id: 20210823195529.560295-6-richard.henderson@linaro.org Signed-off-by: Alistair Francis --- target/riscv/translate.c | 97 +++++++++++++++++++++++++++++++++------- 1 file changed, 81 insertions(+), 16 deletions(-) -- 2.31.1 diff --git a/target/riscv/translate.c b/target/riscv/translate.c index ce4c56c179..d7552dc377 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -39,15 +39,25 @@ static TCGv load_val; #include "exec/gen-icount.h" +/* + * If an operation is being performed on less than TARGET_LONG_BITS, + * it may require the inputs to be sign- or zero-extended; which will + * depend on the exact operation being performed. + */ +typedef enum { + EXT_NONE, + EXT_SIGN, + EXT_ZERO, +} DisasExtend; + typedef struct DisasContext { DisasContextBase base; /* pc_succ_insn points to the instruction following base.pc_next */ target_ulong pc_succ_insn; target_ulong priv_ver; - bool virt_enabled; + target_ulong misa; uint32_t opcode; uint32_t mstatus_fs; - target_ulong misa; uint32_t mem_idx; /* Remember the rounding mode encoded in the previous fp instruction, which we have already installed into env->fp_status. Or -1 for @@ -55,6 +65,8 @@ typedef struct DisasContext { to any system register, which includes CSR_FRM, so we do not have to reset this known value. */ int frm; + bool w; + bool virt_enabled; bool ext_ifencei; bool hlsx; /* vector extension */ @@ -64,7 +76,11 @@ typedef struct DisasContext { uint16_t vlen; uint16_t mlen; bool vl_eq_vlmax; + uint8_t ntemp; CPUState *cs; + TCGv zero; + /* Space for 3 operands plus 1 extra for address computation. */ + TCGv temp[4]; } DisasContext; static inline bool has_ext(DisasContext *ctx, uint32_t ext) @@ -172,27 +188,64 @@ static void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest) } } -/* Wrapper for getting reg values - need to check of reg is zero since - * cpu_gpr[0] is not actually allocated +/* + * Wrappers for getting reg values. + * + * The $zero register does not have cpu_gpr[0] allocated -- we supply the + * constant zero as a source, and an uninitialized sink as destination. + * + * Further, we may provide an extension for word operations. */ -static void gen_get_gpr(DisasContext *ctx, TCGv t, int reg_num) +static TCGv temp_new(DisasContext *ctx) +{ + assert(ctx->ntemp < ARRAY_SIZE(ctx->temp)); + return ctx->temp[ctx->ntemp++] = tcg_temp_new(); +} + +static TCGv get_gpr(DisasContext *ctx, int reg_num, DisasExtend ext) { + TCGv t; + if (reg_num == 0) { - tcg_gen_movi_tl(t, 0); - } else { - tcg_gen_mov_tl(t, cpu_gpr[reg_num]); + return ctx->zero; } + + switch (ctx->w ? ext : EXT_NONE) { + case EXT_NONE: + return cpu_gpr[reg_num]; + case EXT_SIGN: + t = temp_new(ctx); + tcg_gen_ext32s_tl(t, cpu_gpr[reg_num]); + return t; + case EXT_ZERO: + t = temp_new(ctx); + tcg_gen_ext32u_tl(t, cpu_gpr[reg_num]); + return t; + } + g_assert_not_reached(); } -/* Wrapper for setting reg values - need to check of reg is zero since - * cpu_gpr[0] is not actually allocated. this is more for safety purposes, - * since we usually avoid calling the OP_TYPE_gen function if we see a write to - * $zero - */ -static void gen_set_gpr(DisasContext *ctx, int reg_num_dst, TCGv t) +static void gen_get_gpr(DisasContext *ctx, TCGv t, int reg_num) +{ + tcg_gen_mov_tl(t, get_gpr(ctx, reg_num, EXT_NONE)); +} + +static TCGv __attribute__((unused)) dest_gpr(DisasContext *ctx, int reg_num) +{ + if (reg_num == 0 || ctx->w) { + return temp_new(ctx); + } + return cpu_gpr[reg_num]; +} + +static void gen_set_gpr(DisasContext *ctx, int reg_num, TCGv t) { - if (reg_num_dst != 0) { - tcg_gen_mov_tl(cpu_gpr[reg_num_dst], t); + if (reg_num != 0) { + if (ctx->w) { + tcg_gen_ext32s_tl(cpu_gpr[reg_num], t); + } else { + tcg_gen_mov_tl(cpu_gpr[reg_num], t); + } } } @@ -940,6 +993,11 @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) ctx->mlen = 1 << (ctx->sew + 3 - ctx->lmul); ctx->vl_eq_vlmax = FIELD_EX32(tb_flags, TB_FLAGS, VL_EQ_VLMAX); ctx->cs = cs; + ctx->w = false; + ctx->ntemp = 0; + memset(ctx->temp, 0, sizeof(ctx->temp)); + + ctx->zero = tcg_constant_tl(0); } static void riscv_tr_tb_start(DisasContextBase *db, CPUState *cpu) @@ -961,6 +1019,13 @@ static void riscv_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) decode_opc(env, ctx, opcode16); ctx->base.pc_next = ctx->pc_succ_insn; + ctx->w = false; + + for (int i = ctx->ntemp - 1; i >= 0; --i) { + tcg_temp_free(ctx->temp[i]); + ctx->temp[i] = NULL; + } + ctx->ntemp = 0; if (ctx->base.is_jmp == DISAS_NEXT) { target_ulong page_start;