From: Sven Verdoolaege Date: Wed, 10 Nov 2010 12:49:30 +0000 (+0100) Subject: isl_qpolynomial_div_pow: normalize given div X-Git-Tag: isl-0.05~74 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e87d6a05c8cc412abd7c1061cf9cb577f62d6ad6;p=platform%2Fupstream%2Fisl.git isl_qpolynomial_div_pow: normalize given div An isl_div obtained from an isl_set would normalize be expected to have been normalized already, but the user may have constructed the isl_div manually and then we want to make sure it gets normalized. Signed-off-by: Sven Verdoolaege --- diff --git a/isl_polynomial.c b/isl_polynomial.c index a9de881..050f666 100644 --- a/isl_polynomial.c +++ b/isl_polynomial.c @@ -1641,6 +1641,27 @@ error: return NULL; } +/* Remove common factor of non-constant terms and denominator. + */ +static void normalize_div(__isl_keep isl_qpolynomial *qp, int div) +{ + isl_ctx *ctx = qp->div->ctx; + unsigned total = qp->div->n_col - 2; + + isl_seq_gcd(qp->div->row[div] + 2, total, &ctx->normalize_gcd); + isl_int_gcd(ctx->normalize_gcd, + ctx->normalize_gcd, qp->div->row[div][0]); + if (isl_int_is_one(ctx->normalize_gcd)) + return; + + isl_seq_scale_down(qp->div->row[div] + 2, qp->div->row[div] + 2, + ctx->normalize_gcd, total); + isl_int_divexact(qp->div->row[div][0], qp->div->row[div][0], + ctx->normalize_gcd); + isl_int_fdiv_q(qp->div->row[div][1], qp->div->row[div][1], + ctx->normalize_gcd); +} + __isl_give isl_qpolynomial *isl_qpolynomial_div_pow(__isl_take isl_div *div, int power) { @@ -1662,8 +1683,10 @@ __isl_give isl_qpolynomial *isl_qpolynomial_div_pow(__isl_take isl_div *div, if (!qp) goto error; - for (i = 0; i < div->bmap->n_div; ++i) + for (i = 0; i < div->bmap->n_div; ++i) { isl_seq_cpy(qp->div->row[i], div->bmap->div[i], qp->div->n_col); + normalize_div(qp, i); + } for (i = 0; i < 1 + power; ++i) { rec->p[i] = isl_upoly_zero(div->ctx); @@ -1941,27 +1964,6 @@ __isl_give struct isl_upoly *isl_upoly_from_affine(isl_ctx *ctx, isl_int *f, return up; } -/* Remove common factor of non-constant terms and denominator. - */ -static void normalize_div(__isl_keep isl_qpolynomial *qp, int div) -{ - isl_ctx *ctx = qp->div->ctx; - unsigned total = qp->div->n_col - 2; - - isl_seq_gcd(qp->div->row[div] + 2, total, &ctx->normalize_gcd); - isl_int_gcd(ctx->normalize_gcd, - ctx->normalize_gcd, qp->div->row[div][0]); - if (isl_int_is_one(ctx->normalize_gcd)) - return; - - isl_seq_scale_down(qp->div->row[div] + 2, qp->div->row[div] + 2, - ctx->normalize_gcd, total); - isl_int_divexact(qp->div->row[div][0], qp->div->row[div][0], - ctx->normalize_gcd); - isl_int_fdiv_q(qp->div->row[div][1], qp->div->row[div][1], - ctx->normalize_gcd); -} - /* Replace the integer division identified by "div" by the polynomial "s". * The integer division is assumed not to appear in the definition * of any other integer divisions.