From patchwork Tue Oct 25 17:25:37 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 121774 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 C46D2B6FA6 for ; Wed, 26 Oct 2011 04:27:23 +1100 (EST) Received: from localhost ([::1]:37728 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RIkmT-0004UN-OY for incoming@patchwork.ozlabs.org; Tue, 25 Oct 2011 13:27:17 -0400 Received: from eggs.gnu.org ([140.186.70.92]:39663) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RIkmM-0004UA-3d for qemu-devel@nongnu.org; Tue, 25 Oct 2011 13:27:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RIkmK-0004MJ-Ue for qemu-devel@nongnu.org; Tue, 25 Oct 2011 13:27:10 -0400 Received: from mail-ey0-f173.google.com ([209.85.215.173]:41853) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RIkmK-0004M4-QB for qemu-devel@nongnu.org; Tue, 25 Oct 2011 13:27:08 -0400 Received: by eyh6 with SMTP id 6so836488eyh.4 for ; Tue, 25 Oct 2011 10:27:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer; bh=BuhqCCNmz6RPrXsnfMJXZbccMlh3skZnxQIKNyvm1ZM=; b=l9LMrKvGfEj+ZvZsS+hSxujiSKaVMhPwrySfIsIWHPaYtO7X6nePIUWgk/tdnfxsz2 2CXxIZNoMraKIBIThOWQs1XRI2YYGS7LqVGvYgh4/76uWwwtJA5Z4qI/AlBhp85hhEcx nc6cxsBH2mJnnVGcHmDnqqAVqJPMYxkvhm2HE= Received: by 10.216.198.213 with SMTP id v63mr4914883wen.98.1319563627495; Tue, 25 Oct 2011 10:27:07 -0700 (PDT) Received: from localhost.localdomain (c-98-203-235-125.hsd1.wa.comcast.net. [98.203.235.125]) by mx.google.com with ESMTPS id a27sm15769091wbp.16.2011.10.25.10.27.04 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 25 Oct 2011 10:27:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 25 Oct 2011 10:25:37 -0700 Message-Id: <1319563537-17513-1-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 1.7.6.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.215.173 Cc: blauwirbel@gmail.com Subject: [Qemu-devel] [PATCH] tcg: Optimize some forms of deposit. 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 If the deposit replaces the entire word, optimize to a move. If we're inserting to the top of the word, avoid the mask of arg2 as we'll be shifting out all of the garbage and shifting in zeros. If the host is 32-bit, reduce a 64-bit deposit to a 32-bit deposit when possible. Signed-off-by: Richard Henderson --- tcg/tcg-op.h | 65 +++++++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 51 insertions(+), 14 deletions(-) This is the previous patch from the Sparc VIS series split out separately. r~ diff --git a/tcg/tcg-op.h b/tcg/tcg-op.h index fea5983..2276c72 100644 --- a/tcg/tcg-op.h +++ b/tcg/tcg-op.h @@ -2045,38 +2045,75 @@ static inline void tcg_gen_deposit_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2, unsigned int ofs, unsigned int len) { + uint32_t mask; + TCGv_i32 t1; + + if (ofs == 0 && len == 32) { + tcg_gen_mov_i32(ret, arg2); + return; + } if (TCG_TARGET_HAS_deposit_i32 && TCG_TARGET_deposit_i32_valid(ofs, len)) { tcg_gen_op5ii_i32(INDEX_op_deposit_i32, ret, arg1, arg2, ofs, len); - } else { - uint32_t mask = (1u << len) - 1; - TCGv_i32 t1 = tcg_temp_new_i32 (); + return; + } + + mask = (1u << len) - 1; + t1 = tcg_temp_new_i32 (); + if (ofs + len < 32) { tcg_gen_andi_i32(t1, arg2, mask); tcg_gen_shli_i32(t1, t1, ofs); - tcg_gen_andi_i32(ret, arg1, ~(mask << ofs)); - tcg_gen_or_i32(ret, ret, t1); - - tcg_temp_free_i32(t1); + } else { + tcg_gen_shli_i32(t1, arg2, ofs); } + tcg_gen_andi_i32(ret, arg1, ~(mask << ofs)); + tcg_gen_or_i32(ret, ret, t1); + + tcg_temp_free_i32(t1); } static inline void tcg_gen_deposit_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2, unsigned int ofs, unsigned int len) { + uint64_t mask; + TCGv_i64 t1; + + if (ofs == 0 && len == 64) { + tcg_gen_mov_i64(ret, arg2); + return; + } if (TCG_TARGET_HAS_deposit_i64 && TCG_TARGET_deposit_i64_valid(ofs, len)) { tcg_gen_op5ii_i64(INDEX_op_deposit_i64, ret, arg1, arg2, ofs, len); - } else { - uint64_t mask = (1ull << len) - 1; - TCGv_i64 t1 = tcg_temp_new_i64 (); + return; + } + +#if TCG_TARGET_REG_BITS == 32 + if (ofs >= 32) { + tcg_gen_deposit_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), + TCGV_LOW(arg2), ofs - 32, len); + return; + } + if (ofs + len <= 32) { + tcg_gen_deposit_i32(TCGV_LOW(ret), TCGV_LOW(arg1), + TCGV_LOW(arg2), ofs, len); + return; + } +#endif + + mask = (1ull << len) - 1; + t1 = tcg_temp_new_i64 (); + if (ofs + len < 64) { tcg_gen_andi_i64(t1, arg2, mask); tcg_gen_shli_i64(t1, t1, ofs); - tcg_gen_andi_i64(ret, arg1, ~(mask << ofs)); - tcg_gen_or_i64(ret, ret, t1); - - tcg_temp_free_i64(t1); + } else { + tcg_gen_shli_i64(t1, arg2, ofs); } + tcg_gen_andi_i64(ret, arg1, ~(mask << ofs)); + tcg_gen_or_i64(ret, ret, t1); + + tcg_temp_free_i64(t1); } /***************************************/