[GIT] ppl/ppl(bounded_arithmetic): Added wrap_assign.
Module: ppl/ppl Branch: bounded_arithmetic Commit: 5f9892fcb2fce2ee9f7071820035e1be1b31aa59 URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=5f9892fcb2fce... Author: Abramo Bagnara <abramo.bagnara@gmail.com> Date: Wed May 13 23:42:29 2009 +0200 Added wrap_assign. --- src/Interval.defs.hh | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 48 insertions(+), 0 deletions(-) diff --git a/src/Interval.defs.hh b/src/Interval.defs.hh index b0bc3d2..e58b084 100644 --- a/src/Interval.defs.hh +++ b/src/Interval.defs.hh @@ -233,6 +233,11 @@ public: return lt(UPPER, upper(), info(), LOWER, lower(), info()); } + bool check_empty(I_Result r) const { + return (r & I_ANY) == I_EMPTY || + ((r & I_ANY) != I_NOT_EMPTY && is_empty()); + } + bool is_singleton() const { return eq(LOWER, lower(), info(), UPPER, upper(), info()); } @@ -523,6 +528,49 @@ public: return u >= l; } + template <typename T> + typename Enable_If<Is_Singleton<T>::value || Is_Interval<T>::value, Interval&>::type + wrap_assign(const T& x, Bounded_Integer_Type_Width w, + Bounded_Integer_Type_Signedness s, const Interval& refinement) { + if (is_empty()) + return I_EMPTY; + if (lower_is_boundary_infinity() || upper_is_boundary_infinity()) + return assign(refinement); + PPL_DIRTY_TEMP(Boundary, u); + Result r; + r = sub_2exp_assign_r(u, upper(), w, ROUND_UP); + if (!result_overflow(r) && u > lower()) + return assign(refinement); + switch (s) { + case UNSIGNED: + umod_2exp_assign(LOWER, lower(), info(), + LOWER, f_lower(x), f_info(x), w); + umod_2exp_assign(UPPER, upper(), info(), + UPPER, f_upper(x), f_info(x), w); + break; + case SIGNED_2_COMPLEMENT: + smod_2exp_assign(LOWER, lower(), info(), + LOWER, f_lower(x), f_info(x), w); + smod_2exp_assign(UPPER, upper(), info(), + UPPER, f_upper(x), f_info(x), w); + break; + default: + assert(false); + break; + } + if (le(LOWER, lower(), info(), UPPER, upper(), info())) + return intersect_assign(refinement); + PPL_DIRTY_TEMP(Interval, tmp); + tmp.info.clear(); + Boundary_NS::assign(LOWER, tmp.lower(), tmp.info(), + LOWER, lower(), info()); + set_unbounded(UPPER, tmp.upper(), tmp.info()); + tmp.intersect_assign(refinement); + lower_extend(); + intersect_assign(refinement); + return join_assign(tmp); + } + //! Returns the total size in bytes of the memory occupied by \p *this. memory_size_type total_memory_in_bytes() const;
participants (1)
-
Abramo Bagnara