Mark Wielaard b3eda9
commit 81d9832226d6e3d1ee78ee3133189d7b520e7eea
Mark Wielaard b3eda9
Author: Julian Seward <jseward@acm.org>
Mark Wielaard b3eda9
Date:   Tue Nov 20 11:36:53 2018 +0100
Mark Wielaard b3eda9
Mark Wielaard b3eda9
    ppc front end: use new IROps added in 42719898.
Mark Wielaard b3eda9
    
Mark Wielaard b3eda9
    This pertains to bug 386945.
Mark Wielaard b3eda9
    
Mark Wielaard b3eda9
    VEX/priv/guest_ppc_toIR.c:
Mark Wielaard b3eda9
    
Mark Wielaard b3eda9
    gen_POPCOUNT: use Iop_PopCount{32,64} where possible.
Mark Wielaard b3eda9
    
Mark Wielaard b3eda9
    gen_vpopcntd_mode32: use Iop_PopCount32.
Mark Wielaard b3eda9
    
Mark Wielaard b3eda9
    for cntlz{w,d}, use Iop_CtzNat{32,64}.
Mark Wielaard b3eda9
    
Mark Wielaard b3eda9
    gen_byterev32: use Iop_Reverse8sIn32_x1 instead of lengthy sequence.
Mark Wielaard b3eda9
    
Mark Wielaard b3eda9
    verbose_Clz32: remove (was unused anyway).
