[PPL-devel] [GIT] ppl/ppl(floating_point): Added a skeleton for the new linearization function.
Abramo Bagnara
abramo.bagnara at gmail.com
Sat Jul 24 12:51:44 CEST 2010
Il 24/07/2010 12:42, Fabio Bossi ha scritto:
> Module: ppl/ppl
> Branch: floating_point
> Commit: 1c4c91c248d74dc5abb8c5b45507dfe9665ff6b5
> URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=1c4c91c248d74dc5abb8c5b45507dfe9665ff6b5
>
> Author: Fabio Bossi <bossi at cs.unipr.it>
> Date: Sat Jul 24 12:39:51 2010 +0200
>
> Added a skeleton for the new linearization function.
>
> Also added an idea for the linearization of the
> unary negation expression.
>
> ---
> +template <typename Target, typename FP_Interval_Type>
> +bool
> +linearize(const Concrete_Expression<Target>& expr,
> + const Box<FP_Interval_Type>& int_store,
> + const std::map<dimension_type, Linear_Form<FP_Interval_Type>>& lf_store,
> + Linear_Form<FP_Interval_Type>& result) {
> + typedef typename FP_Interval_Type::boundary_type analyzer_format;
> + typedef Linear_Form<FP_Interval_Type> FP_Linear_Form;
> + typedef Box<FP_Interval_Type> FP_Interval_Abstract_Store;
> + typedef std::map<dimension_type, FP_Linear_Form> FP_Linear_Form_Abstract_Store;
> +
> + // Check that analyzer_format is a floating point type.
> + PPL_COMPILE_TIME_CHECK(!std::numeric_limits<analyzer_format>::is_exact,
> + "linearize<Target, FP_Interval_Type>:"
> + " FP_Interval_Type is not the type of an interval with floating point boundaries.");
> +
> + // Check that we are dealing with an expression of floating point type.
> + PPL_ASSERT(expr.is_floating_point());
> +
> + /*
> + Floating_Point_Format analyzed_format = expr.floating_point_format();
> + FP_Interval_Type absolute_error =
> + compute_absolute_error<FP_Interval_Type>(analyzed_format);
> + */
> + switch(expr.kind()) {
> + case INT_CON:
case Integer_Constant<Target>::KIND:
> + // TODO.
> + break;
> + case FP_CON:
> + Floating_Point_Constant<Target> fpc_expr =
> + static_cast<Floating_Point_Constant<Target>>(expr);
> + result = FP_Linear_Form(FP_Interval(fpc_expr.get_value_as_string()));
> + return true;
> + break;
> + case UOP:
> + Unary_Operator<Target> uop_expr =
> + static_cast<Unary_Operator<Target>>(expr);
> + switch (uop_expr.get_uop()) {
> + case PLUS:
case Unary_Operator<Target>::PLUS:
> + return linearize(uop_expr.get_arg(), int_store, lf_store, result);
> + break;
> + case MINUS:
> + if (!linearize(uop_expr.get_arg(), int_store, lf_store, result))
> + return false;
> +
> + result.negate();
> + return true;
> + break;
> + case BNOT:
> + return bnot_linearize(uop_expr, int_store, lf_store, result);
> + break;
> + default:
> + throw std::runtime_error("PPL internal error");
> + }
> + break;
> + case BOP:
> + Binary_Operator<Target> bop_expr =
> + static_cast<Binary_Operator<Target>>(expr);
> + switch (bop_expr.get_bop()) {
> + case ADD:
> + return add_linearize(bop_expr, int_store, lf_store, result);
> + break;
> + case SUB:
> + return sub_linearize(bop_expr, int_store, lf_store, result);
> + break;
> + case MUL:
> + return mul_linearize(bop_expr, int_store, lf_store, result);
> + break;
> + case DIV:
> + return div_linearize(bop_expr, int_store, lf_store, result);
> + break;
> + case REM:
> + case BAND:
> + case BOR:
> + case BXOR:
> + case LSHIFT:
> + case RSHIFT:
> + default:
> + throw std::runtime_error("PPL internal error");
> + }
> + break;
> + case CAST:
> + // TODO.
> + break;
> + default:
> + throw std::runtime_error("PPL internal error");
> + }
> +}
> +
> +} // namespace Parma_Polyhedra_Library
> +
> +#endif // !defined(PPL_linearize_hh)
... e similarmente per tutti gli altri.
More information about the PPL-devel
mailing list