From patchwork Thu Jul 7 12:37:17 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kirill Batuzov X-Patchwork-Id: 103647 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 7D5EF1007D1 for ; Thu, 7 Jul 2011 22:41:25 +1000 (EST) Received: from localhost ([::1]:40969 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QentR-0000Y0-KV for incoming@patchwork.ozlabs.org; Thu, 07 Jul 2011 08:41:21 -0400 Received: from eggs.gnu.org ([140.186.70.92]:45520) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qenpo-0000WP-K6 for qemu-devel@nongnu.org; Thu, 07 Jul 2011 08:37:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qenph-0005Yv-Rr for qemu-devel@nongnu.org; Thu, 07 Jul 2011 08:37:36 -0400 Received: from smtp.ispras.ru ([83.149.198.202]:51666) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qenpg-0005YT-Ok for qemu-devel@nongnu.org; Thu, 07 Jul 2011 08:37:29 -0400 Received: from ispserv.ispras.ru (ispserv.ispras.ru [83.149.198.72]) by smtp.ispras.ru (Postfix) with ESMTP id B67325D407F; Thu, 7 Jul 2011 16:30:31 +0400 (MSD) Received: from bulbul.intra.ispras.ru (winnie.ispras.ru [83.149.198.236]) by ispserv.ispras.ru (Postfix) with ESMTP id 596B63FC48; Thu, 7 Jul 2011 16:37:26 +0400 (MSD) From: Kirill Batuzov To: qemu-devel@nongnu.org Date: Thu, 7 Jul 2011 16:37:17 +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: zhur@ispras.ru Subject: [Qemu-devel] [PATCH v3 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 | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 59 insertions(+), 0 deletions(-) diff --git a/tcg/optimize.c b/tcg/optimize.c index a1bb287..a324e98 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -107,6 +107,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: @@ -121,6 +126,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: @@ -267,6 +279,29 @@ static TCGArg do_constant_folding_2(int op, TCGArg x, TCGArg y) return x; #endif + CASE_OP_32_64(not): + return ~x; + + CASE_OP_32_64(ext8s): + return (int8_t)x; + + CASE_OP_32_64(ext16s): + return (int16_t)x; + + CASE_OP_32_64(ext8u): + return (uint8_t)x; + + CASE_OP_32_64(ext16u): + return (uint16_t)x; + +#if TCG_TARGET_REG_BITS == 64 + case INDEX_op_ext32s_i64: + return (int32_t)x; + + case INDEX_op_ext32u_i64: + return (uint32_t)x; +#endif + default: fprintf(stderr, "Unrecognized operation %d in do_constant_folding.\n", op); @@ -424,6 +459,30 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr, gen_args += 2; args += 2; break; + CASE_OP_32_64(not): + CASE_OP_32_64(ext8s): + CASE_OP_32_64(ext16s): + CASE_OP_32_64(ext8u): + CASE_OP_32_64(ext16u): +#if TCG_TARGET_REG_BITS == 64 + case INDEX_op_ext32s_i64: + case INDEX_op_ext32u_i64: +#endif + if (temps[args[1]].state == TCG_TEMP_CONST) { + gen_opc_buf[op_index] = op_to_movi(op); + tmp = do_constant_folding(op, temps[args[1]].val, 0); + tcg_opt_gen_movi(gen_args, args[0], tmp, nb_temps, nb_globals); + gen_args += 2; + args += 2; + break; + } else { + reset_temp(args[0], nb_temps, nb_globals); + gen_args[0] = args[0]; + gen_args[1] = args[1]; + gen_args += 2; + args += 2; + break; + } CASE_OP_32_64(add): CASE_OP_32_64(sub): CASE_OP_32_64(mul):