Blame 0067-tcg-mips-implement-movcond-op-on-MIPS32R2.patch

5544c1
From 552720cea4c1ca99dd1919cb8a80b6b8f3b13cda 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: implement movcond op on MIPS32R2
5544c1
5544c1
movcond operation can be implemented on MIPS32 Release 2 using the MOVN,
5544c1
MOVZ, SLT and SLTU instructions.
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 | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++
5544c1
 tcg/mips/tcg-target.h |  8 ++++++
5544c1
 2 files changed, 77 insertions(+)
5544c1
5544c1
diff --git a/tcg/mips/tcg-target.c b/tcg/mips/tcg-target.c
5544c1
index b2e1056..c272b38 100644
5544c1
--- a/tcg/mips/tcg-target.c
5544c1
+++ b/tcg/mips/tcg-target.c
5544c1
@@ -308,6 +308,8 @@ enum {
5544c1
     OPC_SRAV     = OPC_SPECIAL | 0x07,
5544c1
     OPC_JR       = OPC_SPECIAL | 0x08,
5544c1
     OPC_JALR     = OPC_SPECIAL | 0x09,
5544c1
+    OPC_MOVZ     = OPC_SPECIAL | 0x0A,
5544c1
+    OPC_MOVN     = OPC_SPECIAL | 0x0B,
5544c1
     OPC_MFHI     = OPC_SPECIAL | 0x10,
5544c1
     OPC_MFLO     = OPC_SPECIAL | 0x12,
5544c1
     OPC_MULT     = OPC_SPECIAL | 0x18,
5544c1
@@ -735,6 +737,68 @@ static void tcg_out_brcond2(TCGContext *s, TCGCond cond, TCGArg arg1,
5544c1
     reloc_pc16(label_ptr, (tcg_target_long) s->code_ptr);
5544c1
 }
5544c1
 
5544c1
+static void tcg_out_movcond(TCGContext *s, TCGCond cond, TCGReg ret,
5544c1
+                            TCGArg c1, TCGArg c2, TCGArg v)
5544c1
+{
5544c1
+    switch (cond) {
5544c1
+    case TCG_COND_EQ:
5544c1
+        if (c1 == 0) {
5544c1
+            tcg_out_opc_reg(s, OPC_MOVZ, ret, v, c2);
5544c1
+        } else if (c2 == 0) {
5544c1
+            tcg_out_opc_reg(s, OPC_MOVZ, ret, v, c1);
5544c1
+        } else {
5544c1
+            tcg_out_opc_reg(s, OPC_XOR, TCG_REG_AT, c1, c2);
5544c1
+            tcg_out_opc_reg(s, OPC_MOVZ, ret, v, TCG_REG_AT);
5544c1
+        }
5544c1
+        break;
5544c1
+    case TCG_COND_NE:
5544c1
+        if (c1 == 0) {
5544c1
+            tcg_out_opc_reg(s, OPC_MOVN, ret, v, c2);
5544c1
+        } else if (c2 == 0) {
5544c1
+            tcg_out_opc_reg(s, OPC_MOVN, ret, v, c1);
5544c1
+        } else {
5544c1
+            tcg_out_opc_reg(s, OPC_XOR, TCG_REG_AT, c1, c2);
5544c1
+            tcg_out_opc_reg(s, OPC_MOVN, ret, v, TCG_REG_AT);
5544c1
+        }
5544c1
+        break;
5544c1
+    case TCG_COND_LT:
5544c1
+        tcg_out_opc_reg(s, OPC_SLT, TCG_REG_AT, c1, c2);
5544c1
+        tcg_out_opc_reg(s, OPC_MOVN, ret, v, TCG_REG_AT);
5544c1
+        break;
5544c1
+    case TCG_COND_LTU:
5544c1
+        tcg_out_opc_reg(s, OPC_SLTU, TCG_REG_AT, c1, c2);
5544c1
+        tcg_out_opc_reg(s, OPC_MOVN, ret, v, TCG_REG_AT);
5544c1
+        break;
5544c1
+    case TCG_COND_GE:
5544c1
+        tcg_out_opc_reg(s, OPC_SLT, TCG_REG_AT, c1, c2);
5544c1
+        tcg_out_opc_reg(s, OPC_MOVZ, ret, v, TCG_REG_AT);
5544c1
+        break;
5544c1
+    case TCG_COND_GEU:
5544c1
+        tcg_out_opc_reg(s, OPC_SLTU, TCG_REG_AT, c1, c2);
5544c1
+        tcg_out_opc_reg(s, OPC_MOVZ, ret, v, TCG_REG_AT);
5544c1
+        break;
5544c1
+    case TCG_COND_LE:
5544c1
+        tcg_out_opc_reg(s, OPC_SLT, TCG_REG_AT, c2, c1);
5544c1
+        tcg_out_opc_reg(s, OPC_MOVZ, ret, v, TCG_REG_AT);
5544c1
+        break;
5544c1
+    case TCG_COND_LEU:
5544c1
+        tcg_out_opc_reg(s, OPC_SLTU, TCG_REG_AT, c2, c1);
5544c1
+        tcg_out_opc_reg(s, OPC_MOVZ, ret, v, TCG_REG_AT);
5544c1
+        break;
5544c1
+    case TCG_COND_GT:
5544c1
+        tcg_out_opc_reg(s, OPC_SLT, TCG_REG_AT, c2, c1);
5544c1
+        tcg_out_opc_reg(s, OPC_MOVN, ret, v, TCG_REG_AT);
5544c1
+        break;
5544c1
+    case TCG_COND_GTU:
5544c1
+        tcg_out_opc_reg(s, OPC_SLTU, TCG_REG_AT, c2, c1);
5544c1
+        tcg_out_opc_reg(s, OPC_MOVN, ret, v, TCG_REG_AT);
5544c1
+        break;
5544c1
+    default:
5544c1
+        tcg_abort();
5544c1
+        break;
5544c1
+    }
5544c1
+}
5544c1
+
5544c1
 static void tcg_out_setcond(TCGContext *s, TCGCond cond, TCGReg ret,
5544c1
                             TCGArg arg1, TCGArg arg2)
5544c1
 {
5544c1
@@ -1468,6 +1532,10 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc,
5544c1
         tcg_out_brcond2(s, args[4], args[0], args[1], args[2], args[3], args[5]);
5544c1
         break;
5544c1
 
5544c1
+    case INDEX_op_movcond_i32:
5544c1
+        tcg_out_movcond(s, args[5], args[0], args[1], args[2], args[3]);
5544c1
+        break;
5544c1
+
5544c1
     case INDEX_op_setcond_i32:
5544c1
         tcg_out_setcond(s, args[3], args[0], args[1], args[2]);
5544c1
         break;
5544c1
@@ -1559,6 +1627,7 @@ static const TCGTargetOpDef mips_op_defs[] = {
5544c1
     { INDEX_op_deposit_i32, { "r", "0", "rZ" } },
5544c1
 
5544c1
     { INDEX_op_brcond_i32, { "rZ", "rZ" } },
5544c1
+    { INDEX_op_movcond_i32, { "r", "rZ", "rZ", "rZ", "0" } },
5544c1
     { INDEX_op_setcond_i32, { "r", "rZ", "rZ" } },
5544c1
     { INDEX_op_setcond2_i32, { "r", "rZ", "rZ", "rZ", "rZ" } },
5544c1
 
5544c1
diff --git a/tcg/mips/tcg-target.h b/tcg/mips/tcg-target.h
5544c1
index 897a737..d147e70 100644
5544c1
--- a/tcg/mips/tcg-target.h
5544c1
+++ b/tcg/mips/tcg-target.h
5544c1
@@ -86,7 +86,15 @@ typedef enum {
5544c1
 #define TCG_TARGET_HAS_orc_i32          0
5544c1
 #define TCG_TARGET_HAS_eqv_i32          0
5544c1
 #define TCG_TARGET_HAS_nand_i32         0
5544c1
+
5544c1
+/* optional instructions only implemented on MIPS4, MIPS32 and Loongson 2 */
5544c1
+#if defined(_MIPS_ARCH_MIPS4) || defined(_MIPS_ARCH_MIPS32) || \
5544c1
+    defined(_MIPS_ARCH_MIPS32R2) || defined(_MIPS_ARCH_LOONGSON2E) || \
5544c1
+    defined(_MIPS_ARCH_LOONGSON2F)
5544c1
+#define TCG_TARGET_HAS_movcond_i32      1
5544c1
+#else
5544c1
 #define TCG_TARGET_HAS_movcond_i32      0
5544c1
+#endif
5544c1
 
5544c1
 /* optional instructions only implemented on MIPS32R2 */
5544c1
 #ifdef _MIPS_ARCH_MIPS32R2
5544c1
-- 
5544c1
1.7.12.1
5544c1