From a5f4d3d6a1379ad4a806e65b2fc7ac86bbaf72ae Mon Sep 17 00:00:00 2001 From: Jan Hubicka Date: Thu, 30 Aug 2018 14:58:42 +0200 Subject: [PATCH] sreal.h (SREAL_PART_BITS): Change to 31; remove seemingly unnecessary comment that it has to be even number. * 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 | 9 +++++++++ gcc/sreal.c | 16 ++++++++-------- gcc/sreal.h | 5 ++--- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e7a1910ee6f..86c96a9bf70 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2018-08-29 Jan Hubicka + + * 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 PR tree-optimization/87147 diff --git a/gcc/sreal.c b/gcc/sreal.c index 925b06501e1..e17d93afb6a 100644 --- a/gcc/sreal.c +++ b/gcc/sreal.c @@ -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); diff --git a/gcc/sreal.h b/gcc/sreal.h index 6f841cf3a58..e2ad1a38e3e 100644 --- a/gcc/sreal.h +++ b/gcc/sreal.h @@ -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. */ }; -- 2.30.2