Mark Wielaard b3eda9
Mark Wielaard b3eda9
diff --git a/VEX/priv/guest_ppc_toIR.c b/VEX/priv/guest_ppc_toIR.c
Mark Wielaard b3eda9
index cb1cae1..8977d4f 100644
Mark Wielaard b3eda9
--- a/VEX/priv/guest_ppc_toIR.c
Mark Wielaard b3eda9
+++ b/VEX/priv/guest_ppc_toIR.c
Mark Wielaard b3eda9
@@ -1595,7 +1595,8 @@ typedef enum {
Mark Wielaard b3eda9
 /* Generate an IR sequence to do a popcount operation on the supplied
Mark Wielaard b3eda9
    IRTemp, and return a new IRTemp holding the result.  'ty' may be
Mark Wielaard b3eda9
    Ity_I32 or Ity_I64 only. */
Mark Wielaard b3eda9
-static IRTemp gen_POPCOUNT ( IRType ty, IRTemp src, _popcount_data_type data_type )
Mark Wielaard b3eda9
+static IRTemp gen_POPCOUNT ( IRType ty, IRTemp src,
Mark Wielaard b3eda9
+                             _popcount_data_type data_type )
Mark Wielaard b3eda9
 {
Mark Wielaard b3eda9
   /* Do count across 2^data_type bits,
Mark Wielaard b3eda9
      byte:        data_type = 3
Mark Wielaard b3eda9
@@ -1611,6 +1612,22 @@ static IRTemp gen_POPCOUNT ( IRType ty, IRTemp src, _popcount_data_type data_typ
Mark Wielaard b3eda9
 
Mark Wielaard b3eda9
    vassert(ty == Ity_I64 || ty == Ity_I32);
Mark Wielaard b3eda9
 
Mark Wielaard b3eda9
+   // Use a single IROp in cases where we can.
Mark Wielaard b3eda9
+
Mark Wielaard b3eda9
+   if (ty == Ity_I64 && data_type == DWORD) {
Mark Wielaard b3eda9
+      IRTemp res = newTemp(Ity_I64);
Mark Wielaard b3eda9
+      assign(res, unop(Iop_PopCount64, mkexpr(src)));
Mark Wielaard b3eda9
+      return res;
Mark Wielaard b3eda9
+   }
Mark Wielaard b3eda9
+
Mark Wielaard b3eda9
+   if (ty == Ity_I32 && data_type == WORD) {
Mark Wielaard b3eda9
+      IRTemp res = newTemp(Ity_I32);
Mark Wielaard b3eda9
+      assign(res, unop(Iop_PopCount32, mkexpr(src)));
Mark Wielaard b3eda9
+      return res;
Mark Wielaard b3eda9
+   }
Mark Wielaard b3eda9
+
Mark Wielaard b3eda9
+   // For the rest, we have to do it the slow way.
Mark Wielaard b3eda9
+
Mark Wielaard b3eda9
    if (ty == Ity_I32) {
Mark Wielaard b3eda9
 
Mark Wielaard b3eda9
       for (idx = 0; idx < WORD; idx++) {
Mark Wielaard b3eda9
@@ -1638,7 +1655,7 @@ static IRTemp gen_POPCOUNT ( IRType ty, IRTemp src, _popcount_data_type data_typ
Mark Wielaard b3eda9
       return nyu;
Mark Wielaard b3eda9
    }
Mark Wielaard b3eda9
 
Mark Wielaard b3eda9
-// else, ty == Ity_I64
Mark Wielaard b3eda9
+   // else, ty == Ity_I64
Mark Wielaard b3eda9
    vassert(mode64);
Mark Wielaard b3eda9
 
Mark Wielaard b3eda9
    for (i = 0; i < DWORD; i++) {
Mark Wielaard b3eda9
@@ -1670,52 +1687,15 @@ static IRTemp gen_POPCOUNT ( IRType ty, IRTemp src, _popcount_data_type data_typ
Mark Wielaard b3eda9
  */
Mark Wielaard b3eda9
 static IRTemp gen_vpopcntd_mode32 ( IRTemp src1, IRTemp src2 )
Mark Wielaard b3eda9
 {
Mark Wielaard b3eda9
-   Int i, shift[6];
Mark Wielaard b3eda9
-   IRTemp mask[6];
Mark Wielaard b3eda9
-   IRTemp old = IRTemp_INVALID;
Mark Wielaard b3eda9
-   IRTemp nyu1 = IRTemp_INVALID;
Mark Wielaard b3eda9
-   IRTemp nyu2 = IRTemp_INVALID;
Mark Wielaard b3eda9
    IRTemp retval = newTemp(Ity_I64);
Mark Wielaard b3eda9
 
Mark Wielaard b3eda9
    vassert(!mode64);
Mark Wielaard b3eda9
 
Mark Wielaard b3eda9
-   for (i = 0; i < WORD; i++) {
Mark Wielaard b3eda9
-      mask[i]  = newTemp(Ity_I32);
Mark Wielaard b3eda9
-      shift[i] = 1 << i;
Mark Wielaard b3eda9
-   }
Mark Wielaard b3eda9
-   assign(mask[0], mkU32(0x55555555));
Mark Wielaard b3eda9
-   assign(mask[1], mkU32(0x33333333));
Mark Wielaard b3eda9
-   assign(mask[2], mkU32(0x0F0F0F0F));
Mark Wielaard b3eda9
-   assign(mask[3], mkU32(0x00FF00FF));
Mark Wielaard b3eda9
-   assign(mask[4], mkU32(0x0000FFFF));
Mark Wielaard b3eda9
-   old = src1;
Mark Wielaard b3eda9
-   for (i = 0; i < WORD; i++) {
Mark Wielaard b3eda9
-      nyu1 = newTemp(Ity_I32);
Mark Wielaard b3eda9
-      assign(nyu1,
Mark Wielaard b3eda9
-             binop(Iop_Add32,
Mark Wielaard b3eda9
-                   binop(Iop_And32,
Mark Wielaard b3eda9
-                         mkexpr(old),
Mark Wielaard b3eda9
-                         mkexpr(mask[i])),
Mark Wielaard b3eda9
-                   binop(Iop_And32,
Mark Wielaard b3eda9
-                         binop(Iop_Shr32, mkexpr(old), mkU8(shift[i])),
Mark Wielaard b3eda9
-                         mkexpr(mask[i]))));
Mark Wielaard b3eda9
-      old = nyu1;
Mark Wielaard b3eda9
-   }
Mark Wielaard b3eda9
-
Mark Wielaard b3eda9
-   old = src2;
Mark Wielaard b3eda9
-   for (i = 0; i < WORD; i++) {
Mark Wielaard b3eda9
-      nyu2 = newTemp(Ity_I32);
Mark Wielaard b3eda9
-      assign(nyu2,
Mark Wielaard b3eda9
-             binop(Iop_Add32,
Mark Wielaard b3eda9
-                   binop(Iop_And32,
Mark Wielaard b3eda9
-                         mkexpr(old),
Mark Wielaard b3eda9
-                         mkexpr(mask[i])),
Mark Wielaard b3eda9
-                   binop(Iop_And32,
Mark Wielaard b3eda9
-                         binop(Iop_Shr32, mkexpr(old), mkU8(shift[i])),
Mark Wielaard b3eda9
-                         mkexpr(mask[i]))));
Mark Wielaard b3eda9
-      old = nyu2;
Mark Wielaard b3eda9
-   }
Mark Wielaard b3eda9
-   assign(retval, unop(Iop_32Uto64, binop(Iop_Add32, mkexpr(nyu1), mkexpr(nyu2))));
Mark Wielaard b3eda9
+   assign(retval,
Mark Wielaard b3eda9
+          unop(Iop_32Uto64,
Mark Wielaard b3eda9
+               binop(Iop_Add32,
Mark Wielaard b3eda9
+                     unop(Iop_PopCount32, mkexpr(src1)),
Mark Wielaard b3eda9
+                     unop(Iop_PopCount32, mkexpr(src2)))));
Mark Wielaard b3eda9
    return retval;
Mark Wielaard b3eda9
 }
Mark Wielaard b3eda9
 
Mark Wielaard b3eda9
@@ -5715,7 +5695,7 @@ static Bool dis_modulo_int ( UInt theInstr )
Mark Wielaard b3eda9
                 rA_address, rS_address);
Mark Wielaard b3eda9
 
Mark Wielaard b3eda9
             assign( rS, getIReg( rS_address ) );
Mark Wielaard b3eda9
-            assign( result, unop( Iop_Ctz32,
Mark Wielaard b3eda9
+            assign( result, unop( Iop_CtzNat32,
Mark Wielaard b3eda9
                                   unop( Iop_64to32, mkexpr( rS ) ) ) );
Mark Wielaard b3eda9
             assign( rA, binop( Iop_32HLto64, mkU32( 0 ), mkexpr( result ) ) );
Mark Wielaard b3eda9
 
Mark Wielaard b3eda9
@@ -5746,7 +5726,7 @@ static Bool dis_modulo_int ( UInt theInstr )
Mark Wielaard b3eda9
                 rA_address, rS_address);
Mark Wielaard b3eda9
 
Mark Wielaard b3eda9
             assign( rS, getIReg( rS_address ) );
Mark Wielaard b3eda9
-            assign( rA, unop( Iop_Ctz64, mkexpr( rS ) ) );
Mark Wielaard b3eda9
+            assign( rA, unop( Iop_CtzNat64, mkexpr( rS ) ) );
Mark Wielaard b3eda9
 
Mark Wielaard b3eda9
             if ( flag_rC == 1 )
Mark Wielaard b3eda9
                set_CR0( mkexpr( rA ) );
Mark Wielaard b3eda9
@@ -6307,7 +6287,6 @@ static Bool dis_int_logic ( UInt theInstr )
Mark Wielaard b3eda9
    IRTemp rS     = newTemp(ty);
Mark Wielaard b3eda9
    IRTemp rA     = newTemp(ty);
Mark Wielaard b3eda9
    IRTemp rB     = newTemp(ty);
Mark Wielaard b3eda9
-   IRExpr* irx;
Mark Wielaard b3eda9
    Bool do_rc    = False;
Mark Wielaard b3eda9
 
Mark Wielaard b3eda9
    assign( rS, getIReg(rS_addr) );
Mark Wielaard b3eda9
@@ -6404,26 +6383,16 @@ static Bool dis_int_logic ( UInt theInstr )
Mark Wielaard b3eda9
          break;
Mark Wielaard b3eda9
          
Mark Wielaard b3eda9
       case 0x01A: { // cntlzw (Count Leading Zeros Word, PPC32 p371)
Mark Wielaard b3eda9
-         IRExpr* lo32;
Mark Wielaard b3eda9
          if (rB_addr!=0) {
Mark Wielaard b3eda9
             vex_printf("dis_int_logic(ppc)(cntlzw,rB_addr)\n");
Mark Wielaard b3eda9
             return False;
Mark Wielaard b3eda9
          }
Mark Wielaard b3eda9
-         DIP("cntlzw%s r%u,r%u\n",
Mark Wielaard b3eda9
-             flag_rC ? ".":"", rA_addr, rS_addr);
Mark Wielaard b3eda9
+         DIP("cntlzw%s r%u,r%u\n", flag_rC ? ".":"", rA_addr, rS_addr);
Mark Wielaard b3eda9
          
Mark Wielaard b3eda9
          // mode64: count in low word only
Mark Wielaard b3eda9
-         lo32 = mode64 ? unop(Iop_64to32, mkexpr(rS)) : mkexpr(rS);
Mark Wielaard b3eda9
-         
Mark Wielaard b3eda9
-         // Iop_Clz32 undefined for arg==0, so deal with that case:
Mark Wielaard b3eda9
-         irx =  binop(Iop_CmpNE32, lo32, mkU32(0));
Mark Wielaard b3eda9
-         assign(rA, mkWidenFrom32(ty,
Mark Wielaard b3eda9
-                         IRExpr_ITE( irx,
Mark Wielaard b3eda9
-                                     unop(Iop_Clz32, lo32),
Mark Wielaard b3eda9
-                                     mkU32(32)),
Mark Wielaard b3eda9
-                         False));
Mark Wielaard b3eda9
-
Mark Wielaard b3eda9
-         // TODO: alternatively: assign(rA, verbose_Clz32(rS));
Mark Wielaard b3eda9
+         IRExpr* lo32 = mode64 ? unop(Iop_64to32, mkexpr(rS)) : mkexpr(rS);
Mark Wielaard b3eda9
+         IRExpr* res32 = unop(Iop_ClzNat32, lo32);
Mark Wielaard b3eda9
+         assign(rA, mode64 ? unop(Iop_32Uto64, res32) : res32);
Mark Wielaard b3eda9
          break;
Mark Wielaard b3eda9
       }
Mark Wielaard b3eda9
          
Mark Wielaard b3eda9
@@ -6521,14 +6490,8 @@ static Bool dis_int_logic ( UInt theInstr )
Mark Wielaard b3eda9
             vex_printf("dis_int_logic(ppc)(cntlzd,rB_addr)\n");
Mark Wielaard b3eda9
             return False;
Mark Wielaard b3eda9
          }
Mark Wielaard b3eda9
-         DIP("cntlzd%s r%u,r%u\n",
Mark Wielaard b3eda9
-             flag_rC ? ".":"", rA_addr, rS_addr);
Mark Wielaard b3eda9
-         // Iop_Clz64 undefined for arg==0, so deal with that case:
Mark Wielaard b3eda9
-         irx =  binop(Iop_CmpNE64, mkexpr(rS), mkU64(0));
Mark Wielaard b3eda9
-         assign(rA, IRExpr_ITE( irx,
Mark Wielaard b3eda9
-                                unop(Iop_Clz64, mkexpr(rS)),
Mark Wielaard b3eda9
-                                mkU64(64) ));
Mark Wielaard b3eda9
-         // TODO: alternatively: assign(rA, verbose_Clz64(rS));
Mark Wielaard b3eda9
+         DIP("cntlzd%s r%u,r%u\n", flag_rC ? ".":"", rA_addr, rS_addr);
Mark Wielaard b3eda9
+         assign(rA, unop(Iop_ClzNat64, mkexpr(rS)));
Mark Wielaard b3eda9
          break;
Mark Wielaard b3eda9
 
Mark Wielaard b3eda9
       case 0x1FC: // cmpb (Power6: compare bytes)
Mark Wielaard b3eda9
@@ -6574,8 +6537,9 @@ static Bool dis_int_logic ( UInt theInstr )
Mark Wielaard b3eda9
          putFReg( rS_addr, mkexpr(frA));
Mark Wielaard b3eda9
          return True;
Mark Wielaard b3eda9
       }
