Blame 0063-tcg-mips-optimize-brcond-arg-0.patch

5544c1
From e30cf829e9d8200364b53b9189c76d2155a32876 Mon Sep 17 00:00:00 2001
5544c1
From: Aurelien Jarno <aurelien@aurel32.net>
5544c1
Date: Fri, 21 Sep 2012 18:20:26 +0200
5544c1
Subject: [PATCH] tcg/mips: optimize brcond arg, 0
5544c1
5544c1
MIPS has some conditional branch instructions when comparing with zero.
5544c1
Use them.
5544c1
5544c1
Reviewed-by: Richard Henderson <rth@twiddle.net>
5544c1
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
5544c1
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
5544c1
---
5544c1
 tcg/mips/tcg-target.c | 38 ++++++++++++++++++++++++++++++--------
5544c1
 1 file changed, 30 insertions(+), 8 deletions(-)
5544c1
5544c1
diff --git a/tcg/mips/tcg-target.c b/tcg/mips/tcg-target.c
5544c1
index c05169f..6aa4527 100644
5544c1
--- a/tcg/mips/tcg-target.c
5544c1
+++ b/tcg/mips/tcg-target.c
5544c1
@@ -278,6 +278,8 @@ static inline int tcg_target_const_match(tcg_target_long val,
5544c1
 enum {
5544c1
     OPC_BEQ      = 0x04 << 26,
5544c1
     OPC_BNE      = 0x05 << 26,
5544c1
+    OPC_BLEZ     = 0x06 << 26,
5544c1
+    OPC_BGTZ     = 0x07 << 26,
5544c1
     OPC_ADDIU    = 0x09 << 26,
5544c1
     OPC_SLTI     = 0x0A << 26,
5544c1
     OPC_SLTIU    = 0x0B << 26,
5544c1
@@ -319,6 +321,10 @@ enum {
5544c1
     OPC_SLT      = OPC_SPECIAL | 0x2A,
5544c1
     OPC_SLTU     = OPC_SPECIAL | 0x2B,
5544c1
 
5544c1
+    OPC_REGIMM   = 0x01 << 26,
5544c1
+    OPC_BLTZ     = OPC_REGIMM | (0x00 << 16),
5544c1
+    OPC_BGEZ     = OPC_REGIMM | (0x01 << 16),
5544c1
+
5544c1
     OPC_SPECIAL3 = 0x1f << 26,
5544c1
     OPC_SEB      = OPC_SPECIAL3 | 0x420,
5544c1
     OPC_SEH      = OPC_SPECIAL3 | 0x620,
5544c1
@@ -590,32 +596,48 @@ static void tcg_out_brcond(TCGContext *s, TCGCond cond, TCGArg arg1,
5544c1
         tcg_out_opc_br(s, OPC_BNE, arg1, arg2);
5544c1
         break;
5544c1
     case TCG_COND_LT:
5544c1
-        tcg_out_opc_reg(s, OPC_SLT, TCG_REG_AT, arg1, arg2);
5544c1
-        tcg_out_opc_br(s, OPC_BNE, TCG_REG_AT, TCG_REG_ZERO);
5544c1
+        if (arg2 == 0) {
5544c1
+            tcg_out_opc_br(s, OPC_BLTZ, 0, arg1);
5544c1
+        } else {
5544c1
+            tcg_out_opc_reg(s, OPC_SLT, TCG_REG_AT, arg1, arg2);
5544c1
+            tcg_out_opc_br(s, OPC_BNE, TCG_REG_AT, TCG_REG_ZERO);
5544c1
+        }
5544c1
         break;
5544c1
     case TCG_COND_LTU:
5544c1
         tcg_out_opc_reg(s, OPC_SLTU, TCG_REG_AT, arg1, arg2);
5544c1
         tcg_out_opc_br(s, OPC_BNE, TCG_REG_AT, TCG_REG_ZERO);
5544c1
         break;
5544c1
     case TCG_COND_GE:
5544c1
-        tcg_out_opc_reg(s, OPC_SLT, TCG_REG_AT, arg1, arg2);
5544c1
-        tcg_out_opc_br(s, OPC_BEQ, TCG_REG_AT, TCG_REG_ZERO);
5544c1
+        if (arg2 == 0) {
5544c1
+            tcg_out_opc_br(s, OPC_BGEZ, 0, arg1);
5544c1
+        } else {
5544c1
+            tcg_out_opc_reg(s, OPC_SLT, TCG_REG_AT, arg1, arg2);
5544c1
+            tcg_out_opc_br(s, OPC_BEQ, TCG_REG_AT, TCG_REG_ZERO);
5544c1
+        }
5544c1
         break;
5544c1
     case TCG_COND_GEU:
5544c1
         tcg_out_opc_reg(s, OPC_SLTU, TCG_REG_AT, arg1, arg2);
5544c1
         tcg_out_opc_br(s, OPC_BEQ, TCG_REG_AT, TCG_REG_ZERO);
5544c1
         break;
5544c1
     case TCG_COND_LE:
5544c1
-        tcg_out_opc_reg(s, OPC_SLT, TCG_REG_AT, arg2, arg1);
5544c1
-        tcg_out_opc_br(s, OPC_BEQ, TCG_REG_AT, TCG_REG_ZERO);
5544c1
+        if (arg2 == 0) {
5544c1
+            tcg_out_opc_br(s, OPC_BLEZ, 0, arg1);
5544c1
+        } else {
5544c1
+            tcg_out_opc_reg(s, OPC_SLT, TCG_REG_AT, arg2, arg1);
5544c1
+            tcg_out_opc_br(s, OPC_BEQ, TCG_REG_AT, TCG_REG_ZERO);
5544c1
+        }
5544c1
         break;
5544c1
     case TCG_COND_LEU:
5544c1
         tcg_out_opc_reg(s, OPC_SLTU, TCG_REG_AT, arg2, arg1);
5544c1
         tcg_out_opc_br(s, OPC_BEQ, TCG_REG_AT, TCG_REG_ZERO);
5544c1
         break;
5544c1
     case TCG_COND_GT:
5544c1
-        tcg_out_opc_reg(s, OPC_SLT, TCG_REG_AT, arg2, arg1);
5544c1
-        tcg_out_opc_br(s, OPC_BNE, TCG_REG_AT, TCG_REG_ZERO);
5544c1
+        if (arg2 == 0) {
5544c1
+            tcg_out_opc_br(s, OPC_BGTZ, 0, arg1);
5544c1
+        } else {
5544c1
+            tcg_out_opc_reg(s, OPC_SLT, TCG_REG_AT, arg2, arg1);
5544c1
+            tcg_out_opc_br(s, OPC_BNE, TCG_REG_AT, TCG_REG_ZERO);
5544c1
+        }
5544c1
         break;
5544c1
     case TCG_COND_GTU:
5544c1
         tcg_out_opc_reg(s, OPC_SLTU, TCG_REG_AT, arg2, arg1);
5544c1
-- 
5544c1
1.7.12.1
5544c1