cb589a
commit 4271989815b5fc933c1e29bc75507c2726dc3738
cb589a
Author: Julian Seward <jseward@acm.org>
cb589a
Date:   Tue Nov 20 10:52:33 2018 +0100
cb589a
cb589a
    Add some new IROps to support improved Memcheck analysis of strlen etc.
cb589a
    
cb589a
    This is part of the fix for bug 386945.  It adds the following IROps, plus
cb589a
    their supporting type- and printing- fragments:
cb589a
    
cb589a
    Iop_Reverse8sIn32_x1: 32-bit byteswap.  A fancy name, but it is consistent
cb589a
    with naming for the other swapping IROps that already exist.
cb589a
    
cb589a
    Iop_PopCount64, Iop_PopCount32: population count
cb589a
    
cb589a
    Iop_ClzNat64, Iop_ClzNat32, Iop_CtzNat64, Iop_CtzNat32: counting leading and
cb589a
    trailing zeroes, with "natural" (Nat) semantics for a zero input, meaning, in
cb589a
    the case of zero input, return the number of bits in the word.  These
cb589a
    functionally overlap with the existing Iop_Clz64, Iop_Clz32, Iop_Ctz64,
cb589a
    Iop_Ctz32.  The existing operations are undefined in case of a zero input.
cb589a
    Adding these new variants avoids the complexity of having to change the
cb589a
    declared semantics of the existing operations.  Instead they are deprecated
cb589a
    but still available for use.
cb589a
cb589a
diff --git a/VEX/priv/ir_defs.c b/VEX/priv/ir_defs.c
cb589a
index 823b6be..3221033 100644
cb589a
--- a/VEX/priv/ir_defs.c
cb589a
+++ b/VEX/priv/ir_defs.c
cb589a
@@ -194,6 +194,14 @@ void ppIROp ( IROp op )
cb589a
       case Iop_Ctz64:    vex_printf("Ctz64"); return;
cb589a
       case Iop_Ctz32:    vex_printf("Ctz32"); return;
cb589a
 
cb589a
+      case Iop_ClzNat64: vex_printf("ClzNat64"); return;
cb589a
+      case Iop_ClzNat32: vex_printf("ClzNat32"); return;
cb589a
+      case Iop_CtzNat64: vex_printf("CtzNat64"); return;
cb589a
+      case Iop_CtzNat32: vex_printf("CtzNat32"); return;
cb589a
+
cb589a
+      case Iop_PopCount64: vex_printf("PopCount64"); return;
cb589a
+      case Iop_PopCount32: vex_printf("PopCount32"); return;
cb589a
+
cb589a
       case Iop_CmpLT32S: vex_printf("CmpLT32S"); return;
cb589a
       case Iop_CmpLE32S: vex_printf("CmpLE32S"); return;
cb589a
       case Iop_CmpLT32U: vex_printf("CmpLT32U"); return;
cb589a
@@ -395,6 +403,7 @@ void ppIROp ( IROp op )
cb589a
 
cb589a
       case Iop_CmpNEZ16x2: vex_printf("CmpNEZ16x2"); return;
cb589a
       case Iop_CmpNEZ8x4:  vex_printf("CmpNEZ8x4"); return;
cb589a
+      case Iop_Reverse8sIn32_x1: vex_printf("Reverse8sIn32_x1"); return;
cb589a
 
cb589a
       case Iop_CmpF64:    vex_printf("CmpF64"); return;
cb589a
 
