/* Operations with long integers.
- Copyright (C) 2006-2013 Free Software Foundation, Inc.
+ Copyright (C) 2006-2015 Free Software Foundation, Inc.
This file is part of GCC.
#include "config.h"
#include "system.h"
#include "coretypes.h"
-#include "tm.h" /* For SHIFT_COUNT_TRUNCATED. */
+#include "tm.h" /* For BITS_PER_UNIT and *_BIG_ENDIAN. */
+#include "alias.h"
+#include "symtab.h"
#include "tree.h"
static int add_double_with_sign (unsigned HOST_WIDE_INT, HOST_WIDE_INT,
if (l1 == 0)
{
*lv = 0;
- *hv = - h1;
+ *hv = - (unsigned HOST_WIDE_INT) h1;
return (*hv & h1) < 0;
}
else
? -((unsigned HOST_WIDE_INT) h1 >> (HOST_BITS_PER_WIDE_INT - 1))
: 0);
- if (SHIFT_COUNT_TRUNCATED)
- count %= prec;
-
if (count >= HOST_BITS_PER_DOUBLE_INT)
{
/* Shifting by the host word size is undefined according to the
;
else if ((prec - count) >= HOST_BITS_PER_WIDE_INT)
{
- *hv &= ~((HOST_WIDE_INT) (-1) << (prec - count - HOST_BITS_PER_WIDE_INT));
+ *hv &= ~(HOST_WIDE_INT_M1U << (prec - count - HOST_BITS_PER_WIDE_INT));
*hv |= signmask << (prec - count - HOST_BITS_PER_WIDE_INT);
}
else
{
*hv = signmask;
- *lv &= ~((unsigned HOST_WIDE_INT) (-1) << (prec - count));
+ *lv &= ~(HOST_WIDE_INT_M1U << (prec - count));
*lv |= signmask << (prec - count);
}
}
{
unsigned HOST_WIDE_INT signmask;
- if (SHIFT_COUNT_TRUNCATED)
- count %= prec;
-
if (count >= HOST_BITS_PER_DOUBLE_INT)
{
/* Shifting by the host word size is undefined according to the
;
else if (prec >= HOST_BITS_PER_WIDE_INT)
{
- *hv &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
+ *hv &= ~(HOST_WIDE_INT_M1U << (prec - HOST_BITS_PER_WIDE_INT));
*hv |= signmask << (prec - HOST_BITS_PER_WIDE_INT);
}
else
{
*hv = signmask;
- *lv &= ~((unsigned HOST_WIDE_INT) (-1) << prec);
+ *lv &= ~(HOST_WIDE_INT_M1U << prec);
*lv |= signmask << prec;
}
}
{
unsigned HOST_WIDE_INT labs_rem = *lrem;
HOST_WIDE_INT habs_rem = *hrem;
- unsigned HOST_WIDE_INT labs_den = lden, ltwice;
- HOST_WIDE_INT habs_den = hden, htwice;
+ unsigned HOST_WIDE_INT labs_den = lden, lnegabs_rem, ldiff;
+ HOST_WIDE_INT habs_den = hden, hnegabs_rem, hdiff;
/* Get absolute values. */
- if (*hrem < 0)
+ if (!uns && *hrem < 0)
neg_double (*lrem, *hrem, &labs_rem, &habs_rem);
- if (hden < 0)
+ if (!uns && hden < 0)
neg_double (lden, hden, &labs_den, &habs_den);
- /* If (2 * abs (lrem) >= abs (lden)), adjust the quotient. */
- mul_double ((HOST_WIDE_INT) 2, (HOST_WIDE_INT) 0,
- labs_rem, habs_rem, <wice, &htwice);
+ /* If abs(rem) >= abs(den) - abs(rem), adjust the quotient. */
+ neg_double (labs_rem, habs_rem, &lnegabs_rem, &hnegabs_rem);
+ add_double (labs_den, habs_den, lnegabs_rem, hnegabs_rem,
+ &ldiff, &hdiff);
- if (((unsigned HOST_WIDE_INT) habs_den
- < (unsigned HOST_WIDE_INT) htwice)
- || (((unsigned HOST_WIDE_INT) habs_den
- == (unsigned HOST_WIDE_INT) htwice)
- && (labs_den <= ltwice)))
+ if (((unsigned HOST_WIDE_INT) habs_rem
+ > (unsigned HOST_WIDE_INT) hdiff)
+ || (habs_rem == hdiff && labs_rem >= ldiff))
{
- if (*hquo < 0)
+ if (quo_neg)
/* quo = quo - 1; */
add_double (*lquo, *hquo,
(HOST_WIDE_INT) -1, (HOST_WIDE_INT) -1, lquo, hquo);
for representing the value. The code to calculate count is
extracted from the GMP manual, section "Integer Import and Export":
http://gmplib.org/manual/Integer-Import-and-Export.html */
- numb = 8*sizeof(HOST_WIDE_INT);
+ numb = 8 * sizeof (HOST_WIDE_INT);
count = (mpz_sizeinbase (val, 2) + numb-1) / numb;
if (count < 2)
count = 2;
- vp = (unsigned HOST_WIDE_INT *) alloca (count * sizeof(HOST_WIDE_INT));
+ vp = (unsigned HOST_WIDE_INT *) alloca (count * sizeof (HOST_WIDE_INT));
vp[0] = 0;
vp[1] = 0;