This series of patches is from a read-through of wide-int.h and wide-int.cc.
(The series from earlier in the week was from a diff of preexisting files.)

This first patch fixes some comments, typos and formatting.  It also
removes some dead code.  I'll follow up with a gdb-friendly replacement
for the old dump function.

Tested on x86_64-linux-gnu.  OK to install?

Thanks,
Richard


Index: gcc/wide-int.cc
===================================================================
--- gcc/wide-int.cc     2014-04-25 11:33:57.809153807 +0100
+++ gcc/wide-int.cc     2014-04-25 12:33:59.202021025 +0100
@@ -37,12 +37,6 @@ typedef unsigned int UDItype __attribute
 #include "longlong.h"
 #endif
 
-/* This is the maximal size of the buffer needed for dump.  */
-const unsigned int MAX_SIZE = (4 * (MAX_BITSIZE_MODE_ANY_INT / 4
-                                   + (MAX_BITSIZE_MODE_ANY_INT
-                                      / HOST_BITS_PER_WIDE_INT)
-                                   + 32));
-
 static const HOST_WIDE_INT zeros[WIDE_INT_MAX_ELTS] = {};
 
 /*
@@ -51,7 +45,7 @@ static const HOST_WIDE_INT zeros[WIDE_IN
 
 /* Quantities to deal with values that hold half of a wide int.  Used
    in multiply and divide.  */
-#define HALF_INT_MASK (((HOST_WIDE_INT)1 << HOST_BITS_PER_HALF_WIDE_INT) - 1)
+#define HALF_INT_MASK (((HOST_WIDE_INT) 1 << HOST_BITS_PER_HALF_WIDE_INT) - 1)
 
 #define BLOCK_OF(TARGET) ((TARGET) / HOST_BITS_PER_WIDE_INT)
 #define BLOCKS_NEEDED(PREC) \
