diff mbox

[cxx-conversion] Make double_int a class with methods and operators. (issue6443093)

Message ID 20120807003514.1236A2226A9@jade.mtv.corp.google.com
State New
Headers show

Commit Message

Lawrence Crowl Aug. 7, 2012, 12:35 a.m. UTC
Convert double_int from a struct with function into a class with
operators and methods.

This patch adds the methods and operators.  In general functions of
the form "double_int_whatever" become member functions "whatever" or,
when possible, operators.

Every attempt has been made to preserve the existing algorithms, even
at the expense of some optimization opportunities.  Some examples:

  The ext operation takes a value and returns a value.  However, that
  return value is usually assigned to the original variable.  An
  operation that modified a variable would be more efficient.

  In some cases, an outer sign-specific function calls an inner
  function with the sign as a parameter, which then decides which
  implementation to do.  Decisions should not be artificially
  introduced, and the implementation of each case should be exposed as
  a separate routine.

  The existing operations are implemented in terms of the new
  operations, which necessarily adds a layer between the new code and
  the existing users.  Once all files have migrated, this layer will
  be removed.

  There are several existing operations implemented in terms of even
  older legacy operations.  This extra layer has not been removed.

On occasion though, parameterized functions are often called
with a constant argments.  To support static statement of intent,
and potentially faster code in the future, there are several new
unparameterized member functions.  Some examples:

  Four routines now encode both 'arithmetic or logical' and 'right or
  left' shift as part of the funciton name.

  Four routines now encode both 'signed or unsigned' and 'less than or
  greater than' as part of the function name.

This patch also converts the file fixed-value.c as an example of the
kind of source level changes.  As part of the process, some of the
"grandfather" calls have been migrated.

To preserve sensible diffs, some transitional local reference
variables have been introduced into the code.  These reference
variables provide the same name for access to *this that the functions
formerly used as parameter names.  As a result, many expressions are
the same and show no diff.  Later patches can remove the transitional
reference variable.

So, this patch is an intermediate patch.  The time for the compiler to
build itself is 0.7% longer.  Most of that should be recovered when
uses of the old interface are removed and the extra layer of functions
are no longer present.  Further performance should be available from
factoring an implementation that will no longer be exposed to clients.

Tested on x86.



--
This patch is available for review at http://codereview.appspot.com/6443093

Comments

Richard Biener Aug. 7, 2012, 8:16 a.m. UTC | #1
On Tue, Aug 7, 2012 at 2:35 AM, Lawrence Crowl <crowl@google.com> wrote:
> Convert double_int from a struct with function into a class with
> operators and methods.
>
> This patch adds the methods and operators.  In general functions of
> the form "double_int_whatever" become member functions "whatever" or,
> when possible, operators.
>
> Every attempt has been made to preserve the existing algorithms, even
> at the expense of some optimization opportunities.  Some examples:
>
>   The ext operation takes a value and returns a value.  However, that
>   return value is usually assigned to the original variable.  An
>   operation that modified a variable would be more efficient.

That's not always the case though and I think the interface should be
consistent with existing behavior to avoid errors creeping in during the
transition.

>   In some cases, an outer sign-specific function calls an inner
>   function with the sign as a parameter, which then decides which
>   implementation to do.  Decisions should not be artificially
>   introduced, and the implementation of each case should be exposed as
>   a separate routine.
>
>   The existing operations are implemented in terms of the new
>   operations, which necessarily adds a layer between the new code and
>   the existing users.  Once all files have migrated, this layer will
>   be removed.
>
>   There are several existing operations implemented in terms of even
>   older legacy operations.  This extra layer has not been removed.
>
> On occasion though, parameterized functions are often called
> with a constant argments.  To support static statement of intent,
> and potentially faster code in the future, there are several new
> unparameterized member functions.  Some examples:
>
>   Four routines now encode both 'arithmetic or logical' and 'right or
>   left' shift as part of the funciton name.
>
>   Four routines now encode both 'signed or unsigned' and 'less than or
>   greater than' as part of the function name.

For most parts overloads that take an (unsigned) HOST_WIDE_INT argument
would be nice, as well as the ability to say dbl + 1.

