From patchwork Fri May 20 12:39:33 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kirill Batuzov X-Patchwork-Id: 96589 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 503C1B71A1 for ; Fri, 20 May 2011 22:40:25 +1000 (EST) Received: from localhost ([::1]:49959 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QNP0A-0006eK-G0 for incoming@patchwork.ozlabs.org; Fri, 20 May 2011 08:40:22 -0400 Received: from eggs.gnu.org ([140.186.70.92]:44767) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QNOzi-0006ax-2J for qemu-devel@nongnu.org; Fri, 20 May 2011 08:39:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QNOzh-0003ZX-A2 for qemu-devel@nongnu.org; Fri, 20 May 2011 08:39:54 -0400 Received: from smtp.ispras.ru ([83.149.198.202]:55472) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QNOzg-0003ZK-P2 for qemu-devel@nongnu.org; Fri, 20 May 2011 08:39:53 -0400 Received: from bulbul.intra.ispras.ru (winnie.ispras.ru [83.149.198.236]) by smtp.ispras.ru (Postfix) with ESMTP id 114825D411B; Fri, 20 May 2011 16:36:09 +0400 (MSD) From: Kirill Batuzov To: qemu-devel@nongnu.org Date: Fri, 20 May 2011 16:39:33 +0400 Message-Id: X-Mailer: git-send-email 1.7.4.1 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 83.149.198.202 Cc: mj.mccormack@samsung.com, zhur@ispras.ru Subject: [Qemu-devel] [PATCH 6/6] Do constant folding for unary operations. 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 Perform constant folding for NOT and EXT{8,16,32}{S,U} operations. Signed-off-by: Kirill Batuzov --- tcg/optimize.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 82 insertions(+), 0 deletions(-) diff --git a/tcg/optimize.c b/tcg/optimize.c index b6b0dc4..bda469a 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -104,6 +104,11 @@ static int op_bits(int op) case INDEX_op_sar_i32: case INDEX_op_rotl_i32: case INDEX_op_rotr_i32: + case INDEX_op_not_i32: + case INDEX_op_ext8s_i32: + case INDEX_op_ext16s_i32: + case INDEX_op_ext8u_i32: + case INDEX_op_ext16u_i32: return 32; #if TCG_TARGET_REG_BITS == 64 case INDEX_op_mov_i64: @@ -118,6 +123,13 @@ static int op_bits(int op) case INDEX_op_sar_i64: case INDEX_op_rotl_i64: case INDEX_op_rotr_i64: + case INDEX_op_not_i64: + case INDEX_op_ext8s_i64: + case INDEX_op_ext16s_i64: + case INDEX_op_ext32s_i64: + case INDEX_op_ext8u_i64: + case INDEX_op_ext16u_i64: + case INDEX_op_ext32u_i64: return 64; #endif default: @@ -245,6 +257,44 @@ static TCGArg do_constant_folding_2(int op, TCGArg x, TCGArg y) return x; #endif + case INDEX_op_not_i32: +#if TCG_TARGET_REG_BITS == 64 + case INDEX_op_not_i64: +#endif + return ~x; + + case INDEX_op_ext8s_i32: + return x & (1 << 7) ? x | ~0xff : x & 0xff; + + case INDEX_op_ext16s_i32: + return x & (1 << 15) ? x | ~0xffff : x & 0xffff; + + case INDEX_op_ext8u_i32: + return x & 0xff; + + case INDEX_op_ext16u_i32: + return x & 0xffff; + +#if TCG_TARGET_REG_BITS == 64 + case INDEX_op_ext8s_i64: + return x & (1 << 7) ? x | ~0xffULL : x & 0xff; + + case INDEX_op_ext16s_i64: + return x & (1 << 15) ? x | ~0xffffULL : x & 0xffff; + + case INDEX_op_ext32s_i64: + return x & (1U << 31) ? x | ~0xffffffffULL : x & 0xffffffff; + + case INDEX_op_ext8u_i64: + return x & 0xff; + + case INDEX_op_ext16u_i64: + return x & 0xffff; + + case INDEX_op_ext32u_i64: + return x & 0xffffffff; +#endif + default: fprintf(stderr, "Unrecognized operation %d in do_constant_folding.\n", op); @@ -345,6 +395,38 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr, gen_args += 2; args += 2; break; + case INDEX_op_not_i32: + case INDEX_op_ext8s_i32: + case INDEX_op_ext16s_i32: + case INDEX_op_ext8u_i32: + case INDEX_op_ext16u_i32: +#if TCG_TARGET_REG_BITS == 64 + case INDEX_op_not_i64: + case INDEX_op_ext8s_i64: + case INDEX_op_ext16s_i64: + case INDEX_op_ext32s_i64: + case INDEX_op_ext8u_i64: + case INDEX_op_ext16u_i64: + case INDEX_op_ext32u_i64: +#endif + if (state[args[1]] == TCG_TEMP_CONST) { + gen_opc_buf[op_index] = op_to_movi(op); + gen_args[0] = args[0]; + gen_args[1] = do_constant_folding(op, vals[args[1]], 0); + reset_temp(state, vals, gen_args[0], nb_temps, nb_globals); + state[gen_args[0]] = TCG_TEMP_CONST; + vals[gen_args[0]] = gen_args[1]; + gen_args += 2; + args += 2; + break; + } else { + reset_temp(state, vals, args[0], nb_temps, nb_globals); + gen_args[0] = args[0]; + gen_args[1] = args[1]; + gen_args += 2; + args += 2; + break; + } case INDEX_op_or_i32: case INDEX_op_and_i32: #if TCG_TARGET_REG_BITS == 64