From 6e7823b95e72be86ab438f8b5c5c3af8d961b116 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Mon, 21 Apr 2008 22:12:55 +0200 Subject: [PATCH] lattice_point.cc: add ceiling function --- lattice_point.cc | 19 +++++++++++++++++++ lattice_point.h | 1 + util.c | 8 +------- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/lattice_point.cc b/lattice_point.cc index 8526a2d..4c9baa2 100644 --- a/lattice_point.cc +++ b/lattice_point.cc @@ -248,6 +248,25 @@ out: return EP; } +/* Computes the ceil of the affine expression specified + * by coef (of length nvar+1) and the denominator denom. + * If PD is not NULL, then it specifies additional constraints + * on the variables that may be used to simplify the resulting + * ceil expression. + * + * Modifies coef argument ! + */ +evalue *ceiling(Value *coef, Value denom, int nvar, Polyhedron *PD) +{ + evalue *EP, *f; + EP = affine2evalue(coef, denom, nvar); + Vector_Oppose(coef, coef, nvar+1); + f = fractional_part(coef, denom, nvar, PD); + eadd(f, EP); + evalue_free(f); + return EP; +} + static evalue *ceil(Value *coef, int len, Value d, barvinok_options *options) { diff --git a/lattice_point.h b/lattice_point.h index 441fd64..1a113ac 100644 --- a/lattice_point.h +++ b/lattice_point.h @@ -9,6 +9,7 @@ extern "C" { #endif evalue *fractional_part(Value *coef, Value denom, int nvar, Polyhedron *PD); +evalue *ceiling(Value *coef, Value denom, int nvar, Polyhedron *PD); #if defined(__cplusplus) } diff --git a/util.c b/util.c index 3a97f9f..4a1ce06 100644 --- a/util.c +++ b/util.c @@ -981,15 +981,9 @@ static evalue* bv_ceil3(Value *coef, int len, Value d, Polyhedron *P) Vector_Oppose(coef, val->p, len); value_absolute(t, d); - EP = affine2evalue(val->p, t, len-1); + EP = ceiling(val->p, t, len-1, P); - Vector_Oppose(val->p, val->p, len); - f = fractional_part(val->p, t, len-1, P); value_clear(t); - - eadd(f, EP); - evalue_free(f); - Vector_Free(val); return EP; -- 2.11.4.GIT