Mark Wielaard b3eda9
-      case 0x1FA: // popcntd (population count doubleword
Mark Wielaard b3eda9
+      case 0x1FA: // popcntd (population count doubleword)
Mark Wielaard b3eda9
       {
Mark Wielaard b3eda9
+          vassert(mode64);
Mark Wielaard b3eda9
     	  DIP("popcntd r%u,r%u\n", rA_addr, rS_addr);
Mark Wielaard b3eda9
     	  IRTemp result = gen_POPCOUNT(ty, rS, DWORD);
Mark Wielaard b3eda9
     	  putIReg( rA_addr, mkexpr(result) );
Mark Wielaard b3eda9
@@ -9154,18 +9118,7 @@ static Bool dis_int_shift ( UInt theInstr )
Mark Wielaard b3eda9
 static IRExpr* /* :: Ity_I32 */ gen_byterev32 ( IRTemp t )
Mark Wielaard b3eda9
 {
Mark Wielaard b3eda9
    vassert(typeOfIRTemp(irsb->tyenv, t) == Ity_I32);
Mark Wielaard b3eda9
-   return
Mark Wielaard b3eda9
-      binop(Iop_Or32,
Mark Wielaard b3eda9
-         binop(Iop_Shl32, mkexpr(t), mkU8(24)),
Mark Wielaard b3eda9
-      binop(Iop_Or32,
Mark Wielaard b3eda9
-         binop(Iop_And32, binop(Iop_Shl32, mkexpr(t), mkU8(8)), 
Mark Wielaard b3eda9
-                          mkU32(0x00FF0000)),
Mark Wielaard b3eda9
-      binop(Iop_Or32,
Mark Wielaard b3eda9
-         binop(Iop_And32, binop(Iop_Shr32, mkexpr(t), mkU8(8)),
Mark Wielaard b3eda9
-                          mkU32(0x0000FF00)),
Mark Wielaard b3eda9
-         binop(Iop_And32, binop(Iop_Shr32, mkexpr(t), mkU8(24)),
Mark Wielaard b3eda9
-                          mkU32(0x000000FF) )
Mark Wielaard b3eda9
-      )));
Mark Wielaard b3eda9
+   return unop(Iop_Reverse8sIn32_x1, mkexpr(t));
Mark Wielaard b3eda9
 }
Mark Wielaard b3eda9
 
Mark Wielaard b3eda9
 /* Generates code to swap the byte order in the lower half of an Ity_I32,
Mark Wielaard b3eda9
@@ -9225,6 +9178,10 @@ static Bool dis_int_ldst_rev ( UInt theInstr )
Mark Wielaard b3eda9
 
Mark Wielaard b3eda9
       case 0x214: // ldbrx (Load Doubleword Byte-Reverse Indexed)
Mark Wielaard b3eda9
       {
Mark Wielaard b3eda9
+         // JRS FIXME:
Mark Wielaard b3eda9
+         // * is the host_endness conditional below actually necessary?
Mark Wielaard b3eda9
+         // * can we just do a 64-bit load followed by by Iop_Reverse8sIn64_x1?
Mark Wielaard b3eda9
+         //   That would be a lot more efficient.
Mark Wielaard b3eda9
          IRExpr * nextAddr;
Mark Wielaard b3eda9
          IRTemp w3 = newTemp( Ity_I32 );
Mark Wielaard b3eda9
          IRTemp w4 = newTemp( Ity_I32 );
Mark Wielaard b3eda9
@@ -17056,8 +17013,8 @@ dis_av_count_bitTranspose ( UInt theInstr, UInt opc2 )
Mark Wielaard b3eda9
       case 0x7C3:    // vpopcntd
Mark Wielaard b3eda9
       {
Mark Wielaard b3eda9
          if (mode64) {
Mark Wielaard b3eda9
-            /* Break vector into 64-bit double words and do the population count
Mark Wielaard b3eda9
-             * on each double word.
Mark Wielaard b3eda9
+            /* Break vector into 64-bit double words and do the population
Mark Wielaard b3eda9
+               count on each double word.
Mark Wielaard b3eda9
              */
Mark Wielaard b3eda9
             IRType ty = Ity_I64;
Mark Wielaard b3eda9
             IRTemp bits0_63   = newTemp(Ity_I64);
Mark Wielaard b3eda9
@@ -17077,15 +17034,16 @@ dis_av_count_bitTranspose ( UInt theInstr, UInt opc2 )
Mark Wielaard b3eda9
                                       mkexpr( cnt_bits0_63 ) ) );