@@ -129,8 +123,8 @@ wi::from_array (HOST_WIDE_INT *val, cons
 
 /* Construct a wide int from a buffer of length LEN.  BUFFER will be
    read according to byte endianess and word endianess of the target.
-   Only the lower LEN bytes of the result are set; the remaining high
-   bytes are cleared.  */
+   Only the lower BUFFER_LEN bytes of the result are set; the remaining
+   high bytes are cleared.  */
 wide_int
 wi::from_buffer (const unsigned char *buffer, unsigned int buffer_len)
 {
@@ -212,7 +206,7 @@ wi::to_mpz (const wide_int_ref &x, mpz_t
     mpz_import (result, len, -1, sizeof (HOST_WIDE_INT), 0, 0, v);
 }
 
-/* Returns VAL converted to TYPE.  If WRAP is true, then out-of-range
+/* Returns X converted to TYPE.  If WRAP is true, then out-of-range
    values of VAL will be wrapped; otherwise, they will be set to the
    appropriate minimum or maximum TYPE bound.  */
 wide_int
@@ -243,8 +237,8 @@ wi::from_mpz (const_tree type, mpz_t x,
      for representing the value.  The code to calculate count is
      extracted from the GMP manual, section "Integer Import and Export":
      http://gmplib.org/manual/Integer-Import-and-Export.html  */
-  numb = 8*sizeof(HOST_WIDE_INT);
-  count = (mpz_sizeinbase (x, 2) + numb-1) / numb;
+  numb = 8 * sizeof(HOST_WIDE_INT);
+  count = (mpz_sizeinbase (x, 2) + numb - 1) / numb;
   HOST_WIDE_INT *val = res.write_val ();
   mpz_export (val, &count, -1, sizeof (HOST_WIDE_INT), 0, 0, x);
   if (count < 1)
@@ -352,9 +346,8 @@ wi::force_to_size (HOST_WIDE_INT *val, c
    where we do allow comparisons of values of different precisions.  */
 static inline HOST_WIDE_INT
 selt (const HOST_WIDE_INT *a, unsigned int len,
-     unsigned int blocks_needed,
-     unsigned int small_prec,
-     unsigned int index, signop sgn)
+      unsigned int blocks_needed, unsigned int small_prec,
+      unsigned int index, signop sgn)
 {
   HOST_WIDE_INT val;
   if (index < len)
@@ -388,7 +381,7 @@ top_bit_of (const HOST_WIDE_INT *a, unsi
 
 /*
  * Comparisons, note that only equality is an operator.  The other
- * comparisons cannot be operators since they are inherently singed or
+ * comparisons cannot be operators since they are inherently signed or
  * unsigned and C++ has no such operators.
  */
 
@@ -401,7 +394,7 @@ wi::eq_p_large (const HOST_WIDE_INT *op0
   int l0 = op0len - 1;
   unsigned int small_prec = prec & (HOST_BITS_PER_WIDE_INT - 1);
 
-  while (op0len != op1len)
+  if (op0len != op1len)
     return false;
 
   if (op0len == BLOCKS_NEEDED (prec) && small_prec)
@@ -741,7 +734,7 @@ wi::mask (HOST_WIDE_INT *val, unsigned i
   unsigned int shift = width & (HOST_BITS_PER_WIDE_INT - 1);
   if (shift != 0)
     {
-      HOST_WIDE_INT last = (((unsigned HOST_WIDE_INT) 1) << shift) - 1;
+      HOST_WIDE_INT last = ((unsigned HOST_WIDE_INT) 1 << shift) - 1;
       val[i++] = negate ? ~last : last;
     }
   else
@@ -774,12 +767,12 @@ wi::shifted_mask (HOST_WIDE_INT *val, un
   unsigned int shift = start & (HOST_BITS_PER_WIDE_INT - 1);
   if (shift)
     {
-      HOST_WIDE_INT block = (((unsigned HOST_WIDE_INT) 1) << shift) - 1;
+      HOST_WIDE_INT block = ((unsigned HOST_WIDE_INT) 1 << shift) - 1;
       shift = end & (HOST_BITS_PER_WIDE_INT - 1);
       if (shift)
        {
          /* case 000111000 */
-         block = (((unsigned HOST_WIDE_INT) 1) << shift) - block - 1;
+         block = ((unsigned HOST_WIDE_INT) 1 << shift) - block - 1;
          val[i++] = negate ? ~block : block;
          return i;
        }
@@ -796,7 +789,7 @@ wi::shifted_mask (HOST_WIDE_INT *val, un
   if (shift != 0)
     {
       /* 000011111 */
-      HOST_WIDE_INT block = (((unsigned HOST_WIDE_INT) 1) << shift) - 1;
+      HOST_WIDE_INT block = ((unsigned HOST_WIDE_INT) 1 << shift) - 1;
       val[i++] = negate ? ~block : block;
     }
   else if (end < prec)
@@ -823,7 +816,7 @@ wi::and_large (HOST_WIDE_INT *val, const
   if (l0 > l1)
     {
       HOST_WIDE_INT op1mask = -top_bit_of (op1, op1len, prec);
-      if (op1mask  == 0)
+      if (op1mask == 0)
        {
          l0 = l1;
          len = l1 + 1;
@@ -1368,7 +1361,7 @@ wi::mul_internal (HOST_WIDE_INT *val, co
        {
          if (sgn == SIGNED)
            {
-             if ((HOST_WIDE_INT) (r) != sext_hwi (r, prec))
+             if ((HOST_WIDE_INT) r != sext_hwi (r, prec))
                *overflow = true;
            }
          else
@@ -2133,60 +2126,3 @@ wi::only_sign_bit_p (const wide_int_ref
 void gt_ggc_mx (widest_int *) { }
 void gt_pch_nx (widest_int *, void (*) (void *, void *), void *) { }
 void gt_pch_nx (widest_int *) { }
-
-/*
- * Private debug printing routines.
- */
-#ifdef DEBUG_WIDE_INT
-/* The debugging routines print results of wide operations into the
-   dump files of the respective passes in which they were called.  */
-static char *
-dumpa (const HOST_WIDE_INT *val, unsigned int len, unsigned int prec, char 
*buf)
-{
-  int i;
-  unsigned int l;
-  const char * sep = "";
-
-  l = sprintf (buf, "[%d (", prec);
-  for (i = len - 1; i >= 0; i--)
-    {
-      l += sprintf (&buf[l], "%s" HOST_WIDE_INT_PRINT_HEX, sep, val[i]);
-      sep = " ";
-    }
-
-  gcc_assert (len != 0);
-
-  l += sprintf (&buf[l], ")]");
-
-  gcc_assert (l < MAX_SIZE);
-  return buf;
-
-
-}
-#endif
-
-#if 0
-/* The debugging routines print results of wide operations into the
-   dump files of the respective passes in which they were called.  */
-char *
-wide_int_ro::dump (char* buf) const
-{
-  int i;
-  unsigned int l;
-  const char * sep = "";
-
-  l = sprintf (buf, "[%d (", precision);
-  for (i = len - 1; i >= 0; i--)
-    {
-      l += sprintf (&buf[l], "%s" HOST_WIDE_INT_PRINT_HEX, sep, val[i]);
-      sep = " ";
-    }
-
-  gcc_assert (len != 0);
-
-  l += sprintf (&buf[l], ")]");
-
-  gcc_assert (l < MAX_SIZE);
-  return buf;
-}
-#endif
Index: gcc/wide-int.h
===================================================================
--- gcc/wide-int.h      2014-04-25 11:33:57.810153815 +0100
+++ gcc/wide-int.h      2014-04-25 11:33:57.818153878 +0100
@@ -98,8 +98,8 @@ #define WIDE_INT_H
 
      1) Shifts and rotations are just weird.  You have to specify a
      precision in which the shift or rotate is to happen in.  The bits
-     above this precision remain unchanged.  While this is what you
-     want, it is clearly is non obvious.
+     above this precision are zeroed.  While this is what you
+     want, it is clearly non obvious.
 
      2) Larger precision math sometimes does not produce the same
      answer as would be expected for doing the math at the proper
@@ -149,7 +149,7 @@ #define WIDE_INT_H
             wide_int x = t;
 
    However, a little more syntax is required for rtl constants since
-   they do have an explicit precision.  To make an rtl into a
+   they do not have an explicit precision.  To make an rtl into a
    wide_int, you have to pair it with a mode.  The canonical way to do
    this is with std::make_pair as in:
 
@@ -159,8 +159,8 @@ #define WIDE_INT_H
    Similarly, a wide_int can only be constructed from a host value if
    the target precision is given explicitly, such as in:
 
-            wide_int x = wi::shwi (c, prec); // sign-extend X if necessary
-            wide_int y = wi::uhwi (c, prec); // zero-extend X if necessary
+            wide_int x = wi::shwi (c, prec); // sign-extend C if necessary
+            wide_int y = wi::uhwi (c, prec); // zero-extend C if necessary
 
    However, offset_int and widest_int have an inherent precision and so
    can be initialized directly from a host value:
@@ -223,15 +223,11 @@ #define WIDE_INT_H
 #include "signop.h"
 #include "insn-modes.h"
 
-#if 0
-#define DEBUG_WIDE_INT
-#endif
-
 /* The MAX_BITSIZE_MODE_ANY_INT is automatically generated by a very
    early examination of the target's mode file.  The WIDE_INT_MAX_ELTS
    can accomodate at least 1 more bit so that unsigned numbers of that
-   mode can be represented.  Note that it is still possible to create
-   fixed_wide_ints that have precisions greater than
+   mode can be represented as a signed value.  Note that it is still
+   possible to create fixed_wide_ints that have precisions greater than
    MAX_BITSIZE_MODE_ANY_INT.  This can be useful when representing a
    double-width multiplication result, for example.  */
 #define WIDE_INT_MAX_ELTS \
@@ -251,11 +247,12 @@ #define ADDR_MAX_BITSIZE 64
 
 /* This is the internal precision used when doing any address
    arithmetic.  The '4' is really 3 + 1.  Three of the bits are for
-   the number of extra bits needed to do bit addresses and single bit is
-   allow everything to be signed without loosing any precision.  Then
-   everything is rounded up to the next HWI for efficiency.  */
+   the number of extra bits needed to do bit addresses and the other bit
+   is to allow everything to be signed without loosing any precision.
+   Then everything is rounded up to the next HWI for efficiency.  */
 #define ADDR_MAX_PRECISION \
-  ((ADDR_MAX_BITSIZE + 4 + HOST_BITS_PER_WIDE_INT - 1) & 
~(HOST_BITS_PER_WIDE_INT - 1))
+  ((ADDR_MAX_BITSIZE + 4 + HOST_BITS_PER_WIDE_INT - 1) \
+   & ~(HOST_BITS_PER_WIDE_INT - 1))
 
 /* The number of HWIs needed to store an offset_int.  */
 #define OFFSET_INT_ELTS (ADDR_MAX_PRECISION / HOST_BITS_PER_WIDE_INT)
@@ -270,9 +267,9 @@ #define WI_UNARY_RESULT(T) \
   typename wi::unary_traits <T>::result_type
 
 /* Define a variable RESULT to hold the result of a binary operation on
-   X and Y, which have types T1 and T2 respectively.  Define VAR to
+   X and Y, which have types T1 and T2 respectively.  Define VAL to
    point to the blocks of RESULT.  Once the user of the macro has
-   filled in VAR, it should call RESULT.set_len to set the number
+   filled in VAL, it should call RESULT.set_len to set the number
    of initialized blocks.  */
 #define WI_BINARY_RESULT_VAR(RESULT, VAL, T1, X, T2, Y) \
   WI_BINARY_RESULT (T1, T2) RESULT = \
@@ -712,8 +709,6 @@ #define INCDEC_OPERATOR(OP, DELTA) \
 #undef ASSIGNMENT_OPERATOR
 #undef INCDEC_OPERATOR
 
-  char *dump (char *) const;
-
   static const bool is_sign_extended
     = wi::int_traits <generic_wide_int <storage> >::is_sign_extended;
 };
@@ -2568,6 +2563,7 @@ wi::div_ceil (const T1 &x, const T2 &y,
   return quotient;
 }
 
+/* Return X / Y, rouding towards +inf.  Treat X and Y as unsigned values.  */
 template <typename T1, typename T2>
 inline WI_BINARY_RESULT (T1, T2)
 wi::udiv_ceil (const T1 &x, const T2 &y)
@@ -2923,8 +2919,7 @@ wi::arshift (const T1 &x, const T2 &y)
 }
 
 /* Return X >> Y, using an arithmetic shift if SGN is SIGNED and a
-   logical shift otherwise.  If BITSIZE is nonzero, only use the low
-   BITSIZE bits of Y.  */
+   logical shift otherwise.  */
 template <typename T1, typename T2>
 inline WI_UNARY_RESULT (T1)
 wi::rshift (const T1 &x, const T2 &y, signop sgn)
@@ -2982,8 +2977,7 @@ wi::parity (const wide_int_ref &x)
 /* Extract WIDTH bits from X, starting at BITPOS.  */
 template <typename T>
 inline unsigned HOST_WIDE_INT
-wi::extract_uhwi (const T &x, unsigned int bitpos,
-                 unsigned int width)
+wi::extract_uhwi (const T &x, unsigned int bitpos, unsigned int width)
 {
   unsigned precision = get_precision (x);
   if (precision < bitpos + width)

Reply via email to