peterdelevoryas / rpms / qemu

Forked from rpms/qemu 2 years ago
Clone

Blame 0051-tcg-i386-Implement-movcond.patch

5544c1
From 7a6273e2995b6c439441316467ab19bd6a48f03f Mon Sep 17 00:00:00 2001
5544c1
From: Richard Henderson <rth@twiddle.net>
5544c1
Date: Fri, 21 Sep 2012 10:13:36 -0700
5544c1
Subject: [PATCH] tcg-i386: Implement movcond
5544c1
5544c1
Signed-off-by: Richard Henderson <rth@twiddle.net>
5544c1
Reviewed-by: Aurelien Jarno <aurelien@aurel32.net>
5544c1
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
5544c1
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
5544c1
---
5544c1
 tcg/i386/tcg-target.c | 29 +++++++++++++++++++++++++++++
5544c1
 tcg/i386/tcg-target.h |  7 ++++++-
5544c1
 2 files changed, 35 insertions(+), 1 deletion(-)
5544c1
5544c1
diff --git a/tcg/i386/tcg-target.c b/tcg/i386/tcg-target.c
5544c1
index 3017858..aa1fa9f 100644
5544c1
--- a/tcg/i386/tcg-target.c
5544c1
+++ b/tcg/i386/tcg-target.c
5544c1
@@ -249,6 +249,7 @@ static inline int tcg_target_const_match(tcg_target_long val,
5544c1
 #define OPC_ADD_GvEv	(OPC_ARITH_GvEv | (ARITH_ADD << 3))
5544c1
 #define OPC_BSWAP	(0xc8 | P_EXT)
5544c1
 #define OPC_CALL_Jz	(0xe8)
5544c1
+#define OPC_CMOVCC      (0x40 | P_EXT)  /* ... plus condition code */
5544c1
 #define OPC_CMP_GvEv	(OPC_ARITH_GvEv | (ARITH_CMP << 3))
5544c1
 #define OPC_DEC_r32	(0x48)
5544c1
 #define OPC_IMUL_GvEv	(0xaf | P_EXT)
5544c1
@@ -936,6 +937,24 @@ static void tcg_out_setcond2(TCGContext *s, const TCGArg *args,
5544c1
 }
5544c1
 #endif
5544c1
 
5544c1
+static void tcg_out_movcond32(TCGContext *s, TCGCond cond, TCGArg dest,
5544c1
+                              TCGArg c1, TCGArg c2, int const_c2,
5544c1
+                              TCGArg v1)
5544c1
+{
5544c1
+    tcg_out_cmp(s, c1, c2, const_c2, 0);
5544c1
+    tcg_out_modrm(s, OPC_CMOVCC | tcg_cond_to_jcc[cond], dest, v1);
5544c1
+}
5544c1
+
5544c1
+#if TCG_TARGET_REG_BITS == 64
5544c1
+static void tcg_out_movcond64(TCGContext *s, TCGCond cond, TCGArg dest,
5544c1
+                              TCGArg c1, TCGArg c2, int const_c2,
5544c1
+                              TCGArg v1)
5544c1
+{
5544c1
+    tcg_out_cmp(s, c1, c2, const_c2, P_REXW);
5544c1
+    tcg_out_modrm(s, OPC_CMOVCC | tcg_cond_to_jcc[cond] | P_REXW, dest, v1);
5544c1
+}
5544c1
+#endif
5544c1
+
5544c1
 static void tcg_out_branch(TCGContext *s, int call, tcg_target_long dest)
5544c1
 {
5544c1
     tcg_target_long disp = dest - (tcg_target_long)s->code_ptr - 5;
5544c1
@@ -1668,6 +1687,10 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc,
5544c1
         tcg_out_setcond32(s, args[3], args[0], args[1],
5544c1
                           args[2], const_args[2]);
5544c1
         break;
5544c1
+    case INDEX_op_movcond_i32:
5544c1
+        tcg_out_movcond32(s, args[5], args[0], args[1],
5544c1
+                          args[2], const_args[2], args[3]);
5544c1
+        break;
5544c1
 
5544c1
     OP_32_64(bswap16):
5544c1
         tcg_out_rolw_8(s, args[0]);
5544c1
@@ -1796,6 +1819,10 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc,
5544c1
         tcg_out_setcond64(s, args[3], args[0], args[1],
5544c1
                           args[2], const_args[2]);
5544c1
         break;
5544c1
+    case INDEX_op_movcond_i64:
5544c1
+        tcg_out_movcond64(s, args[5], args[0], args[1],
5544c1
+                          args[2], const_args[2], args[3]);
5544c1
+        break;
5544c1
 
5544c1
     case INDEX_op_bswap64_i64:
5544c1
         tcg_out_bswap64(s, args[0]);
5544c1
@@ -1880,6 +1907,7 @@ static const TCGTargetOpDef x86_op_defs[] = {
5544c1
     { INDEX_op_setcond_i32, { "q", "r", "ri" } },
5544c1
 
5544c1
     { INDEX_op_deposit_i32, { "Q", "0", "Q" } },
5544c1
+    { INDEX_op_movcond_i32, { "r", "r", "ri", "r", "0" } },
5544c1
 
5544c1
 #if TCG_TARGET_REG_BITS == 32
5544c1
     { INDEX_op_mulu2_i32, { "a", "d", "a", "r" } },
5544c1
@@ -1934,6 +1962,7 @@ static const TCGTargetOpDef x86_op_defs[] = {
5544c1
     { INDEX_op_ext32u_i64, { "r", "r" } },
5544c1
 
5544c1
     { INDEX_op_deposit_i64, { "Q", "0", "Q" } },
5544c1
+    { INDEX_op_movcond_i64, { "r", "r", "re", "r", "0" } },
5544c1
 #endif
5544c1
 
5544c1
 #if TCG_TARGET_REG_BITS == 64
5544c1
diff --git a/tcg/i386/tcg-target.h b/tcg/i386/tcg-target.h
5544c1
index 504f953..b356d76 100644
5544c1
--- a/tcg/i386/tcg-target.h
5544c1
+++ b/tcg/i386/tcg-target.h
5544c1
@@ -86,7 +86,12 @@ typedef enum {
5544c1
 #define TCG_TARGET_HAS_nand_i32         0
5544c1
 #define TCG_TARGET_HAS_nor_i32          0
5544c1
 #define TCG_TARGET_HAS_deposit_i32      1
5544c1
+#if defined(__x86_64__) || defined(__i686__)
5544c1
+/* Use cmov only if the compiler is already doing so.  */
5544c1
+#define TCG_TARGET_HAS_movcond_i32      1
5544c1
+#else
5544c1
 #define TCG_TARGET_HAS_movcond_i32      0
5544c1
+#endif
5544c1
 
5544c1
 #if TCG_TARGET_REG_BITS == 64
5544c1
 #define TCG_TARGET_HAS_div2_i64         1
5544c1
@@ -108,7 +113,7 @@ typedef enum {
5544c1
 #define TCG_TARGET_HAS_nand_i64         0
5544c1
 #define TCG_TARGET_HAS_nor_i64          0
5544c1
 #define TCG_TARGET_HAS_deposit_i64      1
5544c1
-#define TCG_TARGET_HAS_movcond_i64      0
5544c1
+#define TCG_TARGET_HAS_movcond_i64      1
5544c1
 #endif
5544c1
 
5544c1
 #define TCG_TARGET_deposit_i32_valid(ofs, len) \
5544c1
-- 
5544c1
1.7.12.1
5544c1