From patchwork Thu Sep 27 01:55:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 187270 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 BC5E42C00B0 for ; Thu, 27 Sep 2012 13:05:40 +1000 (EST) Received: from localhost ([::1]:37112 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TH3LU-00034p-LQ for incoming@patchwork.ozlabs.org; Wed, 26 Sep 2012 21:56:56 -0400 Received: from eggs.gnu.org ([208.118.235.92]:33844) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TH3Kd-0001Ov-7c for qemu-devel@nongnu.org; Wed, 26 Sep 2012 21:56:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TH3Kb-0005ys-GU for qemu-devel@nongnu.org; Wed, 26 Sep 2012 21:56:03 -0400 Received: from mail-pa0-f45.google.com ([209.85.220.45]:33983) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TH3Kb-0005h9-AA for qemu-devel@nongnu.org; Wed, 26 Sep 2012 21:56:01 -0400 Received: by mail-pa0-f45.google.com with SMTP id fb10so913009pad.4 for ; Wed, 26 Sep 2012 18:56:00 -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=l/4F/JVVJTrFPm9caHMHk7oS0mX0yRZdIQXkY8tu+MM=; b=rrnwEpZSD75FwS+UJ59GtKOY80kSIJFTHJkC3t8ncblLefe98TJCaEAZBW6Jh6hLe7 IpH38orL3fiuvbqpryRf3DztJMTu4pMyjqbp7GH0I0D7uKhk2hyN8EkR3f4tu54WgnaY ncWF03dlN+zC9DvjM89AhGNC0b4f31qIBpa9MtEyCxV7KpcDlMLXRNrP2zSvQl425aT1 8G37kU0hcunYqQD3L3geYu/0MUAPEyjaksPan0aTgoq5/6xqpAnt79zxeaI6uz8SjzE0 AlEY6/ZDlpU6V3zcguWf1HPHGHwaGFU0lJIQx1OG7iiO/3l7XG8QvDZVCksRTA5d/dD1 q8vA== Received: by 10.66.78.199 with SMTP id d7mr5446718pax.77.1348710960844; Wed, 26 Sep 2012 18:56:00 -0700 (PDT) Received: from anchor.twiddle.home.com ([173.160.232.49]) by mx.google.com with ESMTPS id o1sm2830071pax.21.2012.09.26.18.55.59 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 26 Sep 2012 18:56:00 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 26 Sep 2012 18:55:41 -0700 Message-Id: <1348710942-3040-12-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 1.7.11.4 In-Reply-To: <1348710942-3040-1-git-send-email-rth@twiddle.net> References: <1348710942-3040-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.220.45 Cc: Blue Swirl Subject: [Qemu-devel] [PATCH 11/12] tcg-sparc: Emit BPr insns for brcond_i64 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 Signed-off-by: Richard Henderson --- tcg/sparc/tcg-target.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/tcg/sparc/tcg-target.c b/tcg/sparc/tcg-target.c index f3eb246..90a041e 100644 --- a/tcg/sparc/tcg-target.c +++ b/tcg/sparc/tcg-target.c @@ -126,6 +126,7 @@ static const int tcg_target_call_oarg_regs[] = { #define INSN_IMM11(x) ((1 << 13) | ((x) & 0x7ff)) #define INSN_IMM13(x) ((1 << 13) | ((x) & 0x1fff)) +#define INSN_OFF16(x) ((((x) >> 2) & 0x3fff) | ((((x) >> 16) & 3) << 20)) #define INSN_OFF19(x) (((x) >> 2) & 0x07ffff) #define INSN_COND(x) ((x) << 25) @@ -147,6 +148,13 @@ static const int tcg_target_call_oarg_regs[] = { #define COND_VC 0xf #define BA (INSN_OP(0) | INSN_COND(COND_A) | INSN_OP2(0x2)) +#define RCOND_Z 1 +#define RCOND_LEZ 2 +#define RCOND_LZ 3 +#define RCOND_NZ 5 +#define RCOND_GZ 6 +#define RCOND_GEZ 7 + #define MOVCC_ICC (1 << 18) #define MOVCC_XCC (1 << 18 | 1 << 12) @@ -156,6 +164,8 @@ static const int tcg_target_call_oarg_regs[] = { #define BPCC_PN 0 #define BPCC_A (1 << 29) +#define BPR_PT BPCC_PT + #define ARITH_ADD (INSN_OP(2) | INSN_OP3(0x00)) #define ARITH_ADDCC (INSN_OP(2) | INSN_OP3(0x10)) #define ARITH_AND (INSN_OP(2) | INSN_OP3(0x01)) @@ -251,6 +261,16 @@ static void patch_reloc(uint8_t *code_ptr, int type, } *(uint32_t *)code_ptr = value; break; + case R_SPARC_WDISP16: + value -= (long)code_ptr; + if (!check_fit_tl(value >> 2, 16)) { + tcg_abort(); + } + insn = *(uint32_t *)code_ptr; + insn &= ~INSN_OFF16(-1); + insn |= INSN_OFF16(value); + *(uint32_t *)code_ptr = insn; + break; case R_SPARC_WDISP19: value -= (long)code_ptr; if (!check_fit_tl(value >> 2, 19)) { @@ -502,6 +522,15 @@ static const uint8_t tcg_cond_to_bcond[] = { [TCG_COND_GTU] = COND_GU, }; +static const uint8_t tcg_cond_to_rcond[] = { + [TCG_COND_EQ] = RCOND_Z, + [TCG_COND_NE] = RCOND_NZ, + [TCG_COND_LT] = RCOND_LZ, + [TCG_COND_GT] = RCOND_GZ, + [TCG_COND_LE] = RCOND_LEZ, + [TCG_COND_GE] = RCOND_GEZ +}; + static void tcg_out_bpcc0(TCGContext *s, int scond, int flags, int off19) { tcg_out32(s, INSN_OP(0) | INSN_OP2(1) | INSN_COND(scond) | flags | off19); @@ -555,8 +584,24 @@ static void tcg_out_movcond_i32(TCGContext *s, TCGCond cond, TCGArg ret, static void tcg_out_brcond_i64(TCGContext *s, TCGCond cond, TCGArg arg1, TCGArg arg2, int const_arg2, int label) { - tcg_out_cmp(s, arg1, arg2, const_arg2); - tcg_out_bpcc(s, tcg_cond_to_bcond[cond], BPCC_XCC | BPCC_PT, label); + /* For 64-bit signed comparisons vs zero, we can avoid the compare. */ + if (arg2 == 0 && !is_unsigned_cond(cond)) { + TCGLabel *l = &s->labels[label]; + int off16; + + if (l->has_value) { + off16 = INSN_OFF16(l->u.value - (unsigned long)s->code_ptr); + } else { + /* Make sure to preserve destinations during retranslation. */ + off16 = *(uint32_t *)s->code_ptr & INSN_OFF16(-1); + tcg_out_reloc(s, s->code_ptr, R_SPARC_WDISP16, label, 0); + } + tcg_out32(s, INSN_OP(0) | INSN_OP2(3) | BPR_PT | INSN_RS1(arg1) + | INSN_COND(tcg_cond_to_rcond[cond]) | off16); + } else { + tcg_out_cmp(s, arg1, arg2, const_arg2); + tcg_out_bpcc(s, tcg_cond_to_bcond[cond], BPCC_XCC | BPCC_PT, label); + } tcg_out_nop(s); }