From patchwork Wed Feb 13 15:54:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Palmer Dabbelt X-Patchwork-Id: 10810281 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A33DF922 for ; Wed, 13 Feb 2019 16:11:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D7E12DE47 for ; Wed, 13 Feb 2019 16:11:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B8CC2C957; Wed, 13 Feb 2019 16:11:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E9E252DE65 for ; Wed, 13 Feb 2019 16:11:55 +0000 (UTC) Received: from localhost ([127.0.0.1]:59331 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtx8d-00067a-2B for patchwork-qemu-devel@patchwork.kernel.org; Wed, 13 Feb 2019 11:11:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59493) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtwtD-0001nS-FQ for qemu-devel@nongnu.org; Wed, 13 Feb 2019 10:56:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gtwtB-0002eN-IT for qemu-devel@nongnu.org; Wed, 13 Feb 2019 10:55:59 -0500 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]:45305) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gtwtB-0001Vb-81 for qemu-devel@nongnu.org; Wed, 13 Feb 2019 10:55:57 -0500 Received: by mail-pl1-x62a.google.com with SMTP id r14so1330354pls.12 for ; Wed, 13 Feb 2019 07:55:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=subject:date:message-id:in-reply-to:references:cc:from:to; bh=4pdDUSthSFaNpctciMvnBam+yyiPaqzqjMabFEflHNE=; b=LMfew2DFV1TlcWXmhXpth2dRFfDcROD8/M5zMpmazhaQZAuXgwAfJIhDD1wEfoatsh 10fqftP5wRFGSkX13D5dt7ibjsSvlnCp4wK/BopURLF3qFEuIi/DMzwVaZ1DkuUIP9ie q4+3TqMhQ31fU4dgktxNB13WzVwhPumrvmlgAAEYqYCghbbo+Scm2yRaxwPm8PFbhu9E 0hKvFh4JzB1hI4QDAH11zMUwNMFp/Cs6mZAE7wvJm8BTG7q2UcPigrZDvSUy58uq09S9 rTfDJQ+K1aDoY9Mof8s16OkSQmW5Cw4Mex3Oa3Nn2frrKbq6lY0Z6wteDArXpTtOiBfq bvpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:date:message-id:in-reply-to:references :cc:from:to; bh=4pdDUSthSFaNpctciMvnBam+yyiPaqzqjMabFEflHNE=; b=Xw1RBjG9QXNIe2cJZFbUuPNG+5hLqxuDwP9UPJdWe14jbhcKx9caRHaDoSY6MxBHmy lNZ5yPOKn7UM7zHaOZZOB6+haj8czOpWEYK+7E5y/J6BictnV4Zlb34fiZKpdev6JR7n kYKvJHWAujarFAMWjtuSOQh5UDtkKU5yQ561a6XBoCvwht81/EDcXbR7/dq0nLaEXMWa DaloHOWy81cqUFRpoAY/0ADOLtqTEB++tg1NrGtYs6S4wrh775J4jMAVMNaIpSIKR7cQ N42RPdHQhvlFS0/dMpR5j6rYYQ3yiyB+5qxV+u+MqQy72VFTVwCI4ZwVPaIIF5UpLT7H pNAg== X-Gm-Message-State: AHQUAubsyxnLYX5s++H/TOBgzOigNXGKJu1U3jUj12A/KUI9MSMJsrh2 v9VxuDit/c44YBANikyJdQG6niqpD90= X-Google-Smtp-Source: AHgI3IY9aFt9/ShfwCJMBB0r3igsz/UKRlCOv0DNWItGPUBPpm4w24ZXZJjm3UofQJdkNWv0uizTqw== X-Received: by 2002:a17:902:1a2:: with SMTP id b31mr1176528plb.87.1550073310741; Wed, 13 Feb 2019 07:55:10 -0800 (PST) Received: from localhost ([12.206.222.5]) by smtp.gmail.com with ESMTPSA id e9sm74772154pfh.42.2019.02.13.07.55.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Feb 2019 07:55:10 -0800 (PST) Date: Wed, 13 Feb 2019 07:54:00 -0800 Message-Id: <20190213155414.22285-22-palmer@sifive.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20190213155414.22285-1-palmer@sifive.com> References: <20190213155414.22285-1-palmer@sifive.com> From: Palmer Dabbelt To: qemu-riscv@nongnu.org X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::62a Subject: [Qemu-devel] [PATCH v7 21/35] target/riscv: Remove manual decoding from gen_branch() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bastian Koppelmann , Peer Adelt , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Bastian Koppelmann We now utilizes argument-sets of decodetree such that no manual decoding is necessary. Reviewed-by: Richard Henderson Signed-off-by: Bastian Koppelmann Signed-off-by: Peer Adelt --- target/riscv/insn_trans/trans_rvi.inc.c | 46 +++++++++++++++++------- target/riscv/translate.c | 47 ------------------------- 2 files changed, 33 insertions(+), 60 deletions(-) diff --git a/target/riscv/insn_trans/trans_rvi.inc.c b/target/riscv/insn_trans/trans_rvi.inc.c index 39af38081ede..000cb6a37bdd 100644 --- a/target/riscv/insn_trans/trans_rvi.inc.c +++ b/target/riscv/insn_trans/trans_rvi.inc.c @@ -72,41 +72,61 @@ static bool trans_jalr(DisasContext *ctx, arg_jalr *a) return true; } -static bool trans_beq(DisasContext *ctx, arg_beq *a) +static bool gen_branch(DisasContext *ctx, arg_b *a, TCGCond cond) { - gen_branch(ctx, OPC_RISC_BEQ, a->rs1, a->rs2, a->imm); + TCGLabel *l = gen_new_label(); + TCGv source1, source2; + source1 = tcg_temp_new(); + source2 = tcg_temp_new(); + gen_get_gpr(source1, a->rs1); + gen_get_gpr(source2, a->rs2); + + tcg_gen_brcond_tl(cond, source1, source2, l); + gen_goto_tb(ctx, 1, ctx->pc_succ_insn); + gen_set_label(l); /* branch taken */ + + if (!riscv_has_ext(ctx->env, RVC) && ((ctx->base.pc_next + a->imm) & 0x3)) { + /* misaligned */ + gen_exception_inst_addr_mis(ctx); + } else { + gen_goto_tb(ctx, 0, ctx->base.pc_next + a->imm); + } + ctx->base.is_jmp = DISAS_NORETURN; + + tcg_temp_free(source1); + tcg_temp_free(source2); + return true; } +static bool trans_beq(DisasContext *ctx, arg_beq *a) +{ + return gen_branch(ctx, a, TCG_COND_EQ); +} + static bool trans_bne(DisasContext *ctx, arg_bne *a) { - gen_branch(ctx, OPC_RISC_BNE, a->rs1, a->rs2, a->imm); - return true; + return gen_branch(ctx, a, TCG_COND_NE); } static bool trans_blt(DisasContext *ctx, arg_blt *a) { - gen_branch(ctx, OPC_RISC_BLT, a->rs1, a->rs2, a->imm); - return true; + return gen_branch(ctx, a, TCG_COND_LT); } static bool trans_bge(DisasContext *ctx, arg_bge *a) { - gen_branch(ctx, OPC_RISC_BGE, a->rs1, a->rs2, a->imm); - return true; + return gen_branch(ctx, a, TCG_COND_GE); } static bool trans_bltu(DisasContext *ctx, arg_bltu *a) { - gen_branch(ctx, OPC_RISC_BLTU, a->rs1, a->rs2, a->imm); - return true; + return gen_branch(ctx, a, TCG_COND_LTU); } static bool trans_bgeu(DisasContext *ctx, arg_bgeu *a) { - - gen_branch(ctx, OPC_RISC_BGEU, a->rs1, a->rs2, a->imm); - return true; + return gen_branch(ctx, a, TCG_COND_GEU); } static bool trans_lb(DisasContext *ctx, arg_lb *a) diff --git a/target/riscv/translate.c b/target/riscv/translate.c index abdcd0631af4..a3e77b88f6e9 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -532,53 +532,6 @@ static void gen_jal(DisasContext *ctx, int rd, target_ulong imm) ctx->base.is_jmp = DISAS_NORETURN; } -static void gen_branch(DisasContext *ctx, uint32_t opc, int rs1, int rs2, - target_long bimm) -{ - TCGLabel *l = gen_new_label(); - TCGv source1, source2; - source1 = tcg_temp_new(); - source2 = tcg_temp_new(); - gen_get_gpr(source1, rs1); - gen_get_gpr(source2, rs2); - - switch (opc) { - case OPC_RISC_BEQ: - tcg_gen_brcond_tl(TCG_COND_EQ, source1, source2, l); - break; - case OPC_RISC_BNE: - tcg_gen_brcond_tl(TCG_COND_NE, source1, source2, l); - break; - case OPC_RISC_BLT: - tcg_gen_brcond_tl(TCG_COND_LT, source1, source2, l); - break; - case OPC_RISC_BGE: - tcg_gen_brcond_tl(TCG_COND_GE, source1, source2, l); - break; - case OPC_RISC_BLTU: - tcg_gen_brcond_tl(TCG_COND_LTU, source1, source2, l); - break; - case OPC_RISC_BGEU: - tcg_gen_brcond_tl(TCG_COND_GEU, source1, source2, l); - break; - default: - gen_exception_illegal(ctx); - return; - } - tcg_temp_free(source1); - tcg_temp_free(source2); - - gen_goto_tb(ctx, 1, ctx->pc_succ_insn); - gen_set_label(l); /* branch taken */ - if (!has_ext(ctx, RVC) && ((ctx->base.pc_next + bimm) & 0x3)) { - /* misaligned */ - gen_exception_inst_addr_mis(ctx); - } else { - gen_goto_tb(ctx, 0, ctx->base.pc_next + bimm); - } - ctx->base.is_jmp = DISAS_NORETURN; -} - static void gen_load(DisasContext *ctx, uint32_t opc, int rd, int rs1, target_long imm) {