From patchwork Tue Oct 2 18:32:26 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 188619 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 612402C00A3 for ; Wed, 3 Oct 2012 05:01:15 +1000 (EST) Received: from localhost ([::1]:38332 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TJ7Ic-0007gS-Km for incoming@patchwork.ozlabs.org; Tue, 02 Oct 2012 14:34:30 -0400 Received: from eggs.gnu.org ([208.118.235.92]:35748) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TJ7IO-0007KK-Vp for qemu-devel@nongnu.org; Tue, 02 Oct 2012 14:34:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TJ7IM-00080o-VX for qemu-devel@nongnu.org; Tue, 02 Oct 2012 14:34:16 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:35104) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TJ7IM-0007kE-PT for qemu-devel@nongnu.org; Tue, 02 Oct 2012 14:34:14 -0400 Received: by mail-pb0-f45.google.com with SMTP id rp2so9148949pbb.4 for ; Tue, 02 Oct 2012 11:34:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=lcK01R5eNo/3Omvygsta/Duup+kPK/V+GQJKELysYGY=; b=kiI82WL1ubh4POEH5bbusJBk2jux8urycSH090QrRxR8ympwow9NAyhabVzLJ+8onj KSTrAYsZEf3fHf5AKzBS2iRX5fbJTPddCWUtlX+4QAxkkCUqP2G6Woe3OeI8I18fxtrR vQNYNf/Dt859EFbjOEBSI/tC7ucQqUo6qjd56CNDopQtSCMwpDeG9PjeMS9LJAi1BZ6T XIuGFRyWBiH3BHMmhJuez7P9ML/B5vS0mMkHyq8S+qQbodcink/eed+5KyqtYs7Tm8jg utlpge9UGy+zzlyBx08yEcAecoAeFjmnyFXSYuurDRr3Jzbkw0GUxa083Ao8D0+ZTXDk lFgA== Received: by 10.66.88.197 with SMTP id bi5mr46012187pab.58.1349202854404; Tue, 02 Oct 2012 11:34:14 -0700 (PDT) Received: from pebble.twiddle.home (me00536d0.tmodns.net. [208.54.5.224]) by mx.google.com with ESMTPS id nu8sm1259765pbc.45.2012.10.02.11.33.54 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 02 Oct 2012 11:34:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 2 Oct 2012 11:32:26 -0700 Message-Id: <1349202750-16815-7-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 1.7.11.4 In-Reply-To: <1349202750-16815-1-git-send-email-rth@twiddle.net> References: <1349202750-16815-1-git-send-email-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.45 Cc: Aurelien Jarno Subject: [Qemu-devel] [PATCH 06/10] tcg: Split out subroutines from do_constant_folding_cond X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org We can re-use these for implementing double-word folding. Signed-off-by: Richard Henderson Reviewed-by: Aurelien Jarno --- tcg/optimize.c | 146 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 81 insertions(+), 65 deletions(-) diff --git a/tcg/optimize.c b/tcg/optimize.c index 5804b66..38027dc 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -292,6 +292,82 @@ static TCGArg do_constant_folding(TCGOpcode op, TCGArg x, TCGArg y) return res; } +static bool do_constant_folding_cond_32(uint32_t x, uint32_t y, TCGCond c) +{ + switch (c) { + case TCG_COND_EQ: + return x == y; + case TCG_COND_NE: + return x != y; + case TCG_COND_LT: + return (int32_t)x < (int32_t)y; + case TCG_COND_GE: + return (int32_t)x >= (int32_t)y; + case TCG_COND_LE: + return (int32_t)x <= (int32_t)y; + case TCG_COND_GT: + return (int32_t)x > (int32_t)y; + case TCG_COND_LTU: + return x < y; + case TCG_COND_GEU: + return x >= y; + case TCG_COND_LEU: + return x <= y; + case TCG_COND_GTU: + return x > y; + default: + tcg_abort(); + } +} + +static bool do_constant_folding_cond_64(uint64_t x, uint64_t y, TCGCond c) +{ + switch (c) { + case TCG_COND_EQ: + return x == y; + case TCG_COND_NE: + return x != y; + case TCG_COND_LT: + return (int64_t)x < (int64_t)y; + case TCG_COND_GE: + return (int64_t)x >= (int64_t)y; + case TCG_COND_LE: + return (int64_t)x <= (int64_t)y; + case TCG_COND_GT: + return (int64_t)x > (int64_t)y; + case TCG_COND_LTU: + return x < y; + case TCG_COND_GEU: + return x >= y; + case TCG_COND_LEU: + return x <= y; + case TCG_COND_GTU: + return x > y; + default: + tcg_abort(); + } +} + +static bool do_constant_folding_cond_eq(TCGCond c) +{ + switch (c) { + case TCG_COND_GT: + case TCG_COND_LTU: + case TCG_COND_LT: + case TCG_COND_GTU: + case TCG_COND_NE: + return 0; + case TCG_COND_GE: + case TCG_COND_GEU: + case TCG_COND_LE: + case TCG_COND_LEU: + case TCG_COND_EQ: + return 1; + default: + tcg_abort(); + } +} + /* Return 2 if the condition can't be simplified, and the result of the condition (0 or 1) if it can */ static TCGArg do_constant_folding_cond(TCGOpcode op, TCGArg x, @@ -300,69 +376,14 @@ static TCGArg do_constant_folding_cond(TCGOpcode op, TCGArg x, if (temps[x].state == TCG_TEMP_CONST && temps[y].state == TCG_TEMP_CONST) { switch (op_bits(op)) { case 32: - switch (c) { - case TCG_COND_EQ: - return (uint32_t)temps[x].val == (uint32_t)temps[y].val; - case TCG_COND_NE: - return (uint32_t)temps[x].val != (uint32_t)temps[y].val; - case TCG_COND_LT: - return (int32_t)temps[x].val < (int32_t)temps[y].val; - case TCG_COND_GE: - return (int32_t)temps[x].val >= (int32_t)temps[y].val; - case TCG_COND_LE: - return (int32_t)temps[x].val <= (int32_t)temps[y].val; - case TCG_COND_GT: - return (int32_t)temps[x].val > (int32_t)temps[y].val; - case TCG_COND_LTU: - return (uint32_t)temps[x].val < (uint32_t)temps[y].val; - case TCG_COND_GEU: - return (uint32_t)temps[x].val >= (uint32_t)temps[y].val; - case TCG_COND_LEU: - return (uint32_t)temps[x].val <= (uint32_t)temps[y].val; - case TCG_COND_GTU: - return (uint32_t)temps[x].val > (uint32_t)temps[y].val; - } - break; + return do_constant_folding_cond_32(temps[x].val, temps[y].val, c); case 64: - switch (c) { - case TCG_COND_EQ: - return (uint64_t)temps[x].val == (uint64_t)temps[y].val; - case TCG_COND_NE: - return (uint64_t)temps[x].val != (uint64_t)temps[y].val; - case TCG_COND_LT: - return (int64_t)temps[x].val < (int64_t)temps[y].val; - case TCG_COND_GE: - return (int64_t)temps[x].val >= (int64_t)temps[y].val; - case TCG_COND_LE: - return (int64_t)temps[x].val <= (int64_t)temps[y].val; - case TCG_COND_GT: - return (int64_t)temps[x].val > (int64_t)temps[y].val; - case TCG_COND_LTU: - return (uint64_t)temps[x].val < (uint64_t)temps[y].val; - case TCG_COND_GEU: - return (uint64_t)temps[x].val >= (uint64_t)temps[y].val; - case TCG_COND_LEU: - return (uint64_t)temps[x].val <= (uint64_t)temps[y].val; - case TCG_COND_GTU: - return (uint64_t)temps[x].val > (uint64_t)temps[y].val; - } - break; + return do_constant_folding_cond_64(temps[x].val, temps[y].val, c); + default: + tcg_abort(); } } else if (temps_are_copies(x, y)) { - switch (c) { - case TCG_COND_GT: - case TCG_COND_LTU: - case TCG_COND_LT: - case TCG_COND_GTU: - case TCG_COND_NE: - return 0; - case TCG_COND_GE: - case TCG_COND_GEU: - case TCG_COND_LE: - case TCG_COND_LEU: - case TCG_COND_EQ: - return 1; - } + return do_constant_folding_cond_eq(c); } else if (temps[y].state == TCG_TEMP_CONST && temps[y].val == 0) { switch (c) { case TCG_COND_LTU: @@ -375,11 +396,6 @@ static TCGArg do_constant_folding_cond(TCGOpcode op, TCGArg x, } else { return 2; } - - fprintf(stderr, - "Unrecognized bitness %d or condition %d in " - "do_constant_folding_cond.\n", op_bits(op), c); - tcg_abort(); } static bool swap_commutative(TCGArg dest, TCGArg *p1, TCGArg *p2)