aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-chrec.c
diff options
context:
space:
mode:
authorKenneth Zadeck <zadeck@naturalbridge.com>2014-05-06 16:25:05 +0000
committerMike Stump <mrs@gcc.gnu.org>2014-05-06 16:25:05 +0000
commit807e902eea17f3132488c256c963823976b2348c (patch)
treee5e1af94eb1502ba893bd6ce4a11f68877ff62a9 /gcc/tree-chrec.c
parent6122336c832dc4dfedc49279549caddce86306ff (diff)
downloadgcc-807e902eea17f3132488c256c963823976b2348c.zip
gcc-807e902eea17f3132488c256c963823976b2348c.tar.gz
gcc-807e902eea17f3132488c256c963823976b2348c.tar.bz2
Merge in wide-int.
From-SVN: r210113
Diffstat (limited to 'gcc/tree-chrec.c')
-rw-r--r--gcc/tree-chrec.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/gcc/tree-chrec.c b/gcc/tree-chrec.c
index b9350f0..c78d9410 100644
--- a/gcc/tree-chrec.c
+++ b/gcc/tree-chrec.c
@@ -480,7 +480,6 @@ chrec_fold_multiply (tree type,
static tree
tree_fold_binomial (tree type, tree n, unsigned int k)
{
- double_int num, denom, idx, di_res;
bool overflow;
unsigned int i;
tree res;
@@ -491,21 +490,18 @@ tree_fold_binomial (tree type, tree n, unsigned int k)
if (k == 1)
return fold_convert (type, n);
- /* Numerator = n. */
- num = TREE_INT_CST (n);
-
/* Check that k <= n. */
- if (num.ult (double_int::from_uhwi (k)))
+ if (wi::ltu_p (n, k))
return NULL_TREE;
/* Denominator = 2. */
- denom = double_int::from_uhwi (2);
+ wide_int denom = wi::two (TYPE_PRECISION (TREE_TYPE (n)));
/* Index = Numerator-1. */
- idx = num - double_int_one;
+ wide_int idx = wi::sub (n, 1);
/* Numerator = Numerator*Index = n*(n-1). */
- num = num.mul_with_sign (idx, false, &overflow);
+ wide_int num = wi::smul (n, idx, &overflow);
if (overflow)
return NULL_TREE;
@@ -515,17 +511,17 @@ tree_fold_binomial (tree type, tree n, unsigned int k)
--idx;
/* Numerator *= Index. */
- num = num.mul_with_sign (idx, false, &overflow);
+ num = wi::smul (num, idx, &overflow);
if (overflow)
return NULL_TREE;
/* Denominator *= i. */
- denom *= double_int::from_uhwi (i);
+ denom *= i;
}
/* Result = Numerator / Denominator. */
- di_res = num.div (denom, true, EXACT_DIV_EXPR);
- res = build_int_cst_wide (type, di_res.low, di_res.high);
+ wide_int di_res = wi::udiv_trunc (num, denom);
+ res = wide_int_to_tree (type, di_res);
return int_fits_type_p (res, type) ? res : NULL_TREE;
}