[PPL-devel] [GIT] ppl/ppl(floating_point): Removed class absolute_error.
Fabio Bossi
bossi at cs.unipr.it
Wed Jul 21 17:19:22 CEST 2010
Module: ppl/ppl
Branch: floating_point
Commit: 0decead53d0c887298b1dc309e7003d2ce59698f
URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=0decead53d0c887298b1dc309e7003d2ce59698f
Author: Fabio Bossi <bossi at cs.unipr.it>
Date: Wed Jul 21 17:18:30 2010 +0200
Removed class absolute_error.
Cache results locally in compute_absolute_error instead.
---
src/Float.defs.hh | 60 +----------------------------------------------
src/Float.templates.hh | 47 ++++++++++++++++++++++++++++++++----
2 files changed, 43 insertions(+), 64 deletions(-)
diff --git a/src/Float.defs.hh b/src/Float.defs.hh
index 43a0399..e68c3bd 100644
--- a/src/Float.defs.hh
+++ b/src/Float.defs.hh
@@ -361,64 +361,8 @@ public:
#endif
template <typename FP_Interval_Type>
-FP_Interval_Type compute_absolute_error(Floating_Point_Format analyzed_format);
-
-template <typename FP_Interval_Type, Floating_Point_Format>
-struct absolute_error;
-
-template <typename FP_Interval_Type>
-struct absolute_error<FP_Interval_Type, IEEE754_HALF> {
- static const FP_Interval_Type value;
-};
-
-template <typename FP_Interval_Type>
-const FP_Interval_Type absolute_error<FP_Interval_Type, IEEE754_HALF>::value =
- compute_absolute_error<FP_Interval_Type>(IEEE754_HALF);
-
-template <typename FP_Interval_Type>
-struct absolute_error<FP_Interval_Type, IEEE754_SINGLE> {
- static const FP_Interval_Type value;
-};
-
-template <typename FP_Interval_Type>
-const FP_Interval_Type absolute_error<FP_Interval_Type, IEEE754_SINGLE>::value =
- compute_absolute_error<FP_Interval_Type>(IEEE754_SINGLE);
-
-template <typename FP_Interval_Type>
-struct absolute_error<FP_Interval_Type, IEEE754_DOUBLE> {
- static const FP_Interval_Type value;
-};
-
-template <typename FP_Interval_Type>
-const FP_Interval_Type absolute_error<FP_Interval_Type, IEEE754_DOUBLE>::value =
- compute_absolute_error<FP_Interval_Type>(IEEE754_DOUBLE);
-
-template <typename FP_Interval_Type>
-struct absolute_error<FP_Interval_Type, IBM_SINGLE> {
- static const FP_Interval_Type value;
-};
-
-template <typename FP_Interval_Type>
-const FP_Interval_Type absolute_error<FP_Interval_Type, IBM_SINGLE>::value =
- compute_absolute_error<FP_Interval_Type>(IBM_SINGLE);
-
-template <typename FP_Interval_Type>
-struct absolute_error<FP_Interval_Type, IEEE754_QUAD> {
- static const FP_Interval_Type value;
-};
-
-template <typename FP_Interval_Type>
-const FP_Interval_Type absolute_error<FP_Interval_Type, IEEE754_QUAD>::value =
- compute_absolute_error<FP_Interval_Type>(IEEE754_QUAD);
-
-template <typename FP_Interval_Type>
-struct absolute_error<FP_Interval_Type, INTEL_DOUBLE_EXTENDED> {
- static const FP_Interval_Type value;
-};
-
-template <typename FP_Interval_Type>
-const FP_Interval_Type absolute_error<FP_Interval_Type, INTEL_DOUBLE_EXTENDED>::value =
- compute_absolute_error<FP_Interval_Type>(INTEL_DOUBLE_EXTENDED);
+const FP_Interval_Type& compute_absolute_error(
+ Floating_Point_Format analyzed_format);
} // namespace Parma_Polyhedra_Library
diff --git a/src/Float.templates.hh b/src/Float.templates.hh
index feaa8bb..4912b9a 100644
--- a/src/Float.templates.hh
+++ b/src/Float.templates.hh
@@ -29,41 +29,75 @@ site: http://www.cs.unipr.it/ppl/ . */
namespace Parma_Polyhedra_Library {
template <typename FP_Interval_Type>
-FP_Interval_Type compute_absolute_error(
- const Floating_Point_Format analyzed_format) {
+const FP_Interval_Type& compute_absolute_error(
+ const Floating_Point_Format analyzed_format) {
typedef typename FP_Interval_Type::boundary_type analyzer_format;
+ static const FP_Interval_Type ZERO_INTERVAL = FP_Interval_Type(0);
+ // Cached results for each different analyzed format.
+ static FP_Interval_Type ieee754_half_result = ZERO_INTERVAL;
+ static FP_Interval_Type ieee754_single_result = ZERO_INTERVAL;
+ static FP_Interval_Type ieee754_double_result = ZERO_INTERVAL;
+ static FP_Interval_Type ibm_single_result = ZERO_INTERVAL;
+ static FP_Interval_Type ieee754_quad_result = ZERO_INTERVAL;
+ static FP_Interval_Type intel_double_extended_result = ZERO_INTERVAL;
+
+ FP_Interval_Type* to_compute = NULL;
// Get the necessary information on the analyzed's format.
unsigned int f_base;
int f_exponent_bias;
unsigned int f_mantissa_bits;
switch (analyzed_format) {
case IEEE754_HALF:
+ if (ieee754_half_result != ZERO_INTERVAL)
+ return ieee754_half_result;
+
+ to_compute = &ieee754_half_result;
f_base = float_ieee754_half::BASE;
f_exponent_bias = float_ieee754_half::EXPONENT_BIAS;
f_mantissa_bits = float_ieee754_half::MANTISSA_BITS;
break;
case IEEE754_SINGLE:
+ if (ieee754_single_result != ZERO_INTERVAL)
+ return ieee754_single_result;
+
+ to_compute = &ieee754_single_result;
f_base = float_ieee754_single::BASE;
f_exponent_bias = float_ieee754_single::EXPONENT_BIAS;
f_mantissa_bits = float_ieee754_single::MANTISSA_BITS;
break;
case IEEE754_DOUBLE:
+ if (ieee754_double_result != ZERO_INTERVAL)
+ return ieee754_double_result;
+
+ to_compute = &ieee754_double_result;
f_base = float_ieee754_double::BASE;
f_exponent_bias = float_ieee754_double::EXPONENT_BIAS;
f_mantissa_bits = float_ieee754_double::MANTISSA_BITS;
break;
case IBM_SINGLE:
+ if (ibm_single_result != ZERO_INTERVAL)
+ return ibm_single_result;
+
+ to_compute = &ibm_single_result;
f_base = float_ibm_single::BASE;
f_exponent_bias = float_ibm_single::EXPONENT_BIAS;
f_mantissa_bits = float_ibm_single::MANTISSA_BITS;
break;
case IEEE754_QUAD:
+ if (ieee754_quad_result != ZERO_INTERVAL)
+ return ieee754_quad_result;
+
+ to_compute = &ieee754_quad_result;
f_base = float_ieee754_quad::BASE;
f_exponent_bias = float_ieee754_quad::EXPONENT_BIAS;
f_mantissa_bits = float_ieee754_quad::MANTISSA_BITS;
break;
case INTEL_DOUBLE_EXTENDED:
+ if (intel_double_extended_result != ZERO_INTERVAL)
+ return intel_double_extended_result;
+
+ to_compute = &intel_double_extended_result;
f_base = float_intel_double_extended::BASE;
f_exponent_bias = float_intel_double_extended::EXPONENT_BIAS;
f_mantissa_bits = float_intel_double_extended::MANTISSA_BITS;
@@ -72,16 +106,17 @@ FP_Interval_Type compute_absolute_error(
throw std::runtime_error("PPL internal error");
}
+ PPL_ASSERT(to_compute != NULL);
+
analyzer_format omega = std::max(
static_cast<analyzer_format>(pow(f_base,
static_cast<analyzer_format>(1) -
f_exponent_bias - f_mantissa_bits)),
std::numeric_limits<analyzer_format>::denorm_min());
- FP_Interval_Type result;
- result.build(i_constraint(GREATER_OR_EQUAL, -omega),
- i_constraint(LESS_OR_EQUAL, omega));
- return result;
+ to_compute->build(i_constraint(GREATER_OR_EQUAL, -omega),
+ i_constraint(LESS_OR_EQUAL, omega));
+ return *to_compute;
}
} // namespace Parma_Polyhedra_Library
More information about the PPL-devel
mailing list