From patchwork Tue Oct 25 14:50:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 9394793 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 436D860762 for ; Tue, 25 Oct 2016 15:13:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 353A629644 for ; Tue, 25 Oct 2016 15:13:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 28FA629653; Tue, 25 Oct 2016 15:13:25 +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=-6.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7F43E29644 for ; Tue, 25 Oct 2016 15:13:20 +0000 (UTC) Received: from localhost ([::1]:55300 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bz3Pj-0001u2-M0 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 25 Oct 2016 11:13:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60436) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bz33y-00009s-Bz for qemu-devel@nongnu.org; Tue, 25 Oct 2016 10:50:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bz33u-00066D-2T for qemu-devel@nongnu.org; Tue, 25 Oct 2016 10:50:50 -0400 Received: from mout.kundenserver.de ([212.227.126.134]:57053) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1bz33t-00065G-OK for qemu-devel@nongnu.org; Tue, 25 Oct 2016 10:50:45 -0400 Received: from Quad.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue003) with ESMTPSA (Nemesis) id 0MYJ7N-1cTRxY2JsX-00V63c; Tue, 25 Oct 2016 16:50:41 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Tue, 25 Oct 2016 16:50:20 +0200 Message-Id: <1477407021-30755-23-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:94Ps9tJhGSziSjM+J9KhGKeUMjZzWxGiVcHKcQW8+WMMpgM5iuI 7O79Jb1PpLlAPCNEQ7ZZgbCxjgU5vtu3poVaii+it+kzahNRrkc7i1foAbpNX2uzJcFJUSl +QN3b7w638d6qVj75EwaXXC0ds/J0092OQVhCxe9kUSxZ9uLOXUj16ZWLTmioscOg07uw6j tWmkTLohjH2VWU4l038jA== X-UI-Out-Filterresults: notjunk:1; V01:K0:ueLOVqnrzRI=:bD7jOpBYht25mhTktJJC6C MwAdIO1raWt51QetfQZPdRHu2j2ubr9dLso0BYgC+0OfrZXZDZI1dZ/IvSVFbkGtNLDd2hxX/ /leYmST321EOEPtHo2x/4+zMVpLnSa9YhlaP5pCU6cq0F7FbUy3L8e/RBY24RYRkWOj4nZukX WNIIFvEsZ9GW5VunbqAPsxSqfJQ2BRqZ6quBMNvewGIRD0tg6sumwx2YeM3MRfJmABIghJnlq pnePPn3ro5W+zV9+5D6jYwWfyx1QUGHUEaKtvUQ924aA2jeKBBwrTFuh90MdsxvNVDRAVzaQP cZUWFZafYmI+Umdyjz0TLN5dNIG4FpGZoa8VILPprkNBEXAH/ZDrTlYi9WhCBz/jGdbvs9n8f WQrTs1jsuBjcv6jL+IvQmvummy5vQhMdlCyZo3Qgmky3+QgSw1wlYl4eTNtVM6PEObszKrR4D 4FoYc7OKtkYzEd4B4wxW6kStqC9Cq9Ezr7kVsT6eMEz64THT4ETTRn8mKd38TDwX4Q82R1oEu nU2875D6DiVjhbHlDbYbY2liQDzsxNQMD1sSnaAXe1y6SLlkHvhxwz68LsG4AhkPiJa6unZaX LWC/QjH4M+RySAILY3eW1vutj805wjjmviluJInt6eYkY9rJwTiv9K45xs18ij9Wmg3HKKA/s LAHo8mHAt4pnHAjW60RSpb0SSoyYg9HvpzPiB0nY7E5drYukp0RC2W5Prsqrhsbhtlho= 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 22/23] target-m68k: Optimize some comparisons 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Richard Henderson Signed-off-by: Richard Henderson Signed-off-by: Laurent Vivier --- target-m68k/translate.c | 108 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 102 insertions(+), 6 deletions(-) diff --git a/target-m68k/translate.c b/target-m68k/translate.c index 5cc5e14..b5e2995 100644 --- a/target-m68k/translate.c +++ b/target-m68k/translate.c @@ -771,10 +771,43 @@ static void gen_cc_cond(DisasCompare *c, DisasContext *s, int cond) { TCGv tmp, tmp2; TCGCond tcond; + CCOp op = s->cc_op; - /* TODO: Optimize compare/branch pairs rather than always flushing - flag state to CC_OP_FLAGS. */ - gen_flush_flags(s); + /* The CC_OP_CMP form can handle most normal comparisons directly. */ + if (op == CC_OP_CMP) { + c->g1 = c->g2 = 1; + c->v1 = QREG_CC_N; + c->v2 = QREG_CC_V; + switch (cond) { + case 2: /* HI */ + case 3: /* LS */ + tcond = TCG_COND_LEU; + goto done; + case 4: /* CC */ + case 5: /* CS */ + tcond = TCG_COND_LTU; + goto done; + case 6: /* NE */ + case 7: /* EQ */ + tcond = TCG_COND_EQ; + goto done; + case 10: /* PL */ + case 11: /* MI */ + c->g1 = c->g2 = 0; + c->v2 = tcg_const_i32(0); + c->v1 = tmp = tcg_temp_new(); + tcg_gen_sub_i32(tmp, QREG_CC_N, QREG_CC_V); + /* fallthru */ + case 12: /* GE */ + case 13: /* LT */ + tcond = TCG_COND_LT; + goto done; + case 14: /* GT */ + case 15: /* LE */ + tcond = TCG_COND_LE; + goto done; + } + } c->g1 = 1; c->g2 = 0; @@ -785,7 +818,71 @@ static void gen_cc_cond(DisasCompare *c, DisasContext *s, int cond) case 1: /* F */ c->v1 = c->v2; tcond = TCG_COND_NEVER; + goto done; + case 14: /* GT (!(Z || (N ^ V))) */ + case 15: /* LE (Z || (N ^ V)) */ + /* Logic operations clear V, which simplifies LE to (Z || N), + and since Z and N are co-located, this becomes a normal + comparison vs N. */ + if (op == CC_OP_LOGIC) { + c->v1 = QREG_CC_N; + tcond = TCG_COND_LE; + goto done; + } + break; + case 12: /* GE (!(N ^ V)) */ + case 13: /* LT (N ^ V) */ + /* Logic operations clear V, which simplifies this to N. */ + if (op != CC_OP_LOGIC) { + break; + } + /* fallthru */ + case 10: /* PL (!N) */ + case 11: /* MI (N) */ + /* Several cases represent N normally. */ + if (op == CC_OP_ADD || op == CC_OP_SUB || op == CC_OP_LOGIC) { + c->v1 = QREG_CC_N; + tcond = TCG_COND_LT; + goto done; + } + break; + case 6: /* NE (!Z) */ + case 7: /* EQ (Z) */ + /* Some cases fold Z into N. */ + if (op == CC_OP_ADD || op == CC_OP_SUB || op == CC_OP_LOGIC) { + tcond = TCG_COND_EQ; + c->v1 = QREG_CC_N; + goto done; + } break; + case 4: /* CC (!C) */ + case 5: /* CS (C) */ + /* Some cases fold C into X. */ + if (op == CC_OP_ADD || op == CC_OP_SUB) { + tcond = TCG_COND_NE; + c->v1 = QREG_CC_X; + goto done; + } + /* fallthru */ + case 8: /* VC (!V) */ + case 9: /* VS (V) */ + /* Logic operations clear V and C. */ + if (op == CC_OP_LOGIC) { + tcond = TCG_COND_NEVER; + c->v2 = c->v1; + } + break; + } + + /* Otherwise, flush flag state to CC_OP_FLAGS. */ + gen_flush_flags(s); + + switch (cond) { + case 0: /* T */ + case 1: /* F */ + default: + /* Invalid, or handled above. */ + abort(); case 2: /* HI (!C && !Z) -> !(C || Z)*/ case 3: /* LS (C || Z) */ c->v1 = tmp = tcg_temp_new(); @@ -833,10 +930,9 @@ static void gen_cc_cond(DisasCompare *c, DisasContext *s, int cond) tcg_temp_free(tmp2); tcond = TCG_COND_LT; break; - default: - /* Should ever happen. */ - abort(); } + + done: if ((cond & 1) == 0) { tcond = tcg_invert_cond(tcond); }