This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[cxx-conversion] Make double_int a class with methods and operators. (issue6443093)
- From: crowl at google dot com (Lawrence Crowl)
- To: reply at codereview dot appspotmail dot com,dnovillo at google dot com,gcc-patches at gcc dot gnu dot org
- Date: Mon, 6 Aug 2012 17:35:13 -0700 (PDT)
- Subject: [cxx-conversion] Make double_int a class with methods and operators. (issue6443093)
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.
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;
}
--
This patch is available for review at http://codereview.appspot.com/6443093