cb589a
commit dc1523fb3550b4ed9dd4c178741626daaa474da7
cb589a
Author: Mark Wielaard <mark@klomp.org>
cb589a
Date:   Mon Dec 10 17:18:20 2018 +0100
cb589a
cb589a
    PR386945 set_AV_CR6 patch
cb589a
    
cb589a
    https://bugs.kde.org/show_bug.cgi?id=386945#c62
cb589a
cb589a
diff --git a/VEX/priv/guest_ppc_toIR.c b/VEX/priv/guest_ppc_toIR.c
cb589a
index ec2f90a..c3cc6d0 100644
cb589a
--- a/VEX/priv/guest_ppc_toIR.c
cb589a
+++ b/VEX/priv/guest_ppc_toIR.c
cb589a
@@ -2062,45 +2062,88 @@ static void set_CR0 ( IRExpr* result )
cb589a
 static void set_AV_CR6 ( IRExpr* result, Bool test_all_ones )
cb589a
 {
cb589a
    /* CR6[0:3] = {all_ones, 0, all_zeros, 0}
cb589a
-      all_ones  = (v[0] && v[1] && v[2] && v[3])
cb589a
-      all_zeros = ~(v[0] || v[1] || v[2] || v[3])
cb589a
+      32 bit: all_zeros =  (v[0] || v[1] || v[2] || v[3]) == 0x0000'0000
cb589a
+              all_ones  = ~(v[0] && v[1] && v[2] && v[3]) == 0x0000'0000
cb589a
+              where v[] denotes 32-bit lanes
cb589a
+      or
cb589a
+      64 bit: all_zeros =  (v[0] || v[1]) == 0x0000'0000'0000'0000
cb589a
+              all_ones  = ~(v[0] && v[1]) == 0x0000'0000'0000'0000
cb589a
+              where v[] denotes 64-bit lanes
cb589a
+
cb589a
+      The 32- and 64-bit versions compute the same thing, but the 64-bit one
cb589a
+      tries to be a bit more efficient.
cb589a
    */
cb589a
-   IRTemp v0 = newTemp(Ity_V128);
cb589a
-   IRTemp v1 = newTemp(Ity_V128);
cb589a
-   IRTemp v2 = newTemp(Ity_V128);
cb589a
-   IRTemp v3 = newTemp(Ity_V128);
cb589a
-   IRTemp rOnes  = newTemp(Ity_I8);
cb589a
-   IRTemp rZeros = newTemp(Ity_I8);
cb589a
-
cb589a
    vassert(typeOfIRExpr(irsb->tyenv,result) == Ity_V128);
cb589a
 
cb589a
-   assign( v0, result );
cb589a
-   assign( v1, binop(Iop_ShrV128, result, mkU8(32)) );
cb589a
-   assign( v2, binop(Iop_ShrV128, result, mkU8(64)) );
cb589a
-   assign( v3, binop(Iop_ShrV128, result, mkU8(96)) );
cb589a
+   IRTemp overlappedOred  = newTemp(Ity_V128);
cb589a
+   IRTemp overlappedAnded = newTemp(Ity_V128);
cb589a
+
cb589a
+   if (mode64) {
cb589a
+      IRTemp v0 = newTemp(Ity_V128);
cb589a
+      IRTemp v1 = newTemp(Ity_V128);
cb589a
+      assign( v0, result );
cb589a
+      assign( v1, binop(Iop_ShrV128, result, mkU8(64)) );
cb589a
+      assign(overlappedOred,
cb589a
+             binop(Iop_OrV128, mkexpr(v0), mkexpr(v1)));
cb589a
+      assign(overlappedAnded,
cb589a
+             binop(Iop_AndV128, mkexpr(v0), mkexpr(v1)));
cb589a
+   } else {
cb589a
+      IRTemp v0 = newTemp(Ity_V128);
cb589a
+      IRTemp v1 = newTemp(Ity_V128);
cb589a
+      IRTemp v2 = newTemp(Ity_V128);
cb589a
+      IRTemp v3 = newTemp(Ity_V128);
cb589a
+      assign( v0, result );
cb589a
+      assign( v1, binop(Iop_ShrV128, result, mkU8(32)) );
cb589a
+      assign( v2, binop(Iop_ShrV128, result, mkU8(64)) );
cb589a
+      assign( v3, binop(Iop_ShrV128, result, mkU8(96)) );
cb589a
+      assign(overlappedOred,
cb589a
+             binop(Iop_OrV128,
cb589a
+                   binop(Iop_OrV128, mkexpr(v0), mkexpr(v1)),
cb589a
+                   binop(Iop_OrV128, mkexpr(v2), mkexpr(v3))));
cb589a
+      assign(overlappedAnded,
cb589a
+             binop(Iop_AndV128,
cb589a
+                   binop(Iop_AndV128, mkexpr(v0), mkexpr(v1)),
cb589a
+                   binop(Iop_AndV128, mkexpr(v2), mkexpr(v3))));
cb589a
+   }
cb589a
+
cb589a
+   IRTemp rOnes   = newTemp(Ity_I8);
cb589a
+   IRTemp rZeroes = newTemp(Ity_I8);
cb589a
 
cb589a
-   assign( rZeros, unop(Iop_1Uto8,
cb589a
-       binop(Iop_CmpEQ32, mkU32(0xFFFFFFFF),
cb589a
-             unop(Iop_Not32,
cb589a
-                  unop(Iop_V128to32,
cb589a
-                       binop(Iop_OrV128,
cb589a
-                             binop(Iop_OrV128, mkexpr(v0), mkexpr(v1)),
cb589a
-                             binop(Iop_OrV128, mkexpr(v2), mkexpr(v3))))
cb589a
-                  ))) );
cb589a
+   if (mode64) {
cb589a
+      assign(rZeroes,
cb589a
+             unop(Iop_1Uto8,
cb589a
+                  binop(Iop_CmpEQ64,
cb589a
+                        mkU64(0),
cb589a
+                        unop(Iop_V128to64, mkexpr(overlappedOred)))));
cb589a
+      assign(rOnes,
cb589a
+             unop(Iop_1Uto8,
cb589a
+                  binop(Iop_CmpEQ64,
cb589a
+                        mkU64(0),
cb589a
+                        unop(Iop_Not64,
cb589a
+                             unop(Iop_V128to64, mkexpr(overlappedAnded))))));
cb589a
+   } else {
cb589a
+      assign(rZeroes,
cb589a
+             unop(Iop_1Uto8,
cb589a
+                  binop(Iop_CmpEQ32,
cb589a
+                        mkU32(0),
cb589a
+                        unop(Iop_V128to32, mkexpr(overlappedOred)))));
cb589a
+      assign(rOnes,
cb589a
+             unop(Iop_1Uto8,
cb589a
+                  binop(Iop_CmpEQ32,
cb589a
+                        mkU32(0),
cb589a
+                        unop(Iop_Not32,
cb589a
+                             unop(Iop_V128to32, mkexpr(overlappedAnded))))));
cb589a
+   }
cb589a
+
cb589a
+   // rOnes might not be used below.  But iropt will remove it, so there's no
cb589a
+   // inefficiency as a result.
cb589a
 
cb589a
    if (test_all_ones) {
cb589a
-      assign( rOnes, unop(Iop_1Uto8,
cb589a
-         binop(Iop_CmpEQ32, mkU32(0xFFFFFFFF),
cb589a
-               unop(Iop_V128to32,
cb589a
-                    binop(Iop_AndV128,
cb589a
-                          binop(Iop_AndV128, mkexpr(v0), mkexpr(v1)),
cb589a
-                          binop(Iop_AndV128, mkexpr(v2), mkexpr(v3)))
cb589a
-                    ))) );
cb589a
       putCR321( 6, binop(Iop_Or8,
cb589a
                          binop(Iop_Shl8, mkexpr(rOnes),  mkU8(3)),
cb589a
-                         binop(Iop_Shl8, mkexpr(rZeros), mkU8(1))) );
cb589a
+                         binop(Iop_Shl8, mkexpr(rZeroes), mkU8(1))) );
cb589a
    } else {
cb589a
-      putCR321( 6, binop(Iop_Shl8, mkexpr(rZeros), mkU8(1)) );
cb589a
+      putCR321( 6, binop(Iop_Shl8, mkexpr(rZeroes), mkU8(1)) );
cb589a
    }
cb589a
    putCR0( 6, mkU8(0) );
cb589a
 } 
cb589a
diff --git a/memcheck/mc_translate.c b/memcheck/mc_translate.c
cb589a
index c24db91..7f69ee3 100644
cb589a
--- a/memcheck/mc_translate.c
cb589a
+++ b/memcheck/mc_translate.c
cb589a
@@ -8322,6 +8322,9 @@ IRSB* MC_(instrument) ( VgCallbackClosure* closure,
cb589a
 #     elif defined(VGA_amd64)
cb589a
       mce.dlbo.dl_Add64           = DLauto;
cb589a
       mce.dlbo.dl_CmpEQ32_CmpNE32 = DLexpensive;
cb589a
+#     elif defined(VGA_ppc64le)
cb589a
+      // Needed by (at least) set_AV_CR6() in the front end.
cb589a
+      mce.dlbo.dl_CmpEQ64_CmpNE64 = DLexpensive;
cb589a
 #     endif
cb589a
 
cb589a
       /* preInstrumentationAnalysis() will allocate &mce.tmpHowUsed and then