Blame SOURCES/valgrind-3.14.0-set_AV_CR6.patch

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