[PPL-devel] [GIT] ppl/ppl(bounded_arithmetic): In Polyhedron::wrap_assign() handled the case `o == OVERFLOW_IMPOSSIBLE'.
Roberto Bagnara
bagnara at cs.unipr.it
Tue Apr 28 19:19:49 CEST 2009
Module: ppl/ppl
Branch: bounded_arithmetic
Commit: 6431f35e4360c7c8385635f1e262c2f984cf07b1
URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=6431f35e4360c7c8385635f1e262c2f984cf07b1
Author: Roberto Bagnara <bagnara at cs.unipr.it>
Date: Tue Apr 28 19:19:04 2009 +0200
In Polyhedron::wrap_assign() handled the case `o == OVERFLOW_IMPOSSIBLE'.
---
src/Polyhedron_public.cc | 11 ++++-
tests/Polyhedron/wrap1.cc | 115 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 125 insertions(+), 1 deletions(-)
diff --git a/src/Polyhedron_public.cc b/src/Polyhedron_public.cc
index 2bd274d..dc10b87 100644
--- a/src/Polyhedron_public.cc
+++ b/src/Polyhedron_public.cc
@@ -3761,9 +3761,18 @@ PPL::Polyhedron::wrap_assign(const Variables_Set& vars,
//std::cout << "un = " << un << std::endl;
// Special case: this variable does not need wrapping.
- if (un == 0 && ln == 0)
+ if (ln == 0 && un == 0)
continue;
+ // If overflow is impossible, try not to add useless constraints.
+ if (o == OVERFLOW_IMPOSSIBLE) {
+ if (ln < 0)
+ full_range_bounds.insert(min_value <= x);
+ if (un > 0)
+ full_range_bounds.insert(x <= max_value);
+ continue;
+ }
+
if (o == OVERFLOW_UNDEFINED || un - ln > k_threshold)
goto set_full_range;
diff --git a/tests/Polyhedron/wrap1.cc b/tests/Polyhedron/wrap1.cc
index f03be15..d182ca1 100644
--- a/tests/Polyhedron/wrap1.cc
+++ b/tests/Polyhedron/wrap1.cc
@@ -144,6 +144,117 @@ test04() {
return ok;
}
+bool
+test05() {
+ Variable x(0);
+ Variable y(1);
+ C_Polyhedron ph(2);
+ ph.add_constraint(x + 1024 == 8*y);
+ ph.add_constraint(-64 <= x);
+ ph.add_constraint(x <= 448);
+
+ print_constraints(ph, "*** ph ***");
+
+ Variables_Set vars(x, y);
+
+ ph.wrap_assign(vars, BITS_8, UNSIGNED, OVERFLOW_IMPOSSIBLE);
+
+ C_Polyhedron known_result(2);
+ known_result.add_constraint(x >= 0);
+ known_result.add_constraint(x <= 255);
+ known_result.add_constraint(x + 1024 == 8*y);
+
+ bool ok = (ph == known_result);
+
+ print_constraints(ph, "*** ph.wrap_assign(...) ***");
+
+ return ok;
+}
+
+bool
+test06() {
+ Variable x(0);
+ Variable y(1);
+ C_Polyhedron ph(2);
+ ph.add_constraint(x + 1024 == 8*y);
+ ph.add_constraint(-64 <= x);
+ ph.add_constraint(x <= 448);
+
+ print_constraints(ph, "*** ph ***");
+
+ Variables_Set vars(x, y);
+
+ Constraint_System cs;
+ cs.insert(x <= y);
+
+ ph.wrap_assign(vars, BITS_8, UNSIGNED, OVERFLOW_IMPOSSIBLE, &cs);
+
+ C_Polyhedron known_result(2);
+ known_result.add_constraint(x >= 0);
+ known_result.add_constraint(7*x <= 1024);
+ known_result.add_constraint(x + 1024 == 8*y);
+
+ bool ok = (ph == known_result);
+
+ print_constraints(ph, "*** ph.wrap_assign(...) ***");
+
+ return ok;
+}
+
+bool
+test07() {
+ Variable x(0);
+ Variable y(1);
+ C_Polyhedron ph(2);
+ ph.add_constraint(x + 1024 == 8*y);
+
+ print_constraints(ph, "*** ph ***");
+
+ Variables_Set vars(x, y);
+
+ ph.wrap_assign(vars, BITS_8, UNSIGNED, OVERFLOW_WRAPS);
+
+ C_Polyhedron known_result(2);
+ known_result.add_constraint(x >= 0);
+ known_result.add_constraint(x <= 255);
+ known_result.add_constraint(y >= 0);
+ known_result.add_constraint(y <= 255);
+
+ bool ok = (ph == known_result);
+
+ print_constraints(ph, "*** ph.wrap_assign(...) ***");
+
+ return ok;
+}
+
+bool
+test08() {
+ Variable x(0);
+ Variable y(1);
+ C_Polyhedron ph(2);
+ ph.add_constraint(x + 1024 == 8*y);
+
+ print_constraints(ph, "*** ph ***");
+
+ Variables_Set vars(x, y);
+
+ Constraint_System cs;
+ cs.insert(x <= y);
+
+ ph.wrap_assign(vars, BITS_8, UNSIGNED, OVERFLOW_WRAPS, &cs);
+
+ C_Polyhedron known_result(2);
+ known_result.add_constraint(x >= 0);
+ known_result.add_constraint(y <= 255);
+ known_result.add_constraint(x <= y);
+
+ bool ok = (ph == known_result);
+
+ print_constraints(ph, "*** ph.wrap_assign(...) ***");
+
+ return ok;
+}
+
} // namespace
BEGIN_MAIN
@@ -151,4 +262,8 @@ BEGIN_MAIN
DO_TEST(test02);
DO_TEST(test03);
DO_TEST(test04);
+ DO_TEST(test05);
+ DO_TEST(test06);
+ DO_TEST(test07);
+ DO_TEST(test08);
END_MAIN
More information about the PPL-devel
mailing list