render / rpms / qemu

Forked from rpms/qemu 9 months ago
Clone

Blame 0023-tcg-optimize-add-constant-folding-for-setcond.patch

5544c1
From 1bbb9ac3e775b55d0d5c57c209f47e742a9be810 Mon Sep 17 00:00:00 2001
5544c1
From: Aurelien Jarno <aurelien@aurel32.net>
5544c1
Date: Thu, 6 Sep 2012 16:47:14 +0200
5544c1
Subject: [PATCH] tcg/optimize: add constant folding for setcond
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/optimize.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5544c1
 1 file changed, 81 insertions(+)
5544c1
5544c1
diff --git a/tcg/optimize.c b/tcg/optimize.c
5544c1
index 7debc8a..1cb1f36 100644
5544c1
--- a/tcg/optimize.c
5544c1
+++ b/tcg/optimize.c
5544c1
@@ -267,6 +267,67 @@ static TCGArg do_constant_folding(TCGOpcode op, TCGArg x, TCGArg y)
5544c1
     return res;
5544c1
 }
5544c1
 
5544c1
+static TCGArg do_constant_folding_cond(TCGOpcode op, TCGArg x,
5544c1
+                                       TCGArg y, TCGCond c)
5544c1
+{
5544c1
+    switch (op_bits(op)) {
5544c1
+    case 32:
5544c1
+        switch (c) {
5544c1
+        case TCG_COND_EQ:
5544c1
+            return (uint32_t)x == (uint32_t)y;
5544c1
+        case TCG_COND_NE:
5544c1
+            return (uint32_t)x != (uint32_t)y;
5544c1
+        case TCG_COND_LT:
5544c1
+            return (int32_t)x < (int32_t)y;
5544c1
+        case TCG_COND_GE:
5544c1
+            return (int32_t)x >= (int32_t)y;
5544c1
+        case TCG_COND_LE:
5544c1
+            return (int32_t)x <= (int32_t)y;
5544c1
+        case TCG_COND_GT:
5544c1
+            return (int32_t)x > (int32_t)y;
5544c1
+        case TCG_COND_LTU:
5544c1
+            return (uint32_t)x < (uint32_t)y;
5544c1
+        case TCG_COND_GEU:
5544c1
+            return (uint32_t)x >= (uint32_t)y;
5544c1
+        case TCG_COND_LEU:
5544c1
+            return (uint32_t)x <= (uint32_t)y;
5544c1
+        case TCG_COND_GTU:
5544c1
+            return (uint32_t)x > (uint32_t)y;
5544c1
+        }
5544c1
+        break;
5544c1
+    case 64:
5544c1
+        switch (c) {
5544c1
+        case TCG_COND_EQ:
5544c1
+            return (uint64_t)x == (uint64_t)y;
5544c1
+        case TCG_COND_NE:
5544c1
+            return (uint64_t)x != (uint64_t)y;
5544c1
+        case TCG_COND_LT:
5544c1
+            return (int64_t)x < (int64_t)y;
5544c1
+        case TCG_COND_GE:
5544c1
+            return (int64_t)x >= (int64_t)y;
5544c1
+        case TCG_COND_LE:
5544c1
+            return (int64_t)x <= (int64_t)y;
5544c1
+        case TCG_COND_GT:
5544c1
+            return (int64_t)x > (int64_t)y;
5544c1
+        case TCG_COND_LTU:
5544c1
+            return (uint64_t)x < (uint64_t)y;
5544c1
+        case TCG_COND_GEU:
5544c1
+            return (uint64_t)x >= (uint64_t)y;
5544c1
+        case TCG_COND_LEU:
5544c1
+            return (uint64_t)x <= (uint64_t)y;
5544c1
+        case TCG_COND_GTU:
5544c1
+            return (uint64_t)x > (uint64_t)y;
5544c1
+        }
5544c1
+        break;
5544c1
+    }
5544c1
+
5544c1
+    fprintf(stderr,
5544c1
+            "Unrecognized bitness %d or condition %d in "
5544c1
+            "do_constant_folding_cond.\n", op_bits(op), c);
5544c1
+    tcg_abort();
5544c1
+}
5544c1
+
5544c1
+
5544c1
 /* Propagate constants and copies, fold constant expressions. */
5544c1
 static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr,
5544c1
                                     TCGArg *args, TCGOpDef *tcg_op_defs)
5544c1
@@ -522,6 +583,26 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr,
5544c1
                 args += 3;
5544c1
                 break;
5544c1
             }
5544c1
+        CASE_OP_32_64(setcond):
5544c1
+            if (temps[args[1]].state == TCG_TEMP_CONST
5544c1
+                && temps[args[2]].state == TCG_TEMP_CONST) {
5544c1
+                gen_opc_buf[op_index] = op_to_movi(op);
5544c1
+                tmp = do_constant_folding_cond(op, temps[args[1]].val,
5544c1
+                                               temps[args[2]].val, args[3]);
5544c1
+                tcg_opt_gen_movi(gen_args, args[0], tmp, nb_temps, nb_globals);
5544c1
+                gen_args += 2;
5544c1
+                args += 4;
5544c1
+                break;
5544c1
+            } else {
5544c1
+                reset_temp(args[0], nb_temps, nb_globals);
5544c1
+                gen_args[0] = args[0];
5544c1
+                gen_args[1] = args[1];
5544c1
+                gen_args[2] = args[2];
5544c1
+                gen_args[3] = args[3];
5544c1
+                gen_args += 4;
5544c1
+                args += 4;
5544c1
+                break;
5544c1
+            }
5544c1
         case INDEX_op_call:
5544c1
             nb_call_args = (args[0] >> 16) + (args[0] & 0xffff);
5544c1
             if (!(args[nb_call_args + 1] & (TCG_CALL_CONST | TCG_CALL_PURE))) {
5544c1
-- 
5544c1
1.7.12.1
5544c1