cb589a
@@ -2719,6 +2728,7 @@ void typeOfPrimop ( IROp op,
cb589a
          UNARY(Ity_I16, Ity_I16);
cb589a
       case Iop_Not32:
cb589a
       case Iop_CmpNEZ16x2: case Iop_CmpNEZ8x4:
cb589a
+      case Iop_Reverse8sIn32_x1:
cb589a
          UNARY(Ity_I32, Ity_I32);
cb589a
 
cb589a
       case Iop_Not64:
cb589a
@@ -2782,9 +2792,13 @@ void typeOfPrimop ( IROp op,
cb589a
          BINARY(Ity_I64,Ity_I64, Ity_I128);
cb589a
 
cb589a
       case Iop_Clz32: case Iop_Ctz32:
cb589a
+      case Iop_ClzNat32: case Iop_CtzNat32:
cb589a
+      case Iop_PopCount32:
cb589a
          UNARY(Ity_I32, Ity_I32);
cb589a
 
cb589a
       case Iop_Clz64: case Iop_Ctz64:
cb589a
+      case Iop_ClzNat64: case Iop_CtzNat64:
cb589a
+      case Iop_PopCount64:
cb589a
          UNARY(Ity_I64, Ity_I64);
cb589a
 
cb589a
       case Iop_DivU32: case Iop_DivS32: case Iop_DivU32E: case Iop_DivS32E:
cb589a
diff --git a/VEX/pub/libvex_ir.h b/VEX/pub/libvex_ir.h
cb589a
index 17bcb55..93fa5ac 100644
cb589a
--- a/VEX/pub/libvex_ir.h
cb589a
+++ b/VEX/pub/libvex_ir.h
cb589a
@@ -452,12 +452,21 @@ typedef
cb589a
       Iop_MullS8, Iop_MullS16, Iop_MullS32, Iop_MullS64,
cb589a
       Iop_MullU8, Iop_MullU16, Iop_MullU32, Iop_MullU64,
cb589a
 
cb589a
-      /* Wierdo integer stuff */
cb589a
+      /* Counting bits */
cb589a
+      /* Ctz64/Ctz32/Clz64/Clz32 are UNDEFINED when given arguments of zero.
cb589a
+         You must ensure they are never given a zero argument.  As of
cb589a
+         2018-Nov-14 they are deprecated.  Try to use the Nat variants
cb589a
+         immediately below, if you can.
cb589a
+      */
cb589a
       Iop_Clz64, Iop_Clz32,   /* count leading zeroes */
cb589a
       Iop_Ctz64, Iop_Ctz32,   /* count trailing zeros */
cb589a
-      /* Ctz64/Ctz32/Clz64/Clz32 are UNDEFINED when given arguments of
cb589a
-         zero.  You must ensure they are never given a zero argument.
cb589a
-      */
cb589a
+      /* Count leading/trailing zeroes, with "natural" semantics for the
cb589a
+         case where the input is zero: then the result is the number of bits
cb589a
+         in the word. */
cb589a
+      Iop_ClzNat64, Iop_ClzNat32,
cb589a
+      Iop_CtzNat64, Iop_CtzNat32,
cb589a
+      /* Population count -- compute the number of 1 bits in the argument. */
cb589a
+      Iop_PopCount64, Iop_PopCount32,
cb589a
 
cb589a
       /* Standard integer comparisons */
cb589a
       Iop_CmpLT32S, Iop_CmpLT64S,
cb589a
@@ -831,6 +840,9 @@ typedef
cb589a
       /* MISC (vector integer cmp != 0) */
cb589a
       Iop_CmpNEZ16x2, Iop_CmpNEZ8x4,
cb589a
 
cb589a
+      /* Byte swap in a 32-bit word */
cb589a
+      Iop_Reverse8sIn32_x1,
cb589a
+
cb589a
       /* ------------------ 64-bit SIMD FP ------------------------ */
cb589a
 
cb589a
       /* Convertion to/from int */
cb589a
@@ -1034,8 +1046,9 @@ typedef
cb589a
       Iop_Slice64,  // (I64, I64, I8) -> I64
cb589a
 
cb589a
       /* REVERSE the order of chunks in vector lanes.  Chunks must be
cb589a
-         smaller than the vector lanes (obviously) and so may be 8-,
cb589a
-         16- and 32-bit in size. */
cb589a
+         smaller than the vector lanes (obviously) and so may be 8-, 16- and
cb589a
+         32-bit in size.  Note that the degenerate case,
cb589a
+         Iop_Reverse8sIn64_x1, is a simply a vanilla byte-swap. */
cb589a
       /* Examples:
cb589a
             Reverse8sIn16_x4([a,b,c,d,e,f,g,h]) = [b,a,d,c,f,e,h,g]
cb589a
             Reverse8sIn32_x2([a,b,c,d,e,f,g,h]) = [d,c,b,a,h,g,f,e]