dcavalca / rpms / qemu

Forked from rpms/qemu 11 months ago
Clone

Blame 0056-tcg-hppa-Fix-brcond2-and-setcond2.patch

5544c1
From 3616400bc0065f7114172ad7801d9d88332ef981 Mon Sep 17 00:00:00 2001
5544c1
From: Richard Henderson <rth@twiddle.net>
5544c1
Date: Tue, 18 Sep 2012 19:59:47 -0700
5544c1
Subject: [PATCH] tcg-hppa: Fix brcond2 and setcond2
5544c1
5544c1
Neither of these functions were performing double-word
5544c1
compares properly.
5544c1
5544c1
Signed-off-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/hppa/tcg-target.c | 51 ++++++++++++++++++++++++++++++++++++++++++---------
5544c1
 1 file changed, 42 insertions(+), 9 deletions(-)
5544c1
5544c1
diff --git a/tcg/hppa/tcg-target.c b/tcg/hppa/tcg-target.c
5544c1
index 8b81b70..a76569d 100644
5544c1
--- a/tcg/hppa/tcg-target.c
5544c1
+++ b/tcg/hppa/tcg-target.c
5544c1
@@ -820,19 +820,34 @@ static void tcg_out_comclr(TCGContext *s, int cond, TCGArg ret,
5544c1
     tcg_out32(s, op);
5544c1
 }
5544c1
 
5544c1
+static TCGCond const tcg_high_cond[] = {
5544c1
+    [TCG_COND_EQ] = TCG_COND_EQ,
5544c1
+    [TCG_COND_NE] = TCG_COND_NE,
5544c1
+    [TCG_COND_LT] = TCG_COND_LT,
5544c1
+    [TCG_COND_LE] = TCG_COND_LT,
5544c1
+    [TCG_COND_GT] = TCG_COND_GT,
5544c1
+    [TCG_COND_GE] = TCG_COND_GT,
5544c1
+    [TCG_COND_LTU] = TCG_COND_LTU,
5544c1
+    [TCG_COND_LEU] = TCG_COND_LTU,
5544c1
+    [TCG_COND_GTU] = TCG_COND_GTU,
5544c1
+    [TCG_COND_GEU] = TCG_COND_GTU
5544c1
+};
5544c1
+
5544c1
 static void tcg_out_brcond2(TCGContext *s, int cond, TCGArg al, TCGArg ah,
5544c1
                             TCGArg bl, int blconst, TCGArg bh, int bhconst,
5544c1
                             int label_index)
5544c1
 {
5544c1
     switch (cond) {
5544c1
     case TCG_COND_EQ:
5544c1
+        tcg_out_comclr(s, TCG_COND_NE, TCG_REG_R0, al, bl, blconst);
5544c1
+        tcg_out_brcond(s, TCG_COND_EQ, ah, bh, bhconst, label_index);
5544c1
+        break;
5544c1
     case TCG_COND_NE:
5544c1
-        tcg_out_comclr(s, tcg_invert_cond(cond), TCG_REG_R0, al, bl, blconst);
5544c1
-        tcg_out_brcond(s, cond, ah, bh, bhconst, label_index);
5544c1
+        tcg_out_brcond(s, TCG_COND_NE, al, bl, bhconst, label_index);
5544c1
+        tcg_out_brcond(s, TCG_COND_NE, ah, bh, bhconst, label_index);
5544c1
         break;
5544c1
-
5544c1
     default:
5544c1
-        tcg_out_brcond(s, cond, ah, bh, bhconst, label_index);
5544c1
+        tcg_out_brcond(s, tcg_high_cond[cond], ah, bh, bhconst, label_index);
5544c1
         tcg_out_comclr(s, TCG_COND_NE, TCG_REG_R0, ah, bh, bhconst);
5544c1
         tcg_out_brcond(s, tcg_unsigned_cond(cond),
5544c1
                        al, bl, blconst, label_index);
5544c1
@@ -853,9 +868,8 @@ static void tcg_out_setcond2(TCGContext *s, int cond, TCGArg ret,
5544c1
 {
5544c1
     int scratch = TCG_REG_R20;
5544c1
 
5544c1
-    if (ret != al && ret != ah
5544c1
-        && (blconst || ret != bl)
5544c1
-        && (bhconst || ret != bh)) {
5544c1
+    /* Note that the low parts are fully consumed before scratch is set.  */
5544c1
+    if (ret != ah && (bhconst || ret != bh)) {
5544c1
         scratch = ret;
5544c1
     }
5544c1
 
5544c1
@@ -867,13 +881,32 @@ static void tcg_out_setcond2(TCGContext *s, int cond, TCGArg ret,
5544c1
         tcg_out_movi(s, TCG_TYPE_I32, scratch, cond == TCG_COND_NE);
5544c1
         break;
5544c1
 
5544c1
-    default:
5544c1
+    case TCG_COND_GE:
5544c1
+    case TCG_COND_GEU:
5544c1
+    case TCG_COND_LT:
5544c1
+    case TCG_COND_LTU:
5544c1
+        /* Optimize compares with low part zero.  */
5544c1
+        if (bl == 0) {
5544c1
+            tcg_out_setcond(s, cond, ret, ah, bh, bhconst);
5544c1
+            return;
5544c1
+        }
5544c1
+        /* FALLTHRU */
5544c1
+
5544c1
+    case TCG_COND_LE:
5544c1
+    case TCG_COND_LEU:
5544c1
+    case TCG_COND_GT:
5544c1
+    case TCG_COND_GTU:
5544c1
+        /* <= : ah < bh | (ah == bh && al <= bl) */
5544c1
         tcg_out_setcond(s, tcg_unsigned_cond(cond), scratch, al, bl, blconst);
5544c1
         tcg_out_comclr(s, TCG_COND_EQ, TCG_REG_R0, ah, bh, bhconst);
5544c1
         tcg_out_movi(s, TCG_TYPE_I32, scratch, 0);
5544c1
-        tcg_out_comclr(s, cond, TCG_REG_R0, ah, bh, bhconst);
5544c1
+        tcg_out_comclr(s, tcg_invert_cond(tcg_high_cond[cond]),
5544c1
+                       TCG_REG_R0, ah, bh, bhconst);
5544c1
         tcg_out_movi(s, TCG_TYPE_I32, scratch, 1);
5544c1
         break;
5544c1
+
5544c1
+    default:
5544c1
+        tcg_abort();
5544c1
     }
5544c1
 
5544c1
     tcg_out_mov(s, TCG_TYPE_I32, ret, scratch);
5544c1
-- 
5544c1
1.7.12.1
5544c1