[GIT] ppl/ppl(master): Some efficiency improvements. Comments improved.

Module: ppl/ppl Branch: master Commit: eb54ad2e7508d44ada8ef80161f416e5ec9f48a2 URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=eb54ad2e7508d...
Author: Patricia Hill p.m.hill@leeds.ac.uk Date: Tue May 12 16:42:06 2009 +0100
Some efficiency improvements. Comments improved.
---
src/Grid_public.cc | 38 +++++++++++++++++++++----------------- 1 files changed, 21 insertions(+), 17 deletions(-)
diff --git a/src/Grid_public.cc b/src/Grid_public.cc index 498e8a7..0fae952 100644 --- a/src/Grid_public.cc +++ b/src/Grid_public.cc @@ -2700,13 +2700,13 @@ PPL::Grid::wrap_assign(const Variables_Set& vars, PPL_DIRTY_TEMP_COEFFICIENT(f_d); PPL_DIRTY_TEMP_COEFFICIENT(v_n); PPL_DIRTY_TEMP_COEFFICIENT(v_d); - PPL_DIRTY_TEMP_COEFFICIENT(f); for (Variables_Set::const_iterator i = vars.begin(), - vars_end = vars.end(); i != vars.end(); ++i) { + vars_end = vars.end(); i != vars.end(); ++i) { const Variable x = Variable(*i); if (!gr.frequency_no_check(x, f_n, f_d, v_n, v_d)) continue; if (f_n == 0) { + // `x' is a constant in `gr'. if ((v_n > max_value * v_d) || (v_n < min_value * v_d)) { // The value is outside the range of the bounded integer type. @@ -2717,16 +2717,18 @@ PPL::Grid::wrap_assign(const Variables_Set& vars, } assert(o == OVERFLOW_WRAPS); // The value v_n for `x' is wrapped modulo the 'wrap_frequency'. - f = v_d * wrap_frequency; - v_n %= f; + Coefficient& wrap_modulus = f_n; + wrap_modulus = v_d * wrap_frequency; + v_n %= wrap_modulus; // `v_n' is the value closest to 0 and may be negative. if (s == UNSIGNED && v_n < 0) - v_n += f; + v_n += wrap_modulus; unconstrain(x); add_constraint(v_d * x == v_n); } continue; } + // `x' is not a constant in `gr'. if (2*f_n > f_d * wrap_frequency) { // If the grid frequency for `x' in `vars' is more than half the @@ -2737,18 +2739,19 @@ PPL::Grid::wrap_assign(const Variables_Set& vars, v_n *= f_d; add_mul_assign(v_n, f_n, v_d); v_d *= f_d; - PPL_DIRTY_TEMP_COEFFICIENT(gcd); - gcd_assign(gcd, v_n, v_d); - exact_div_assign(v_n, v_n, gcd); - exact_div_assign(v_d, v_d, gcd); } add_constraint(v_d * x == v_n); } + else if (o == OVERFLOW_WRAPS) + // We know that `x' is not a constant, so, if overflow wraps, + // `x' may wrap to a value modulo the `wrap_frequency'. + add_grid_generator(parameter(wrap_frequency * x)); else - if (o == OVERFLOW_WRAPS) - // We know that `x' is not a constant, so `x' may wrap - // to a value modulo the `wrap_frequency'. - add_grid_generator(parameter(wrap_frequency * x)); + // If overflow is impossible but the grid frequency is no more than + // half the wrap frequency, then there is more than one possible + // value for `x' in the range of the bounded integer type, + // so the grid is unchanged. + assert(o == OVERFLOW_IMPOSSIBLE && 2*f_n <= f_d * wrap_frequency); } return; } @@ -2756,6 +2759,10 @@ PPL::Grid::wrap_assign(const Variables_Set& vars, assert(o == OVERFLOW_UNDEFINED); // If overflow is undefined, then all we know is that the variable // may take any integer within the range of the bounded integer type. + PPL_DIRTY_TEMP_COEFFICIENT(coeff_x); + const Grid_Generator& point = gen_sys[0]; + Coefficient& div_x = wrap_frequency; + div_x = point.divisor(); for (Variables_Set::const_iterator i = vars.begin(), vars_end = vars.end(); i != vars.end(); ++i) { const Variable x = Variable(*i); @@ -2767,10 +2774,7 @@ PPL::Grid::wrap_assign(const Variables_Set& vars, } else { // `x' is a constant `v' in `gr'. - PPL_DIRTY_TEMP_COEFFICIENT(coeff_x); - PPL_DIRTY_TEMP_COEFFICIENT(div_x); - coeff_x = gen_sys[0].coefficient(x); - div_x = gen_sys[0].divisor(); + coeff_x = point.coefficient(x); // If the value `v' for `x' is not within the range for the // bounded integer type, then `x' may wrap to any value `v + z' // where `z' is an integer; otherwise `x' is unchanged.
participants (1)
-
Patricia Hill