From patchwork Tue Feb 19 17:39:57 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 221934 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 73FEC2C007B for ; Wed, 20 Feb 2013 11:33:49 +1100 (EST) Received: from localhost ([::1]:37274 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U7rCY-0006M7-F4 for incoming@patchwork.ozlabs.org; Tue, 19 Feb 2013 12:41:58 -0500 Received: from eggs.gnu.org ([208.118.235.92]:44301) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U7rCE-00063s-Rs for qemu-devel@nongnu.org; Tue, 19 Feb 2013 12:41:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U7rC2-000866-1o for qemu-devel@nongnu.org; Tue, 19 Feb 2013 12:41:38 -0500 Received: from mail-pb0-f51.google.com ([209.85.160.51]:62449) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U7rC1-00083W-Gn for qemu-devel@nongnu.org; Tue, 19 Feb 2013 12:41:25 -0500 Received: by mail-pb0-f51.google.com with SMTP id un15so2348355pbc.24 for ; Tue, 19 Feb 2013 09:41:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=VGkaFCeqZW2D/INyBSbjQOvKKXxgs9FrMpgxep4VjIk=; b=T86R8gS2uDJJPNnRYqqqfiqUqowVkJRLhl3NvboUVa473m47T9eQ5ulfroiIRlk4ki AIHYMPrrE6Dc6m8EUlypUy6sx5DCewQXwuI2x8fkowit/78PGWR9zLjDFDZxVbyPlT4s vmO0XHScqISF/7cXrRubmYKDZkSFlIT+Ri+VZlzgMKd+GTmyortly5BD8EHUXqYTT33A Y1yPuxbAIzWoe7mA9MiGt7rUsKqxbDn8XuSeLWRYEcc12u2Owu2gXZEhba7eDPI/ax/i VQuwf5Xdw2U8nqqpDjiJOklslKaAvquUoc2NxraIjWcDo7XTCU/5hoaWTSO0WIPekSpo QaZA== X-Received: by 10.66.85.73 with SMTP id f9mr47706151paz.13.1361295679291; Tue, 19 Feb 2013 09:41:19 -0800 (PST) Received: from anchor.twiddle.net (50-194-63-110-static.hfc.comcastbusiness.net. [50.194.63.110]) by mx.google.com with ESMTPS id 1sm18659295pbg.18.2013.02.19.09.41.17 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 19 Feb 2013 09:41:18 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 19 Feb 2013 09:39:57 -0800 Message-Id: <1361295631-21316-24-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1361295631-21316-1-git-send-email-rth@twiddle.net> References: <1361295631-21316-1-git-send-email-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.160.51 Cc: blauwirbel@gmail.com, pbonzini@redhat.com, afaerber@suse.de, aurelien@aurel32.net Subject: [Qemu-devel] [PATCH 23/57] target-i386: convert gen_compute_eflags_c to TCG 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 Do the switch at translation time, converting the helper templates to TCG opcodes. In some cases CF can be computed with a single setcond, though others it may require a little more work. In the CC_OP_DYNAMIC case, compute the whole EFLAGS, same as for ZF/SF/PF. Reviewed-by: Blue Swirl Signed-off-by: Paolo Bonzini Signed-off-by: Richard Henderson --- target-i386/translate.c | 109 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 98 insertions(+), 11 deletions(-) diff --git a/target-i386/translate.c b/target-i386/translate.c index 06aa7bf..ea1b003 100644 --- a/target-i386/translate.c +++ b/target-i386/translate.c @@ -869,17 +869,6 @@ static void gen_op_update_neg_cc(void) tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]); } -/* compute eflags.C to reg */ -static void gen_compute_eflags_c(DisasContext *s, TCGv reg, bool inv) -{ - gen_update_cc_op(s); - gen_helper_cc_compute_c(cpu_tmp2_i32, cpu_env, cpu_cc_op); - tcg_gen_extu_i32_tl(reg, cpu_tmp2_i32); - if (inv) { - tcg_gen_xori_tl(reg, reg, 1); - } -} - /* compute all eflags to cc_src */ static void gen_compute_eflags(DisasContext *s) { @@ -892,6 +881,104 @@ static void gen_compute_eflags(DisasContext *s) tcg_gen_extu_i32_tl(cpu_cc_src, cpu_tmp2_i32); } +/* compute eflags.C to reg */ +static void gen_compute_eflags_c(DisasContext *s, TCGv reg, bool inv) +{ + TCGv t0, t1; + int size; + + switch (s->cc_op) { + case CC_OP_SUBB ... CC_OP_SUBQ: + /* (DATA_TYPE)(CC_DST + CC_SRC) < (DATA_TYPE)CC_SRC */ + size = s->cc_op - CC_OP_SUBB; + t1 = gen_ext_tl(cpu_tmp0, cpu_cc_src, size, false); + /* If no temporary was used, be careful not to alias t1 and t0. */ + t0 = TCGV_EQUAL(t1, cpu_cc_src) ? cpu_tmp0 : reg; + tcg_gen_add_tl(t0, cpu_cc_dst, cpu_cc_src); + gen_extu(size, t0); + goto add_sub; + + case CC_OP_ADDB ... CC_OP_ADDQ: + /* (DATA_TYPE)CC_DST < (DATA_TYPE)CC_SRC */ + size = s->cc_op - CC_OP_ADDB; + t1 = gen_ext_tl(cpu_tmp0, cpu_cc_src, size, false); + t0 = gen_ext_tl(reg, cpu_cc_dst, size, false); + add_sub: + tcg_gen_setcond_tl(inv ? TCG_COND_GEU : TCG_COND_LTU, reg, t0, t1); + inv = false; + break; + + case CC_OP_SBBB ... CC_OP_SBBQ: + /* (DATA_TYPE)(CC_DST + CC_SRC + 1) <= (DATA_TYPE)CC_SRC */ + size = s->cc_op - CC_OP_SBBB; + t1 = gen_ext_tl(cpu_tmp0, cpu_cc_src, size, false); + if (TCGV_EQUAL(t1, reg) && TCGV_EQUAL(reg, cpu_cc_src)) { + tcg_gen_mov_tl(cpu_tmp0, cpu_cc_src); + t1 = cpu_tmp0; + } + + tcg_gen_add_tl(reg, cpu_cc_dst, cpu_cc_src); + tcg_gen_addi_tl(reg, reg, 1); + gen_extu(size, reg); + t0 = reg; + goto adc_sbb; + + case CC_OP_ADCB ... CC_OP_ADCQ: + /* (DATA_TYPE)CC_DST <= (DATA_TYPE)CC_SRC */ + size = s->cc_op - CC_OP_ADCB; + t1 = gen_ext_tl(cpu_tmp0, cpu_cc_src, size, false); + t0 = gen_ext_tl(reg, cpu_cc_dst, size, false); + adc_sbb: + tcg_gen_setcond_tl(inv ? TCG_COND_GTU : TCG_COND_LEU, reg, t0, t1); + inv = false; + break; + + case CC_OP_LOGICB ... CC_OP_LOGICQ: + tcg_gen_movi_tl(reg, 0); + break; + + case CC_OP_INCB ... CC_OP_INCQ: + case CC_OP_DECB ... CC_OP_DECQ: + if (inv) { + tcg_gen_xori_tl(reg, cpu_cc_src, 1); + } else { + tcg_gen_mov_tl(reg, cpu_cc_src); + } + inv = false; + break; + + case CC_OP_SHLB ... CC_OP_SHLQ: + /* (CC_SRC >> (DATA_BITS - 1)) & 1 */ + size = s->cc_op - CC_OP_SHLB; + tcg_gen_shri_tl(reg, cpu_cc_src, (8 << size) - 1); + tcg_gen_andi_tl(reg, reg, 1); + break; + + case CC_OP_MULB ... CC_OP_MULQ: + tcg_gen_setcondi_tl(inv ? TCG_COND_EQ : TCG_COND_NE, + reg, cpu_cc_src, 0); + inv = false; + break; + + case CC_OP_EFLAGS: + case CC_OP_SARB ... CC_OP_SARQ: + /* CC_SRC & 1 */ + tcg_gen_andi_tl(reg, cpu_cc_src, 1); + break; + + default: + /* The need to compute only C from CC_OP_DYNAMIC is important + in efficiently implementing e.g. INC at the start of a TB. */ + gen_update_cc_op(s); + gen_helper_cc_compute_c(cpu_tmp2_i32, cpu_env, cpu_cc_op); + tcg_gen_extu_i32_tl(reg, cpu_tmp2_i32); + break; + } + if (inv) { + tcg_gen_xori_tl(reg, reg, 1); + } +} + /* compute eflags.P to reg */ static void gen_compute_eflags_p(DisasContext *s, TCGv reg) {