sreal.h (SREAL_PART_BITS): Change to 31; remove seemingly unnecessary comment that...
authorJan Hubicka <jh@suse.cz>
Thu, 30 Aug 2018 12:58:42 +0000 (14:58 +0200)
committerJan Hubicka <hubicka@gcc.gnu.org>
Thu, 30 Aug 2018 12:58:42 +0000 (12:58 +0000)
* sreal.h (SREAL_PART_BITS): Change to 31; remove seemingly unnecessary
comment that it has to be even number.
(class sreal): Change m_sig type to int32_t.
* sreal.c (sreal::dump, sreal::to_int, opreator+, operator-): Use
int64_t for temporary calculations.
(sreal_verify_basics): Drop one bit from minimum and maximum.

From-SVN: r263981

gcc/ChangeLog
gcc/sreal.c
gcc/sreal.h

index e7a1910..86c96a9 100644 (file)
@@ -1,3 +1,12 @@
+2018-08-29  Jan Hubicka  <jh@suse.cz>
+
+       * sreal.h (SREAL_PART_BITS): Change to 31; remove seemingly unnecessary
+       comment that it has to be even number.
+       (class sreal): Change m_sig type to int32_t.
+       * sreal.c (sreal::dump, sreal::to_int, opreator+, operator-): Use
+       int64_t for temporary calculations.
+       (sreal_verify_basics): Drop one bit from minimum and maximum.
+
 2018-08-30  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/87147
index 925b065..e17d93a 100644 (file)
@@ -64,7 +64,7 @@ along with GCC; see the file COPYING3.  If not see
 void
 sreal::dump (FILE *file) const
 {
-  fprintf (file, "(%" PRIi64 " * 2^%d)", m_sig, m_exp);
+  fprintf (file, "(%" PRIi64 " * 2^%d)", (int64_t)m_sig, m_exp);
 }
 
 DEBUG_FUNCTION void
@@ -114,7 +114,7 @@ sreal::to_int () const
   if (m_exp >= SREAL_PART_BITS)
     return sign * INTTYPE_MAXIMUM (int64_t);
   if (m_exp > 0)
-    return sign * (SREAL_ABS (m_sig) << m_exp);
+    return sign * (SREAL_ABS ((int64_t)m_sig) << m_exp);
   if (m_exp < 0)
     return m_sig >> -m_exp;
   return m_sig;
@@ -167,7 +167,7 @@ sreal::operator+ (const sreal &other) const
       bb = &tmp;
     }
 
-  r_sig = a_p->m_sig + bb->m_sig;
+  r_sig = a_p->m_sig + (int64_t)bb->m_sig;
   sreal r (r_sig, r_exp);
   return r;
 }
@@ -211,7 +211,7 @@ sreal::operator- (const sreal &other) const
       bb = &tmp;
     }
 
-  r_sig = sign * ((int64_t) a_p->m_sig - bb->m_sig);
+  r_sig = sign * ((int64_t) a_p->m_sig - (int64_t)bb->m_sig);
   sreal r (r_sig, r_exp);
   return r;
 }
@@ -277,15 +277,15 @@ namespace selftest {
 static void
 sreal_verify_basics (void)
 {
-  sreal minimum = INT_MIN;
-  sreal maximum = INT_MAX;
+  sreal minimum = INT_MIN/2;
+  sreal maximum = INT_MAX/2;
 
   sreal seven = 7;
   sreal minus_two = -2;
   sreal minus_nine = -9;
 
-  ASSERT_EQ (INT_MIN, minimum.to_int ());
-  ASSERT_EQ (INT_MAX, maximum.to_int ());
+  ASSERT_EQ (INT_MIN/2, minimum.to_int ());
+  ASSERT_EQ (INT_MAX/2, maximum.to_int ());
 
   ASSERT_FALSE (minus_two < minus_two);
   ASSERT_FALSE (seven < seven);
index 6f841cf..e2ad1a3 100644 (file)
@@ -20,8 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 #ifndef GCC_SREAL_H
 #define GCC_SREAL_H
 
-/* SREAL_PART_BITS has to be an even number.  */
-#define SREAL_PART_BITS 32
+#define SREAL_PART_BITS 31
 
 #define UINT64_BITS    64
 
@@ -137,7 +136,7 @@ private:
   static sreal signedless_plus (const sreal &a, const sreal &b, bool negative);
   static sreal signedless_minus (const sreal &a, const sreal &b, bool negative);
 
-  int64_t m_sig;                       /* Significant.  */
+  int32_t m_sig;                       /* Significant.  */
   signed int m_exp;                    /* Exponent.  */
 };