From patchwork Tue Oct 25 14:50:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 686536 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3t3H034hphz9t80 for ; Wed, 26 Oct 2016 02:20:19 +1100 (AEDT) Received: from localhost ([::1]:55344 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bz3WS-0008S8-9d for incoming@patchwork.ozlabs.org; Tue, 25 Oct 2016 11:20:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60421) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bz33w-00008W-UL for qemu-devel@nongnu.org; Tue, 25 Oct 2016 10:50:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bz33r-000646-U8 for qemu-devel@nongnu.org; Tue, 25 Oct 2016 10:50:48 -0400 Received: from mout.kundenserver.de ([212.227.126.134]:53301) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1bz33r-00062J-Af for qemu-devel@nongnu.org; Tue, 25 Oct 2016 10:50:43 -0400 Received: from Quad.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue003) with ESMTPSA (Nemesis) id 0MFOee-1cB6IO0vUC-00EO1N; Tue, 25 Oct 2016 16:50:40 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Tue, 25 Oct 2016 16:50:18 +0200 Message-Id: <1477407021-30755-21-git-send-email-laurent@vivier.eu> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1477407021-30755-1-git-send-email-laurent@vivier.eu> References: <1477407021-30755-1-git-send-email-laurent@vivier.eu> X-Provags-ID: V03:K0:fpubTd6M8ERp6C5ImM4i8NcjDNjZSFx6X3xk9E3wlUHj3tGLpcU G9nqqofbMcbMtdJ0t/727J5Nt8GpeRQwcbSgZ2GmBkYcALd7vARlDgBJel7MSp11f69wdlW R604sBtNvU6QJzpBPkLDAI30U7mP46hUGaZ7d0ebaTlwfFXe+3OH4ApsziPNU7tTarwsmUC u2Gl+3JgeFMNAblu29CNQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:k6hUQK3P3T8=:aKsfBf6rGrK4C602HpukZY cEDcDfvThJp8SaomGoTzKZAm7jTN+bAutydpANRTnzhRKnPB95obq3seOlxXOvmTMcZo/FUPn T4paip1sxqNwniMav23uOw1y+n7JIbubUtZDwHPJoft/RQvSvE67R5fGdC2WrrT7yH6NhIrJX keXZ5nO35XiXuKe5ofPCg7HycVyJp2zoqixC8/LMGz2/PPQemYFB/YywmGNpMzGU49tnrJ7eK D0L+55+2pz8yUYTpBgZqKis+OTZx1ok0GTc27AHzCT6lNVhvEVuhcOrvjxKFURUYqQCkxq20i r5uoZfDXTH+Rh5OveaNdz6ErqzHdtAo+rU1lNR5X/Jw7GrezjseIMyfql8wRVlXM9tNg5PR9/ EduUCikotcLIxO6dYn60StPAzXaljRVe0JwXHwRvNYC5s1MVnK8bBDFN6oah4l7aj9/PvN0ir Tbg0FLLsG2Sac1MRDM8hEj70iwi4yej2JWlFdEa/qZaJ1xnjenKQfq0vPc5XR2xQSZieQTc+Q RkMN5hEGZvkPZshkMa0ft5ba/8D93nNu9H6YrlUgn/8Y+6D07Y/QsjmFTVTLPKhC84X44xhH3 2ukRb7O90opzStnAm4sbKOjPHZMjHS4GtVv/ghXDXzCFdwAuQHZcjir+V+W5fmWEYd2lzFoQn A3hjVXiod8EiRfk8O55/3hqr/D5Xax3GnC7TD3xeBzDDg88lLKtNjcVByw2bS3ssrkSU= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.134 Subject: [Qemu-devel] [PATCH 20/23] target-m68k: Introduce DisasCompare 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: Laurent Vivier , gerg@uclinux.org, schwab@linux-m68k.org, agraf@suse.de, Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Signed-off-by: Richard Henderson Signed-off-by: Laurent Vivier --- target-m68k/translate.c | 85 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 61 insertions(+), 24 deletions(-) diff --git a/target-m68k/translate.c b/target-m68k/translate.c index 85d5c95..4a650e1 100644 --- a/target-m68k/translate.c +++ b/target-m68k/translate.c @@ -759,8 +759,15 @@ static TCGv gen_ea(CPUM68KState *env, DisasContext *s, uint16_t insn, return NULL_QREG; } -/* This generates a conditional branch, clobbering all temporaries. */ -static void gen_jmpcc(DisasContext *s, int cond, TCGLabel *l1) +typedef struct { + TCGCond tcond; + bool g1; + bool g2; + TCGv v1; + TCGv v2; +} DisasCompare; + +static void gen_cc_cond(DisasCompare *c, DisasContext *s, int cond) { TCGv tmp, tmp2; TCGCond tcond; @@ -768,61 +775,92 @@ static void gen_jmpcc(DisasContext *s, int cond, TCGLabel *l1) /* TODO: Optimize compare/branch pairs rather than always flushing flag state to CC_OP_FLAGS. */ gen_flush_flags(s); - update_cc_op(s); + + c->g1 = 1; + c->g2 = 0; + c->v2 = tcg_const_i32(0); + switch (cond) { case 0: /* T */ - tcg_gen_br(l1); - return; case 1: /* F */ - return; + c->v1 = c->v2; + tcond = TCG_COND_NEVER; + break; case 2: /* HI (!C && !Z) -> !(C || Z)*/ case 3: /* LS (C || Z) */ - tmp = tcg_temp_new(); - tcg_gen_setcondi_i32(TCG_COND_EQ, tmp, QREG_CC_Z, 0); + c->v1 = tmp = tcg_temp_new(); + c->g1 = 0; + tcg_gen_setcond_i32(TCG_COND_EQ, tmp, QREG_CC_Z, c->v2); tcg_gen_or_i32(tmp, tmp, QREG_CC_C); - tcond = (cond & 1 ? TCG_COND_NE : TCG_COND_EQ); + tcond = TCG_COND_NE; break; case 4: /* CC (!C) */ case 5: /* CS (C) */ - tmp = QREG_CC_C; - tcond = (cond & 1 ? TCG_COND_NE : TCG_COND_EQ); + c->v1 = QREG_CC_C; + tcond = TCG_COND_NE; break; case 6: /* NE (!Z) */ case 7: /* EQ (Z) */ - tmp = QREG_CC_Z; - tcond = (cond & 1 ? TCG_COND_EQ : TCG_COND_NE); + c->v1 = QREG_CC_Z; + tcond = TCG_COND_EQ; break; case 8: /* VC (!V) */ case 9: /* VS (V) */ - tmp = QREG_CC_V; - tcond = (cond & 1 ? TCG_COND_LT : TCG_COND_GE); + c->v1 = QREG_CC_V; + tcond = TCG_COND_LT; break; case 10: /* PL (!N) */ case 11: /* MI (N) */ - tmp = QREG_CC_N; - tcond = (cond & 1 ? TCG_COND_LT : TCG_COND_GE); + c->v1 = QREG_CC_N; + tcond = TCG_COND_LT; break; case 12: /* GE (!(N ^ V)) */ case 13: /* LT (N ^ V) */ - tmp = tcg_temp_new(); + c->v1 = tmp = tcg_temp_new(); + c->g1 = 0; tcg_gen_xor_i32(tmp, QREG_CC_N, QREG_CC_V); - tcond = (cond & 1 ? TCG_COND_LT : TCG_COND_GE); + tcond = TCG_COND_LT; break; case 14: /* GT (!(Z || (N ^ V))) */ case 15: /* LE (Z || (N ^ V)) */ - tmp = tcg_temp_new(); - tcg_gen_setcondi_i32(TCG_COND_EQ, tmp, QREG_CC_Z, 0); + c->v1 = tmp = tcg_temp_new(); + c->g1 = 0; + tcg_gen_setcond_i32(TCG_COND_EQ, tmp, QREG_CC_Z, c->v2); tcg_gen_neg_i32(tmp, tmp); tmp2 = tcg_temp_new(); tcg_gen_xor_i32(tmp2, QREG_CC_N, QREG_CC_V); tcg_gen_or_i32(tmp, tmp, tmp2); - tcond = (cond & 1 ? TCG_COND_LT : TCG_COND_GE); + tcg_temp_free(tmp2); + tcond = TCG_COND_LT; break; default: /* Should ever happen. */ abort(); } - tcg_gen_brcondi_i32(tcond, tmp, 0, l1); + if ((cond & 1) == 0) { + tcond = tcg_invert_cond(tcond); + } + c->tcond = tcond; +} + +static void free_cond(DisasCompare *c) +{ + if (!c->g1) { + tcg_temp_free(c->v1); + } + if (!c->g2) { + tcg_temp_free(c->v2); + } +} + +static void gen_jmpcc(DisasContext *s, int cond, TCGLabel *l1) +{ + DisasCompare c; + + gen_cc_cond(&c, s, cond); + update_cc_op(s); + tcg_gen_brcond_i32(c.tcond, c.v1, c.v2, l1); + free_cond(&c); } DISAS_INSN(scc) @@ -1678,7 +1716,6 @@ DISAS_INSN(branch) /* bsr */ gen_push(s, tcg_const_i32(s->pc)); } - update_cc_op(s); if (op > 1) { /* Bcc */ l1 = gen_new_label();