From patchwork Sat May 24 15:53:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 352128 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 CAAD41400A8 for ; Sun, 25 May 2014 02:00:05 +1000 (EST) Received: from localhost ([::1]:48431 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WoEMd-0004LX-8p for incoming@patchwork.ozlabs.org; Sat, 24 May 2014 12:00:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46494) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WoEHY-0003f7-30 for qemu-devel@nongnu.org; Sat, 24 May 2014 11:54:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WoEHS-0001Ko-4G for qemu-devel@nongnu.org; Sat, 24 May 2014 11:54:48 -0400 Received: from mail-pa0-x22e.google.com ([2607:f8b0:400e:c03::22e]:44177) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WoEHR-0001Kc-LQ for qemu-devel@nongnu.org; Sat, 24 May 2014 11:54:42 -0400 Received: by mail-pa0-f46.google.com with SMTP id kq14so5479435pab.19 for ; Sat, 24 May 2014 08:54:40 -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=r7BlNAvm8SIfJI4265GuslZ41X6V07FD/PLVEciWWDY=; b=YsA9jBfxtoxvjVwZw7Q9CNNu/Mt/lMnv7rJjPoMjS9uenj+nAm6ZxKy2ccwTdcRi6v 4fLtTrRA5zjMtu3Sh99wcJwMehP5BEH+q3Lyu5BXAsYiuq/nUwevj9coVHyHobmATcU0 LZ+PLjb4M9VSpUjsk86HeHbBnde6+jjcNEvLnRnUEFOKjfrSdGxvdazPVVe3WwwCM2+A PeWgNbDOrbwWblh6Qk+yW/xTnWuWcUyERiNxkWLTXaSuLGODBqhzBedEdZ7xt3seu59E 9mS3MxvzLW35dpwUYaIQvLoRn3NvFZJf0p8ey2iG8bAeZRcHR1ew9M/MlQfwx2RpEH5T KaeQ== X-Received: by 10.68.89.4 with SMTP id bk4mr14658439pbb.153.1400946880357; Sat, 24 May 2014 08:54:40 -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.38 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 May 2014 08:54:39 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 24 May 2014 08:53:56 -0700 Message-Id: <1400946841-21079-20-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:c03::22e Cc: peter.maydell@linaro.org Subject: [Qemu-devel] [PULL 19/24] tcg-mips: Simplify brcond 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 Use the same table to fold comparisons as with setcond. Reviewed-by: Paolo Bonzini Signed-off-by: Richard Henderson --- tcg/mips/tcg-target.c | 87 ++++++++++++++++++++++++--------------------------- 1 file changed, 41 insertions(+), 46 deletions(-) diff --git a/tcg/mips/tcg-target.c b/tcg/mips/tcg-target.c index 278925c..c0a7a04 100644 --- a/tcg/mips/tcg-target.c +++ b/tcg/mips/tcg-target.c @@ -634,70 +634,65 @@ static void tcg_out_setcond(TCGContext *s, TCGCond cond, TCGReg ret, } } -static void tcg_out_brcond(TCGContext *s, TCGCond cond, TCGArg arg1, - TCGArg arg2, int label_index) +static void tcg_out_brcond(TCGContext *s, TCGCond cond, TCGReg arg1, + TCGReg arg2, int label_index) { - TCGLabel *l = &s->labels[label_index]; + static const MIPSInsn b_zero[16] = { + [TCG_COND_LT] = OPC_BLTZ, + [TCG_COND_GT] = OPC_BGTZ, + [TCG_COND_LE] = OPC_BLEZ, + [TCG_COND_GE] = OPC_BGEZ, + }; + + TCGLabel *l; + MIPSInsn s_opc = OPC_SLTU; + MIPSInsn b_opc; + int cmp_map; switch (cond) { case TCG_COND_EQ: - tcg_out_opc_br(s, OPC_BEQ, arg1, arg2); + b_opc = OPC_BEQ; break; case TCG_COND_NE: - tcg_out_opc_br(s, OPC_BNE, arg1, arg2); + b_opc = OPC_BNE; break; + case TCG_COND_LT: - if (arg2 == 0) { - tcg_out_opc_br(s, OPC_BLTZ, 0, arg1); - } else { - tcg_out_opc_reg(s, OPC_SLT, TCG_TMP0, arg1, arg2); - tcg_out_opc_br(s, OPC_BNE, TCG_TMP0, TCG_REG_ZERO); - } - break; - case TCG_COND_LTU: - tcg_out_opc_reg(s, OPC_SLTU, TCG_TMP0, arg1, arg2); - tcg_out_opc_br(s, OPC_BNE, TCG_TMP0, TCG_REG_ZERO); - break; - case TCG_COND_GE: - if (arg2 == 0) { - tcg_out_opc_br(s, OPC_BGEZ, 0, arg1); - } else { - tcg_out_opc_reg(s, OPC_SLT, TCG_TMP0, arg1, arg2); - tcg_out_opc_br(s, OPC_BEQ, TCG_TMP0, TCG_REG_ZERO); - } - break; - case TCG_COND_GEU: - tcg_out_opc_reg(s, OPC_SLTU, TCG_TMP0, arg1, arg2); - tcg_out_opc_br(s, OPC_BEQ, TCG_TMP0, TCG_REG_ZERO); - break; + case TCG_COND_GT: case TCG_COND_LE: + case TCG_COND_GE: if (arg2 == 0) { - tcg_out_opc_br(s, OPC_BLEZ, 0, arg1); - } else { - tcg_out_opc_reg(s, OPC_SLT, TCG_TMP0, arg2, arg1); - tcg_out_opc_br(s, OPC_BEQ, TCG_TMP0, TCG_REG_ZERO); + b_opc = b_zero[cond]; + arg2 = arg1; + arg1 = 0; + break; } - break; + s_opc = OPC_SLT; + /* FALLTHRU */ + + case TCG_COND_LTU: + case TCG_COND_GTU: case TCG_COND_LEU: - tcg_out_opc_reg(s, OPC_SLTU, TCG_TMP0, arg2, arg1); - tcg_out_opc_br(s, OPC_BEQ, TCG_TMP0, TCG_REG_ZERO); - break; - case TCG_COND_GT: - if (arg2 == 0) { - tcg_out_opc_br(s, OPC_BGTZ, 0, arg1); - } else { - tcg_out_opc_reg(s, OPC_SLT, TCG_TMP0, arg2, arg1); - tcg_out_opc_br(s, OPC_BNE, TCG_TMP0, TCG_REG_ZERO); + case TCG_COND_GEU: + cmp_map = mips_cmp_map[cond]; + if (cmp_map & MIPS_CMP_SWAP) { + TCGReg t = arg1; + arg1 = arg2; + arg2 = t; } + tcg_out_opc_reg(s, s_opc, TCG_TMP0, arg1, arg2); + b_opc = (cmp_map & MIPS_CMP_INV ? OPC_BEQ : OPC_BNE); + arg1 = TCG_TMP0; + arg2 = TCG_REG_ZERO; break; - case TCG_COND_GTU: - tcg_out_opc_reg(s, OPC_SLTU, TCG_TMP0, arg2, arg1); - tcg_out_opc_br(s, OPC_BNE, TCG_TMP0, TCG_REG_ZERO); - break; + default: tcg_abort(); break; } + + tcg_out_opc_br(s, b_opc, arg1, arg2); + l = &s->labels[label_index]; if (l->has_value) { reloc_pc16(s->code_ptr - 1, l->u.value_ptr); } else {