[PPL-devel] [GIT] ppl/ppl(floating_point): Using uint16_t instead of uint32_t in float_ieee754_half.

Fabio Biselli fabio.biselli at studenti.unipr.it
Tue Oct 6 17:19:30 CEST 2009


Module: ppl/ppl
Branch: floating_point
Commit: 9c35b656767f36003e45c04094861a5f06140eb8
URL:    http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=9c35b656767f36003e45c04094861a5f06140eb8

Author: Fabio Biselli <fabio.biselli at studenti.unipr.it>
Date:   Tue Oct  6 19:15:32 2009 +0200

Using uint16_t instead of uint32_t in float_ieee754_half.
Extended float_ibm_single.

---

 src/Float.defs.hh                                  |   34 +++++++++--
 src/Float.inlines.hh                               |   59 ++++++++++++++++++++
 tests/Floating_Point_Expression/digitalfilters1.cc |    1 +
 3 files changed, 87 insertions(+), 7 deletions(-)

diff --git a/src/Float.defs.hh b/src/Float.defs.hh
index 3f65b2b..303e988 100644
--- a/src/Float.defs.hh
+++ b/src/Float.defs.hh
@@ -42,13 +42,13 @@ namespace Parma_Polyhedra_Library {
 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
 
 struct float_ieee754_half {
-  uint32_t word;
-  static const uint32_t SGN_MASK = 0x8000;
-  static const uint32_t EXP_MASK = 0xfc00;
-  static const uint32_t POS_INF = 0xfc00;
-  static const uint32_t NEG_INF = 0x7c00;
-  static const uint32_t POS_ZERO = 0x0000;
-  static const uint32_t NEG_ZERO = 0x8000;
+  uint16_t word;
+  static const uint16_t SGN_MASK = 0x8000;
+  static const uint16_t EXP_MASK = 0xfc00;
+  static const uint16_t POS_INF = 0xfc00;
+  static const uint16_t NEG_INF = 0x7c00;
+  static const uint16_t POS_ZERO = 0x0000;
+  static const uint16_t NEG_ZERO = 0x8000;
   static const unsigned int EXPONENT_BITS = 5;
   static const unsigned int MANTISSA_BITS = 10;
   static const int EXPONENT_MAX = (1 << (EXPONENT_BITS - 1)) - 1;
@@ -147,9 +147,29 @@ struct float_ieee754_double {
 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
 
 struct float_ibm_single {
+  uint32_t word;
+  static const uint32_t SGN_MASK = 0x80000000;
+  static const uint32_t EXP_MASK = 0x7f000000;
+  static const uint32_t POS_INF = 0x7f000000;
+  static const uint32_t NEG_INF = 0xff000000;
+  static const uint32_t POS_ZERO = 0x00000000;
+  static const uint32_t NEG_ZERO = 0x80000000;
   static const unsigned int EXPONENT_BITS = 7;
   static const unsigned int MANTISSA_BITS = 24;
   static const int EXPONENT_BIAS = 64;
+  static const int EXPONENT_MAX = (1 << (EXPONENT_BITS - 1)) - 1;
+  static const int EXPONENT_MIN = -EXPONENT_MAX + 1;
+  static const int EXPONENT_MIN_DENORM = EXPONENT_MIN
+					- static_cast<int>(MANTISSA_BITS);
+  int is_inf() const;
+  int is_nan() const;
+  int is_zero() const;
+  int sign_bit() const;
+  void negate();
+  void dec();
+  void inc();
+  void set_max(bool negative);
+  void build(bool negative, mpz_t mantissa, int exponent);
 };
 
 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
diff --git a/src/Float.inlines.hh b/src/Float.inlines.hh
index dcbe93f..9b01fa5 100644
--- a/src/Float.inlines.hh
+++ b/src/Float.inlines.hh
@@ -228,6 +228,65 @@ float_ieee754_double::build(bool negative, mpz_t mantissa, int exponent) {
 }
 
 inline int
+float_ibm_single::is_inf() const {
+  if (word == NEG_INF)
+    return -1;
+  if (word == POS_INF)
+    return 1;
+  return 0;
+}
+
+inline int
+float_ibm_single::is_nan() const {
+  return (word & ~SGN_MASK) > POS_INF;
+}
+
+inline int
+float_ibm_single::is_zero() const {
+  if (word == NEG_ZERO)
+    return -1;
+  if (word == POS_ZERO)
+    return 1;
+  return 0;
+}
+
+inline void
+float_ibm_single::negate() {
+  word ^= SGN_MASK;
+}
+
+inline int
+float_ibm_single::sign_bit() const {
+  return !!(word & SGN_MASK);
+}
+
+inline void
+float_ibm_single::dec() {
+  --word;
+}
+
+inline void
+float_ibm_single::inc() {
+  ++word;
+}
+
+inline void
+float_ibm_single::set_max(bool negative) {
+  word = 0x7f000000;
+  if (negative)
+    word |= SGN_MASK;
+}
+
+inline void
+float_ibm_single::build(bool negative, mpz_t mantissa, int exponent) {
+  word = mpz_get_ui(mantissa) & ((1UL << MANTISSA_BITS) - 1);
+  if (negative)
+    word |= SGN_MASK;
+  word |= static_cast<uint32_t>(exponent + EXPONENT_BIAS) << MANTISSA_BITS;
+}
+
+  ///asasdasda
+inline int
 float_intel_double_extended::is_inf() const {
   if (lsp != LSP_INF)
     return 0;
diff --git a/tests/Floating_Point_Expression/digitalfilters1.cc b/tests/Floating_Point_Expression/digitalfilters1.cc
index acc28e6..7d2a2f1 100644
--- a/tests/Floating_Point_Expression/digitalfilters1.cc
+++ b/tests/Floating_Point_Expression/digitalfilters1.cc
@@ -86,6 +86,7 @@ test01() {
     abstract_store.affine_image(R, X - S);
     abstract_store.affine_image(Y, X);
 
+
     // if (R <= -D) Y = S - D;
     FP_Interval_Abstract_Store as_then(abstract_store);
     as_then.refine_with_constraint(R <= -D);




More information about the PPL-devel mailing list