Mark Wielaard b3eda9
          } else {
Mark Wielaard b3eda9
             /* Break vector into 32-bit words and do the population count
Mark Wielaard b3eda9
-             * on each doubleword.
Mark Wielaard b3eda9
+               on each 32-bit word.
Mark Wielaard b3eda9
              */
Mark Wielaard b3eda9
             IRTemp bits0_31, bits32_63, bits64_95, bits96_127;
Mark Wielaard b3eda9
             bits0_31 = bits32_63 = bits64_95 = bits96_127 = IRTemp_INVALID;
Mark Wielaard b3eda9
-            IRTemp cnt_bits0_63   = newTemp(Ity_I64);
Mark Wielaard b3eda9
+            IRTemp cnt_bits0_63    = newTemp(Ity_I64);
Mark Wielaard b3eda9
             IRTemp cnt_bits64_127  = newTemp(Ity_I64);
Mark Wielaard b3eda9
 
Mark Wielaard b3eda9
             DIP("vpopcntd v%d,v%d\n", vRT_addr, vRB_addr);
Mark Wielaard b3eda9
-            breakV128to4x32(mkexpr( vB), &bits96_127, &bits64_95, &bits32_63, &bits0_31 );
Mark Wielaard b3eda9
+            breakV128to4x32(mkexpr( vB), &bits96_127, &bits64_95,
Mark Wielaard b3eda9
+                                         &bits32_63, &bits0_31 );
Mark Wielaard b3eda9
 
Mark Wielaard b3eda9
             cnt_bits0_63   = gen_vpopcntd_mode32(bits0_31, bits32_63);
Mark Wielaard b3eda9
             cnt_bits64_127 = gen_vpopcntd_mode32(bits64_95, bits96_127);
Mark Wielaard b3eda9
@@ -29103,10 +29061,12 @@ DisResult disInstr_PPC_WRK (
Mark Wielaard b3eda9
 
Mark Wielaard b3eda9
       /* Miscellaneous ISA 2.06 instructions */
Mark Wielaard b3eda9
       case 0x1FA: // popcntd
Mark Wielaard b3eda9
+         if (!mode64) goto decode_failure;
Mark Wielaard b3eda9
+         /* else fallthru */
Mark Wielaard b3eda9
       case 0x17A: // popcntw
Mark Wielaard b3eda9
       case 0x7A:  // popcntb
Mark Wielaard b3eda9
-	  if (dis_int_logic( theInstr )) goto decode_success;
Mark Wielaard b3eda9
-    	  goto decode_failure;
Mark Wielaard b3eda9
+         if (dis_int_logic( theInstr )) goto decode_success;
Mark Wielaard b3eda9
+         goto decode_failure;
Mark Wielaard b3eda9
 
Mark Wielaard b3eda9
       case 0x0FC: // bpermd
Mark Wielaard b3eda9
          if (!mode64) goto decode_failure;
Mark Wielaard b3eda9
@@ -29669,94 +29629,6 @@ DisResult disInstr_PPC ( IRSB*        irsb_IN,
Mark Wielaard b3eda9
    return dres;
Mark Wielaard b3eda9
 }
Mark Wielaard b3eda9
 
Mark Wielaard b3eda9
-
Mark Wielaard b3eda9
-/*------------------------------------------------------------*/
Mark Wielaard b3eda9
-/*--- Unused stuff                                         ---*/
Mark Wielaard b3eda9
-/*------------------------------------------------------------*/
Mark Wielaard b3eda9
-
Mark Wielaard b3eda9
-///* A potentially more memcheck-friendly implementation of Clz32, with
Mark Wielaard b3eda9
-//   the boundary case Clz32(0) = 32, which is what ppc requires. */
Mark Wielaard b3eda9
-//
Mark Wielaard b3eda9
-//static IRExpr* /* :: Ity_I32 */ verbose_Clz32 ( IRTemp arg )
Mark Wielaard b3eda9
-//{
Mark Wielaard b3eda9
-//   /* Welcome ... to SSA R Us. */
Mark Wielaard b3eda9
-//   IRTemp n1  = newTemp(Ity_I32);
Mark Wielaard b3eda9
-//   IRTemp n2  = newTemp(Ity_I32);
Mark Wielaard b3eda9
-//   IRTemp n3  = newTemp(Ity_I32);
Mark Wielaard b3eda9
-//   IRTemp n4  = newTemp(Ity_I32);
Mark Wielaard b3eda9
-//   IRTemp n5  = newTemp(Ity_I32);
Mark Wielaard b3eda9
-//   IRTemp n6  = newTemp(Ity_I32);
Mark Wielaard b3eda9
-//   IRTemp n7  = newTemp(Ity_I32);
Mark Wielaard b3eda9
-//   IRTemp n8  = newTemp(Ity_I32);
Mark Wielaard b3eda9
-//   IRTemp n9  = newTemp(Ity_I32);
Mark Wielaard b3eda9
-//   IRTemp n10 = newTemp(Ity_I32);
Mark Wielaard b3eda9
-//   IRTemp n11 = newTemp(Ity_I32);
Mark Wielaard b3eda9
-//   IRTemp n12 = newTemp(Ity_I32);
Mark Wielaard b3eda9
-//
Mark Wielaard b3eda9
-//   /* First, propagate the most significant 1-bit into all lower
Mark Wielaard b3eda9
-//      positions in the word. */
Mark Wielaard b3eda9
-//   /* unsigned int clz ( unsigned int n )
Mark Wielaard b3eda9
-//      {
Mark Wielaard b3eda9
-//         n |= (n >> 1);
Mark Wielaard b3eda9
-//         n |= (n >> 2);
Mark Wielaard b3eda9
-//         n |= (n >> 4);
Mark Wielaard b3eda9
-//         n |= (n >> 8);
Mark Wielaard b3eda9
-//         n |= (n >> 16);
Mark Wielaard b3eda9
-//         return bitcount(~n);
Mark Wielaard b3eda9
-//      }
Mark Wielaard b3eda9
-//   */
Mark Wielaard b3eda9
-//   assign(n1, mkexpr(arg));
Mark Wielaard b3eda9
-//   assign(n2, binop(Iop_Or32, mkexpr(n1), binop(Iop_Shr32, mkexpr(n1), mkU8(1))));
Mark Wielaard b3eda9
-//   assign(n3, binop(Iop_Or32, mkexpr(n2), binop(Iop_Shr32, mkexpr(n2), mkU8(2))));
Mark Wielaard b3eda9
-//   assign(n4, binop(Iop_Or32, mkexpr(n3), binop(Iop_Shr32, mkexpr(n3), mkU8(4))));
Mark Wielaard b3eda9
-//   assign(n5, binop(Iop_Or32, mkexpr(n4), binop(Iop_Shr32, mkexpr(n4), mkU8(8))));
Mark Wielaard b3eda9
-//   assign(n6, binop(Iop_Or32, mkexpr(n5), binop(Iop_Shr32, mkexpr(n5), mkU8(16))));
Mark Wielaard b3eda9
-//   /* This gives a word of the form 0---01---1.  Now invert it, giving
Mark Wielaard b3eda9
-//      a word of the form 1---10---0, then do a population-count idiom
Mark Wielaard b3eda9
-//      (to count the 1s, which is the number of leading zeroes, or 32
Mark Wielaard b3eda9
-//      if the original word was 0. */
Mark Wielaard b3eda9
-//   assign(n7, unop(Iop_Not32, mkexpr(n6)));
Mark Wielaard b3eda9
-//
Mark Wielaard b3eda9
-//   /* unsigned int bitcount ( unsigned int n )
Mark Wielaard b3eda9
-//      {
Mark Wielaard b3eda9
-//         n = n - ((n >> 1) & 0x55555555);
Mark Wielaard b3eda9
-//         n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
Mark Wielaard b3eda9
-//         n = (n + (n >> 4)) & 0x0F0F0F0F;
Mark Wielaard b3eda9
-//         n = n + (n >> 8);
Mark Wielaard b3eda9
-//         n = (n + (n >> 16)) & 0x3F;
Mark Wielaard b3eda9
-//         return n;
Mark Wielaard b3eda9
-//      }
Mark Wielaard b3eda9
-//   */
Mark Wielaard b3eda9
-//   assign(n8, 
Mark Wielaard b3eda9
-//          binop(Iop_Sub32, 
Mark Wielaard b3eda9
-//                mkexpr(n7),  
Mark Wielaard b3eda9
-//                binop(Iop_And32, 
Mark Wielaard b3eda9
-//                      binop(Iop_Shr32, mkexpr(n7), mkU8(1)),
Mark Wielaard b3eda9
-//                      mkU32(0x55555555))));
Mark Wielaard b3eda9
-//   assign(n9,
Mark Wielaard b3eda9
-//          binop(Iop_Add32,
Mark Wielaard b3eda9
-//                binop(Iop_And32, mkexpr(n8), mkU32(0x33333333)),
Mark Wielaard b3eda9
-//                binop(Iop_And32,
Mark Wielaard b3eda9
-//                      binop(Iop_Shr32, mkexpr(n8), mkU8(2)),
Mark Wielaard b3eda9
-//                      mkU32(0x33333333))));
Mark Wielaard b3eda9
-//   assign(n10,
Mark Wielaard b3eda9
-//          binop(Iop_And32,
Mark Wielaard b3eda9
-//                binop(Iop_Add32, 
Mark Wielaard b3eda9
-//                      mkexpr(n9), 
Mark Wielaard b3eda9
-//                      binop(Iop_Shr32, mkexpr(n9), mkU8(4))),
Mark Wielaard b3eda9
-//                mkU32(0x0F0F0F0F)));
Mark Wielaard b3eda9
-//   assign(n11,
Mark Wielaard b3eda9
-//          binop(Iop_Add32,
Mark Wielaard b3eda9
-//                mkexpr(n10),
Mark Wielaard b3eda9
-//                binop(Iop_Shr32, mkexpr(n10), mkU8(8))));
Mark Wielaard b3eda9
-//   assign(n12,
Mark Wielaard b3eda9
-//          binop(Iop_Add32,
Mark Wielaard b3eda9
-//                mkexpr(n11),
Mark Wielaard b3eda9
-//                binop(Iop_Shr32, mkexpr(n11), mkU8(16))));
Mark Wielaard b3eda9
-//   return
Mark Wielaard b3eda9
-//      binop(Iop_And32, mkexpr(n12), mkU32(0x3F));
Mark Wielaard b3eda9
-//}
Mark Wielaard b3eda9
-
Mark Wielaard b3eda9
 /*--------------------------------------------------------------------*/
Mark Wielaard b3eda9
 /*--- end                                         guest_ppc_toIR.c ---*/
Mark Wielaard b3eda9
 /*--------------------------------------------------------------------*/