static int neg_double (unsigned HOST_WIDE_INT, HOST_WIDE_INT,
unsigned HOST_WIDE_INT *, HOST_WIDE_INT *);
-static 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);
-
static int mul_double_wide_with_sign (unsigned HOST_WIDE_INT, HOST_WIDE_INT,
unsigned HOST_WIDE_INT, HOST_WIDE_INT,
unsigned HOST_WIDE_INT *, HOST_WIDE_INT *,
bool);
#define mul_double(l1,h1,l2,h2,lv,hv) \
- mul_double_with_sign (l1, h1, l2, h2, lv, hv, false)
-
-static void lshift_double (unsigned HOST_WIDE_INT, HOST_WIDE_INT,
- HOST_WIDE_INT, unsigned int,
- unsigned HOST_WIDE_INT *, HOST_WIDE_INT *, bool);
+ mul_double_wide_with_sign (l1, h1, l2, h2, lv, hv, NULL, NULL, false)
static int div_and_round_double (unsigned, int, unsigned HOST_WIDE_INT,
HOST_WIDE_INT, unsigned HOST_WIDE_INT,
}
}
-/* Multiply two doubleword integers with doubleword result.
+/* Multiply two doubleword integers with quadword result.
Return nonzero if the operation overflows according to UNSIGNED_P.
Each argument is given as two `HOST_WIDE_INT' pieces.
One argument is L1 and H1; the other, L2 and H2.
- The value is stored as two `HOST_WIDE_INT' pieces in *LV and *HV. */
-
-static int
-mul_double_with_sign (unsigned HOST_WIDE_INT l1, HOST_WIDE_INT h1,
- unsigned HOST_WIDE_INT l2, HOST_WIDE_INT h2,
- unsigned HOST_WIDE_INT *lv, HOST_WIDE_INT *hv,
- bool unsigned_p)
-{
- unsigned HOST_WIDE_INT toplow;
- HOST_WIDE_INT tophigh;
-
- return mul_double_wide_with_sign (l1, h1, l2, h2,
- lv, hv, &toplow, &tophigh,
- unsigned_p);
-}
+ The value is stored as four `HOST_WIDE_INT' pieces in *LV and *HV,
+ *LW and *HW.
+ If lw is NULL then only the low part and no overflow is computed. */
static int
mul_double_wide_with_sign (unsigned HOST_WIDE_INT l1, HOST_WIDE_INT h1,
}
decode (prod, lv, hv);
+
+ /* We are not interested in the wide part nor in overflow. */
+ if (lw == NULL)
+ return 0;
+
decode (prod + 4, lw, hw);
/* Unsigned overflow is immediate. */
static void
lshift_double (unsigned HOST_WIDE_INT l1, HOST_WIDE_INT h1,
- HOST_WIDE_INT count, unsigned int prec,
- unsigned HOST_WIDE_INT *lv, HOST_WIDE_INT *hv, bool arith)
+ unsigned HOST_WIDE_INT count, unsigned int prec,
+ unsigned HOST_WIDE_INT *lv, HOST_WIDE_INT *hv)
{
unsigned HOST_WIDE_INT signmask;
- if (count < 0)
- {
- rshift_double (l1, h1, absu_hwi (count), prec, lv, hv, arith);
- return;
- }
-
if (SHIFT_COUNT_TRUNCATED)
count %= prec;
return ret;
}
+/* Multiplies *this with B and returns a reference to *this. */
+
+double_int &
+double_int::operator *= (double_int b)
+{
+ mul_double (low, high, b.low, b.high, &low, &high);
+ return *this;
+}
+
/* Returns A * B. If the operation overflows according to UNSIGNED_P,
*OVERFLOW is set to nonzero. */
double_int::mul_with_sign (double_int b, bool unsigned_p, bool *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);
+ double_int ret, tem;
+ *overflow = mul_double_wide_with_sign (a.low, a.high, b.low, b.high,
+ &ret.low, &ret.high,
+ &tem.low, &tem.high, unsigned_p);
return ret;
}
return ret;
}
+/* Adds B to *this and returns a reference to *this. */
+
+double_int &
+double_int::operator += (double_int b)
+{
+ add_double (low, high, b.low, b.high, &low, &high);
+ return *this;
+}
+
+
/* Returns A + B. If the operation overflows according to UNSIGNED_P,
*OVERFLOW is set to nonzero. */
return ret;
}
+/* Subtracts B from *this and returns a reference to *this. */
+
+double_int &
+double_int::operator -= (double_int b)
+{
+ neg_double (b.low, b.high, &b.low, &b.high);
+ add_double (low, high, b.low, b.high, &low, &high);
+ return *this;
+}
+
+
/* Returns A - B. If the operation overflows via inconsistent sign bits,
*OVERFLOW is set to nonzero. */
return bits;
}
+/* Shift A left by COUNT places. */
+
+double_int
+double_int::lshift (HOST_WIDE_INT count) const
+{
+ double_int ret;
+
+ gcc_checking_assert (count >= 0);
+
+ if (count >= HOST_BITS_PER_DOUBLE_INT)
+ {
+ /* Shifting by the host word size is undefined according to the
+ ANSI standard, so we must handle this as a special case. */
+ ret.high = 0;
+ ret.low = 0;
+ }
+ else if (count >= HOST_BITS_PER_WIDE_INT)
+ {
+ ret.high = low << (count - HOST_BITS_PER_WIDE_INT);
+ ret.low = 0;
+ }
+ else
+ {
+ ret.high = (((unsigned HOST_WIDE_INT) high << count)
+ | (low >> (HOST_BITS_PER_WIDE_INT - count - 1) >> 1));
+ ret.low = low << count;
+ }
+
+ return ret;
+}
+
/* Shift A left by COUNT places keeping only PREC bits of result. Shift
right if COUNT is negative. ARITH true specifies arithmetic shifting;
otherwise use logical shift. */
double_int
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);
+ if (count > 0)
+ lshift_double (low, high, count, prec, &ret.low, &ret.high);
+ else
+ rshift_double (low, high, absu_hwi (count), prec, &ret.low, &ret.high, arith);
return ret;
}
double_int
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);
+ if (count > 0)
+ rshift_double (low, high, count, prec, &ret.low, &ret.high, arith);
+ else
+ lshift_double (low, high, absu_hwi (count), prec, &ret.low, &ret.high);
return ret;
}
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);
+ if (count > 0)
+ lshift_double (low, high, count, prec, &r.low, &r.high);
+ else
+ rshift_double (low, high, absu_hwi (count), prec, &r.low, &r.high, true);
return r;
}
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);
+ if (count > 0)
+ rshift_double (low, high, count, prec, &r.low, &r.high, true);
+ else
+ lshift_double (low, high, absu_hwi (count), prec, &r.low, &r.high);
return r;
}
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);
+ if (count > 0)
+ lshift_double (low, high, count, prec, &r.low, &r.high);
+ else
+ rshift_double (low, high, absu_hwi (count), prec, &r.low, &r.high, false);
return r;
}
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);
+ if (count > 0)
+ rshift_double (low, high, count, prec, &r.low, &r.high, false);
+ else
+ lshift_double (low, high, absu_hwi (count), prec, &r.low, &r.high);
return r;
}
if (count < 0)
count += prec;
- t1 = this->lshift (count, prec, false);
- t2 = this->rshift (prec - count, prec, false);
+ t1 = this->llshift (count, prec);
+ t2 = this->lrshift (prec - count, prec);
return t1 | t2;
}
if (count < 0)
count += prec;
- t1 = this->rshift (count, prec, false);
- t2 = this->lshift (prec - count, prec, false);
+ t1 = this->lrshift (count, prec);
+ t2 = this->llshift (prec - count, prec);
return t1 | t2;
}
/* The offset embedded in MEM_REFs can be negative. Bias them
so that the resulting offset adjustment is positive. */
moff = mem_ref_offset (base1);
- moff = moff.alshift (BITS_PER_UNIT == 8
- ? 3 : exact_log2 (BITS_PER_UNIT),
- HOST_BITS_PER_DOUBLE_INT);
+ moff = moff.lshift (BITS_PER_UNIT == 8 ? 3 : exact_log2 (BITS_PER_UNIT));
if (moff.is_negative ())
offset2p += (-moff).low;
else
|| TREE_CODE (dbase2) == TARGET_MEM_REF)
{
double_int moff = mem_ref_offset (dbase2);
- moff = moff.alshift (BITS_PER_UNIT == 8
- ? 3 : exact_log2 (BITS_PER_UNIT),
- HOST_BITS_PER_DOUBLE_INT);
+ moff = moff.lshift (BITS_PER_UNIT == 8 ? 3 : exact_log2 (BITS_PER_UNIT));
if (moff.is_negative ())
doffset1 -= (-moff).low;
else
/* The offset embedded in MEM_REFs can be negative. Bias them
so that the resulting offset adjustment is positive. */
moff = mem_ref_offset (base1);
- moff = moff.alshift (BITS_PER_UNIT == 8
- ? 3 : exact_log2 (BITS_PER_UNIT),
- HOST_BITS_PER_DOUBLE_INT);
+ moff = moff.lshift (BITS_PER_UNIT == 8 ? 3 : exact_log2 (BITS_PER_UNIT));
if (moff.is_negative ())
offset2 += (-moff).low;
else
offset1 += moff.low;
moff = mem_ref_offset (base2);
- moff = moff.alshift (BITS_PER_UNIT == 8
- ? 3 : exact_log2 (BITS_PER_UNIT),
- HOST_BITS_PER_DOUBLE_INT);
+ moff = moff.lshift (BITS_PER_UNIT == 8 ? 3 : exact_log2 (BITS_PER_UNIT));
if (moff.is_negative ())
offset1 += (-moff).low;
else
TREE_OPERAND (ref->base, 0)))
{
double_int off1 = mem_ref_offset (base);
- off1 = off1.alshift (BITS_PER_UNIT == 8
- ? 3 : exact_log2 (BITS_PER_UNIT),
- HOST_BITS_PER_DOUBLE_INT);
+ off1 = off1.lshift (BITS_PER_UNIT == 8
+ ? 3 : exact_log2 (BITS_PER_UNIT));
off1 = off1 + double_int::from_shwi (offset);
double_int off2 = mem_ref_offset (ref->base);
- off2 = off2.alshift (BITS_PER_UNIT == 8
- ? 3 : exact_log2 (BITS_PER_UNIT),
- HOST_BITS_PER_DOUBLE_INT);
+ off2 = off2.lshift (BITS_PER_UNIT == 8
+ ? 3 : exact_log2 (BITS_PER_UNIT));
off2 = off2 + double_int::from_shwi (ref_offset);
if (off1.fits_shwi () && off2.fits_shwi ())
{