From patchwork Sat May 24 15:53:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 352134 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 63BEE1400A8 for ; Sun, 25 May 2014 02:04:18 +1000 (EST) Received: from localhost ([::1]:48538 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WoEQh-0001Jk-HP for incoming@patchwork.ozlabs.org; Sat, 24 May 2014 12:04:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46370) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WoEHL-00039Z-9y for qemu-devel@nongnu.org; Sat, 24 May 2014 11:54:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WoEHF-0001HV-AH for qemu-devel@nongnu.org; Sat, 24 May 2014 11:54:35 -0400 Received: from mail-pb0-x22c.google.com ([2607:f8b0:400e:c01::22c]:61562) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WoEHE-0001HA-R6 for qemu-devel@nongnu.org; Sat, 24 May 2014 11:54:29 -0400 Received: by mail-pb0-f44.google.com with SMTP id rq2so5563659pbb.17 for ; Sat, 24 May 2014 08:54:27 -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:in-reply-to:references; bh=aMY4TwTINoO1Ii7CXhGAQ8W4g9YtEDAJa30JoT9FN2k=; b=vTMsZWMBk4s+EnWhTlhZUQPHMTkmccr15UunqA9ULMbn365tLFTIU7/HASr/aXHieF iJemulTPiI7pYaf8J/1VQJo+zbJaV/V0xH2RRQBP1WNuBW5yL8EU/knL02Rh+TaRZyP5 zqAUmy1YKZ4M9sQkpJOU5YrTaQGncJhzHEP2EZfK7Zw4KIBTBwYj9KlQV6RODhkjSO5o YrggDcsxpN2HOuNvxIFTh/n16WDN//F5e8fBXB4QMDHoWMyVl+LROIGGV9WJbTMMMyZ0 yhul00RqOdbrn0HPtHexZULHys2sVGi0wZ8g8R8CwmLIEjMeu4MzT13iE58e/09AZ6f4 bLnQ== X-Received: by 10.68.130.38 with SMTP id ob6mr14559541pbb.141.1400946867466; Sat, 24 May 2014 08:54:27 -0700 (PDT) Received: from pike.twiddle.home (50-194-63-110-static.hfc.comcastbusiness.net. [50.194.63.110]) by mx.google.com with ESMTPSA id ie9sm30663048pad.29.2014.05.24.08.54.25 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 May 2014 08:54:26 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 24 May 2014 08:53:49 -0700 Message-Id: <1400946841-21079-13-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1400946841-21079-1-git-send-email-rth@twiddle.net> References: <1400946841-21079-1-git-send-email-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c01::22c Cc: peter.maydell@linaro.org Subject: [Qemu-devel] [PULL 12/24] tcg-mips: Use EXT for AND on mips32r2 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 At the same time, tidy deposit by introducing tcg_out_opc_bf. Reviewed-by: Paolo Bonzini Signed-off-by: Richard Henderson --- tcg/mips/tcg-target.c | 60 ++++++++++++++++++++++++++++++++++++++++++--------- tcg/mips/tcg-target.h | 4 ---- 2 files changed, 50 insertions(+), 14 deletions(-) diff --git a/tcg/mips/tcg-target.c b/tcg/mips/tcg-target.c index 78caf25..54571fb 100644 --- a/tcg/mips/tcg-target.c +++ b/tcg/mips/tcg-target.c @@ -155,6 +155,16 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int type, reloc_pc16(code_ptr, (tcg_insn_unit *)value); } +#define TCG_CT_CONST_ZERO 0x100 +#define TCG_CT_CONST_U16 0x200 +#define TCG_CT_CONST_S16 0x400 +#define TCG_CT_CONST_P2M1 0x800 + +static inline bool is_p2m1(tcg_target_long val) +{ + return val && ((val + 1) & val) == 0; +} + /* parse target specific constraints */ static int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str) { @@ -200,6 +210,9 @@ static int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str) case 'J': ct->ct |= TCG_CT_CONST_S16; break; + case 'K': + ct->ct |= TCG_CT_CONST_P2M1; + break; case 'Z': /* We are cheating a bit here, using the fact that the register ZERO is also the register number 0. Hence there is no need @@ -220,16 +233,19 @@ static inline int tcg_target_const_match(tcg_target_long val, TCGType type, { int ct; ct = arg_ct->ct; - if (ct & TCG_CT_CONST) + if (ct & TCG_CT_CONST) { return 1; - else if ((ct & TCG_CT_CONST_ZERO) && val == 0) + } else if ((ct & TCG_CT_CONST_ZERO) && val == 0) { return 1; - else if ((ct & TCG_CT_CONST_U16) && val == (uint16_t)val) + } else if ((ct & TCG_CT_CONST_U16) && val == (uint16_t)val) { return 1; - else if ((ct & TCG_CT_CONST_S16) && val == (int16_t)val) + } else if ((ct & TCG_CT_CONST_S16) && val == (int16_t)val) { return 1; - else - return 0; + } else if ((ct & TCG_CT_CONST_P2M1) + && use_mips32r2_instructions && is_p2m1(val)) { + return 1; + } + return 0; } /* instruction opcodes */ @@ -293,6 +309,7 @@ enum { OPC_MUL = OPC_SPECIAL2 | 0x002, OPC_SPECIAL3 = 0x1f << 26, + OPC_EXT = OPC_SPECIAL3 | 0x000, OPC_INS = OPC_SPECIAL3 | 0x004, OPC_WSBH = OPC_SPECIAL3 | 0x0a0, OPC_SEB = OPC_SPECIAL3 | 0x420, @@ -330,6 +347,22 @@ static inline void tcg_out_opc_imm(TCGContext *s, int opc, } /* + * Type bitfield + */ +static inline void tcg_out_opc_bf(TCGContext *s, int opc, TCGReg rt, + TCGReg rs, int msb, int lsb) +{ + int32_t inst; + + inst = opc; + inst |= (rs & 0x1F) << 21; + inst |= (rt & 0x1F) << 16; + inst |= (msb & 0x1F) << 11; + inst |= (lsb & 0x1F) << 6; + tcg_out32(s, inst); +} + +/* * Type branch */ static inline void tcg_out_opc_br(TCGContext *s, int opc, @@ -1455,7 +1488,14 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc, case INDEX_op_and_i32: if (const_args[2]) { - tcg_out_opc_imm(s, OPC_ANDI, args[0], args[1], args[2]); + if (args[2] == (uint16_t)args[2]) { + tcg_out_opc_imm(s, OPC_ANDI, args[0], args[1], args[2]); + } else { + int msb = ctz32(~args[2]) - 1; + assert(use_mips32r2_instructions); + assert(is_p2m1(args[2])); + tcg_out_opc_bf(s, OPC_EXT, args[0], args[1], msb, 0); + } } else { tcg_out_opc_reg(s, OPC_AND, args[0], args[1], args[2]); } @@ -1535,8 +1575,8 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc, break; case INDEX_op_deposit_i32: - tcg_out_opc_imm(s, OPC_INS, args[0], args[2], - ((args[3] + args[4] - 1) << 11) | (args[3] << 6)); + tcg_out_opc_bf(s, OPC_INS, args[0], args[2], + args[3] + args[4] - 1, args[3]); break; case INDEX_op_brcond_i32: @@ -1604,7 +1644,7 @@ static const TCGTargetOpDef mips_op_defs[] = { { INDEX_op_remu_i32, { "r", "rZ", "rZ" } }, { INDEX_op_sub_i32, { "r", "rZ", "rJ" } }, - { INDEX_op_and_i32, { "r", "rZ", "rI" } }, + { INDEX_op_and_i32, { "r", "rZ", "rIK" } }, { INDEX_op_nor_i32, { "r", "rZ", "rZ" } }, { INDEX_op_not_i32, { "r", "rZ" } }, { INDEX_op_or_i32, { "r", "rZ", "rIZ" } }, diff --git a/tcg/mips/tcg-target.h b/tcg/mips/tcg-target.h index c959d1c..b5face8 100644 --- a/tcg/mips/tcg-target.h +++ b/tcg/mips/tcg-target.h @@ -67,10 +67,6 @@ typedef enum { TCG_AREG0 = TCG_REG_S0, } TCGReg; -#define TCG_CT_CONST_ZERO 0x100 -#define TCG_CT_CONST_U16 0x200 -#define TCG_CT_CONST_S16 0x400 - /* used for function call generation */ #define TCG_TARGET_STACK_ALIGN 8 #define TCG_TARGET_CALL_STACK_OFFSET 16