> -typedef struct
> +typedef struct double_int
>  {
> +public:
> +  /* Normally, we would define constructors to create instances.
> +     Two things prevent us from doing so.
> +     First, defining a constructor makes the class non-POD in C++03,
> +     and we certainly want double_int to be a POD.
> +     Second, the GCC conding conventions prefer explicit conversion,
> +     and explicit conversion operators are not available until C++11.  */
> +
> +  static double_int make (unsigned HOST_WIDE_INT cst);
> +  static double_int make (HOST_WIDE_INT cst);
> +  static double_int make (unsigned int cst);
> +  static double_int make (int cst);

Did we somehow decide to not allow constructors?  It's odd to convert to
C++ and end up with static member functions resembling them ...

Also I believe the conversion above introduces possible migration errors.
Think of a previous

 HOST_WIDE_INT a;
 double_int d = uhwi_to_double_int (a);

if you write that now as

 HOST_WIDE_INT a;
 double_int d = double_int::make (a);

you get the effect of shwi_to_double_int.  Oops.  So as an intermediate
I'd like you _not_ to introduce the make () overloads.

Btw, if HOST_WIDE_INT == int the above won't even compile.

Richard.

> +  /* No copy assignment operator or destructor to keep the type a POD.  */
> +
> +  /* There are some special value-creation static member functions.  */
> +
> +  static double_int mask (unsigned prec);
> +  static double_int max_value (unsigned int prec, bool uns);
> +  static double_int min_value (unsigned int prec, bool uns);
> +
> +  /* The following functions are mutating operations.  */
> +
> +  double_int &operator ++(); // prefix
> +  double_int &operator --(); // prefix
> +  double_int &operator *= (double_int);
> +  double_int &operator += (double_int);
> +  double_int &operator -= (double_int);
> +
> +  /* The following functions are non-mutating operations.  */
> +
> +  /* Conversion functions.  */
> +
> +  HOST_WIDE_INT to_signed () const;
> +  unsigned HOST_WIDE_INT to_unsigned () const;
> +
> +  /* Conversion query functions.  */
> +
> +  bool fits_unsigned() const;
> +  bool fits_signed() const;
> +  bool fits (bool uns) const;
> +
> +  /* Attribute query functions.  */
> +
> +  int trailing_zeros () const;
> +  int popcount () const;
> +
> +  /* Arithmetic query operations.  */
> +
> +  bool multiple_of (double_int, bool, double_int *) const;
> +
> +  /* Arithmetic operation functions.  */
> +
> +  double_int set_bit (unsigned) const;
> +  double_int mul_with_sign (double_int, bool, int *) const;
> +
> +  double_int operator * (double_int b) const;
> +  double_int operator + (double_int b) const;
> +  double_int operator - (double_int b) const;
> +  double_int operator - () const;
> +  double_int operator ~ () const;
> +  double_int operator & (double_int b) const;
> +  double_int operator | (double_int b) const;
> +  double_int operator ^ (double_int b) const;
> +  double_int and_not (double_int b) const;
> +
> +  double_int lshift (HOST_WIDE_INT count, unsigned int prec, bool arith) const;
> +  double_int rshift (HOST_WIDE_INT count, unsigned int prec, bool arith) const;
> +  double_int alshift (HOST_WIDE_INT count, unsigned int prec) const;
> +  double_int arshift (HOST_WIDE_INT count, unsigned int prec) const;
> +  double_int llshift (HOST_WIDE_INT count, unsigned int prec) const;
> +  double_int lrshift (HOST_WIDE_INT count, unsigned int prec) const;
> +  double_int lrotate (HOST_WIDE_INT count, unsigned int prec) const;
> +  double_int rrotate (HOST_WIDE_INT count, unsigned int prec) const;
> +
> +  /* You must ensure that double_int::ext is called on the operands
> +     of the following operations, if the precision of the numbers
> +     is less than HOST_BITS_PER_DOUBLE_INT bits.  */
> +  double_int div (double_int, bool, unsigned) const;
> +  double_int sdiv (double_int, unsigned) const;
> +  double_int udiv (double_int, unsigned) const;
> +  double_int mod (double_int, bool, unsigned) const;
> +  double_int smod (double_int, unsigned) const;
> +  double_int umod (double_int, unsigned) const;
> +  double_int divmod (double_int, bool, unsigned, double_int *) const;
> +  double_int sdivmod (double_int, unsigned, double_int *) const;
> +  double_int udivmod (double_int, unsigned, double_int *) const;
> +
> +  /* Precision control functions.  */
> +
> +  double_int ext (unsigned prec, bool uns) const;
> +  double_int zext (unsigned prec) const;
> +  double_int sext (unsigned prec) const;
> +
> +  /* Comparative functions.  */
> +
> +  bool is_zero () const;
> +  bool is_one () const;
> +  bool is_minus_one () const;
> +  bool is_negative () const;
> +
> +  int cmp (double_int b, bool uns) const;
> +  int ucmp (double_int b) const;
> +  int scmp (double_int b) const;
> +
> +  bool ult (double_int b) const;
> +  bool ugt (double_int b) const;
> +  bool slt (double_int b) const;
> +  bool sgt (double_int b) const;
> +
> +  double_int max (double_int b, bool uns);
> +  double_int smax (double_int b);
> +  double_int umax (double_int b);
> +
> +  double_int min (double_int b, bool uns);
> +  double_int smin (double_int b);
> +  double_int umin (double_int b);
> +
> +  bool operator == (double_int cst2) const;
> +  bool operator != (double_int cst2) const;
> +
> +  /* Please migrate away from using these member variables publically.  */
> +
>    unsigned HOST_WIDE_INT low;
>    HOST_WIDE_INT high;
> +
>  } double_int;
>
>  #define HOST_BITS_PER_DOUBLE_INT (2 * HOST_BITS_PER_WIDE_INT)
> @@ -63,66 +187,160 @@ typedef struct
>  /* Constructs double_int from integer CST.  The bits over the precision of
>     HOST_WIDE_INT are filled with the sign bit.  */
>
> -static inline double_int
> -shwi_to_double_int (HOST_WIDE_INT cst)
> +inline
> +double_int double_int::make (HOST_WIDE_INT cst)
>  {
>    double_int r;
> -
>    r.low = (unsigned HOST_WIDE_INT) cst;
>    r.high = cst < 0 ? -1 : 0;
> -
>    return r;
>  }
>
> +inline
> +double_int double_int::make (int cst)
> +{
> +  return double_int::make (static_cast <HOST_WIDE_INT> (cst));
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
> +static inline double_int
> +shwi_to_double_int (HOST_WIDE_INT cst)
> +{
> +  return double_int::make (cst);
> +}
> +
>  /* Some useful constants.  */
> +/* FIXME(crowl): Maybe remove after converting callers?
> +   The problem is that a named constant would not be as optimizable,
> +   while the functional syntax is more verbose.  */
>
> -#define double_int_minus_one (shwi_to_double_int (-1))
> -#define double_int_zero (shwi_to_double_int (0))
> -#define double_int_one (shwi_to_double_int (1))
> -#define double_int_two (shwi_to_double_int (2))
> -#define double_int_ten (shwi_to_double_int (10))
> +#define double_int_minus_one (double_int::make (-1))
> +#define double_int_zero (double_int::make (0))
> +#define double_int_one (double_int::make (1))
> +#define double_int_two (double_int::make (2))
> +#define double_int_ten (double_int::make (10))
>
>  /* Constructs double_int from unsigned integer CST.  The bits over the
>     precision of HOST_WIDE_INT are filled with zeros.  */
>
> -static inline double_int
> -uhwi_to_double_int (unsigned HOST_WIDE_INT cst)
> +inline
> +double_int double_int::make (unsigned HOST_WIDE_INT cst)
>  {
>    double_int r;
> -
>    r.low = cst;
>    r.high = 0;
> -
>    return r;
>  }
>
> +inline
> +double_int double_int::make (unsigned int cst)
> +{
> +  return double_int::make (static_cast <unsigned HOST_WIDE_INT> (cst));
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
> +static inline double_int
> +uhwi_to_double_int (unsigned HOST_WIDE_INT cst)
> +{
> +  return double_int::make (cst);
> +}
> +
> +inline double_int &
> +double_int::operator ++ ()
> +{
> +  *this + double_int_one;
> +  return *this;
> +}
> +
> +inline double_int &
> +double_int::operator -- ()
> +{
> +  *this - double_int_one;
> +  return *this;
> +}
> +
> +inline double_int &
> +double_int::operator *= (double_int b)
> +{
> +  *this = *this * b;
> +  return *this;
> +}
> +
> +inline double_int &
> +double_int::operator += (double_int b)
> +{
> +  *this = *this + b;
> +  return *this;
> +}
> +
> +inline double_int &
> +double_int::operator -= (double_int b)
> +{
> +  *this = *this - b;
> +  return *this;
> +}
> +
>  /* Returns value of CST as a signed number.  CST must satisfy
> -   double_int_fits_in_shwi_p.  */
> +   double_int::fits_signed.  */
> +
> +inline HOST_WIDE_INT
> +double_int::to_signed () const
> +{
> +  return (HOST_WIDE_INT) low;
> +}
>
> +/* FIXME(crowl): Remove after converting callers.  */
>  static inline HOST_WIDE_INT
>  double_int_to_shwi (double_int cst)
>  {
> -  return (HOST_WIDE_INT) cst.low;
> +  return cst.to_signed ();
>  }
>
>  /* Returns value of CST as an unsigned number.  CST must satisfy
> -   double_int_fits_in_uhwi_p.  */
> +   double_int::fits_unsigned.  */
> +
> +inline unsigned HOST_WIDE_INT
> +double_int::to_unsigned () const
> +{
> +  return low;
> +}
>
> +/* FIXME(crowl): Remove after converting callers.  */
>  static inline unsigned HOST_WIDE_INT
>  double_int_to_uhwi (double_int cst)
>  {
> -  return cst.low;
> +  return cst.to_unsigned ();
>  }
>
> -bool double_int_fits_in_hwi_p (double_int, bool);
> -bool double_int_fits_in_shwi_p (double_int);
> -
>  /* Returns true if CST fits in unsigned HOST_WIDE_INT.  */
>
> +inline bool
> +double_int::fits_unsigned () const
> +{
> +  return high == 0;
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
>  static inline bool
>  double_int_fits_in_uhwi_p (double_int cst)
>  {
> -  return cst.high == 0;
> +  return cst.fits_unsigned ();
> +}
> +
> +/* Returns true if CST fits in signed HOST_WIDE_INT.  */
> +
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline bool
> +double_int_fits_in_shwi_p (double_int cst)
> +{
> +  return cst.fits_signed ();
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline bool
> +double_int_fits_in_hwi_p (double_int cst, bool uns)
> +{
> +  return cst.fits (uns);
>  }
>
>  /* The following operations perform arithmetics modulo 2^precision,
> @@ -130,88 +348,258 @@ double_int_fits_in_uhwi_p (double_int cs
>     you are representing numbers with precision less than
>     HOST_BITS_PER_DOUBLE_INT bits.  */
>
> -double_int double_int_mul (double_int, double_int);
> -double_int double_int_mul_with_sign (double_int, double_int, bool, int *);
> -double_int double_int_add (double_int, double_int);
> -double_int double_int_sub (double_int, double_int);
> -double_int double_int_neg (double_int);
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline double_int
> +double_int_mul (double_int a, double_int b)
> +{
> +  return a * b;
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline double_int
> +double_int_mul_with_sign (double_int a, double_int b,
> +                         bool unsigned_p, int *overflow)
> +{
> +  return a.mul_with_sign (b, unsigned_p, overflow);
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline double_int
> +double_int_add (double_int a, double_int b)
> +{
> +  return a + b;
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline double_int
> +double_int_sub (double_int a, double_int b)
> +{
> +  return a - b;
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline double_int
> +double_int_neg (double_int a)
> +{
> +  return -a;
> +}
>
>  /* You must ensure that double_int_ext is called on the operands
>     of the following operations, if the precision of the numbers
>     is less than HOST_BITS_PER_DOUBLE_INT bits.  */
> -double_int double_int_div (double_int, double_int, bool, unsigned);
> -double_int double_int_sdiv (double_int, double_int, unsigned);
> -double_int double_int_udiv (double_int, double_int, unsigned);
> -double_int double_int_mod (double_int, double_int, bool, unsigned);
> -double_int double_int_smod (double_int, double_int, unsigned);
> -double_int double_int_umod (double_int, double_int, unsigned);
> -double_int double_int_divmod (double_int, double_int, bool, unsigned, double_int *);
> -double_int double_int_sdivmod (double_int, double_int, unsigned, double_int *);
> -double_int double_int_udivmod (double_int, double_int, unsigned, double_int *);
>
> -bool double_int_multiple_of (double_int, double_int, bool, double_int *);
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline double_int
> +double_int_div (double_int a, double_int b, bool uns, unsigned code)
> +{
> +  return a.div (b, uns, code);
> +}
>
> -double_int double_int_setbit (double_int, unsigned);
> -int double_int_ctz (double_int);
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline double_int
> +double_int_sdiv (double_int a, double_int b, unsigned code)
> +{
> +  return a.sdiv (b, code);
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline double_int
> +double_int_udiv (double_int a, double_int b, unsigned code)
> +{
> +  return a.udiv (b, code);
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline double_int
> +double_int_mod (double_int a, double_int b, bool uns, unsigned code)
> +{
> +  return a.mod (b, uns, code);
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline double_int
> +double_int_smod (double_int a, double_int b, unsigned code)
> +{
> +  return a.smod (b, code);
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline double_int
> +double_int_umod (double_int a, double_int b, unsigned code)
> +{
> +  return a.umod (b, code);
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline double_int
> +double_int_divmod (double_int a, double_int b, bool uns,
> +                  unsigned code, double_int *mod)
> +{
> +  return a.divmod (b, uns, code, mod);
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline double_int
> +double_int_sdivmod (double_int a, double_int b, unsigned code, double_int *mod)
> +{
> +  return a.sdivmod (b, code, mod);
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline double_int
> +double_int_udivmod (double_int a, double_int b, unsigned code, double_int *mod)
> +{
> +  return a.udivmod (b, code, mod);
> +}
> +
> +/***/
> +
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline bool
> +double_int_multiple_of (double_int product, double_int factor,
> +                        bool unsigned_p, double_int *multiple)
> +{
> +  return product.multiple_of (factor, unsigned_p, multiple);
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline double_int
> +double_int_setbit (double_int a, unsigned bitpos)
> +{
> +  return a.set_bit (bitpos);
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline int
> +double_int_ctz (double_int a)
> +{
> +  return a.trailing_zeros ();
> +}
>
>  /* Logical operations.  */
>
>  /* Returns ~A.  */
>
> +inline double_int
> +double_int::operator ~ () const
> +{
> +  double_int result;
> +  result.low = ~low;
> +  result.high = ~high;
> +  return result;
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
>  static inline double_int
>  double_int_not (double_int a)
>  {
> -  a.low = ~a.low;
> -  a.high = ~a.high;
> -  return a;
> +  return ~a;
>  }
>
>  /* Returns A | B.  */
>
> +inline double_int
> +double_int::operator | (double_int b) const
> +{
> +  double_int result;
> +  result.low = low | b.low;
> +  result.high = high | b.high;
> +  return result;
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
>  static inline double_int
>  double_int_ior (double_int a, double_int b)
>  {
> -  a.low |= b.low;
> -  a.high |= b.high;
> -  return a;
> +  return a | b;
>  }
>
>  /* Returns A & B.  */
>
> +inline double_int
> +double_int::operator & (double_int b) const
> +{
> +  double_int result;
> +  result.low = low & b.low;
> +  result.high = high & b.high;
> +  return result;
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
>  static inline double_int
>  double_int_and (double_int a, double_int b)
>  {
> -  a.low &= b.low;
> -  a.high &= b.high;
> -  return a;
> +  return a & b;
>  }
>
>  /* Returns A & ~B.  */
>
> +inline double_int
> +double_int::and_not (double_int b) const
> +{
> +  double_int result;
> +  result.low = low & ~b.low;
> +  result.high = high & ~b.high;
> +  return result;
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
>  static inline double_int
>  double_int_and_not (double_int a, double_int b)
>  {
> -  a.low &= ~b.low;
> -  a.high &= ~b.high;
> -  return a;
> +  return a.and_not (b);
>  }
>
>  /* Returns A ^ B.  */
>
> +inline double_int
> +double_int::operator ^ (double_int b) const
> +{
> +  double_int result;
> +  result.low = low ^ b.low;
> +  result.high = high ^ b.high;
> +  return result;
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
>  static inline double_int
>  double_int_xor (double_int a, double_int b)
>  {
> -  a.low ^= b.low;
> -  a.high ^= b.high;
> -  return a;
> +  return a ^ b;
>  }
>
>
>  /* Shift operations.  */
> -double_int double_int_lshift (double_int, HOST_WIDE_INT, unsigned int, bool);
> -double_int double_int_rshift (double_int, HOST_WIDE_INT, unsigned int, bool);
> -double_int double_int_lrotate (double_int, HOST_WIDE_INT, unsigned int);
> -double_int double_int_rrotate (double_int, HOST_WIDE_INT, unsigned int);
> +
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline double_int
> +double_int_lshift (double_int a, HOST_WIDE_INT count, unsigned int prec,
> +                  bool arith)
> +{
> +  return a.lshift (count, prec, arith);
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline double_int
> +double_int_rshift (double_int a, HOST_WIDE_INT count, unsigned int prec,
> +                  bool arith)
> +{
> +  return a.rshift (count, prec, arith);
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline double_int
> +double_int_lrotate (double_int a, HOST_WIDE_INT count, unsigned int prec)
> +{
> +  return a.lrotate (count, prec);
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline double_int
> +double_int_rrotate (double_int a, HOST_WIDE_INT count, unsigned int prec)
> +{
> +  return a.rrotate (count, prec);
> +}
>
>  /* Returns true if CST is negative.  Of course, CST is considered to
>     be signed.  */
> @@ -222,29 +610,115 @@ double_int_negative_p (double_int cst)
>    return cst.high < 0;
>  }
>
> -int double_int_cmp (double_int, double_int, bool);
> -int double_int_scmp (double_int, double_int);
> -int double_int_ucmp (double_int, double_int);
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline int
> +double_int_cmp (double_int a, double_int b, bool uns)
> +{
> +  return a.cmp (b, uns);
> +}
>
> -double_int double_int_max (double_int, double_int, bool);
> -double_int double_int_smax (double_int, double_int);
> -double_int double_int_umax (double_int, double_int);
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline int
> +double_int_scmp (double_int a, double_int b)
> +{
> +  return a.scmp (b);
> +}
>
> -double_int double_int_min (double_int, double_int, bool);
> -double_int double_int_smin (double_int, double_int);
> -double_int double_int_umin (double_int, double_int);
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline int
> +double_int_ucmp (double_int a, double_int b)
> +{
> +  return a.ucmp (b);
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline double_int
> +double_int_max (double_int a, double_int b, bool uns)
> +{
> +  return a.max (b, uns);
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline double_int
> +double_int_smax (double_int a, double_int b)
> +{
> +  return a.smax (b);
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline double_int
> +double_int_umax (double_int a, double_int b)
> +{
> +  return a.umax (b);
> +}
> +
> +
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline double_int
> +double_int_min (double_int a, double_int b, bool uns)
> +{
> +  return a.min (b, uns);
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline double_int
> +double_int_smin (double_int a, double_int b)
> +{
> +  return a.smin (b);
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline double_int
> +double_int_umin (double_int a, double_int b)
> +{
> +  return a.umin (b);
> +}
>
>  void dump_double_int (FILE *, double_int, bool);
>
>  /* Zero and sign extension of numbers in smaller precisions.  */
>
> -double_int double_int_ext (double_int, unsigned, bool);
> -double_int double_int_sext (double_int, unsigned);
> -double_int double_int_zext (double_int, unsigned);
> -double_int double_int_mask (unsigned);
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline double_int
> +double_int_ext (double_int a, unsigned prec, bool uns)
> +{
> +  return a.ext (prec, uns);
> +}
>
> -double_int double_int_max_value (unsigned int, bool);
> -double_int double_int_min_value (unsigned int, bool);
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline double_int
> +double_int_sext (double_int a, unsigned prec)
> +{
> +  return a.sext (prec);
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline double_int
> +double_int_zext (double_int a, unsigned prec)
> +{
> +  return a.zext (prec);
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline double_int
> +double_int_mask (unsigned prec)
> +{
> +  return double_int::mask (prec);
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline double_int
> +double_int_max_value (unsigned int prec, bool uns)
> +{
> +  return double_int::max_value (prec, uns);
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
> +inline double_int
> +double_int_min_value (unsigned int prec, bool uns)
> +{
> +  return double_int::min_value (prec, uns);
> +}
>
>  #define ALL_ONES (~((unsigned HOST_WIDE_INT) 0))
>
> @@ -254,64 +728,122 @@ double_int double_int_min_value (unsigne
>
>  /* Returns true if CST is zero.  */
>
> +inline bool
> +double_int::is_zero () const
> +{
> +  return low == 0 && high == 0;
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
>  static inline bool
>  double_int_zero_p (double_int cst)
>  {
> -  return cst.low == 0 && cst.high == 0;
> +  return cst.is_zero ();
>  }
>
>  /* Returns true if CST is one.  */
>
> +inline bool
> +double_int::is_one () const
> +{
> +  return low == 1 && high == 0;
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
>  static inline bool
>  double_int_one_p (double_int cst)
>  {
> -  return cst.low == 1 && cst.high == 0;
> +  return cst.is_one ();
>  }
>
>  /* Returns true if CST is minus one.  */
>
> +inline bool
> +double_int::is_minus_one () const
> +{
> +  return low == ALL_ONES && high == -1;
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
>  static inline bool
>  double_int_minus_one_p (double_int cst)
>  {
> -  return (cst.low == ALL_ONES && cst.high == -1);
> +  return cst.is_minus_one ();
> +}
> +
> +/* Returns true if CST is negative.  */
> +
> +inline bool
> +double_int::is_negative () const
> +{
> +  return high < 0;
>  }
>
>  /* Returns true if CST1 == CST2.  */
>
> +inline bool
> +double_int::operator == (double_int cst2) const
> +{
> +  return low == cst2.low && high == cst2.high;
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
>  static inline bool
>  double_int_equal_p (double_int cst1, double_int cst2)
>  {
> -  return cst1.low == cst2.low && cst1.high == cst2.high;
> +  return cst1 == cst2;
> +}
> +
> +/* Returns true if CST1 != CST2.  */
> +
> +inline bool
> +double_int::operator != (double_int cst2) const
> +{
> +  return low != cst2.low || high != cst2.high;
>  }
>
>  /* Return number of set bits of CST.  */
>
> +inline int
> +double_int::popcount () const
> +{
> +  return popcount_hwi (high) + popcount_hwi (low);
> +}
> +
> +/* FIXME(crowl): Remove after converting callers.  */
>  static inline int
>  double_int_popcount (double_int cst)
>  {
> -  return popcount_hwi (cst.high) + popcount_hwi (cst.low);
> +  return cst.popcount ();
>  }
>
>
>  /* Legacy interface with decomposed high/low parts.  */
>
> +/* FIXME(crowl): Remove after converting callers.  */
>  extern int add_double_with_sign (unsigned HOST_WIDE_INT, HOST_WIDE_INT,
>                                  unsigned HOST_WIDE_INT, HOST_WIDE_INT,
>                                  unsigned HOST_WIDE_INT *, HOST_WIDE_INT *,
>                                  bool);
> +/* FIXME(crowl): Remove after converting callers.  */
>  #define add_double(l1,h1,l2,h2,lv,hv) \
>    add_double_with_sign (l1, h1, l2, h2, lv, hv, false)
> +/* FIXME(crowl): Remove after converting callers.  */
>  extern int neg_double (unsigned HOST_WIDE_INT, HOST_WIDE_INT,
>                        unsigned HOST_WIDE_INT *, HOST_WIDE_INT *);
> +/* FIXME(crowl): Remove after converting callers.  */
>  extern int mul_double_with_sign (unsigned HOST_WIDE_INT, HOST_WIDE_INT,
>                                  unsigned HOST_WIDE_INT, HOST_WIDE_INT,
>                                  unsigned HOST_WIDE_INT *, HOST_WIDE_INT *,
>                                  bool);
> +/* FIXME(crowl): Remove after converting callers.  */
>  #define mul_double(l1,h1,l2,h2,lv,hv) \
>    mul_double_with_sign (l1, h1, l2, h2, lv, hv, false)
> +/* FIXME(crowl): Remove after converting callers.  */
>  extern void lshift_double (unsigned HOST_WIDE_INT, HOST_WIDE_INT,
>                            HOST_WIDE_INT, unsigned int,
>                            unsigned HOST_WIDE_INT *, HOST_WIDE_INT *, bool);
> +/* FIXME(crowl): Remove after converting callers.  */
>  extern int div_and_round_double (unsigned, int, unsigned HOST_WIDE_INT,
>                                  HOST_WIDE_INT, unsigned HOST_WIDE_INT,
>                                  HOST_WIDE_INT, unsigned HOST_WIDE_INT *,
> Index: gcc/fixed-value.c
> ===================================================================
> --- gcc/fixed-value.c   (revision 190186)
> +++ gcc/fixed-value.c   (working copy)
> @@ -111,13 +111,11 @@ fixed_from_string (FIXED_VALUE_TYPE *f,
>        /* From the spec, we need to evaluate 1 to the maximal value.  */
>        f->data.low = -1;
>        f->data.high = -1;
> -      f->data = double_int_ext (f->data,
> -                               GET_MODE_FBIT (f->mode)
> -                               + GET_MODE_IBIT (f->mode), 1);
> +      f->data = f->data.zext (GET_MODE_FBIT (f->mode)
> +                               + GET_MODE_IBIT (f->mode));
>      }
>    else
> -    f->data = double_int_ext (f->data,
> -                             SIGNED_FIXED_POINT_MODE_P (f->mode)
> +    f->data = f->data.ext (SIGNED_FIXED_POINT_MODE_P (f->mode)
>                               + GET_MODE_FBIT (f->mode)
>                               + GET_MODE_IBIT (f->mode),
>                               UNSIGNED_FIXED_POINT_MODE_P (f->mode));
> @@ -159,8 +157,8 @@ fixed_saturate1 (enum machine_mode mode,
>        double_int max;
>        max.low = -1;
>        max.high = -1;
> -      max = double_int_ext (max, i_f_bits, 1);
> -      if (double_int_cmp (a, max, 1) == 1)
> +      max = max.zext (i_f_bits);
> +      if (a.ugt (max))
>         {
>           if (sat_p)
>             *f = max;
> @@ -173,21 +171,19 @@ fixed_saturate1 (enum machine_mode mode,
>        double_int max, min;
>        max.high = -1;
>        max.low = -1;
> -      max = double_int_ext (max, i_f_bits, 1);
> +      max = max.zext (i_f_bits);
>        min.high = 0;
>        min.low = 1;
> -      lshift_double (min.low, min.high, i_f_bits,
> -                    HOST_BITS_PER_DOUBLE_INT,
> -                    &min.low, &min.high, 1);
> -      min = double_int_ext (min, 1 + i_f_bits, 0);
> -      if (double_int_cmp (a, max, 0) == 1)
> +      min = min.alshift (i_f_bits, HOST_BITS_PER_DOUBLE_INT);
> +      min = min.sext (1 + i_f_bits);
> +      if (a.sgt (max))
>         {
>           if (sat_p)
>             *f = max;
>           else
>             overflow_p = true;
>         }
> -      else if (double_int_cmp (a, min, 0) == -1)
> +      else if (a.slt (min))
>         {
>           if (sat_p)
>             *f = min;
> @@ -221,10 +217,10 @@ fixed_saturate2 (enum machine_mode mode,
>        max_r.low = 0;
>        max_s.high = -1;
>        max_s.low = -1;
> -      max_s = double_int_ext (max_s, i_f_bits, 1);
> -      if (double_int_cmp (a_high, max_r, 1) == 1
> -         || (double_int_equal_p (a_high, max_r) &&
> -             double_int_cmp (a_low, max_s, 1) == 1))
> +      max_s = max_s.zext (i_f_bits);
> +      if (a_high.ugt (max_r)
> +         || (a_high == max_r &&
> +             a_low.ugt (max_s)))
>         {
>           if (sat_p)
>             *f = max_s;
> @@ -239,27 +235,25 @@ fixed_saturate2 (enum machine_mode mode,
>        max_r.low = 0;
>        max_s.high = -1;
>        max_s.low = -1;
> -      max_s = double_int_ext (max_s, i_f_bits, 1);
> +      max_s = max_s.zext (i_f_bits);
>        min_r.high = -1;
>        min_r.low = -1;
>        min_s.high = 0;
>        min_s.low = 1;
> -      lshift_double (min_s.low, min_s.high, i_f_bits,
> -                    HOST_BITS_PER_DOUBLE_INT,
> -                    &min_s.low, &min_s.high, 1);
> -      min_s = double_int_ext (min_s, 1 + i_f_bits, 0);
> -      if (double_int_cmp (a_high, max_r, 0) == 1
> -         || (double_int_equal_p (a_high, max_r) &&
> -             double_int_cmp (a_low, max_s, 1) == 1))
> +      min_s = min_s.alshift (i_f_bits, HOST_BITS_PER_DOUBLE_INT);
> +      min_s = min_s.sext (1 + i_f_bits);
> +      if (a_high.sgt (max_r)
> +         || (a_high == max_r &&
> +             a_low.ugt (max_s)))
>         {
>           if (sat_p)
>             *f = max_s;
>           else
>             overflow_p = true;
>         }
> -      else if (double_int_cmp (a_high, min_r, 0) == -1
> -              || (double_int_equal_p (a_high, min_r) &&
> -                  double_int_cmp (a_low, min_s, 1) == -1))
> +      else if (a_high.slt (min_r)
> +              || (a_high == min_r &&
> +                  a_low.ult (min_s)))
>         {
>           if (sat_p)
>             *f = min_s;
> @@ -297,19 +291,19 @@ do_fixed_add (FIXED_VALUE_TYPE *f, const
>    /* This was a conditional expression but it triggered a bug in
>       Sun C 5.5.  */
>    if (subtract_p)
> -    temp = double_int_neg (b->data);
> +    temp = -b->data;
>    else
>      temp = b->data;
>
>    unsigned_p = UNSIGNED_FIXED_POINT_MODE_P (a->mode);
>    i_f_bits = GET_MODE_IBIT (a->mode) + GET_MODE_FBIT (a->mode);
>    f->mode = a->mode;
> -  f->data = double_int_add (a->data, temp);
> +  f->data = a->data + temp;
>    if (unsigned_p) /* Unsigned type.  */
>      {
>        if (subtract_p) /* Unsigned subtraction.  */
>         {
> -         if (double_int_cmp (a->data, b->data, 1) == -1)
> +         if (a->data.ult (b->data))
>             {
>               if (sat_p)
>                 {
> @@ -322,9 +316,9 @@ do_fixed_add (FIXED_VALUE_TYPE *f, const
>         }
>        else /* Unsigned addition.  */
>         {
> -         f->data = double_int_ext (f->data, i_f_bits, 1);
> -         if (double_int_cmp (f->data, a->data, 1) == -1
> -             || double_int_cmp (f->data, b->data, 1) == -1)
> +         f->data = f->data.zext (i_f_bits);
> +         if (f->data.ult (a->data)
> +             || f->data.ult (b->data))
>             {
>               if (sat_p)
>                 {
> @@ -353,22 +347,17 @@ do_fixed_add (FIXED_VALUE_TYPE *f, const
>             {
>               f->data.low = 1;
>               f->data.high = 0;
> -             lshift_double (f->data.low, f->data.high, i_f_bits,
> -                            HOST_BITS_PER_DOUBLE_INT,
> -                            &f->data.low, &f->data.high, 1);
> +             f->data = f->data.alshift (i_f_bits, HOST_BITS_PER_DOUBLE_INT);
>               if (get_fixed_sign_bit (a->data, i_f_bits) == 0)
>                 {
> -                 double_int one;
> -                 one.low = 1;
> -                 one.high = 0;
> -                 f->data = double_int_sub (f->data, one);
> +                 --f->data;
>                 }
>             }
>           else
>             overflow_p = true;
>         }
>      }
> -  f->data = double_int_ext (f->data, (!unsigned_p) + i_f_bits, unsigned_p);
> +  f->data = f->data.ext ((!unsigned_p) + i_f_bits, unsigned_p);
>    return overflow_p;
>  }
>
> @@ -386,11 +375,10 @@ do_fixed_multiply (FIXED_VALUE_TYPE *f,
>    f->mode = a->mode;
>    if (GET_MODE_PRECISION (f->mode) <= HOST_BITS_PER_WIDE_INT)
>      {
> -      f->data = double_int_mul (a->data, b->data);
> -      lshift_double (f->data.low, f->data.high,
> -                    (-GET_MODE_FBIT (f->mode)),
> +      f->data = a->data * b->data;
> +      f->data = f->data.lshift ((-GET_MODE_FBIT (f->mode)),
>                      HOST_BITS_PER_DOUBLE_INT,
> -                    &f->data.low, &f->data.high, !unsigned_p);
> +                    !unsigned_p);
>        overflow_p = fixed_saturate1 (f->mode, f->data, &f->data, sat_p);
>      }
>    else
> @@ -412,43 +400,43 @@ do_fixed_multiply (FIXED_VALUE_TYPE *f,
>        b_low.high = 0;
>
>        /* Perform four multiplications.  */
> -      low_low = double_int_mul (a_low, b_low);
> -      low_high = double_int_mul (a_low, b_high);
> -      high_low = double_int_mul (a_high, b_low);
> -      high_high = double_int_mul (a_high, b_high);
> +      low_low = a_low * b_low;
> +      low_high = a_low * b_high;
> +      high_low = a_high * b_low;
> +      high_high = a_high * b_high;
>
>        /* Accumulate four results to {r, s}.  */
>        temp1.high = high_low.low;
>        temp1.low = 0;
> -      s = double_int_add (low_low, temp1);
> -      if (double_int_cmp (s, low_low, 1) == -1
> -         || double_int_cmp (s, temp1, 1) == -1)
> +      s = low_low + temp1;
> +      if (s.ult (low_low)
> +         || s.ult (temp1))
>         carry ++; /* Carry */
>        temp1.high = s.high;
>        temp1.low = s.low;
>        temp2.high = low_high.low;
>        temp2.low = 0;
> -      s = double_int_add (temp1, temp2);
> -      if (double_int_cmp (s, temp1, 1) == -1
> -         || double_int_cmp (s, temp2, 1) == -1)
> +      s = temp1 + temp2;
> +      if (s.ult (temp1)
> +         || s.ult (temp2))
>         carry ++; /* Carry */
>
>        temp1.low = high_low.high;
>        temp1.high = 0;
> -      r = double_int_add (high_high, temp1);
> +      r = high_high + temp1;
>        temp1.low = low_high.high;
>        temp1.high = 0;
> -      r = double_int_add (r, temp1);
> +      r += temp1;
>        temp1.low = carry;
>        temp1.high = 0;
> -      r = double_int_add (r, temp1);
> +      r += temp1;
>
>        /* We need to subtract b from r, if a < 0.  */
>        if (!unsigned_p && a->data.high < 0)
> -       r = double_int_sub (r, b->data);
> +       r -= b->data;
>        /* We need to subtract a from r, if b < 0.  */
>        if (!unsigned_p && b->data.high < 0)
> -       r = double_int_sub (r, a->data);
> +       r -= a->data;
>
>        /* Shift right the result by FBIT.  */
>        if (GET_MODE_FBIT (f->mode) == HOST_BITS_PER_DOUBLE_INT)
> @@ -470,29 +458,23 @@ do_fixed_multiply (FIXED_VALUE_TYPE *f,
>         }
>        else
>         {
> -         lshift_double (s.low, s.high,
> -                        (-GET_MODE_FBIT (f->mode)),
> -                        HOST_BITS_PER_DOUBLE_INT,
> -                        &s.low, &s.high, 0);
> -         lshift_double (r.low, r.high,
> -                        (HOST_BITS_PER_DOUBLE_INT
> +         s = s.llshift ((-GET_MODE_FBIT (f->mode)), HOST_BITS_PER_DOUBLE_INT);
> +         f->data = r.llshift ((HOST_BITS_PER_DOUBLE_INT
>                           - GET_MODE_FBIT (f->mode)),
> -                        HOST_BITS_PER_DOUBLE_INT,
> -                        &f->data.low, &f->data.high, 0);
> +                        HOST_BITS_PER_DOUBLE_INT);
>           f->data.low = f->data.low | s.low;
>           f->data.high = f->data.high | s.high;
>           s.low = f->data.low;
>           s.high = f->data.high;
> -         lshift_double (r.low, r.high,
> -                        (-GET_MODE_FBIT (f->mode)),
> +         r = r.lshift ((-GET_MODE_FBIT (f->mode)),
>                          HOST_BITS_PER_DOUBLE_INT,
> -                        &r.low, &r.high, !unsigned_p);
> +                        !unsigned_p);
>         }
>
>        overflow_p = fixed_saturate2 (f->mode, r, s, &f->data, sat_p);
>      }
>
> -  f->data = double_int_ext (f->data, (!unsigned_p) + i_f_bits, unsigned_p);
> +  f->data = f->data.ext ((!unsigned_p) + i_f_bits, unsigned_p);
>    return overflow_p;
>  }
>
> @@ -510,11 +492,10 @@ do_fixed_divide (FIXED_VALUE_TYPE *f, co
>    f->mode = a->mode;
>    if (GET_MODE_PRECISION (f->mode) <= HOST_BITS_PER_WIDE_INT)
>      {
> -      lshift_double (a->data.low, a->data.high,
> -                    GET_MODE_FBIT (f->mode),
> +      f->data = a->data.lshift (GET_MODE_FBIT (f->mode),
>                      HOST_BITS_PER_DOUBLE_INT,
> -                    &f->data.low, &f->data.high, !unsigned_p);
> -      f->data = double_int_div (f->data, b->data, unsigned_p, TRUNC_DIV_EXPR);
> +                    !unsigned_p);
> +      f->data = f->data.div (b->data, unsigned_p, TRUNC_DIV_EXPR);
>        overflow_p = fixed_saturate1 (f->mode, f->data, &f->data, sat_p);
>      }
>    else
> @@ -527,7 +508,7 @@ do_fixed_divide (FIXED_VALUE_TYPE *f, co
>        /* If a < 0, negate a.  */
>        if (!unsigned_p && a->data.high < 0)
>         {
> -         pos_a = double_int_neg (a->data);
> +         pos_a = -a->data;
>           num_of_neg ++;
>         }
>        else
> @@ -536,7 +517,7 @@ do_fixed_divide (FIXED_VALUE_TYPE *f, co
>        /* If b < 0, negate b.  */
>        if (!unsigned_p && b->data.high < 0)
>         {
> -         pos_b = double_int_neg (b->data);
> +         pos_b = -b->data;
>           num_of_neg ++;
>         }
>        else
> @@ -551,24 +532,15 @@ do_fixed_divide (FIXED_VALUE_TYPE *f, co
>         }
>        else
>         {
> -         lshift_double (pos_a.low, pos_a.high,
> -                        GET_MODE_FBIT (f->mode),
> -                        HOST_BITS_PER_DOUBLE_INT,
> -                        &s.low, &s.high, 0);
> -         lshift_double (pos_a.low, pos_a.high,
> -                        - (HOST_BITS_PER_DOUBLE_INT
> +         s = pos_a.llshift (GET_MODE_FBIT (f->mode), HOST_BITS_PER_DOUBLE_INT);
> +         r = pos_a.llshift (- (HOST_BITS_PER_DOUBLE_INT
>                             - GET_MODE_FBIT (f->mode)),
> -                        HOST_BITS_PER_DOUBLE_INT,
> -                        &r.low, &r.high, 0);
> +                        HOST_BITS_PER_DOUBLE_INT);
>         }
>
>        /* Divide r by pos_b to quo_r.  The remainder is in mod.  */
> -      div_and_round_double (TRUNC_DIV_EXPR, 1, r.low, r.high, pos_b.low,
> -                           pos_b.high, &quo_r.low, &quo_r.high, &mod.low,
> -                           &mod.high);
> -
> -      quo_s.high = 0;
> -      quo_s.low = 0;
> +      quo_r = r.divmod (pos_b, 1, TRUNC_DIV_EXPR, &mod);
> +      quo_s = double_int_zero;
>
>        for (i = 0; i < HOST_BITS_PER_DOUBLE_INT; i++)
>         {
> @@ -576,37 +548,34 @@ do_fixed_divide (FIXED_VALUE_TYPE *f, co
>           int leftmost_mod = (mod.high < 0);
>
>           /* Shift left mod by 1 bit.  */
> -         lshift_double (mod.low, mod.high, 1, HOST_BITS_PER_DOUBLE_INT,
> -                        &mod.low, &mod.high, 0);
> +         mod = mod.llshift (1, HOST_BITS_PER_DOUBLE_INT);
>
>           /* Test the leftmost bit of s to add to mod.  */
>           if (s.high < 0)
>             mod.low += 1;
>
>           /* Shift left quo_s by 1 bit.  */
> -         lshift_double (quo_s.low, quo_s.high, 1, HOST_BITS_PER_DOUBLE_INT,
> -                        &quo_s.low, &quo_s.high, 0);
> +         quo_s = quo_s.llshift (1, HOST_BITS_PER_DOUBLE_INT);
>
>           /* Try to calculate (mod - pos_b).  */
> -         temp = double_int_sub (mod, pos_b);
> +         temp = mod - pos_b;
>
> -         if (leftmost_mod == 1 || double_int_cmp (mod, pos_b, 1) != -1)
> +         if (leftmost_mod == 1 || mod.ucmp (pos_b) != -1)
>             {
>               quo_s.low += 1;
>               mod = temp;
>             }
>
>           /* Shift left s by 1 bit.  */
> -         lshift_double (s.low, s.high, 1, HOST_BITS_PER_DOUBLE_INT,
> -                        &s.low, &s.high, 0);
> +         s = s.llshift (1, HOST_BITS_PER_DOUBLE_INT);
>
>         }
>
>        if (num_of_neg == 1)
>         {
> -         quo_s = double_int_neg (quo_s);
> +         quo_s = -quo_s;
>           if (quo_s.high == 0 && quo_s.low == 0)
> -           quo_r = double_int_neg (quo_r);
> +           quo_r = -quo_r;
>           else
>             {
>               quo_r.low = ~quo_r.low;
> @@ -618,7 +587,7 @@ do_fixed_divide (FIXED_VALUE_TYPE *f, co
>        overflow_p = fixed_saturate2 (f->mode, quo_r, quo_s, &f->data, sat_p);
>      }
>
> -  f->data = double_int_ext (f->data, (!unsigned_p) + i_f_bits, unsigned_p);
> +  f->data = f->data.ext ((!unsigned_p) + i_f_bits, unsigned_p);
>    return overflow_p;
>  }
>
> @@ -643,10 +612,9 @@ do_fixed_shift (FIXED_VALUE_TYPE *f, con
>
>    if (GET_MODE_PRECISION (f->mode) <= HOST_BITS_PER_WIDE_INT || (!left_p))
>      {
> -      lshift_double (a->data.low, a->data.high,
> -                    left_p ? b->data.low : (-b->data.low),
> +      f->data = a->data.lshift (left_p ? b->data.low : (-b->data.low),
>                      HOST_BITS_PER_DOUBLE_INT,
> -                    &f->data.low, &f->data.high, !unsigned_p);
> +                    !unsigned_p);
>        if (left_p) /* Only left shift saturates.  */
>         overflow_p = fixed_saturate1 (f->mode, f->data, &f->data, sat_p);
>      }
> @@ -661,23 +629,20 @@ do_fixed_shift (FIXED_VALUE_TYPE *f, con
>         }
>        else
>         {
> -         lshift_double (a->data.low, a->data.high,
> -                        b->data.low,
> +         temp_low = a->data.lshift (b->data.low,
>                          HOST_BITS_PER_DOUBLE_INT,
> -                        &temp_low.low, &temp_low.high, !unsigned_p);
> +                        !unsigned_p);
>           /* Logical shift right to temp_high.  */
> -         lshift_double (a->data.low, a->data.high,
> -                        b->data.low - HOST_BITS_PER_DOUBLE_INT,
> -                        HOST_BITS_PER_DOUBLE_INT,
> -                        &temp_high.low, &temp_high.high, 0);
> +         temp_high = a->data.llshift (b->data.low - HOST_BITS_PER_DOUBLE_INT,
> +                        HOST_BITS_PER_DOUBLE_INT);
>         }
>        if (!unsigned_p && a->data.high < 0) /* Signed-extend temp_high.  */
> -       temp_high = double_int_ext (temp_high, b->data.low, unsigned_p);
> +       temp_high = temp_high.ext (b->data.low, unsigned_p);
>        f->data = temp_low;
>        overflow_p = fixed_saturate2 (f->mode, temp_high, temp_low, &f->data,
>                                     sat_p);
>      }
> -  f->data = double_int_ext (f->data, (!unsigned_p) + i_f_bits, unsigned_p);
> +  f->data = f->data.ext ((!unsigned_p) + i_f_bits, unsigned_p);
>    return overflow_p;
>  }
>
> @@ -692,8 +657,8 @@ do_fixed_neg (FIXED_VALUE_TYPE *f, const
>    bool unsigned_p = UNSIGNED_FIXED_POINT_MODE_P (a->mode);
>    int i_f_bits = GET_MODE_IBIT (a->mode) + GET_MODE_FBIT (a->mode);
>    f->mode = a->mode;
> -  f->data = double_int_neg (a->data);
> -  f->data = double_int_ext (f->data, (!unsigned_p) + i_f_bits, unsigned_p);
> +  f->data = -a->data;
> +  f->data = f->data.ext ((!unsigned_p) + i_f_bits, unsigned_p);
>
>    if (unsigned_p) /* Unsigned type.  */
>      {
> @@ -718,7 +683,7 @@ do_fixed_neg (FIXED_VALUE_TYPE *f, const
>               /* Saturate to the maximum by subtracting f->data by one.  */
>               f->data.low = -1;
>               f->data.high = -1;
> -             f->data = double_int_ext (f->data, i_f_bits, 1);
> +             f->data = f->data.zext (i_f_bits);
>             }
>           else
>             overflow_p = true;
> @@ -789,25 +754,25 @@ fixed_compare (int icode, const FIXED_VA
>    switch (code)
>      {
>      case NE_EXPR:
> -      return !double_int_equal_p (op0->data, op1->data);
> +      return op0->data != op1->data;
>
>      case EQ_EXPR:
> -      return double_int_equal_p (op0->data, op1->data);
> +      return op0->data == op1->data;
>
>      case LT_EXPR:
> -      return double_int_cmp (op0->data, op1->data,
> +      return op0->data.cmp (op1->data,
>                              UNSIGNED_FIXED_POINT_MODE_P (op0->mode)) == -1;
>
>      case LE_EXPR:
> -      return double_int_cmp (op0->data, op1->data,
> +      return op0->data.cmp (op1->data,
>                              UNSIGNED_FIXED_POINT_MODE_P (op0->mode)) != 1;
>
>      case GT_EXPR:
> -      return double_int_cmp (op0->data, op1->data,
> +      return op0->data.cmp (op1->data,
>                              UNSIGNED_FIXED_POINT_MODE_P (op0->mode)) == 1;
>
>      case GE_EXPR:
> -      return double_int_cmp (op0->data, op1->data,
> +      return op0->data.cmp (op1->data,
>                              UNSIGNED_FIXED_POINT_MODE_P (op0->mode)) != -1;
>
>      default:
> @@ -835,19 +800,15 @@ fixed_convert (FIXED_VALUE_TYPE *f, enum
>        /* Left shift a to temp_high, temp_low based on a->mode.  */
>        double_int temp_high, temp_low;
>        int amount = GET_MODE_FBIT (mode) - GET_MODE_FBIT (a->mode);
> -      lshift_double (a->data.low, a->data.high,
> -                    amount,
> +      temp_low = a->data.lshift (amount,
>                      HOST_BITS_PER_DOUBLE_INT,
> -                    &temp_low.low, &temp_low.high,
>                      SIGNED_FIXED_POINT_MODE_P (a->mode));
>        /* Logical shift right to temp_high.  */
> -      lshift_double (a->data.low, a->data.high,
> -                    amount - HOST_BITS_PER_DOUBLE_INT,
> -                    HOST_BITS_PER_DOUBLE_INT,
> -                    &temp_high.low, &temp_high.high, 0);
> +      temp_high = a->data.llshift (amount - HOST_BITS_PER_DOUBLE_INT,
> +                    HOST_BITS_PER_DOUBLE_INT);
>        if (SIGNED_FIXED_POINT_MODE_P (a->mode)
>           && a->data.high < 0) /* Signed-extend temp_high.  */
> -       temp_high = double_int_ext (temp_high, amount, 0);
> +       temp_high = temp_high.sext (amount);
>        f->mode = mode;
>        f->data = temp_low;
>        if (SIGNED_FIXED_POINT_MODE_P (a->mode) ==
> @@ -885,10 +846,9 @@ fixed_convert (FIXED_VALUE_TYPE *f, enum
>                       /* Set to maximum.  */
>                       f->data.low = -1;  /* Set to all ones.  */
>                       f->data.high = -1;  /* Set to all ones.  */
> -                     f->data = double_int_ext (f->data,
> -                                               GET_MODE_FBIT (f->mode)
> -                                               + GET_MODE_IBIT (f->mode),
> -                                               1); /* Clear the sign.  */
> +                     f->data = f->data.zext (GET_MODE_FBIT (f->mode)
> +                                               + GET_MODE_IBIT (f->mode));
> +                                               /* Clear the sign.  */
>                     }
>                   else
>                     overflow_p = true;
> @@ -903,10 +863,8 @@ fixed_convert (FIXED_VALUE_TYPE *f, enum
>      {
>        /* Right shift a to temp based on a->mode.  */
>        double_int temp;
> -      lshift_double (a->data.low, a->data.high,
> -                    GET_MODE_FBIT (mode) - GET_MODE_FBIT (a->mode),
> +      temp = a->data.lshift (GET_MODE_FBIT (mode) - GET_MODE_FBIT (a->mode),
>                      HOST_BITS_PER_DOUBLE_INT,
> -                    &temp.low, &temp.high,
>                      SIGNED_FIXED_POINT_MODE_P (a->mode));
>        f->mode = mode;
>        f->data = temp;
> @@ -944,10 +902,9 @@ fixed_convert (FIXED_VALUE_TYPE *f, enum
>                       /* Set to maximum.  */
>                       f->data.low = -1;  /* Set to all ones.  */
>                       f->data.high = -1;  /* Set to all ones.  */
> -                     f->data = double_int_ext (f->data,
> -                                               GET_MODE_FBIT (f->mode)
> -                                               + GET_MODE_IBIT (f->mode),
> -                                               1); /* Clear the sign.  */
> +                     f->data = f->data.zext (GET_MODE_FBIT (f->mode)
> +                                               + GET_MODE_IBIT (f->mode));
> +                                               /* Clear the sign.  */
>                     }
>                   else
>                     overflow_p = true;
> @@ -959,8 +916,7 @@ fixed_convert (FIXED_VALUE_TYPE *f, enum
>         }
>      }
>
> -  f->data = double_int_ext (f->data,
> -                           SIGNED_FIXED_POINT_MODE_P (f->mode)
> +  f->data = f->data.ext (SIGNED_FIXED_POINT_MODE_P (f->mode)
>                             + GET_MODE_FBIT (f->mode)
>                             + GET_MODE_IBIT (f->mode),
>                             UNSIGNED_FIXED_POINT_MODE_P (f->mode));
> @@ -988,19 +944,14 @@ fixed_convert_from_int (FIXED_VALUE_TYPE
>      }
>    else
>      {
> -      lshift_double (a.low, a.high,
> -                    amount,
> -                    HOST_BITS_PER_DOUBLE_INT,
> -                    &temp_low.low, &temp_low.high, 0);
> +      temp_low = a.llshift (amount, HOST_BITS_PER_DOUBLE_INT);
>
>        /* Logical shift right to temp_high.  */
> -      lshift_double (a.low, a.high,
> -                    amount - HOST_BITS_PER_DOUBLE_INT,
> -                    HOST_BITS_PER_DOUBLE_INT,
> -                    &temp_high.low, &temp_high.high, 0);
> +      temp_high = a.llshift (amount - HOST_BITS_PER_DOUBLE_INT,
> +                    HOST_BITS_PER_DOUBLE_INT);
>      }
>    if (!unsigned_p && a.high < 0) /* Signed-extend temp_high.  */
> -    temp_high = double_int_ext (temp_high, amount, 0);
> +    temp_high = temp_high.sext (amount);
>
>    f->mode = mode;
>    f->data = temp_low;
> @@ -1038,10 +989,9 @@ fixed_convert_from_int (FIXED_VALUE_TYPE
>                   /* Set to maximum.  */
>                   f->data.low = -1;  /* Set to all ones.  */
>                   f->data.high = -1;  /* Set to all ones.  */
> -                 f->data = double_int_ext (f->data,
> -                                           GET_MODE_FBIT (f->mode)
> -                                           + GET_MODE_IBIT (f->mode),
> -                                           1); /* Clear the sign.  */
> +                 f->data = f->data.zext (GET_MODE_FBIT (f->mode)
> +                                           + GET_MODE_IBIT (f->mode));
> +                                           /* Clear the sign.  */
>                 }
>               else
>                 overflow_p = true;
> @@ -1051,8 +1001,7 @@ fixed_convert_from_int (FIXED_VALUE_TYPE
>                                           &f->data, sat_p);
>         }
>      }
> -  f->data = double_int_ext (f->data,
> -                           SIGNED_FIXED_POINT_MODE_P (f->mode)
> +  f->data = f->data.ext (SIGNED_FIXED_POINT_MODE_P (f->mode)
>                             + GET_MODE_FBIT (f->mode)
>                             + GET_MODE_IBIT (f->mode),
>                             UNSIGNED_FIXED_POINT_MODE_P (f->mode));
> @@ -1093,10 +1042,8 @@ fixed_convert_from_real (FIXED_VALUE_TYP
>             {
>               f->data.low = 1;
>               f->data.high = 0;
> -             lshift_double (f->data.low, f->data.high, i_f_bits,
> -                            HOST_BITS_PER_DOUBLE_INT,
> -                            &f->data.low, &f->data.high, 1);
> -             f->data = double_int_ext (f->data, 1 + i_f_bits, 0);
> +             f->data = f->data.alshift (i_f_bits, HOST_BITS_PER_DOUBLE_INT);
> +             f->data = f->data.sext (1 + i_f_bits);
>             }
>         }
>        else
> @@ -1108,12 +1055,12 @@ fixed_convert_from_real (FIXED_VALUE_TYP
>         {
>           f->data.low = -1;
>           f->data.high = -1;
> -         f->data = double_int_ext (f->data, i_f_bits, 1);
> +         f->data = f->data.zext (i_f_bits);
>         }
>        else
>         overflow_p = true;
>      }
> -  f->data = double_int_ext (f->data, (!unsigned_p) + i_f_bits, unsigned_p);
> +  f->data = f->data.ext ((!unsigned_p) + i_f_bits, unsigned_p);
>    return overflow_p;
>  }
>
>
> --
> This patch is available for review at http://codereview.appspot.com/6443093
Mike Stump Aug. 7, 2012, 5:22 p.m. UTC | #2
On Aug 6, 2012, at 5:35 PM, Lawrence Crowl wrote:
> Convert double_int from a struct with function into a class with
> operators and methods.

We have a wide_int class that replaces this class.  :-(  It would have been better to just convert it.  Do you guys have a timeframe for the cxx-conversion landing?
Diego Novillo Aug. 7, 2012, 5:25 p.m. UTC | #3
On 12-08-07 13:22 , Mike Stump wrote:
> On Aug 6, 2012, at 5:35 PM, Lawrence Crowl wrote:
>> Convert double_int from a struct with function into a class with
>> operators and methods.
>
> We have a wide_int class that replaces this class.  :-(  It would
> have been better to just convert it.  Do you guys have a timeframe
> for the cxx-conversion landing?

Soon (for "soon" measured in days).  I will try to send the merge 
patches this week.


Diego.
Lawrence Crowl Aug. 7, 2012, 6:38 p.m. UTC | #4
On 8/7/12, Richard Guenther <richard.guenther@gmail.com> wrote:
> On Tue, Aug 7, 2012 at 2:35 AM, Lawrence Crowl <crowl@google.com> wrote:
> > Convert double_int from a struct with function into a class with
> > operators and methods.
> >
> > This patch adds the methods and operators.  In general functions of
> > the form "double_int_whatever" become member functions "whatever" or,
> > when possible, operators.
> >
> > Every attempt has been made to preserve the existing algorithms, even
> > at the expense of some optimization opportunities.  Some examples:
> >
> >   The ext operation takes a value and returns a value.  However, that
> >   return value is usually assigned to the original variable.  An
> >   operation that modified a variable would be more efficient.
>
> That's not always the case though and I think the interface should be
> consistent with existing behavior to avoid errors creeping in during the
> transition.

We should probably think about naming conventions for mutating operations,
as I expect we will want them eventually.

> >   In some cases, an outer sign-specific function calls an inner
> >   function with the sign as a parameter, which then decides which
> >   implementation to do.  Decisions should not be artificially
> >   introduced, and the implementation of each case should be exposed as
> >   a separate routine.
> >
> >   The existing operations are implemented in terms of the new
> >   operations, which necessarily adds a layer between the new code and
> >   the existing users.  Once all files have migrated, this layer will
> >   be removed.
> >
> >   There are several existing operations implemented in terms of even
> >   older legacy operations.  This extra layer has not been removed.
> >
> > On occasion though, parameterized functions are often called
> > with a constant argments.  To support static statement of intent,
> > and potentially faster code in the future, there are several new
> > unparameterized member functions.  Some examples:
> >
> >   Four routines now encode both 'arithmetic or logical' and 'right or
> >   left' shift as part of the funciton name.
> >
> >   Four routines now encode both 'signed or unsigned' and 'less than or
> >   greater than' as part of the function name.
>
> For most parts overloads that take an (unsigned) HOST_WIDE_INT argument
> would be nice, as well as the ability to say dbl + 1.

Hm.  There seems to be significant opinion that there should not be any
implicit conversions.  I am okay with operations as above, but would like
to hear the opinions of others.

> > -typedef struct
> > +typedef struct double_int
> >  {
> > +public:
> > +  /* Normally, we would define constructors to create instances.
> > +     Two things prevent us from doing so.
> > +     First, defining a constructor makes the class non-POD in C++03,
> > +     and we certainly want double_int to be a POD.
> > +     Second, the GCC conding conventions prefer explicit conversion,
> > +     and explicit conversion operators are not available until C++11.
> > */
> > +
> > +  static double_int make (unsigned HOST_WIDE_INT cst);
> > +  static double_int make (HOST_WIDE_INT cst);
> > +  static double_int make (unsigned int cst);
> > +  static double_int make (int cst);
>
> Did we somehow decide to not allow constructors?  It's odd to convert to
> C++ and end up with static member functions resembling them ...

Constructors are allowed, but PODs are often passed more efficiently.
That property seemed particularly important for double_int.

> Also I believe the conversion above introduces possible migration errors.
> Think of a previous
>
>  HOST_WIDE_INT a;
>  double_int d = uhwi_to_double_int (a);
>
> if you write that now as
>
>  HOST_WIDE_INT a;
>  double_int d = double_int::make (a);
>
> you get the effect of shwi_to_double_int.  Oops.

Hm.  I think the code was more likely to be wrong originally,
but I take your point.

> So as an intermediate
> I'd like you _not_ to introduce the make () overloads.

Okay.

> Btw, if HOST_WIDE_INT == int the above won't even compile.

Is that true of any host?  I am not aware of any.  Anyway, it is
moot if we remove the overloads.
Lawrence Crowl Aug. 7, 2012, 6:42 p.m. UTC | #5
On 8/7/12, Mike Stump <mikestump@comcast.net> wrote:
> On Aug 6, 2012, at 5:35 PM, Lawrence Crowl wrote:
>> Convert double_int from a struct with function into a class with
>> operators and methods.
>
> We have a wide_int class that replaces this class.  :-(

Really?  Where?  I don't see neither definition nor use under gcc.

> It would have been better to just convert it.

That depends on how easy it is to migrate.  In the process I
learned that double_int isn't actually a double int, but is a
precision-controlled int.
Mike Stump Aug. 7, 2012, 7:54 p.m. UTC | #6
On Aug 7, 2012, at 11:38 AM, Lawrence Crowl wrote:
> Hm.  There seems to be significant opinion that there should not be any
> implicit conversions.  I am okay with operations as above, but would like
> to hear the opinions of others.

If there is an agreed upon and expected semantic, having them are useful.  In the wide-int world, which replaces double_int, I think there is an agreeable semantic and I think it is useful, so, I think we should plan on having them, though, I'd be fine with punting their implementation until such time as someone needs it.  If no one every needs the routine, I don't see the harm in not implementing it.

>> Did we somehow decide to not allow constructors?  It's odd to convert to
>> C++ and end up with static member functions resembling them ...
> 
> Constructors are allowed, but PODs are often passed more efficiently.
> That property seemed particularly important for double_int.

Show us the difference in timing.  Show us the generated code.  I can't imagine that it could ever matter.  I think a pretty abi is worth the cost.
Mike Stump Aug. 7, 2012, 8:22 p.m. UTC | #7
On Aug 7, 2012, at 11:42 AM, Lawrence Crowl wrote:
> On 8/7/12, Mike Stump <mikestump@comcast.net> wrote:
>> On Aug 6, 2012, at 5:35 PM, Lawrence Crowl wrote:
>>> Convert double_int from a struct with function into a class with
>>> operators and methods.
>> 
>> We have a wide_int class that replaces this class.  :-(
> 
> Really?  Where?  I don't see neither definition nor use under gcc.

It is being developed; it is largely done, but is going through final reviews now.  When we finish with those review bits, we'll send it out.  It sounds like you'll beat us to the merge window, so, we'll cope with the fallout.

>> It would have been better to just convert it.
> 
> That depends on how easy it is to migrate.  In the process I
> learned that double_int isn't actually a double int, but is a
> precision-controlled int.

Well, I'd call it a pair of HOST_WIDE_INTs...  I think calling it a precision-controlled int is a tad optimistic.  For example, if want to control it to be 2048 bits, you'd find that your hopes are misplaced.  :-)
Richard Henderson Aug. 7, 2012, 11:08 p.m. UTC | #8
On 08/06/2012 05:35 PM, Lawrence Crowl wrote:
> +inline double_int &
> +double_int::operator ++ ()
> +{
> +  *this + double_int_one;
> +  return *this;
> +}
> +
> +inline double_int &
> +double_int::operator -- ()
> +{
> +  *this - double_int_one;
> +  return *this;
> +}

Surely unused results there?


r~
Miles Bader Aug. 8, 2012, 7:09 a.m. UTC | #9
Mike Stump <mikestump@comcast.net> writes:
>> Constructors are allowed, but PODs are often passed more efficiently.
>> That property seemed particularly important for double_int.
>
> Show us the difference in timing.  Show us the generated code.  I
> can't imagine that it could ever matter.

I'm also curious about that statement...  PODs don't really seem to
offer much advantage with modern compilers, except in a few very
specific cases (of which this doesn't seem to be one), e.g. in unions.

-miles
Richard Biener Aug. 8, 2012, 7:42 a.m. UTC | #10
On Wed, Aug 8, 2012 at 9:09 AM, Miles Bader <miles@gnu.org> wrote:
> Mike Stump <mikestump@comcast.net> writes:
>>> Constructors are allowed, but PODs are often passed more efficiently.
>>> That property seemed particularly important for double_int.
>>
>> Show us the difference in timing.  Show us the generated code.  I
>> can't imagine that it could ever matter.
>
> I'm also curious about that statement...  PODs don't really seem to
> offer much advantage with modern compilers, except in a few very
> specific cases (of which this doesn't seem to be one), e.g. in unions.

They make a difference for the by-value passing ABI.  double-ints can
be passed in two registers on most platforms.

Richard.

> -miles
>
> --
> values of β will give rise to dom!
Richard Biener Aug. 8, 2012, 7:47 a.m. UTC | #11
On Tue, Aug 7, 2012 at 8:38 PM, Lawrence Crowl <crowl@google.com> wrote:
> On 8/7/12, Richard Guenther <richard.guenther@gmail.com> wrote:
>> On Tue, Aug 7, 2012 at 2:35 AM, Lawrence Crowl <crowl@google.com> wrote:
>> > Convert double_int from a struct with function into a class with
>> > operators and methods.
>> >
>> > This patch adds the methods and operators.  In general functions of
>> > the form "double_int_whatever" become member functions "whatever" or,
>> > when possible, operators.
>> >
>> > Every attempt has been made to preserve the existing algorithms, even
>> > at the expense of some optimization opportunities.  Some examples:
>> >
>> >   The ext operation takes a value and returns a value.  However, that
>> >   return value is usually assigned to the original variable.  An
>> >   operation that modified a variable would be more efficient.
>>
>> That's not always the case though and I think the interface should be
>> consistent with existing behavior to avoid errors creeping in during the
>> transition.
>
> We should probably think about naming conventions for mutating operations,
> as I expect we will want them eventually.

Right.  In the end I would prefer explicit constructors.

>> >   In some cases, an outer sign-specific function calls an inner
>> >   function with the sign as a parameter, which then decides which
>> >   implementation to do.  Decisions should not be artificially
>> >   introduced, and the implementation of each case should be exposed as
>> >   a separate routine.
>> >
>> >   The existing operations are implemented in terms of the new
>> >   operations, which necessarily adds a layer between the new code and
>> >   the existing users.  Once all files have migrated, this layer will
>> >   be removed.
>> >
>> >   There are several existing operations implemented in terms of even
>> >   older legacy operations.  This extra layer has not been removed.
>> >
>> > On occasion though, parameterized functions are often called
>> > with a constant argments.  To support static statement of intent,
>> > and potentially faster code in the future, there are several new
>> > unparameterized member functions.  Some examples:
>> >
>> >   Four routines now encode both 'arithmetic or logical' and 'right or
>> >   left' shift as part of the funciton name.
>> >
>> >   Four routines now encode both 'signed or unsigned' and 'less than or
>> >   greater than' as part of the function name.
>>
>> For most parts overloads that take an (unsigned) HOST_WIDE_INT argument
>> would be nice, as well as the ability to say dbl + 1.
>
> Hm.  There seems to be significant opinion that there should not be any
> implicit conversions.  I am okay with operations as above, but would like
> to hear the opinions of others.

Well, I'd simply add

   double_int operator+(HOST_WIDE_INT);
   double_int operator+(unsigned HOST_WIDE_INT);

and be done with it ;)  Yes, a tad bit more inconvenient on the implementation
side compared to a non-explicit constructor from HOST_WIDE_INT or a
conversion operator ... but adhering to the rule that we do _not_ want such
automatic conversions (well, yet, for the start).

>> > -typedef struct
>> > +typedef struct double_int
>> >  {
>> > +public:
>> > +  /* Normally, we would define constructors to create instances.
>> > +     Two things prevent us from doing so.
>> > +     First, defining a constructor makes the class non-POD in C++03,
>> > +     and we certainly want double_int to be a POD.
>> > +     Second, the GCC conding conventions prefer explicit conversion,
>> > +     and explicit conversion operators are not available until C++11.
>> > */
>> > +
>> > +  static double_int make (unsigned HOST_WIDE_INT cst);
>> > +  static double_int make (HOST_WIDE_INT cst);
>> > +  static double_int make (unsigned int cst);
>> > +  static double_int make (int cst);
>>
>> Did we somehow decide to not allow constructors?  It's odd to convert to
>> C++ and end up with static member functions resembling them ...
>
> Constructors are allowed, but PODs are often passed more efficiently.
> That property seemed particularly important for double_int.

True - I forgot about this issue.  Same for the return values.  I suppose we
need to inspect code quality before going this route.

>> Also I believe the conversion above introduces possible migration errors.
>> Think of a previous
>>
>>  HOST_WIDE_INT a;
>>  double_int d = uhwi_to_double_int (a);
>>
>> if you write that now as
>>
>>  HOST_WIDE_INT a;
>>  double_int d = double_int::make (a);
>>
>> you get the effect of shwi_to_double_int.  Oops.
>
> Hm.  I think the code was more likely to be wrong originally,
> but I take your point.
>
>> So as an intermediate
>> I'd like you _not_ to introduce the make () overloads.
>
> Okay.
>
>> Btw, if HOST_WIDE_INT == int the above won't even compile.
>
> Is that true of any host?  I am not aware of any.  Anyway, it is
> moot if we remove the overloads.

Right.  I'd simply rely on int / unsigned int promotion to HOST_WIDE_INT
or unsigned HOST_WIDE_INT and only provide overloads for HOST_WIDE_INT
kinds anyway.

Richard.

> --
> Lawrence Crowl
Miles Bader Aug. 8, 2012, 8:29 a.m. UTC | #12
Richard Guenther <richard.guenther@gmail.com> writes:
>>>> Constructors are allowed, but PODs are often passed more efficiently.
>>>> That property seemed particularly important for double_int.
>>>
>>> Show us the difference in timing.  Show us the generated code.  I
>>> can't imagine that it could ever matter.
>>
>> I'm also curious about that statement...  PODs don't really seem to
>> offer much advantage with modern compilers, except in a few very
>> specific cases (of which this doesn't seem to be one), e.g. in unions.
>
> They make a difference for the by-value passing ABI.  double-ints can
> be passed in two registers on most platforms.

Sure, but that doesn't seem to depend on PODness -- non-PODs can be
passed in two registers as well, AFAICS...

E.g., in the following:

   typedef long valtype;

   struct X { valtype x, y; };
   struct Y { Y (valtype a, valtype b) : x (a), y (b) { } valtype x, y; };

   extern void fx (X x);
   void test_x () {X x = { 1, 2 }; fx (x); }

   extern void fy (Y y);
   void test_y () {Y y (1, 2); fy (y); }

test_x and test_y use exactly the same calling sequence (and contain
exactly the same assembly code)...  [on x86-64]

Thanks,

-miles
Marc Glisse Aug. 8, 2012, 8:33 a.m. UTC | #13
On Wed, 8 Aug 2012, Richard Guenther wrote:

>>>> +  static double_int make (unsigned HOST_WIDE_INT cst);
>>>> +  static double_int make (HOST_WIDE_INT cst);
>>>> +  static double_int make (unsigned int cst);
>>>> +  static double_int make (int cst);
[...]
>>> Btw, if HOST_WIDE_INT == int the above won't even compile.
>>
>> Is that true of any host?  I am not aware of any.  Anyway, it is
>> moot if we remove the overloads.
>
> Right.  I'd simply rely on int / unsigned int promotion to HOST_WIDE_INT
> or unsigned HOST_WIDE_INT and only provide overloads for HOST_WIDE_INT
> kinds anyway.

Sadly, that doesn't work with the current C++ rules (there is a proposal 
to change that for C++1y):

void f(long);
void f(unsigned long);
void g(int x){f(x);}

e.cc: In function ‘void g(int)’:
e.cc:3:18: error: call of overloaded ‘f(int&)’ is ambiguous
e.cc:3:18: note: candidates are:
e.cc:1:6: note: void f(long int)
e.cc:2:6: note: void f(long unsigned int)
Richard Biener Aug. 8, 2012, 8:42 a.m. UTC | #14
On Wed, Aug 8, 2012 at 10:33 AM, Marc Glisse <marc.glisse@inria.fr> wrote:
> On Wed, 8 Aug 2012, Richard Guenther wrote:
>
>>>>> +  static double_int make (unsigned HOST_WIDE_INT cst);
>>>>> +  static double_int make (HOST_WIDE_INT cst);
>>>>> +  static double_int make (unsigned int cst);
>>>>> +  static double_int make (int cst);
>
> [...]
>
>>>> Btw, if HOST_WIDE_INT == int the above won't even compile.
>>>
>>>
>>> Is that true of any host?  I am not aware of any.  Anyway, it is
>>> moot if we remove the overloads.
>>
>>
>> Right.  I'd simply rely on int / unsigned int promotion to HOST_WIDE_INT
>> or unsigned HOST_WIDE_INT and only provide overloads for HOST_WIDE_INT
>> kinds anyway.
>
>
> Sadly, that doesn't work with the current C++ rules (there is a proposal to
> change that for C++1y):
>
> void f(long);
> void f(unsigned long);
> void g(int x){f(x);}
>
> e.cc: In function ‘void g(int)’:
> e.cc:3:18: error: call of overloaded ‘f(int&)’ is ambiguous
> e.cc:3:18: note: candidates are:
> e.cc:1:6: note: void f(long int)
> e.cc:2:6: note: void f(long unsigned int)

Ick ... I forgot that integer promotions do not apply for int -> long.
 So even f(1) would
be ambiguous, right?  So I suppose we have to bite the bullet and add overloads
for all (unsigned) integer types from int to HOST_WIDE_INT (if HOST_WIDE_INT
is long long then we have to add overloads for int, unsigned int, long and
unsigned long).

Or use template magic to force promotion to HOST_WIDE_INT for integer
types smaller than HOST_WIDE_INT...

Richard.

> --
> Marc Glisse
Gabriel Dos Reis Aug. 8, 2012, 9:36 a.m. UTC | #15
On Wed, Aug 8, 2012 at 3:29 AM, Miles Bader <miles@gnu.org> wrote:
> Richard Guenther <richard.guenther@gmail.com> writes:
>>>>> Constructors are allowed, but PODs are often passed more efficiently.
>>>>> That property seemed particularly important for double_int.
>>>>
>>>> Show us the difference in timing.  Show us the generated code.  I
>>>> can't imagine that it could ever matter.
>>>
>>> I'm also curious about that statement...  PODs don't really seem to
>>> offer much advantage with modern compilers, except in a few very
>>> specific cases (of which this doesn't seem to be one), e.g. in unions.
>>
>> They make a difference for the by-value passing ABI.  double-ints can
>> be passed in two registers on most platforms.
>
> Sure, but that doesn't seem to depend on PODness -- non-PODs can be
> passed in two registers as well, AFAICS...
>
> E.g., in the following:
>
>    typedef long valtype;
>
>    struct X { valtype x, y; };
>    struct Y { Y (valtype a, valtype b) : x (a), y (b) { } valtype x, y; };
>
>    extern void fx (X x);
>    void test_x () {X x = { 1, 2 }; fx (x); }
>
>    extern void fy (Y y);
>    void test_y () {Y y (1, 2); fy (y); }
>
> test_x and test_y use exactly the same calling sequence (and contain
> exactly the same assembly code)...  [on x86-64]

It is not PODness in the standard sense that matters.
It is podness from the ABI perspecitve: Y does not
have a user-defined copy-constructor nor a desctructor;
it is not a polymorphic type, so it is OK to pass in registers
just like X.

-- Gaby
Lawrence Crowl Aug. 8, 2012, 10:17 p.m. UTC | #16
On 8/7/12, Mike Stump <mikestump@comcast.net> wrote:
> On Aug 7, 2012, at 11:38 AM, Lawrence Crowl wrote:
> > Hm.  There seems to be significant opinion that there should not be any
> > implicit conversions.  I am okay with operations as above, but would like
> > to hear the opinions of others.
>
> If there is an agreed upon and expected semantic, having them are useful.
> In the wide-int world, which replaces double_int, I think there is an
> agreeable semantic and I think it is useful, so, I think we should plan on
> having them, though, I'd be fine with punting their implementation until
> such time as someone needs it.  If no one every needs the routine, I don't
> see the harm in not implementing it.

At present, there are no functions equivalent to (double_int + int), so
there can be no expressions that need this overload.  I have no objection
to adding such an overload, but if there are no objections, I would rather
do it as a separate patch.
Lawrence Crowl Aug. 8, 2012, 10:20 p.m. UTC | #17
On 8/7/12, Mike Stump <mikestump@comcast.net> wrote:
> On Aug 7, 2012, at 11:42 AM, Lawrence Crowl wrote:
> > On 8/7/12, Mike Stump <mikestump@comcast.net> wrote:
> > > On Aug 6, 2012, at 5:35 PM, Lawrence Crowl wrote:
> > > > Convert double_int from a struct with function into a class
> > > > with operators and methods.
> > >
> > > We have a wide_int class that replaces this class.  :-(
> >
> > Really?  Where?  I don't see neither definition nor use
> > under gcc.
>
> It is being developed; it is largely done, but is going through
> final reviews now.  When we finish with those review bits, we'll
> send it out.  It sounds like you'll beat us to the merge window,
> so, we'll cope with the fallout.

Can I have a pointer to the interface?

> > > It would have been better to just convert it.
> >
> > That depends on how easy it is to migrate.  In the process I
> > learned that double_int isn't actually a double int, but is a
> > precision-controlled int.
>
> Well, I'd call it a pair of HOST_WIDE_INTs...  I think calling
> it a precision-controlled int is a tad optimistic.  For example,
> if want to control it to be 2048 bits, you'd find that your hopes
> are misplaced.  :-)

Yes, well, it's clearly all relying on the host being bigger than
the target.
Lawrence Crowl Aug. 8, 2012, 10:21 p.m. UTC | #18
On 8/7/12, Richard Henderson <rth@redhat.com> wrote:
> On 08/06/2012 05:35 PM, Lawrence Crowl wrote:
> > +inline double_int &
> > +double_int::operator ++ ()
> > +{
> > +  *this + double_int_one;
> > +  return *this;
> > +}
> > +
> > +inline double_int &
> > +double_int::operator -- ()
> > +{
> > +  *this - double_int_one;
> > +  return *this;
> > +}
>
> Surely unused results there?

Typically yes, but that is the interface for that operator.
Lawrence Crowl Aug. 8, 2012, 10:25 p.m. UTC | #19
On 8/8/12, Richard Guenther <richard.guenther@gmail.com> wrote:
> On Aug 7, 2012 Lawrence Crowl <crowl@google.com> wrote:
> > We should probably think about naming conventions for mutating
> > operations, as I expect we will want them eventually.
>
> Right.  In the end I would prefer explicit constructors.

I don't think we're thinking about the same thing.

I'm talking about member functions like mystring.append ("foo").
The += operator is mutating as well.

Constructors do not mutate, they create.
Lawrence Crowl Aug. 8, 2012, 10:32 p.m. UTC | #20
On 8/8/12, Richard Guenther <richard.guenther@gmail.com> wrote:
> On Aug 7, 2012 Lawrence Crowl <crowl@google.com> wrote:
> > On 8/7/12, Richard Guenther <richard.guenther@gmail.com> wrote:
> > > For most parts overloads that take an (unsigned) HOST_WIDE_INT
> > > argument would be nice, as well as the ability to say dbl + 1.
> >
> > Hm.  There seems to be significant opinion that there should
> > not be any implicit conversions.  I am okay with operations as
> > above, but would like to hear the opinions of others.
>
> Well, I'd simply add
>
>   double_int operator+(HOST_WIDE_INT);
>   double_int operator+(unsigned HOST_WIDE_INT);
>
> and be done with it ;)  Yes, a tad bit more inconvenient on the
> implementation side compared to a non-explicit constructor from
> HOST_WIDE_INT or a conversion operator ... but adhering to the
> rule that we do _not_ want such automatic conversions (well, yet,
> for the start).

Ah, we have a different definition of implicit conversion.  In my
mind, the above overloads do an implicit conversion.  The issue
is that the calling code does not make the conversion obvious.
Note the difference in

   a = b + i;
   a = b + double_int(i);

Using overloads as above is generally safer than using an implicit
converting constructor or an implicit conversion operator.  If folks
are really only objecting to the implementation technique, we have
a somewhat different outcome.
Lawrence Crowl Aug. 8, 2012, 10:38 p.m. UTC | #21
On 8/8/12, Richard Guenther <richard.guenther@gmail.com> wrote:
> On Aug 8, 2012 Marc Glisse <marc.glisse@inria.fr> wrote:
> > On Wed, 8 Aug 2012, Richard Guenther wrote:
> > > > > > +  static double_int make (unsigned HOST_WIDE_INT cst);
> > > > > > +  static double_int make (HOST_WIDE_INT cst);
> > > > > > +  static double_int make (unsigned int cst);
> > > > > > +  static double_int make (int cst);
> >
> > [...]
> >
> > > > > Btw, if HOST_WIDE_INT == int the above won't even compile.
> > > >
> > > > Is that true of any host?  I am not aware of any.  Anyway,
> > > > it is moot if we remove the overloads.
> > >
> > > Right.  I'd simply rely on int / unsigned int promotion to
> > > HOST_WIDE_INT or unsigned HOST_WIDE_INT and only provide
> > > overloads for HOST_WIDE_INT kinds anyway.
> >
> > Sadly, that doesn't work with the current C++ rules (there is
> > a proposal to change that for C++1y):
> >
> > void f(long);
> > void f(unsigned long);
> > void g(int x){f(x);}
> >
> > e.cc: In function ‘void g(int)’:
> > e.cc:3:18: error: call of overloaded ‘f(int&)’ is ambiguous
> > e.cc:3:18: note: candidates are:
> > e.cc:1:6: note: void f(long int)
> > e.cc:2:6: note: void f(long unsigned int)
>
> Ick ... I forgot that integer promotions do not apply for int
> -> long.  So even f(1) would be ambiguous, right?  So I suppose
> we have to bite the bullet and add overloads for all (unsigned)
> integer types from int to HOST_WIDE_INT (if HOST_WIDE_INT is
> long long then we have to add overloads for int, unsigned int,
> long and unsigned long).
>
> Or use template magic to force promotion to HOST_WIDE_INT for
> integer types smaller than HOST_WIDE_INT...

I did not get to the structure I had accidentally.  However, with
the prior suggestion to preserve exact semantics to existing calls,
it is all moot because we cannot have overloading.

We can test whether the code is making double_ints with cross-sign
ints by adding undefined overloads.  I think we should do that and
make all such crossings explicit.  However, I want to wait for a
separate patch.
Lawrence Crowl Aug. 8, 2012, 11:24 p.m. UTC | #22
On 8/8/12, Gabriel Dos Reis <gdr@integrable-solutions.net> wrote:
> On Aug 8, 2012 Miles Bader <miles@gnu.org> wrote:
> > Richard Guenther <richard.guenther@gmail.com> writes:
> > > > > > Constructors are allowed, but PODs are often passed
> > > > > > more efficiently.  That property seemed particularly
> > > > > > important for double_int.
> > > > >
> > > > > Show us the difference in timing.  Show us the generated
> > > > > code.  I can't imagine that it could ever matter.
> > > >
> > > > I'm also curious about that statement...  PODs don't really
> > > > seem to offer much advantage with modern compilers, except
> > > > in a few very specific cases (of which this doesn't seem
> > > > to be one), e.g. in unions.
> > >
> > > They make a difference for the by-value passing ABI.
> > > double-ints can be passed in two registers on most platforms.
> >
> > Sure, but that doesn't seem to depend on PODness -- non-PODs
> > can be passed in two registers as well, AFAICS...
> >
> > E.g., in the following:
> >
> > typedef long valtype;
> >
> > struct X { valtype x, y; };
> > struct Y { valtype x, y;
> > >  Y (valtype a, valtype b) : x (a), y (b) { }
> > };
> >
> > extern void fx (X x);
> > void test_x () {X x = { 1, 2 }; fx (x); }
> >
> > extern void fy (Y y);
> > void test_y () {Y y (1, 2); fy (y); }
> >
> > test_x and test_y use exactly the same calling sequence (and
> > contain exactly the same assembly code)...  [on x86-64]
>
> It is not PODness in the standard sense that matters.  It is
> podness from the ABI perspecitve: Y does not have a user-defined
> copy-constructor nor a desctructor; it is not a polymorphic type,
> so it is OK to pass in registers just like X.

Well, more specifically, the Itanium ABI says if the copy constructor
and the destructor are trivial, one passes the class in registers.
Other ABIs can make other choices.  Older ABIs often pass all
structs and classes indirectly.

The adding in inline versions of various special members into
the following code results in the following worst-case changes.

			x86			x86_64
instructions:		48 -> 69 = 144%		38 -> 53 = 139%
stack operations:	 6 -> 10 = 167%		 2 ->  6 = 300%
memory operations:	28 -> 38 = 136%		22 -> 28 = 127%

These numbers are not huge, particularly in context, but worth
considering.

In any event, the point is moot.  To implement the exact semantics of
current expressions using shwi_to_double_int and uhwi_to_double_int,
we cannot use constructors anyway.  So, there remains no immediate
reason to use any constructors.


struct type
{
#ifdef DEFAULT
  type ();
#endif
#ifdef INITIAL
  type (int);
#endif
#ifdef COPYCON
  type (const type &from)
        : field1 (from.field1),
          field2 (from.field2)
        {
        }
#endif
#ifdef DESTRUCT
  ~type ()
        {
        field1 = 0;
        field2 = 0;
        }
#endif
  type method (type);
  long int field1;
  long int field2;
};

extern type global;

void callee (type arg);

void function_caller ()
{
  type local (global);
  callee (local);
  callee (global);
}

void method_caller (type arg1, type arg2)
{
  type var1 (global);
  type var2 = arg2;
  arg1.method (arg2);
  var1.method (var2);
}
Lawrence Crowl Aug. 9, 2012, 1:15 a.m. UTC | #23
On 8/8/12, Miles Bader <miles@gnu.org> wrote:
> Mike Stump <mikestump@comcast.net> writes:
> > > Constructors are allowed, but PODs are often passed more
> > > efficiently.  That property seemed particularly important
> > > for double_int.
> >
> > Show us the difference in timing.  Show us the generated code.
> > I can't imagine that it could ever matter.
>
> I'm also curious about that statement...  PODs don't really
> seem to offer much advantage with modern compilers, except in a
> few very specific cases (of which this doesn't seem to be one),
> e.g. in unions.

Which brings up a critical point that double_int is used in trees,
which are in a union, and so double_int must be a POD until trees
are no longer unions.
Richard Biener Aug. 9, 2012, 8:21 a.m. UTC | #24
On Thu, Aug 9, 2012 at 12:17 AM, Lawrence Crowl <crowl@google.com> wrote:
> On 8/7/12, Mike Stump <mikestump@comcast.net> wrote:
>> On Aug 7, 2012, at 11:38 AM, Lawrence Crowl wrote:
>> > Hm.  There seems to be significant opinion that there should not be any
>> > implicit conversions.  I am okay with operations as above, but would like
>> > to hear the opinions of others.
>>
>> If there is an agreed upon and expected semantic, having them are useful.
>> In the wide-int world, which replaces double_int, I think there is an
>> agreeable semantic and I think it is useful, so, I think we should plan on
>> having them, though, I'd be fine with punting their implementation until
>> such time as someone needs it.  If no one every needs the routine, I don't
>> see the harm in not implementing it.
>
> At present, there are no functions equivalent to (double_int + int), so
> there can be no expressions that need this overload.  I have no objection
> to adding such an overload, but if there are no objections, I would rather
> do it as a separate patch.

Sure.  It's just one of the possibilities to clean up existing code.

Richard.

> --
> Lawrence Crowl
Richard Biener Aug. 9, 2012, 8:22 a.m. UTC | #25
On Thu, Aug 9, 2012 at 12:25 AM, Lawrence Crowl <crowl@google.com> wrote:
> On 8/8/12, Richard Guenther <richard.guenther@gmail.com> wrote:
>> On Aug 7, 2012 Lawrence Crowl <crowl@google.com> wrote:
>> > We should probably think about naming conventions for mutating
>> > operations, as I expect we will want them eventually.
>>
>> Right.  In the end I would prefer explicit constructors.
>
> I don't think we're thinking about the same thing.
>
> I'm talking about member functions like mystring.append ("foo").
> The += operator is mutating as well.
>
> Constructors do not mutate, they create.

Ah.  For simple objects like double_int I prefer to have either all ops mutating
or all ops non-mutating.

Richard.

> --
> Lawrence Crowl
Gabriel Dos Reis Aug. 9, 2012, 8:26 a.m. UTC | #26
On Thu, Aug 9, 2012 at 3:22 AM, Richard Guenther
<richard.guenther@gmail.com> wrote:
> On Thu, Aug 9, 2012 at 12:25 AM, Lawrence Crowl <crowl@google.com> wrote:
>> On 8/8/12, Richard Guenther <richard.guenther@gmail.com> wrote:
>>> On Aug 7, 2012 Lawrence Crowl <crowl@google.com> wrote:
>>> > We should probably think about naming conventions for mutating
>>> > operations, as I expect we will want them eventually.
>>>
>>> Right.  In the end I would prefer explicit constructors.
>>
>> I don't think we're thinking about the same thing.
>>
>> I'm talking about member functions like mystring.append ("foo").
>> The += operator is mutating as well.
>>
>> Constructors do not mutate, they create.
>
> Ah.  For simple objects like double_int I prefer to have either all ops mutating
> or all ops non-mutating.

Hmm, isn't that a bit extreme?  I mean that does not hold for simple
types that int
or double, etc.

-- Gaby
Mike Stump Aug. 9, 2012, 3:10 p.m. UTC | #27
On Aug 9, 2012, at 1:22 AM, Richard Guenther wrote:
> Ah.  For simple objects like double_int I prefer to have either all ops mutating
> or all ops non-mutating.

wide_int, which replaces double_int for int types, is always non-mutating, by value interface.  In C++, it will be const & input parameters, to avoid the copies and retain the performance. We maintain a cache under it, and reuse out of it for the long lived objects, for short lived, we just allocate the on the stack as needed.
Michael Matz Aug. 9, 2012, 3:19 p.m. UTC | #28
Hi,

On Thu, 9 Aug 2012, Mike Stump wrote:

> > Ah.  For simple objects like double_int I prefer to have either all 
> > ops mutating or all ops non-mutating.
> 
> wide_int, which replaces double_int for int types, is always 
> non-mutating, by value interface.  In C++, it will be const & input 
> parameters, to avoid the copies and retain the performance. We maintain 
> a cache under it, and reuse out of it for the long lived objects, for 
> short lived, we just allocate the on the stack as needed.

Hmm.  And maintaining a cache is faster than 
passing/returning/manipulating two registers?


Ciao,
Michael.
Mike Stump Aug. 9, 2012, 5:34 p.m. UTC | #29
On Aug 9, 2012, at 8:19 AM, Michael Matz wrote:
> Hmm.  And maintaining a cache is faster than 
> passing/returning/manipulating two registers?

For the most part, we merely mirror existing code, check out lookup_const_double and immed_double_const.  If the existing code is wrong, love to have someone fix it.  :-)  Also, bear in mind, on a port with with OImode math for example, on a 32-bit host, it would be 8 registers...
Michael Matz Aug. 10, 2012, midnight UTC | #30
Hi,

On Thu, 9 Aug 2012, Mike Stump wrote:

> On Aug 9, 2012, at 8:19 AM, Michael Matz wrote:
> > Hmm.  And maintaining a cache is faster than 
> > passing/returning/manipulating two registers?
> 
> For the most part, we merely mirror existing code, check out 
> lookup_const_double and immed_double_const.

No, I won't without patches on this list.  You keep repeating bragging 
about wide_int during the last two weeks, without offering anything 
concrete about it whatsoever.  You'll understand that I (or anybody else) 
can't usefully discuss with you any merits or demerits of the 
implementation you chose.  (can I btw. complain about the retainment of 
underscores?  If it's a base data type, then why not wideint?  Make that a 
testament for the "quality" of feedback you'll get with the information 
given)

I mean, preparing the audience for an upcoming _suggested_ change in data 
structure of course is fine.  But argueing as if the change happenend 
already, and what's more concerning, as if the change was even already 
suggested and agreed upon even though that's not the case, is just bad 
style.

I would suggest to stay conservative about whatever you have (except if 
it's momentarily materializing), and _especially don't argue against or 
for or not against or for whatever improvement is suggested on the grounds 
that you have a better, as of yet secret but surely taking-over-the-world 
very-soon-now implementation of datastructure X_.  Nobody has seen it yet, 
so you can't expect to get any feedback on it.  Certainly that's the thing 
you need to get it into the code base.

> If the existing code is wrong, love to have someone fix it.  :-)  Also, 
> bear in mind, on a port with with OImode math for example, on a 32-bit 
> host, it would be 8 registers...

Nice try.  But what problem do _you_ want to solve?  For instance why 
should a port with OImode for example be interesting to the FSF?  I hope 
you recognize this as half-rhethorical question, but still, how exactly 
will wide_int help for the goal (which remains to be shown as useful), how 
is it implemented?, why isn't it worse than crap on sensible (i.e. 64bit) 
hosts, and why should everybody not interested in such target pay the 
price, or why isn't there a price to pay for non-OI-targets?

I'm actually more intersted in comments to the first part, but still, 
comments on OI appreciated.


Ciao,
Michael.
Mike Stump Aug. 10, 2012, 2:53 a.m. UTC | #31
On Aug 9, 2012, at 5:00 PM, Michael Matz wrote:
> On Thu, 9 Aug 2012, Mike Stump wrote:
> 
>> On Aug 9, 2012, at 8:19 AM, Michael Matz wrote:
>>> Hmm.  And maintaining a cache is faster than 
>>> passing/returning/manipulating two registers?
>> 
>> For the most part, we merely mirror existing code, check out 
>> lookup_const_double and immed_double_const.
> 
> No, I won't without patches on this list.

Ah, we are discussing the code in the gcc tree currently.  You _can_ comment on it, if you like to.  I was only pointing out that this choice we didn't make nor deviate from the code in the top of the tree.  If you think it is wrong to cache it, then talking about the code in the top of the tree is the right place to discuss it.  Though, you don't have to if you don't want to.

> You keep repeating bragging

Such hostility.  Why?  I don't get it.  I _asked_ about when the cxx branch was going to land, I stated that I liked non-mutating interfaces, I gave a heads up that we have a wide-int class to replace double-int for ints.  I _only_ gave a heads up because of the submitted change to the cxx branch conflicts on a larger than expected scale with the wide-int change.  I think giving a heads up before the conflict happens is good citizenship.

> I mean, preparing the audience for an upcoming _suggested_ change in data 
> structure of course is fine.  But argueing as if the change happenend 
> already, and what's more concerning, as if the change was even already 
> suggested and agreed upon even though that's not the case, is just bad 
> style.

So, let me get this straight, alerting people that I have a patch that conflicts with another posted patch is, bad style?  Odd.  I saw it listed on page 10 of the etiquette guide, maybe you could update the guide for us.

> I would suggest to stay conservative about whatever you have (except if 
> it's momentarily materializing), and _especially don't argue against or 
> for or not against or for whatever improvement is suggested

Ah, that's a misunderstanding on your part.  I was not arguing for, or against the double_int changes.  In fact, I'm very supportive of those changes and the entire cxx branch, not that you'd know that, as I think all of the changes are a slam dunk and don't need any support from me.  The :-( in the email that you read, was just a comment that someone is going to have to resolve conflicts.  Now that we know the timing of the cxx branch landing, we expect, we'll handle the conflicts on the wide-int side.  If the timing was different, we'd land the wide-int change first, then the :-( in the heads up comment would be read more as, we're sorry, but we've just scrambled the tree on you, so sorry.

Let me be perfectly clear, I support the double_int changes and the entire cxx-conversion branch.  No work I may or may not have matters or should be considered in reviewing any patches.  I'm a firm believer in the first in, wins method of resolving conflicts.  Sorry if anyone thought I was objecting in anyway to the double_int work.

> Nobody has seen it yet,

Actually, that's not true; but, it doesn't matter any.

> so you can't expect to get any feedback on it.

I don't recall asking for feedback on it.  The feedback I requested that you quote above, was feedback on the code in the top of the tree.
diff mbox

Patch

Index: gcc/ChangeLog.cxx-conversion

2012-08-06   Lawrence Crowl  <crowl@google.com>

	* hash-table.h
	(typedef double_int): Change to struct (POD).
	(double_int::make): New overloads for int to double-int conversion.
	(double_int::mask): New.
	(double_int::max_value): New.
	(double_int::min_value): New.
	(double_int::operator ++): New.
	(double_int::operator --): New.
	(double_int::operator *=): New.
	(double_int::operator +=): New.
	(double_int::operator -=): New.
	(double_int::to_signed): New.
	(double_int::to_unsigned): New.
	(double_int::fits_unsigned): New.
	(double_int::fits_signed): New.
	(double_int::fits): New.
	(double_int::trailing_zeros): New.
	(double_int::popcount): New.
	(double_int::multiple_of): New.
	(double_int::set_bit): New.
	(double_int::mul_with_sign): New.
	(double_int::operator * (binary)): New.
	(double_int::operator + (binary)): New.
	(double_int::operator - (binary)): New.
	(double_int::operator - (unary)): New.
	(double_int::operator ~ (unary)): New.
	(double_int::operator & (binary)): New.
	(double_int::operator | (binary)): New.
	(double_int::operator ^ (binary)): New.
	(double_int::and_not): New.
	(double_int::lshift): New.
	(double_int::rshift): New.
	(double_int::alshift): New.
	(double_int::arshift): New.
	(double_int::llshift): New.
	(double_int::lrshift): New.
	(double_int::lrotate): New.
	(double_int::rrotate): New.
	(double_int::div): New.
	(double_int::sdiv): New.
	(double_int::udiv): New.
	(double_int::mod): New.
	(double_int::smod): New.
	(double_int::umod): New.
	(double_int::divmod): New.
	(double_int::sdivmod): New.
	(double_int::udivmod): New.
	(double_int::ext): New.
	(double_int::zext): New.
	(double_int::sext): New.
	(double_int::is_zero): New.
	(double_int::is_one): New.
	(double_int::is_minus_one): New.
	(double_int::is_negative): New.
	(double_int::cmp): New.
	(double_int::ucmp): New.
	(double_int::scmp): New.
	(double_int::ult): New.
	(double_int::ugt): New.
	(double_int::slt): New.
	(double_int::sgt): New.
	(double_int::max): New.
	(double_int::smax): New.
	(double_int::umax): New.
	(double_int::min): New.
	(double_int::smin): New.
	(double_int::umin): New.
	(double_int::operator ==): New.
	(double_int::operator !=): New.
	(shwi_to_double_int): Change implementation to use member function.
	(double_int_minus_one): Likewise.
	(double_int_zero): Likewise.
	(double_int_one): Likewise.
	(double_int_two): Likewise.
	(double_int_ten): Likewise.
	(uhwi_to_double_int): Likewise.
	(double_int_to_shwi): Likewise.
	(double_int_to_uhwi): Likewise.
	(double_int_fits_in_uhwi_p): Likewise.
	(double_int_fits_in_shwi_p): Likewise.
	(double_int_fits_in_hwi_p): Likewise.
	(double_int_mul): Likewise.
	(double_int_mul_with_sign): Likewise.
	(double_int_add): Likewise.
	(double_int_sub): Likewise.
	(double_int_neg): Likewise.
	(double_int_div): Likewise.
	(double_int_sdiv): Likewise.
	(double_int_udiv): Likewise.
	(double_int_mod): Likewise.
	(double_int_smod): Likewise.
	(double_int_umod): Likewise.
	(double_int_divmod): Likewise.
	(double_int_sdivmod): Likewise.
	(double_int_udivmod): Likewise.
	(double_int_multiple_of): Likewise.
	(double_int_setbit): Likewise.
	(double_int_ctz): Likewise.
	(double_int_not): Likewise.
	(double_int_ior): Likewise.
	(double_int_and): Likewise.
	(double_int_and_not): Likewise.
	(double_int_xor): Likewise.
	(double_int_lshift): Likewise.
	(double_int_rshift): Likewise.
	(double_int_lrotate): Likewise.
	(double_int_rrotate): Likewise.
	(double_int_cmp): Likewise.
	(double_int_scmp): Likewise.
	(double_int_ucmp): Likewise.
	(double_int_max): Likewise.
	(double_int_smax): Likewise.
	(double_int_umax): Likewise.
	(double_int_min): Likewise.
	(double_int_smin): Likewise.
	(double_int_umin): Likewise.
	(double_int_ext): Likewise.
	(double_int_sext): Likewise.
	(double_int_zext): Likewise.
	(double_int_mask): Likewise.
	(double_int_max_value): Likewise.
	(double_int_min_value): Likewise.
	(double_int_zero_p): Likewise.
	(double_int_one_p): Likewise.
	(double_int_minus_one_p): Likewise.
	(double_int_equal_p): Likewise.
	(double_int_popcount): Likewise.
	* hash-table.c
	(double_int_mask): Reuse implementation for double_int::mask.
	(double_int_max_value): Likewise.
	(double_int_min_value): Likewise.
	(double_int_ext): Likewise.
	(double_int_zext): Likewise.
	(double_int_sext): Likewise.
	(double_int_mul_with_sign): Likewise.
	(double_int_divmod): Likewise.
	(double_int_sdivmod): Likewise.
	(double_int_udivmod): Likewise.
	(double_int_div): Likewise.
	(double_int_sdiv): Likewise.
	(double_int_udiv): Likewise.
	(double_int_mod): Likewise.
	(double_int_smod): Likewise.
	(double_int_umod): Likewise.
	(double_int_multiple_of): Likewise.
	(double_int_lshift): Likewise.
	(double_int_rshift): Likewise.
	(double_int_lrotate): Likewise.
	(double_int_rrotate): Likewise.
	(double_int_cmp): Likewise.
	(double_int_ucmp): Likewise.
	(double_int_scmp): Likewise.
	(double_int_max): Likewise.
	(double_int_smax): Likewise.
	(double_int_umax): Likewise.
	(double_int_min): Likewise.
	(double_int_smin): Likewise.
	(double_int_umin): Likewise.
	(double_int_min): Likewise.
	(double_int_min): Likewise.
	(double_int_min): Likewise.
	(double_int_min): Likewise.
	(double_int_min): Likewise.
	(double_int_min): Likewise.
	(double_int::alshift): New.
	(double_int::arshift): New.
	(double_int::llshift): New.
	(double_int::lrshift): New.
	(double_int::ult): New.
	(double_int::ugt): New.
	(double_int::slt): New.
	(double_int::sgt): New.
	(double_int_setbit): Reuse implementation for double_int::set_bit,
	which avoids a name conflict with a macro.
	(double_int_double_int_ctz): Reuse implementation for
	double_int::trailing_zeros.
	(double_int_fits_in_shwi_p): Reuse implementation for
	double_int::fits_signed.
	(double_int_fits_in_hwi_p): Reuse implementation for double_int::fits.
	(double_int_mul): Reuse implementation for binary
	double_int::operator *.
	(double_int_add): Likewise.
	(double_int_sub): Likewise.
	(double_int_neg): Reuse implementation for unary
	double_int::operator -.
	(double_int_max_value): Likewise.
	* fixed-value.c: Change to use member functions introduced above.


Index: gcc/double-int.c
===================================================================
--- gcc/double-int.c	(revision 190186)
+++ gcc/double-int.c	(working copy)
@@ -595,7 +595,7 @@  div_and_round_double (unsigned code, int
 /* Returns mask for PREC bits.  */
 
 double_int
-double_int_mask (unsigned prec)
+double_int::mask (unsigned prec)
 {
   unsigned HOST_WIDE_INT m;
   double_int mask;
@@ -620,20 +620,20 @@  double_int_mask (unsigned prec)
    of precision PREC.  */
 
 double_int
-double_int_max_value (unsigned int prec, bool uns)
+double_int::max_value (unsigned int prec, bool uns)
 {
-  return double_int_mask (prec - (uns ? 0 : 1));
+  return double_int::mask (prec - (uns ? 0 : 1));
 }
 
 /* Returns a minimum value for signed or unsigned integer
    of precision PREC.  */
 
 double_int
-double_int_min_value (unsigned int prec, bool uns)
+double_int::min_value (unsigned int prec, bool uns)
 {
   if (uns)
     return double_int_zero;
-  return double_int_lshift (double_int_one, prec - 1, prec, false);
+  return double_int_one.lshift (prec - 1, prec, false);
 }
 
 /* Clears the bits of CST over the precision PREC.  If UNS is false, the bits
@@ -644,20 +644,21 @@  double_int_min_value (unsigned int prec,
    of CST, with the given signedness.  */
 
 double_int
-double_int_ext (double_int cst, unsigned prec, bool uns)
+double_int::ext (unsigned prec, bool uns) const
 {
   if (uns)
-    return double_int_zext (cst, prec);
+    return this->zext (prec);
   else
-    return double_int_sext (cst, prec);
+    return this->sext (prec);
 }
 
-/* The same as double_int_ext with UNS = true.  */
+/* The same as double_int::ext with UNS = true.  */
 
 double_int
-double_int_zext (double_int cst, unsigned prec)
+double_int::zext (unsigned prec) const
 {
-  double_int mask = double_int_mask (prec);
+  const double_int &cst = *this;
+  double_int mask = double_int::mask (prec);
   double_int r;
 
   r.low = cst.low & mask.low;
@@ -666,12 +667,13 @@  double_int_zext (double_int cst, unsigne
   return r;
 }
 
-/* The same as double_int_ext with UNS = false.  */
+/* The same as double_int::ext with UNS = false.  */
 
 double_int
-double_int_sext (double_int cst, unsigned prec)
+double_int::sext (unsigned prec) const
 {
-  double_int mask = double_int_mask (prec);
+  const double_int &cst = *this;
+  double_int mask = double_int::mask (prec);
   double_int r;
   unsigned HOST_WIDE_INT snum;
 
@@ -699,8 +701,9 @@  double_int_sext (double_int cst, unsigne
 /* Returns true if CST fits in signed HOST_WIDE_INT.  */
 
 bool
-double_int_fits_in_shwi_p (double_int cst)
+double_int::fits_signed () const
 {
+  const double_int &cst = *this;
   if (cst.high == 0)
     return (HOST_WIDE_INT) cst.low >= 0;
   else if (cst.high == -1)
@@ -713,19 +716,20 @@  double_int_fits_in_shwi_p (double_int cs
    unsigned HOST_WIDE_INT if UNS is true.  */
 
 bool
-double_int_fits_in_hwi_p (double_int cst, bool uns)
+double_int::fits (bool uns) const
 {
   if (uns)
-    return double_int_fits_in_uhwi_p (cst);
+    return this->fits_unsigned ();
   else
-    return double_int_fits_in_shwi_p (cst);
+    return this->fits_signed ();
 }
 
 /* Returns A * B.  */
 
 double_int
-double_int_mul (double_int a, double_int b)
+double_int::operator * (double_int b) const
 {
+  const double_int &a = *this;
   double_int ret;
   mul_double (a.low, a.high, b.low, b.high, &ret.low, &ret.high);
   return ret;
@@ -735,9 +739,9 @@  double_int_mul (double_int a, double_int
    *OVERFLOW is set to nonzero.  */
 
 double_int
-double_int_mul_with_sign (double_int a, double_int b,
-                          bool unsigned_p, int *overflow)
+double_int::mul_with_sign (double_int b, bool unsigned_p, int *overflow) const
 {
+  const double_int &a = *this;
   double_int ret;
   *overflow = mul_double_with_sign (a.low, a.high, b.low, b.high,
                                     &ret.low, &ret.high, unsigned_p);
@@ -747,8 +751,9 @@  double_int_mul_with_sign (double_int a, 
 /* Returns A + B.  */
 
 double_int
-double_int_add (double_int a, double_int b)
+double_int::operator + (double_int b) const
 {
+  const double_int &a = *this;
   double_int ret;
   add_double (a.low, a.high, b.low, b.high, &ret.low, &ret.high);
   return ret;
@@ -757,8 +762,9 @@  double_int_add (double_int a, double_int
 /* Returns A - B.  */
 
 double_int
-double_int_sub (double_int a, double_int b)
+double_int::operator - (double_int b) const
 {
+  const double_int &a = *this;
   double_int ret;
   neg_double (b.low, b.high, &b.low, &b.high);
   add_double (a.low, a.high, b.low, b.high, &ret.low, &ret.high);
@@ -768,8 +774,9 @@  double_int_sub (double_int a, double_int
 /* Returns -A.  */
 
 double_int
-double_int_neg (double_int a)
+double_int::operator - () const
 {
+  const double_int &a = *this;
   double_int ret;
   neg_double (a.low, a.high, &ret.low, &ret.high);
   return ret;
@@ -781,9 +788,10 @@  double_int_neg (double_int a)
    stored to MOD.  */
 
 double_int
-double_int_divmod (double_int a, double_int b, bool uns, unsigned code,
-		   double_int *mod)
+double_int::divmod (double_int b, bool uns, unsigned code,
+		    double_int *mod) const
 {
+  const double_int &a = *this;
   double_int ret;
 
   div_and_round_double (code, uns, a.low, a.high,
@@ -792,20 +800,20 @@  double_int_divmod (double_int a, double_
   return ret;
 }
 
-/* The same as double_int_divmod with UNS = false.  */
+/* The same as double_int::divmod with UNS = false.  */
 
 double_int
-double_int_sdivmod (double_int a, double_int b, unsigned code, double_int *mod)
+double_int::sdivmod (double_int b, unsigned code, double_int *mod) const
 {
-  return double_int_divmod (a, b, false, code, mod);
+  return this->divmod (b, false, code, mod);
 }
 
-/* The same as double_int_divmod with UNS = true.  */
+/* The same as double_int::divmod with UNS = true.  */
 
 double_int
-double_int_udivmod (double_int a, double_int b, unsigned code, double_int *mod)
+double_int::udivmod (double_int b, unsigned code, double_int *mod) const
 {
-  return double_int_divmod (a, b, true, code, mod);
+  return this->divmod (b, true, code, mod);
 }
 
 /* Returns A / B (computed as unsigned depending on UNS, and rounded as
@@ -813,27 +821,27 @@  double_int_udivmod (double_int a, double
    must be included before tree.h.  */
 
 double_int
-double_int_div (double_int a, double_int b, bool uns, unsigned code)
+double_int::div (double_int b, bool uns, unsigned code) const
 {
   double_int mod;
 
-  return double_int_divmod (a, b, uns, code, &mod);
+  return this->divmod (b, uns, code, &mod);
 }
 
-/* The same as double_int_div with UNS = false.  */
+/* The same as double_int::div with UNS = false.  */
 
 double_int
-double_int_sdiv (double_int a, double_int b, unsigned code)
+double_int::sdiv (double_int b, unsigned code) const
 {
-  return double_int_div (a, b, false, code);
+  return this->div (b, false, code);
 }
 
-/* The same as double_int_div with UNS = true.  */
+/* The same as double_int::div with UNS = true.  */
 
 double_int
-double_int_udiv (double_int a, double_int b, unsigned code)
+double_int::udiv (double_int b, unsigned code) const
 {
-  return double_int_div (a, b, true, code);
+  return this->div (b, true, code);
 }
 
 /* Returns A % B (computed as unsigned depending on UNS, and rounded as
@@ -841,28 +849,28 @@  double_int_udiv (double_int a, double_in
    must be included before tree.h.  */
 
 double_int
-double_int_mod (double_int a, double_int b, bool uns, unsigned code)
+double_int::mod (double_int b, bool uns, unsigned code) const
 {
   double_int mod;
 
-  double_int_divmod (a, b, uns, code, &mod);
+  this->divmod (b, uns, code, &mod);
   return mod;
 }
 
-/* The same as double_int_mod with UNS = false.  */
+/* The same as double_int::mod with UNS = false.  */
 
 double_int
-double_int_smod (double_int a, double_int b, unsigned code)
+double_int::smod (double_int b, unsigned code) const
 {
-  return double_int_mod (a, b, false, code);
+  return this->mod (b, false, code);
 }
 
-/* The same as double_int_mod with UNS = true.  */
+/* The same as double_int::mod with UNS = true.  */
 
 double_int
-double_int_umod (double_int a, double_int b, unsigned code)
+double_int::umod (double_int b, unsigned code) const
 {
-  return double_int_mod (a, b, true, code);
+  return this->mod (b, true, code);
 }
 
 /* Return TRUE iff PRODUCT is an integral multiple of FACTOR, and return
@@ -870,13 +878,13 @@  double_int_umod (double_int a, double_in
    unchanged.  */
 
 bool
-double_int_multiple_of (double_int product, double_int factor,
-			bool unsigned_p, double_int *multiple)
+double_int::multiple_of (double_int factor,
+			 bool unsigned_p, double_int *multiple) const
 {
   double_int remainder;
-  double_int quotient = double_int_divmod (product, factor, unsigned_p,
+  double_int quotient = this->divmod (factor, unsigned_p,
 					   TRUNC_DIV_EXPR, &remainder);
-  if (double_int_zero_p (remainder))
+  if (remainder.is_zero ())
     {
       *multiple = quotient;
       return true;
@@ -887,8 +895,9 @@  double_int_multiple_of (double_int produ
 
 /* Set BITPOS bit in A.  */
 double_int
-double_int_setbit (double_int a, unsigned bitpos)
+double_int::set_bit (unsigned bitpos) const
 {
+  double_int a = *this;
   if (bitpos < HOST_BITS_PER_WIDE_INT)
     a.low |= (unsigned HOST_WIDE_INT) 1 << bitpos;
   else
@@ -899,8 +908,9 @@  double_int_setbit (double_int a, unsigne
 
 /* Count trailing zeros in A.  */
 int
-double_int_ctz (double_int a)
+double_int::trailing_zeros () const
 {
+  const double_int &a = *this;
   unsigned HOST_WIDE_INT w = a.low ? a.low : (unsigned HOST_WIDE_INT) a.high;
   unsigned bits = a.low ? 0 : HOST_BITS_PER_WIDE_INT;
   if (!w)
@@ -914,30 +924,76 @@  double_int_ctz (double_int a)
    otherwise use logical shift.  */
 
 double_int
-double_int_lshift (double_int a, HOST_WIDE_INT count, unsigned int prec, bool arith)
+double_int::lshift (HOST_WIDE_INT count, unsigned int prec, bool arith) const
 {
+  const double_int &a = *this;
   double_int ret;
   lshift_double (a.low, a.high, count, prec, &ret.low, &ret.high, arith);
   return ret;
 }
 
-/* Shift A rigth by COUNT places keeping only PREC bits of result.  Shift
+/* Shift A right by COUNT places keeping only PREC bits of result.  Shift
    left if COUNT is negative.  ARITH true specifies arithmetic shifting;
    otherwise use logical shift.  */
 
 double_int
-double_int_rshift (double_int a, HOST_WIDE_INT count, unsigned int prec, bool arith)
+double_int::rshift (HOST_WIDE_INT count, unsigned int prec, bool arith) const
 {
+  const double_int &a = *this;
   double_int ret;
   lshift_double (a.low, a.high, -count, prec, &ret.low, &ret.high, arith);
   return ret;
 }
 
+/* Arithmetic shift A left by COUNT places keeping only PREC bits of result.
+   Shift right if COUNT is negative.  */
+
+double_int
+double_int::alshift (HOST_WIDE_INT count, unsigned int prec) const
+{
+  double_int r;
+  lshift_double (low, high, count, prec, &r.low, &r.high, true);
+  return r;
+}
+
+/* Arithmetic shift A right by COUNT places keeping only PREC bits of result.
+   Shift left if COUNT is negative.  */
+
+double_int
+double_int::arshift (HOST_WIDE_INT count, unsigned int prec) const
+{
+  double_int r;
+  lshift_double (low, high, -count, prec, &r.low, &r.high, true);
+  return r;
+}
+
+/* Logical shift A left by COUNT places keeping only PREC bits of result.
+   Shift right if COUNT is negative.  */
+
+double_int
+double_int::llshift (HOST_WIDE_INT count, unsigned int prec) const
+{
+  double_int r;
+  lshift_double (low, high, count, prec, &r.low, &r.high, false);
+  return r;
+}
+
+/* Logical shift A right by COUNT places keeping only PREC bits of result.
+   Shift left if COUNT is negative.  */
+
+double_int
+double_int::lrshift (HOST_WIDE_INT count, unsigned int prec) const
+{
+  double_int r;
+  lshift_double (low, high, -count, prec, &r.low, &r.high, false);
+  return r;
+}
+
 /* Rotate  A left by COUNT places keeping only PREC bits of result.
    Rotate right if COUNT is negative.  */
 
 double_int
-double_int_lrotate (double_int a, HOST_WIDE_INT count, unsigned int prec)
+double_int::lrotate (HOST_WIDE_INT count, unsigned int prec) const
 {
   double_int t1, t2;
 
@@ -945,17 +1001,17 @@  double_int_lrotate (double_int a, HOST_W
   if (count < 0)
     count += prec;
 
-  t1 = double_int_lshift (a, count, prec, false);
-  t2 = double_int_rshift (a, prec - count, prec, false);
+  t1 = this->lshift (count, prec, false);
+  t2 = this->rshift (prec - count, prec, false);
 
-  return double_int_ior (t1, t2);
+  return t1 | t2;
 }
 
 /* Rotate A rigth by COUNT places keeping only PREC bits of result.
    Rotate right if COUNT is negative.  */
 
 double_int
-double_int_rrotate (double_int a, HOST_WIDE_INT count, unsigned int prec)
+double_int::rrotate (HOST_WIDE_INT count, unsigned int prec) const
 {
   double_int t1, t2;
 
@@ -963,30 +1019,31 @@  double_int_rrotate (double_int a, HOST_W
   if (count < 0)
     count += prec;
 
-  t1 = double_int_rshift (a, count, prec, false);
-  t2 = double_int_lshift (a, prec - count, prec, false);
+  t1 = this->rshift (count, prec, false);
+  t2 = this->lshift (prec - count, prec, false);
 
-  return double_int_ior (t1, t2);
+  return t1 | t2;
 }
 
 /* Returns -1 if A < B, 0 if A == B and 1 if A > B.  Signedness of the
    comparison is given by UNS.  */
 
 int
-double_int_cmp (double_int a, double_int b, bool uns)
+double_int::cmp (double_int b, bool uns) const
 {
   if (uns)
-    return double_int_ucmp (a, b);
+    return this->ucmp (b);
   else
-    return double_int_scmp (a, b);
+    return this->scmp (b);
 }
 
 /* Compares two unsigned values A and B.  Returns -1 if A < B, 0 if A == B,
    and 1 if A > B.  */
 
 int
-double_int_ucmp (double_int a, double_int b)
+double_int::ucmp (double_int b) const
 {
+  const double_int &a = *this;
   if ((unsigned HOST_WIDE_INT) a.high < (unsigned HOST_WIDE_INT) b.high)
     return -1;
   if ((unsigned HOST_WIDE_INT) a.high > (unsigned HOST_WIDE_INT) b.high)
@@ -1003,8 +1060,9 @@  double_int_ucmp (double_int a, double_in
    and 1 if A > B.  */
 
 int
-double_int_scmp (double_int a, double_int b)
+double_int::scmp (double_int b) const
 {
+  const double_int &a = *this;
   if (a.high < b.high)
     return -1;
   if (a.high > b.high)
@@ -1017,49 +1075,111 @@  double_int_scmp (double_int a, double_in
   return 0;
 }
 
+/* Compares two unsigned values A and B for less-than.  */
+
+bool
+double_int::ult (double_int b) const
+{
+  if ((unsigned HOST_WIDE_INT) high < (unsigned HOST_WIDE_INT) b.high)
+    return true;
+  if ((unsigned HOST_WIDE_INT) high > (unsigned HOST_WIDE_INT) b.high)
+    return false;
+  if (low < b.low)
+    return true;
+  return false;
+}
+
+/* Compares two unsigned values A and B for greater-than.  */
+
+bool
+double_int::ugt (double_int b) const
+{
+  if ((unsigned HOST_WIDE_INT) high > (unsigned HOST_WIDE_INT) b.high)
+    return true;
+  if ((unsigned HOST_WIDE_INT) high < (unsigned HOST_WIDE_INT) b.high)
+    return false;
+  if (low > b.low)
+    return true;
+  return false;
+}
+
+/* Compares two signed values A and B for less-than.  */
+
+bool
+double_int::slt (double_int b) const
+{
+  if (high < b.high)
+    return true;
+  if (high > b.high)
+    return false;
+  if (low < b.low)
+    return true;
+  return false;
+}
+
+/* Compares two signed values A and B for greater-than.  */
+
+bool
+double_int::sgt (double_int b) const
+{
+  if (high > b.high)
+    return true;
+  if (high < b.high)
+    return false;
+  if (low > b.low)
+    return true;
+  return false;
+}
+
+
 /* Compares two values A and B.  Returns max value.  Signedness of the
    comparison is given by UNS.  */
 
 double_int
-double_int_max (double_int a, double_int b, bool uns)
+double_int::max (double_int b, bool uns)
 {
-  return (double_int_cmp (a, b, uns) == 1) ? a : b;
+  return (this->cmp (b, uns) == 1) ? *this : b;
 }
 
 /* Compares two signed values A and B.  Returns max value.  */
 
-double_int double_int_smax (double_int a, double_int b)
+double_int
+double_int::smax (double_int b)
 {
-  return (double_int_scmp (a, b) == 1) ? a : b;
+  return (this->scmp (b) == 1) ? *this : b;
 }
 
 /* Compares two unsigned values A and B.  Returns max value.  */
 
-double_int double_int_umax (double_int a, double_int b)
+double_int
+double_int::umax (double_int b)
 {
-  return (double_int_ucmp (a, b) == 1) ? a : b;
+  return (this->ucmp (b) == 1) ? *this : b;
 }
 
 /* Compares two values A and B.  Returns mix value.  Signedness of the
    comparison is given by UNS.  */
 
-double_int double_int_min (double_int a, double_int b, bool uns)
+double_int
+double_int::min (double_int b, bool uns)
 {
-  return (double_int_cmp (a, b, uns) == -1) ? a : b;
+  return (this->cmp (b, uns) == -1) ? *this : b;
 }
 
 /* Compares two signed values A and B.  Returns min value.  */
 
-double_int double_int_smin (double_int a, double_int b)
+double_int
+double_int::smin (double_int b)
 {
-  return (double_int_scmp (a, b) == -1) ? a : b;
+  return (this->scmp (b) == -1) ? *this : b;
 }
 
 /* Compares two unsigned values A and B.  Returns min value.  */
 
-double_int double_int_umin (double_int a, double_int b)
+double_int
+double_int::umin (double_int b)
 {
-  return (double_int_ucmp (a, b) == -1) ? a : b;
+  return (this->ucmp (b) == -1) ? *this : b;
 }
 
 /* Splits last digit of *CST (taken as unsigned) in BASE and returns it.  */
@@ -1087,19 +1207,19 @@  dump_double_int (FILE *file, double_int 
   unsigned digits[100], n;
   int i;
 
-  if (double_int_zero_p (cst))
+  if (cst.is_zero ())
     {
       fprintf (file, "0");
       return;
     }
 
-  if (!uns && double_int_negative_p (cst))
+  if (!uns && cst.is_negative ())
     {
       fprintf (file, "-");
-      cst = double_int_neg (cst);
+      cst = -cst;
     }
 
-  for (n = 0; !double_int_zero_p (cst); n++)
+  for (n = 0; !cst.is_zero (); n++)
     digits[n] = double_int_split_digit (&cst, 10);
   for (i = n - 1; i >= 0; i--)
     fprintf (file, "%u", digits[i]);
@@ -1115,10 +1235,10 @@  mpz_set_double_int (mpz_t result, double
   bool negate = false;
   unsigned HOST_WIDE_INT vp[2];
 
-  if (!uns && double_int_negative_p (val))
+  if (!uns && val.is_negative ())
     {
       negate = true;
-      val = double_int_neg (val);
+      val = -val;
     }
 
   vp[0] = val.low;
@@ -1176,9 +1296,9 @@  mpz_get_double_int (const_tree type, mpz
   res.low = vp[0];
   res.high = (HOST_WIDE_INT) vp[1];
 
-  res = double_int_ext (res, TYPE_PRECISION (type), TYPE_UNSIGNED (type));
+  res = res.ext (TYPE_PRECISION (type), TYPE_UNSIGNED (type));
   if (mpz_sgn (val) < 0)
-    res = double_int_neg (res);
+    res = -res;
 
   return res;
 }
Index: gcc/double-int.h
===================================================================
--- gcc/double-int.h	(revision 190186)
+++ gcc/double-int.h	(working copy)
@@ -50,10 +50,134 @@  along with GCC; see the file COPYING3.  
    numbers with precision higher than HOST_WIDE_INT).  It might be less
    confusing to have them both signed or both unsigned.  */
 
-typedef struct
+typedef struct double_int
 {
+public:
+  /* Normally, we would define constructors to create instances.
+     Two things prevent us from doing so.
+     First, defining a constructor makes the class non-POD in C++03,
+     and we certainly want double_int to be a POD.
+     Second, the GCC conding conventions prefer explicit conversion,
+     and explicit conversion operators are not available until C++11.  */
+
+  static double_int make (unsigned HOST_WIDE_INT cst);
+  static double_int make (HOST_WIDE_INT cst);
+  static double_int make (unsigned int cst);
+  static double_int make (int cst);
+
+  /* No copy assignment operator or destructor to keep the type a POD.  */
+
+  /* There are some special value-creation static member functions.  */
+
+  static double_int mask (unsigned prec);
+  static double_int max_value (unsigned int prec, bool uns);
+  static double_int min_value (unsigned int prec, bool uns);
+
+  /* The following functions are mutating operations.  */
+
+  double_int &operator ++(); // prefix
+  double_int &operator --(); // prefix
+  double_int &operator *= (double_int);
+  double_int &operator += (double_int);
+  double_int &operator -= (double_int);
+
+  /* The following functions are non-mutating operations.  */
+
+  /* Conversion functions.  */
+
+  HOST_WIDE_INT to_signed () const;
+  unsigned HOST_WIDE_INT to_unsigned () const;
+
+  /* Conversion query functions.  */
+
+  bool fits_unsigned() const;
+  bool fits_signed() const;
+  bool fits (bool uns) const;
+
+  /* Attribute query functions.  */
+
+  int trailing_zeros () const;
+  int popcount () const;
+
+  /* Arithmetic query operations.  */
+
+  bool multiple_of (double_int, bool, double_int *) const;
+
+  /* Arithmetic operation functions.  */
+
+  double_int set_bit (unsigned) const;
+  double_int mul_with_sign (double_int, bool, int *) const;
+
+  double_int operator * (double_int b) const;
+  double_int operator + (double_int b) const;
+  double_int operator - (double_int b) const;
+  double_int operator - () const;
+  double_int operator ~ () const;
+  double_int operator & (double_int b) const;
+  double_int operator | (double_int b) const;
+  double_int operator ^ (double_int b) const;
+  double_int and_not (double_int b) const;
+
+  double_int lshift (HOST_WIDE_INT count, unsigned int prec, bool arith) const;
+  double_int rshift (HOST_WIDE_INT count, unsigned int prec, bool arith) const;
+  double_int alshift (HOST_WIDE_INT count, unsigned int prec) const;
+  double_int arshift (HOST_WIDE_INT count, unsigned int prec) const;
+  double_int llshift (HOST_WIDE_INT count, unsigned int prec) const;
+  double_int lrshift (HOST_WIDE_INT count, unsigned int prec) const;
+  double_int lrotate (HOST_WIDE_INT count, unsigned int prec) const;
+  double_int rrotate (HOST_WIDE_INT count, unsigned int prec) const;
+
+  /* You must ensure that double_int::ext is called on the operands
+     of the following operations, if the precision of the numbers
+     is less than HOST_BITS_PER_DOUBLE_INT bits.  */
+  double_int div (double_int, bool, unsigned) const;
+  double_int sdiv (double_int, unsigned) const;
+  double_int udiv (double_int, unsigned) const;
+  double_int mod (double_int, bool, unsigned) const;
+  double_int smod (double_int, unsigned) const;
+  double_int umod (double_int, unsigned) const;
+  double_int divmod (double_int, bool, unsigned, double_int *) const;
+  double_int sdivmod (double_int, unsigned, double_int *) const;
+  double_int udivmod (double_int, unsigned, double_int *) const;
+
+  /* Precision control functions.  */
+
+  double_int ext (unsigned prec, bool uns) const;
+  double_int zext (unsigned prec) const;
+  double_int sext (unsigned prec) const;
+
+  /* Comparative functions.  */
+
+  bool is_zero () const;
+  bool is_one () const;
+  bool is_minus_one () const;
+  bool is_negative () const;
+
+  int cmp (double_int b, bool uns) const;
+  int ucmp (double_int b) const;
+  int scmp (double_int b) const;
+
+  bool ult (double_int b) const;
+  bool ugt (double_int b) const;
+  bool slt (double_int b) const;
+  bool sgt (double_int b) const;
+
+  double_int max (double_int b, bool uns);
+  double_int smax (double_int b);
+  double_int umax (double_int b);
+
+  double_int min (double_int b, bool uns);
+  double_int smin (double_int b);
+  double_int umin (double_int b);
+
+  bool operator == (double_int cst2) const;
+  bool operator != (double_int cst2) const;
+
+  /* Please migrate away from using these member variables publically.  */
+
   unsigned HOST_WIDE_INT low;
   HOST_WIDE_INT high;
+
 } double_int;
 
 #define HOST_BITS_PER_DOUBLE_INT (2 * HOST_BITS_PER_WIDE_INT)
@@ -63,66 +187,160 @@  typedef struct
 /* Constructs double_int from integer CST.  The bits over the precision of
    HOST_WIDE_INT are filled with the sign bit.  */
 
-static inline double_int
-shwi_to_double_int (HOST_WIDE_INT cst)
+inline
+double_int double_int::make (HOST_WIDE_INT cst)
 {
   double_int r;
-
   r.low = (unsigned HOST_WIDE_INT) cst;
   r.high = cst < 0 ? -1 : 0;
-
   return r;
 }
 
+inline
+double_int double_int::make (int cst)
+{
+  return double_int::make (static_cast <HOST_WIDE_INT> (cst));
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
+static inline double_int
+shwi_to_double_int (HOST_WIDE_INT cst)
+{
+  return double_int::make (cst);
+}
+
 /* Some useful constants.  */
+/* FIXME(crowl): Maybe remove after converting callers?
+   The problem is that a named constant would not be as optimizable,
+   while the functional syntax is more verbose.  */
 
-#define double_int_minus_one (shwi_to_double_int (-1))
-#define double_int_zero (shwi_to_double_int (0))
-#define double_int_one (shwi_to_double_int (1))
-#define double_int_two (shwi_to_double_int (2))
-#define double_int_ten (shwi_to_double_int (10))
+#define double_int_minus_one (double_int::make (-1))
+#define double_int_zero (double_int::make (0))
+#define double_int_one (double_int::make (1))
+#define double_int_two (double_int::make (2))
+#define double_int_ten (double_int::make (10))
 
 /* Constructs double_int from unsigned integer CST.  The bits over the
    precision of HOST_WIDE_INT are filled with zeros.  */
 
-static inline double_int
-uhwi_to_double_int (unsigned HOST_WIDE_INT cst)
+inline
+double_int double_int::make (unsigned HOST_WIDE_INT cst)
 {
   double_int r;
-
   r.low = cst;
   r.high = 0;
-
   return r;
 }
 
+inline
+double_int double_int::make (unsigned int cst)
+{
+  return double_int::make (static_cast <unsigned HOST_WIDE_INT> (cst));
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
+static inline double_int
+uhwi_to_double_int (unsigned HOST_WIDE_INT cst)
+{
+  return double_int::make (cst);
+}
+
+inline double_int &
+double_int::operator ++ ()
+{
+  *this + double_int_one;
+  return *this;
+}
+
+inline double_int &
+double_int::operator -- ()
+{
+  *this - double_int_one;
+  return *this;
+}
+
+inline double_int &
+double_int::operator *= (double_int b)
+{
+  *this = *this * b;
+  return *this;
+}
+
+inline double_int &
+double_int::operator += (double_int b)
+{
+  *this = *this + b;
+  return *this;
+}
+
+inline double_int &
+double_int::operator -= (double_int b)
+{
+  *this = *this - b;
+  return *this;
+}
+
 /* Returns value of CST as a signed number.  CST must satisfy
-   double_int_fits_in_shwi_p.  */
+   double_int::fits_signed.  */
+
+inline HOST_WIDE_INT
+double_int::to_signed () const
+{
+  return (HOST_WIDE_INT) low;
+}
 
+/* FIXME(crowl): Remove after converting callers.  */
 static inline HOST_WIDE_INT
 double_int_to_shwi (double_int cst)
 {
-  return (HOST_WIDE_INT) cst.low;
+  return cst.to_signed ();
 }
 
 /* Returns value of CST as an unsigned number.  CST must satisfy
-   double_int_fits_in_uhwi_p.  */
+   double_int::fits_unsigned.  */
+
+inline unsigned HOST_WIDE_INT
+double_int::to_unsigned () const
+{
+  return low;
+}
 
+/* FIXME(crowl): Remove after converting callers.  */
 static inline unsigned HOST_WIDE_INT
 double_int_to_uhwi (double_int cst)
 {
-  return cst.low;
+  return cst.to_unsigned ();
 }
 
-bool double_int_fits_in_hwi_p (double_int, bool);
-bool double_int_fits_in_shwi_p (double_int);
-
 /* Returns true if CST fits in unsigned HOST_WIDE_INT.  */
 
+inline bool
+double_int::fits_unsigned () const
+{
+  return high == 0;
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
 static inline bool
 double_int_fits_in_uhwi_p (double_int cst)
 {
-  return cst.high == 0;
+  return cst.fits_unsigned ();
+}
+
+/* Returns true if CST fits in signed HOST_WIDE_INT.  */
+
+/* FIXME(crowl): Remove after converting callers.  */
+inline bool
+double_int_fits_in_shwi_p (double_int cst)
+{
+  return cst.fits_signed ();
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
+inline bool
+double_int_fits_in_hwi_p (double_int cst, bool uns)
+{
+  return cst.fits (uns);
 }
 
 /* The following operations perform arithmetics modulo 2^precision,
@@ -130,88 +348,258 @@  double_int_fits_in_uhwi_p (double_int cs
    you are representing numbers with precision less than
    HOST_BITS_PER_DOUBLE_INT bits.  */
 
-double_int double_int_mul (double_int, double_int);
-double_int double_int_mul_with_sign (double_int, double_int, bool, int *);
-double_int double_int_add (double_int, double_int);
-double_int double_int_sub (double_int, double_int);
-double_int double_int_neg (double_int);
+/* FIXME(crowl): Remove after converting callers.  */
+inline double_int
+double_int_mul (double_int a, double_int b)
+{
+  return a * b;
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
+inline double_int
+double_int_mul_with_sign (double_int a, double_int b,
+			  bool unsigned_p, int *overflow)
+{
+  return a.mul_with_sign (b, unsigned_p, overflow);
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
+inline double_int
+double_int_add (double_int a, double_int b)
+{
+  return a + b;
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
+inline double_int
+double_int_sub (double_int a, double_int b)
+{
+  return a - b;
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
+inline double_int
+double_int_neg (double_int a)
+{
+  return -a;
+}
 
 /* You must ensure that double_int_ext is called on the operands
    of the following operations, if the precision of the numbers
    is less than HOST_BITS_PER_DOUBLE_INT bits.  */
-double_int double_int_div (double_int, double_int, bool, unsigned);
-double_int double_int_sdiv (double_int, double_int, unsigned);
-double_int double_int_udiv (double_int, double_int, unsigned);
-double_int double_int_mod (double_int, double_int, bool, unsigned);
-double_int double_int_smod (double_int, double_int, unsigned);
-double_int double_int_umod (double_int, double_int, unsigned);
-double_int double_int_divmod (double_int, double_int, bool, unsigned, double_int *);
-double_int double_int_sdivmod (double_int, double_int, unsigned, double_int *);
-double_int double_int_udivmod (double_int, double_int, unsigned, double_int *);
 
-bool double_int_multiple_of (double_int, double_int, bool, double_int *);
+/* FIXME(crowl): Remove after converting callers.  */
+inline double_int
+double_int_div (double_int a, double_int b, bool uns, unsigned code)
+{
+  return a.div (b, uns, code);
+}
 
-double_int double_int_setbit (double_int, unsigned);
-int double_int_ctz (double_int);
+/* FIXME(crowl): Remove after converting callers.  */
+inline double_int
+double_int_sdiv (double_int a, double_int b, unsigned code)
+{
+  return a.sdiv (b, code);
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
+inline double_int
+double_int_udiv (double_int a, double_int b, unsigned code)
+{
+  return a.udiv (b, code);
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
+inline double_int
+double_int_mod (double_int a, double_int b, bool uns, unsigned code)
+{
+  return a.mod (b, uns, code);
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
+inline double_int
+double_int_smod (double_int a, double_int b, unsigned code)
+{
+  return a.smod (b, code);
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
+inline double_int
+double_int_umod (double_int a, double_int b, unsigned code)
+{
+  return a.umod (b, code);
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
+inline double_int
+double_int_divmod (double_int a, double_int b, bool uns,
+		   unsigned code, double_int *mod)
+{
+  return a.divmod (b, uns, code, mod);
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
+inline double_int
+double_int_sdivmod (double_int a, double_int b, unsigned code, double_int *mod)
+{
+  return a.sdivmod (b, code, mod);
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
+inline double_int
+double_int_udivmod (double_int a, double_int b, unsigned code, double_int *mod)
+{
+  return a.udivmod (b, code, mod);
+}
+
+/***/
+
+/* FIXME(crowl): Remove after converting callers.  */
+inline bool
+double_int_multiple_of (double_int product, double_int factor,
+                        bool unsigned_p, double_int *multiple)
+{
+  return product.multiple_of (factor, unsigned_p, multiple);
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
+inline double_int
+double_int_setbit (double_int a, unsigned bitpos)
+{
+  return a.set_bit (bitpos);
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
+inline int
+double_int_ctz (double_int a)
+{
+  return a.trailing_zeros ();
+}
 
 /* Logical operations.  */
 
 /* Returns ~A.  */
 
+inline double_int
+double_int::operator ~ () const
+{
+  double_int result;
+  result.low = ~low;
+  result.high = ~high;
+  return result;
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
 static inline double_int
 double_int_not (double_int a)
 {
-  a.low = ~a.low;
-  a.high = ~a.high;
-  return a;
+  return ~a;
 }
 
 /* Returns A | B.  */
 
+inline double_int
+double_int::operator | (double_int b) const
+{
+  double_int result;
+  result.low = low | b.low;
+  result.high = high | b.high;
+  return result;
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
 static inline double_int
 double_int_ior (double_int a, double_int b)
 {
-  a.low |= b.low;
-  a.high |= b.high;
-  return a;
+  return a | b;
 }
 
 /* Returns A & B.  */
 
+inline double_int
+double_int::operator & (double_int b) const
+{
+  double_int result;
+  result.low = low & b.low;
+  result.high = high & b.high;
+  return result;
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
 static inline double_int
 double_int_and (double_int a, double_int b)
 {
-  a.low &= b.low;
-  a.high &= b.high;
-  return a;
+  return a & b;
 }
 
 /* Returns A & ~B.  */
 
+inline double_int
+double_int::and_not (double_int b) const
+{
+  double_int result;
+  result.low = low & ~b.low;
+  result.high = high & ~b.high;
+  return result;
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
 static inline double_int
 double_int_and_not (double_int a, double_int b)
 {
-  a.low &= ~b.low;
-  a.high &= ~b.high;
-  return a;
+  return a.and_not (b);
 }
 
 /* Returns A ^ B.  */
 
+inline double_int
+double_int::operator ^ (double_int b) const
+{
+  double_int result;
+  result.low = low ^ b.low;
+  result.high = high ^ b.high;
+  return result;
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
 static inline double_int
 double_int_xor (double_int a, double_int b)
 {
-  a.low ^= b.low;
-  a.high ^= b.high;
-  return a;
+  return a ^ b;
 }
 
 
 /* Shift operations.  */
-double_int double_int_lshift (double_int, HOST_WIDE_INT, unsigned int, bool);
-double_int double_int_rshift (double_int, HOST_WIDE_INT, unsigned int, bool);
-double_int double_int_lrotate (double_int, HOST_WIDE_INT, unsigned int);
-double_int double_int_rrotate (double_int, HOST_WIDE_INT, unsigned int);
+
+/* FIXME(crowl): Remove after converting callers.  */
+inline double_int
+double_int_lshift (double_int a, HOST_WIDE_INT count, unsigned int prec,
+		   bool arith)
+{
+  return a.lshift (count, prec, arith);
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
+inline double_int
+double_int_rshift (double_int a, HOST_WIDE_INT count, unsigned int prec,
+		   bool arith)
+{
+  return a.rshift (count, prec, arith);
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
+inline double_int
+double_int_lrotate (double_int a, HOST_WIDE_INT count, unsigned int prec)
+{
+  return a.lrotate (count, prec);
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
+inline double_int
+double_int_rrotate (double_int a, HOST_WIDE_INT count, unsigned int prec)
+{
+  return a.rrotate (count, prec);
+}
 
 /* Returns true if CST is negative.  Of course, CST is considered to
    be signed.  */
@@ -222,29 +610,115 @@  double_int_negative_p (double_int cst)
   return cst.high < 0;
 }
 
-int double_int_cmp (double_int, double_int, bool);
-int double_int_scmp (double_int, double_int);
-int double_int_ucmp (double_int, double_int);
+/* FIXME(crowl): Remove after converting callers.  */
+inline int
+double_int_cmp (double_int a, double_int b, bool uns)
+{
+  return a.cmp (b, uns);
+}
 
-double_int double_int_max (double_int, double_int, bool);
-double_int double_int_smax (double_int, double_int);
-double_int double_int_umax (double_int, double_int);
+/* FIXME(crowl): Remove after converting callers.  */
+inline int
+double_int_scmp (double_int a, double_int b)
+{
+  return a.scmp (b);
+}
 
-double_int double_int_min (double_int, double_int, bool);
-double_int double_int_smin (double_int, double_int);
-double_int double_int_umin (double_int, double_int);
+/* FIXME(crowl): Remove after converting callers.  */
+inline int
+double_int_ucmp (double_int a, double_int b)
+{
+  return a.ucmp (b);
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
+inline double_int
+double_int_max (double_int a, double_int b, bool uns)
+{
+  return a.max (b, uns);
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
+inline double_int
+double_int_smax (double_int a, double_int b)
+{
+  return a.smax (b);
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
+inline double_int
+double_int_umax (double_int a, double_int b)
+{
+  return a.umax (b);
+}
+
+
+/* FIXME(crowl): Remove after converting callers.  */
+inline double_int
+double_int_min (double_int a, double_int b, bool uns)
+{
+  return a.min (b, uns);
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
+inline double_int
+double_int_smin (double_int a, double_int b)
+{
+  return a.smin (b);
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
+inline double_int
+double_int_umin (double_int a, double_int b)
+{
+  return a.umin (b);
+}
 
 void dump_double_int (FILE *, double_int, bool);
 
 /* Zero and sign extension of numbers in smaller precisions.  */
 
-double_int double_int_ext (double_int, unsigned, bool);
-double_int double_int_sext (double_int, unsigned);
-double_int double_int_zext (double_int, unsigned);
-double_int double_int_mask (unsigned);
+/* FIXME(crowl): Remove after converting callers.  */
+inline double_int
+double_int_ext (double_int a, unsigned prec, bool uns)
+{ 
+  return a.ext (prec, uns);
+}
 
-double_int double_int_max_value (unsigned int, bool);
-double_int double_int_min_value (unsigned int, bool);
+/* FIXME(crowl): Remove after converting callers.  */
+inline double_int
+double_int_sext (double_int a, unsigned prec)
+{
+  return a.sext (prec);
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
+inline double_int
+double_int_zext (double_int a, unsigned prec)
+{
+  return a.zext (prec);
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
+inline double_int
+double_int_mask (unsigned prec)
+{
+  return double_int::mask (prec);
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
+inline double_int
+double_int_max_value (unsigned int prec, bool uns)
+{
+  return double_int::max_value (prec, uns);
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
+inline double_int
+double_int_min_value (unsigned int prec, bool uns)
+{
+  return double_int::min_value (prec, uns);
+}
 
 #define ALL_ONES (~((unsigned HOST_WIDE_INT) 0))
 
@@ -254,64 +728,122 @@  double_int double_int_min_value (unsigne
 
 /* Returns true if CST is zero.  */
 
+inline bool
+double_int::is_zero () const
+{
+  return low == 0 && high == 0;
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
 static inline bool
 double_int_zero_p (double_int cst)
 {
-  return cst.low == 0 && cst.high == 0;
+  return cst.is_zero ();
 }
 
 /* Returns true if CST is one.  */
 
+inline bool
+double_int::is_one () const
+{
+  return low == 1 && high == 0;
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
 static inline bool
 double_int_one_p (double_int cst)
 {
-  return cst.low == 1 && cst.high == 0;
+  return cst.is_one ();
 }
 
 /* Returns true if CST is minus one.  */
 
+inline bool
+double_int::is_minus_one () const
+{
+  return low == ALL_ONES && high == -1;
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
 static inline bool
 double_int_minus_one_p (double_int cst)
 {
-  return (cst.low == ALL_ONES && cst.high == -1);
+  return cst.is_minus_one ();
+}
+
+/* Returns true if CST is negative.  */
+
+inline bool
+double_int::is_negative () const
+{
+  return high < 0;
 }
 
 /* Returns true if CST1 == CST2.  */
 
+inline bool
+double_int::operator == (double_int cst2) const
+{
+  return low == cst2.low && high == cst2.high;
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
 static inline bool
 double_int_equal_p (double_int cst1, double_int cst2)
 {
-  return cst1.low == cst2.low && cst1.high == cst2.high;
+  return cst1 == cst2;
+}
+
+/* Returns true if CST1 != CST2.  */
+
+inline bool
+double_int::operator != (double_int cst2) const
+{
+  return low != cst2.low || high != cst2.high;
 }
 
 /* Return number of set bits of CST.  */
 
+inline int
+double_int::popcount () const
+{
+  return popcount_hwi (high) + popcount_hwi (low);
+}
+
+/* FIXME(crowl): Remove after converting callers.  */
 static inline int
 double_int_popcount (double_int cst)
 {
-  return popcount_hwi (cst.high) + popcount_hwi (cst.low);
+  return cst.popcount ();
 }
 
 
 /* Legacy interface with decomposed high/low parts.  */
 
+/* FIXME(crowl): Remove after converting callers.  */
 extern int add_double_with_sign (unsigned HOST_WIDE_INT, HOST_WIDE_INT,
 				 unsigned HOST_WIDE_INT, HOST_WIDE_INT,
 				 unsigned HOST_WIDE_INT *, HOST_WIDE_INT *,
 				 bool);
+/* FIXME(crowl): Remove after converting callers.  */
 #define add_double(l1,h1,l2,h2,lv,hv) \
   add_double_with_sign (l1, h1, l2, h2, lv, hv, false)
+/* FIXME(crowl): Remove after converting callers.  */
 extern int neg_double (unsigned HOST_WIDE_INT, HOST_WIDE_INT,
 		       unsigned HOST_WIDE_INT *, HOST_WIDE_INT *);
+/* FIXME(crowl): Remove after converting callers.  */
 extern int mul_double_with_sign (unsigned HOST_WIDE_INT, HOST_WIDE_INT,
 				 unsigned HOST_WIDE_INT, HOST_WIDE_INT,
 				 unsigned HOST_WIDE_INT *, HOST_WIDE_INT *,
 				 bool);
+/* FIXME(crowl): Remove after converting callers.  */
 #define mul_double(l1,h1,l2,h2,lv,hv) \
   mul_double_with_sign (l1, h1, l2, h2, lv, hv, false)
+/* FIXME(crowl): Remove after converting callers.  */
 extern void lshift_double (unsigned HOST_WIDE_INT, HOST_WIDE_INT,
 			   HOST_WIDE_INT, unsigned int,
 			   unsigned HOST_WIDE_INT *, HOST_WIDE_INT *, bool);
+/* FIXME(crowl): Remove after converting callers.  */
 extern int div_and_round_double (unsigned, int, unsigned HOST_WIDE_INT,
 				 HOST_WIDE_INT, unsigned HOST_WIDE_INT,
 				 HOST_WIDE_INT, unsigned HOST_WIDE_INT *,
Index: gcc/fixed-value.c
===================================================================
--- gcc/fixed-value.c	(revision 190186)
+++ gcc/fixed-value.c	(working copy)
@@ -111,13 +111,11 @@  fixed_from_string (FIXED_VALUE_TYPE *f, 
       /* From the spec, we need to evaluate 1 to the maximal value.  */
       f->data.low = -1;
       f->data.high = -1;
-      f->data = double_int_ext (f->data,
-				GET_MODE_FBIT (f->mode)
-				+ GET_MODE_IBIT (f->mode), 1);
+      f->data = f->data.zext (GET_MODE_FBIT (f->mode)
+				+ GET_MODE_IBIT (f->mode));
     }
   else
-    f->data = double_int_ext (f->data,
-			      SIGNED_FIXED_POINT_MODE_P (f->mode)
+    f->data = f->data.ext (SIGNED_FIXED_POINT_MODE_P (f->mode)
 			      + GET_MODE_FBIT (f->mode)
 			      + GET_MODE_IBIT (f->mode),
 			      UNSIGNED_FIXED_POINT_MODE_P (f->mode));
@@ -159,8 +157,8 @@  fixed_saturate1 (enum machine_mode mode,
       double_int max;
       max.low = -1;
       max.high = -1;
-      max = double_int_ext (max, i_f_bits, 1);
-      if (double_int_cmp (a, max, 1) == 1)
+      max = max.zext (i_f_bits);
+      if (a.ugt (max))
 	{
 	  if (sat_p)
 	    *f = max;
@@ -173,21 +171,19 @@  fixed_saturate1 (enum machine_mode mode,
       double_int max, min;
       max.high = -1;
       max.low = -1;
-      max = double_int_ext (max, i_f_bits, 1);
+      max = max.zext (i_f_bits);
       min.high = 0;
       min.low = 1;
-      lshift_double (min.low, min.high, i_f_bits,
-		     HOST_BITS_PER_DOUBLE_INT,
-		     &min.low, &min.high, 1);
-      min = double_int_ext (min, 1 + i_f_bits, 0);
-      if (double_int_cmp (a, max, 0) == 1)
+      min = min.alshift (i_f_bits, HOST_BITS_PER_DOUBLE_INT);
+      min = min.sext (1 + i_f_bits);
+      if (a.sgt (max))
 	{
 	  if (sat_p)
 	    *f = max;
 	  else
 	    overflow_p = true;
 	}
-      else if (double_int_cmp (a, min, 0) == -1)
+      else if (a.slt (min))
 	{
 	  if (sat_p)
 	    *f = min;
@@ -221,10 +217,10 @@  fixed_saturate2 (enum machine_mode mode,
       max_r.low = 0;
       max_s.high = -1;
       max_s.low = -1;
-      max_s = double_int_ext (max_s, i_f_bits, 1);
-      if (double_int_cmp (a_high, max_r, 1) == 1
-	  || (double_int_equal_p (a_high, max_r) &&
-	      double_int_cmp (a_low, max_s, 1) == 1))
+      max_s = max_s.zext (i_f_bits);
+      if (a_high.ugt (max_r)
+	  || (a_high == max_r &&
+	      a_low.ugt (max_s)))
 	{
 	  if (sat_p)
 	    *f = max_s;
@@ -239,27 +235,25 @@  fixed_saturate2 (enum machine_mode mode,
       max_r.low = 0;
       max_s.high = -1;
       max_s.low = -1;
-      max_s = double_int_ext (max_s, i_f_bits, 1);
+      max_s = max_s.zext (i_f_bits);
       min_r.high = -1;
       min_r.low = -1;
       min_s.high = 0;
       min_s.low = 1;
-      lshift_double (min_s.low, min_s.high, i_f_bits,
-		     HOST_BITS_PER_DOUBLE_INT,
-		     &min_s.low, &min_s.high, 1);
-      min_s = double_int_ext (min_s, 1 + i_f_bits, 0);
-      if (double_int_cmp (a_high, max_r, 0) == 1
-	  || (double_int_equal_p (a_high, max_r) &&
-	      double_int_cmp (a_low, max_s, 1) == 1))
+      min_s = min_s.alshift (i_f_bits, HOST_BITS_PER_DOUBLE_INT);
+      min_s = min_s.sext (1 + i_f_bits);
+      if (a_high.sgt (max_r)
+	  || (a_high == max_r &&
+	      a_low.ugt (max_s)))
 	{
 	  if (sat_p)
 	    *f = max_s;
 	  else
 	    overflow_p = true;
 	}
-      else if (double_int_cmp (a_high, min_r, 0) == -1
-	       || (double_int_equal_p (a_high, min_r) &&
-		   double_int_cmp (a_low, min_s, 1) == -1))
+      else if (a_high.slt (min_r)
+	       || (a_high == min_r &&
+		   a_low.ult (min_s)))
 	{
 	  if (sat_p)
 	    *f = min_s;
@@ -297,19 +291,19 @@  do_fixed_add (FIXED_VALUE_TYPE *f, const
   /* This was a conditional expression but it triggered a bug in
      Sun C 5.5.  */
   if (subtract_p)
-    temp = double_int_neg (b->data);
+    temp = -b->data;
   else
     temp = b->data;
 
   unsigned_p = UNSIGNED_FIXED_POINT_MODE_P (a->mode);
   i_f_bits = GET_MODE_IBIT (a->mode) + GET_MODE_FBIT (a->mode);
   f->mode = a->mode;
-  f->data = double_int_add (a->data, temp);
+  f->data = a->data + temp;
   if (unsigned_p) /* Unsigned type.  */
     {
       if (subtract_p) /* Unsigned subtraction.  */
 	{
-	  if (double_int_cmp (a->data, b->data, 1) == -1)
+	  if (a->data.ult (b->data))
 	    {
 	      if (sat_p)
 		{
@@ -322,9 +316,9 @@  do_fixed_add (FIXED_VALUE_TYPE *f, const
 	}
       else /* Unsigned addition.  */
 	{
-	  f->data = double_int_ext (f->data, i_f_bits, 1);
-	  if (double_int_cmp (f->data, a->data, 1) == -1
-	      || double_int_cmp (f->data, b->data, 1) == -1)
+	  f->data = f->data.zext (i_f_bits);
+	  if (f->data.ult (a->data)
+	      || f->data.ult (b->data))
 	    {
 	      if (sat_p)
 		{
@@ -353,22 +347,17 @@  do_fixed_add (FIXED_VALUE_TYPE *f, const
 	    {
 	      f->data.low = 1;
 	      f->data.high = 0;
-	      lshift_double (f->data.low, f->data.high, i_f_bits,
-			     HOST_BITS_PER_DOUBLE_INT,
-			     &f->data.low, &f->data.high, 1);
+	      f->data = f->data.alshift (i_f_bits, HOST_BITS_PER_DOUBLE_INT);
 	      if (get_fixed_sign_bit (a->data, i_f_bits) == 0)
 		{
-		  double_int one;
-		  one.low = 1;
-		  one.high = 0;
-		  f->data = double_int_sub (f->data, one);
+		  --f->data;
 		}
 	    }
 	  else
 	    overflow_p = true;
 	}
     }
-  f->data = double_int_ext (f->data, (!unsigned_p) + i_f_bits, unsigned_p);
+  f->data = f->data.ext ((!unsigned_p) + i_f_bits, unsigned_p);
   return overflow_p;
 }
 
@@ -386,11 +375,10 @@  do_fixed_multiply (FIXED_VALUE_TYPE *f, 
   f->mode = a->mode;
   if (GET_MODE_PRECISION (f->mode) <= HOST_BITS_PER_WIDE_INT)
     {
-      f->data = double_int_mul (a->data, b->data);
-      lshift_double (f->data.low, f->data.high,
-		     (-GET_MODE_FBIT (f->mode)),
+      f->data = a->data * b->data;
+      f->data = f->data.lshift ((-GET_MODE_FBIT (f->mode)),
 		     HOST_BITS_PER_DOUBLE_INT,
-		     &f->data.low, &f->data.high, !unsigned_p);
+		     !unsigned_p);
       overflow_p = fixed_saturate1 (f->mode, f->data, &f->data, sat_p);
     }
   else
@@ -412,43 +400,43 @@  do_fixed_multiply (FIXED_VALUE_TYPE *f, 
       b_low.high = 0;
 
       /* Perform four multiplications.  */
-      low_low = double_int_mul (a_low, b_low);
-      low_high = double_int_mul (a_low, b_high);
-      high_low = double_int_mul (a_high, b_low);
-      high_high = double_int_mul (a_high, b_high);
+      low_low = a_low * b_low;
+      low_high = a_low * b_high;
+      high_low = a_high * b_low;
+      high_high = a_high * b_high;
 
       /* Accumulate four results to {r, s}.  */
       temp1.high = high_low.low;
       temp1.low = 0;
-      s = double_int_add (low_low, temp1);
-      if (double_int_cmp (s, low_low, 1) == -1
-	  || double_int_cmp (s, temp1, 1) == -1)
+      s = low_low + temp1;
+      if (s.ult (low_low)
+	  || s.ult (temp1))
 	carry ++; /* Carry */
       temp1.high = s.high;
       temp1.low = s.low;
       temp2.high = low_high.low;
       temp2.low = 0;
-      s = double_int_add (temp1, temp2);
-      if (double_int_cmp (s, temp1, 1) == -1
-	  || double_int_cmp (s, temp2, 1) == -1)
+      s = temp1 + temp2;
+      if (s.ult (temp1)
+	  || s.ult (temp2))
 	carry ++; /* Carry */
 
       temp1.low = high_low.high;
       temp1.high = 0;
-      r = double_int_add (high_high, temp1);
+      r = high_high + temp1;
       temp1.low = low_high.high;
       temp1.high = 0;
-      r = double_int_add (r, temp1);
+      r += temp1;
       temp1.low = carry;
       temp1.high = 0;
-      r = double_int_add (r, temp1);
+      r += temp1;
 
       /* We need to subtract b from r, if a < 0.  */
       if (!unsigned_p && a->data.high < 0)
-	r = double_int_sub (r, b->data);
+	r -= b->data;
       /* We need to subtract a from r, if b < 0.  */
       if (!unsigned_p && b->data.high < 0)
-	r = double_int_sub (r, a->data);
+	r -= a->data;
 
       /* Shift right the result by FBIT.  */
       if (GET_MODE_FBIT (f->mode) == HOST_BITS_PER_DOUBLE_INT)
@@ -470,29 +458,23 @@  do_fixed_multiply (FIXED_VALUE_TYPE *f, 
 	}
       else
 	{
-	  lshift_double (s.low, s.high,
-			 (-GET_MODE_FBIT (f->mode)),
-			 HOST_BITS_PER_DOUBLE_INT,
-			 &s.low, &s.high, 0);
-	  lshift_double (r.low, r.high,
-			 (HOST_BITS_PER_DOUBLE_INT
+	  s = s.llshift ((-GET_MODE_FBIT (f->mode)), HOST_BITS_PER_DOUBLE_INT);
+	  f->data = r.llshift ((HOST_BITS_PER_DOUBLE_INT
 			  - GET_MODE_FBIT (f->mode)),
-			 HOST_BITS_PER_DOUBLE_INT,
-			 &f->data.low, &f->data.high, 0);
+			 HOST_BITS_PER_DOUBLE_INT);
 	  f->data.low = f->data.low | s.low;
 	  f->data.high = f->data.high | s.high;
 	  s.low = f->data.low;
 	  s.high = f->data.high;
-	  lshift_double (r.low, r.high,
-			 (-GET_MODE_FBIT (f->mode)),
+	  r = r.lshift ((-GET_MODE_FBIT (f->mode)),
 			 HOST_BITS_PER_DOUBLE_INT,
-			 &r.low, &r.high, !unsigned_p);
+			 !unsigned_p);
 	}
 
       overflow_p = fixed_saturate2 (f->mode, r, s, &f->data, sat_p);
     }
 
-  f->data = double_int_ext (f->data, (!unsigned_p) + i_f_bits, unsigned_p);
+  f->data = f->data.ext ((!unsigned_p) + i_f_bits, unsigned_p);
   return overflow_p;
 }
 
@@ -510,11 +492,10 @@  do_fixed_divide (FIXED_VALUE_TYPE *f, co
   f->mode = a->mode;
   if (GET_MODE_PRECISION (f->mode) <= HOST_BITS_PER_WIDE_INT)
     {
-      lshift_double (a->data.low, a->data.high,
-		     GET_MODE_FBIT (f->mode),
+      f->data = a->data.lshift (GET_MODE_FBIT (f->mode),
 		     HOST_BITS_PER_DOUBLE_INT,
-		     &f->data.low, &f->data.high, !unsigned_p);
-      f->data = double_int_div (f->data, b->data, unsigned_p, TRUNC_DIV_EXPR);
+		     !unsigned_p);
+      f->data = f->data.div (b->data, unsigned_p, TRUNC_DIV_EXPR);
       overflow_p = fixed_saturate1 (f->mode, f->data, &f->data, sat_p);
     }
   else
@@ -527,7 +508,7 @@  do_fixed_divide (FIXED_VALUE_TYPE *f, co
       /* If a < 0, negate a.  */
       if (!unsigned_p && a->data.high < 0)
 	{
-	  pos_a = double_int_neg (a->data);
+	  pos_a = -a->data;
 	  num_of_neg ++;
 	}
       else
@@ -536,7 +517,7 @@  do_fixed_divide (FIXED_VALUE_TYPE *f, co
       /* If b < 0, negate b.  */
       if (!unsigned_p && b->data.high < 0)
 	{
-	  pos_b = double_int_neg (b->data);
+	  pos_b = -b->data;
 	  num_of_neg ++;
 	}
       else
@@ -551,24 +532,15 @@  do_fixed_divide (FIXED_VALUE_TYPE *f, co
 	}
       else
  	{
-	  lshift_double (pos_a.low, pos_a.high,
-			 GET_MODE_FBIT (f->mode),
-			 HOST_BITS_PER_DOUBLE_INT,
-			 &s.low, &s.high, 0);
-	  lshift_double (pos_a.low, pos_a.high,
-			 - (HOST_BITS_PER_DOUBLE_INT
+	  s = pos_a.llshift (GET_MODE_FBIT (f->mode), HOST_BITS_PER_DOUBLE_INT);
+	  r = pos_a.llshift (- (HOST_BITS_PER_DOUBLE_INT
 			    - GET_MODE_FBIT (f->mode)),
-			 HOST_BITS_PER_DOUBLE_INT,
-			 &r.low, &r.high, 0);
+			 HOST_BITS_PER_DOUBLE_INT);
  	}
 
       /* Divide r by pos_b to quo_r.  The remainder is in mod.  */
-      div_and_round_double (TRUNC_DIV_EXPR, 1, r.low, r.high, pos_b.low,
-			    pos_b.high, &quo_r.low, &quo_r.high, &mod.low,
-			    &mod.high);
-
-      quo_s.high = 0;
-      quo_s.low = 0;
+      quo_r = r.divmod (pos_b, 1, TRUNC_DIV_EXPR, &mod);
+      quo_s = double_int_zero;
 
       for (i = 0; i < HOST_BITS_PER_DOUBLE_INT; i++)
 	{
@@ -576,37 +548,34 @@  do_fixed_divide (FIXED_VALUE_TYPE *f, co
 	  int leftmost_mod = (mod.high < 0);
 
 	  /* Shift left mod by 1 bit.  */
-	  lshift_double (mod.low, mod.high, 1, HOST_BITS_PER_DOUBLE_INT,
-			 &mod.low, &mod.high, 0);
+	  mod = mod.llshift (1, HOST_BITS_PER_DOUBLE_INT);
 
 	  /* Test the leftmost bit of s to add to mod.  */
 	  if (s.high < 0)
 	    mod.low += 1;
 
 	  /* Shift left quo_s by 1 bit.  */
-	  lshift_double (quo_s.low, quo_s.high, 1, HOST_BITS_PER_DOUBLE_INT,
-			 &quo_s.low, &quo_s.high, 0);
+	  quo_s = quo_s.llshift (1, HOST_BITS_PER_DOUBLE_INT);
 
 	  /* Try to calculate (mod - pos_b).  */
-	  temp = double_int_sub (mod, pos_b);
+	  temp = mod - pos_b;
 
-	  if (leftmost_mod == 1 || double_int_cmp (mod, pos_b, 1) != -1)
+	  if (leftmost_mod == 1 || mod.ucmp (pos_b) != -1)
 	    {
 	      quo_s.low += 1;
 	      mod = temp;
 	    }
 
 	  /* Shift left s by 1 bit.  */
-	  lshift_double (s.low, s.high, 1, HOST_BITS_PER_DOUBLE_INT,
-			 &s.low, &s.high, 0);
+	  s = s.llshift (1, HOST_BITS_PER_DOUBLE_INT);
 
 	}
 
       if (num_of_neg == 1)
 	{
-	  quo_s = double_int_neg (quo_s);
+	  quo_s = -quo_s;
 	  if (quo_s.high == 0 && quo_s.low == 0)
-	    quo_r = double_int_neg (quo_r);
+	    quo_r = -quo_r;
 	  else
 	    {
 	      quo_r.low = ~quo_r.low;
@@ -618,7 +587,7 @@  do_fixed_divide (FIXED_VALUE_TYPE *f, co
       overflow_p = fixed_saturate2 (f->mode, quo_r, quo_s, &f->data, sat_p);
     }
 
-  f->data = double_int_ext (f->data, (!unsigned_p) + i_f_bits, unsigned_p);
+  f->data = f->data.ext ((!unsigned_p) + i_f_bits, unsigned_p);
   return overflow_p;
 }
 
@@ -643,10 +612,9 @@  do_fixed_shift (FIXED_VALUE_TYPE *f, con
 
   if (GET_MODE_PRECISION (f->mode) <= HOST_BITS_PER_WIDE_INT || (!left_p))
     {
-      lshift_double (a->data.low, a->data.high,
-		     left_p ? b->data.low : (-b->data.low),
+      f->data = a->data.lshift (left_p ? b->data.low : (-b->data.low),
 		     HOST_BITS_PER_DOUBLE_INT,
-		     &f->data.low, &f->data.high, !unsigned_p);
+		     !unsigned_p);
       if (left_p) /* Only left shift saturates.  */
 	overflow_p = fixed_saturate1 (f->mode, f->data, &f->data, sat_p);
     }
@@ -661,23 +629,20 @@  do_fixed_shift (FIXED_VALUE_TYPE *f, con
 	}
       else
 	{
-	  lshift_double (a->data.low, a->data.high,
-			 b->data.low,
+	  temp_low = a->data.lshift (b->data.low,
 			 HOST_BITS_PER_DOUBLE_INT,
-			 &temp_low.low, &temp_low.high, !unsigned_p);
+			 !unsigned_p);
 	  /* Logical shift right to temp_high.  */
-	  lshift_double (a->data.low, a->data.high,
-			 b->data.low - HOST_BITS_PER_DOUBLE_INT,
-			 HOST_BITS_PER_DOUBLE_INT,
-			 &temp_high.low, &temp_high.high, 0);
+	  temp_high = a->data.llshift (b->data.low - HOST_BITS_PER_DOUBLE_INT,
+			 HOST_BITS_PER_DOUBLE_INT);
 	}
       if (!unsigned_p && a->data.high < 0) /* Signed-extend temp_high.  */
-	temp_high = double_int_ext (temp_high, b->data.low, unsigned_p);
+	temp_high = temp_high.ext (b->data.low, unsigned_p);
       f->data = temp_low;
       overflow_p = fixed_saturate2 (f->mode, temp_high, temp_low, &f->data,
 				    sat_p);
     }
-  f->data = double_int_ext (f->data, (!unsigned_p) + i_f_bits, unsigned_p);
+  f->data = f->data.ext ((!unsigned_p) + i_f_bits, unsigned_p);
   return overflow_p;
 }
 
@@ -692,8 +657,8 @@  do_fixed_neg (FIXED_VALUE_TYPE *f, const
   bool unsigned_p = UNSIGNED_FIXED_POINT_MODE_P (a->mode);
   int i_f_bits = GET_MODE_IBIT (a->mode) + GET_MODE_FBIT (a->mode);
   f->mode = a->mode;
-  f->data = double_int_neg (a->data);
-  f->data = double_int_ext (f->data, (!unsigned_p) + i_f_bits, unsigned_p);
+  f->data = -a->data;
+  f->data = f->data.ext ((!unsigned_p) + i_f_bits, unsigned_p);
 
   if (unsigned_p) /* Unsigned type.  */
     {
@@ -718,7 +683,7 @@  do_fixed_neg (FIXED_VALUE_TYPE *f, const
 	      /* Saturate to the maximum by subtracting f->data by one.  */
 	      f->data.low = -1;
 	      f->data.high = -1;
-	      f->data = double_int_ext (f->data, i_f_bits, 1);
+	      f->data = f->data.zext (i_f_bits);
 	    }
 	  else
 	    overflow_p = true;
@@ -789,25 +754,25 @@  fixed_compare (int icode, const FIXED_VA
   switch (code)
     {
     case NE_EXPR:
-      return !double_int_equal_p (op0->data, op1->data);
+      return op0->data != op1->data;
 
     case EQ_EXPR:
-      return double_int_equal_p (op0->data, op1->data);
+      return op0->data == op1->data;
 
     case LT_EXPR:
-      return double_int_cmp (op0->data, op1->data,
+      return op0->data.cmp (op1->data,
 			     UNSIGNED_FIXED_POINT_MODE_P (op0->mode)) == -1;
 
     case LE_EXPR:
-      return double_int_cmp (op0->data, op1->data,
+      return op0->data.cmp (op1->data,
 			     UNSIGNED_FIXED_POINT_MODE_P (op0->mode)) != 1;
 
     case GT_EXPR:
-      return double_int_cmp (op0->data, op1->data,
+      return op0->data.cmp (op1->data,
 			     UNSIGNED_FIXED_POINT_MODE_P (op0->mode)) == 1;
 
     case GE_EXPR:
-      return double_int_cmp (op0->data, op1->data,
+      return op0->data.cmp (op1->data,
 			     UNSIGNED_FIXED_POINT_MODE_P (op0->mode)) != -1;
 
     default:
@@ -835,19 +800,15 @@  fixed_convert (FIXED_VALUE_TYPE *f, enum
       /* Left shift a to temp_high, temp_low based on a->mode.  */
       double_int temp_high, temp_low;
       int amount = GET_MODE_FBIT (mode) - GET_MODE_FBIT (a->mode);
-      lshift_double (a->data.low, a->data.high,
-		     amount,
+      temp_low = a->data.lshift (amount,
 		     HOST_BITS_PER_DOUBLE_INT,
-		     &temp_low.low, &temp_low.high,
 		     SIGNED_FIXED_POINT_MODE_P (a->mode));
       /* Logical shift right to temp_high.  */
-      lshift_double (a->data.low, a->data.high,
-		     amount - HOST_BITS_PER_DOUBLE_INT,
-		     HOST_BITS_PER_DOUBLE_INT,
-		     &temp_high.low, &temp_high.high, 0);
+      temp_high = a->data.llshift (amount - HOST_BITS_PER_DOUBLE_INT,
+		     HOST_BITS_PER_DOUBLE_INT);
       if (SIGNED_FIXED_POINT_MODE_P (a->mode)
 	  && a->data.high < 0) /* Signed-extend temp_high.  */
-	temp_high = double_int_ext (temp_high, amount, 0);
+	temp_high = temp_high.sext (amount);
       f->mode = mode;
       f->data = temp_low;
       if (SIGNED_FIXED_POINT_MODE_P (a->mode) ==
@@ -885,10 +846,9 @@  fixed_convert (FIXED_VALUE_TYPE *f, enum
 		      /* Set to maximum.  */
 		      f->data.low = -1;  /* Set to all ones.  */
 		      f->data.high = -1;  /* Set to all ones.  */
-		      f->data = double_int_ext (f->data,
-						GET_MODE_FBIT (f->mode)
-						+ GET_MODE_IBIT (f->mode),
-						1); /* Clear the sign.  */
+		      f->data = f->data.zext (GET_MODE_FBIT (f->mode)
+						+ GET_MODE_IBIT (f->mode));
+						/* Clear the sign.  */
 		    }
 		  else
 		    overflow_p = true;
@@ -903,10 +863,8 @@  fixed_convert (FIXED_VALUE_TYPE *f, enum
     {
       /* Right shift a to temp based on a->mode.  */
       double_int temp;
-      lshift_double (a->data.low, a->data.high,
-		     GET_MODE_FBIT (mode) - GET_MODE_FBIT (a->mode),
+      temp = a->data.lshift (GET_MODE_FBIT (mode) - GET_MODE_FBIT (a->mode),
 		     HOST_BITS_PER_DOUBLE_INT,
-		     &temp.low, &temp.high,
 		     SIGNED_FIXED_POINT_MODE_P (a->mode));
       f->mode = mode;
       f->data = temp;
@@ -944,10 +902,9 @@  fixed_convert (FIXED_VALUE_TYPE *f, enum
 		      /* Set to maximum.  */
 		      f->data.low = -1;  /* Set to all ones.  */
 		      f->data.high = -1;  /* Set to all ones.  */
-		      f->data = double_int_ext (f->data,
-						GET_MODE_FBIT (f->mode)
-						+ GET_MODE_IBIT (f->mode),
-						1); /* Clear the sign.  */
+		      f->data = f->data.zext (GET_MODE_FBIT (f->mode)
+						+ GET_MODE_IBIT (f->mode));
+						/* Clear the sign.  */
 		    }
 		  else
 		    overflow_p = true;
@@ -959,8 +916,7 @@  fixed_convert (FIXED_VALUE_TYPE *f, enum
 	}
     }
 
-  f->data = double_int_ext (f->data,
-			    SIGNED_FIXED_POINT_MODE_P (f->mode)
+  f->data = f->data.ext (SIGNED_FIXED_POINT_MODE_P (f->mode)
 			    + GET_MODE_FBIT (f->mode)
 			    + GET_MODE_IBIT (f->mode),
 			    UNSIGNED_FIXED_POINT_MODE_P (f->mode));
@@ -988,19 +944,14 @@  fixed_convert_from_int (FIXED_VALUE_TYPE
     }
   else
     {
-      lshift_double (a.low, a.high,
-		     amount,
-		     HOST_BITS_PER_DOUBLE_INT,
-		     &temp_low.low, &temp_low.high, 0);
+      temp_low = a.llshift (amount, HOST_BITS_PER_DOUBLE_INT);
 
       /* Logical shift right to temp_high.  */
-      lshift_double (a.low, a.high,
-		     amount - HOST_BITS_PER_DOUBLE_INT,
-		     HOST_BITS_PER_DOUBLE_INT,
-		     &temp_high.low, &temp_high.high, 0);
+      temp_high = a.llshift (amount - HOST_BITS_PER_DOUBLE_INT,
+		     HOST_BITS_PER_DOUBLE_INT);
     }
   if (!unsigned_p && a.high < 0) /* Signed-extend temp_high.  */
-    temp_high = double_int_ext (temp_high, amount, 0);
+    temp_high = temp_high.sext (amount);
 
   f->mode = mode;
   f->data = temp_low;
@@ -1038,10 +989,9 @@  fixed_convert_from_int (FIXED_VALUE_TYPE
 		  /* Set to maximum.  */
 		  f->data.low = -1;  /* Set to all ones.  */
 		  f->data.high = -1;  /* Set to all ones.  */
-		  f->data = double_int_ext (f->data,
-					    GET_MODE_FBIT (f->mode)
-					    + GET_MODE_IBIT (f->mode),
-					    1); /* Clear the sign.  */
+		  f->data = f->data.zext (GET_MODE_FBIT (f->mode)
+					    + GET_MODE_IBIT (f->mode));
+					    /* Clear the sign.  */
 		}
 	      else
 		overflow_p = true;
@@ -1051,8 +1001,7 @@  fixed_convert_from_int (FIXED_VALUE_TYPE
 					  &f->data, sat_p);
 	}
     }
-  f->data = double_int_ext (f->data,
-			    SIGNED_FIXED_POINT_MODE_P (f->mode)
+  f->data = f->data.ext (SIGNED_FIXED_POINT_MODE_P (f->mode)
 			    + GET_MODE_FBIT (f->mode)
 			    + GET_MODE_IBIT (f->mode),
 			    UNSIGNED_FIXED_POINT_MODE_P (f->mode));
@@ -1093,10 +1042,8 @@  fixed_convert_from_real (FIXED_VALUE_TYP
 	    {
 	      f->data.low = 1;
 	      f->data.high = 0;
-	      lshift_double (f->data.low, f->data.high, i_f_bits,
-			     HOST_BITS_PER_DOUBLE_INT,
-			     &f->data.low, &f->data.high, 1);
-	      f->data = double_int_ext (f->data, 1 + i_f_bits, 0);
+	      f->data = f->data.alshift (i_f_bits, HOST_BITS_PER_DOUBLE_INT);
+	      f->data = f->data.sext (1 + i_f_bits);
 	    }
 	}
       else
@@ -1108,12 +1055,12 @@  fixed_convert_from_real (FIXED_VALUE_TYP
 	{
 	  f->data.low = -1;
 	  f->data.high = -1;
-	  f->data = double_int_ext (f->data, i_f_bits, 1);
+	  f->data = f->data.zext (i_f_bits);
 	}
       else
 	overflow_p = true;
     }
-  f->data = double_int_ext (f->data, (!unsigned_p) + i_f_bits, unsigned_p);
+  f->data = f->data.ext ((!unsigned_p) + i_f_bits, unsigned_p);
   return overflow_p;
 }