aboutsummaryrefslogtreecommitdiff
path: root/gcc/sreal.h
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2014-12-10 15:10:21 +0100
committerMartin Liska <marxin@gcc.gnu.org>2014-12-10 14:10:21 +0000
commitd1704358924217b920bb60e0197282154fa02a4b (patch)
treeffe4ab982c92ed3a2f7657504310fbfd73c09665 /gcc/sreal.h
parent42c0b54df5517af870ae4f50c32886ac77af2046 (diff)
downloadgcc-d1704358924217b920bb60e0197282154fa02a4b.zip
gcc-d1704358924217b920bb60e0197282154fa02a4b.tar.gz
gcc-d1704358924217b920bb60e0197282154fa02a4b.tar.bz2
New sreal implementation which uses int64_t as m_sig.
* sreal.c (sreal::shift_right): New implementation for int64_t as m_sig. (sreal::normalize): Likewise. (sreal::to_int): Likewise. (sreal::operator+): Likewise. (sreal::operator-): Likewise. (sreal::operator*): Likewise. (sreal::operator/): Likewise. (sreal::signedless_minus): Removed. (sreal::signedless_plus): Removed. (sreal::debug): const keyword is added. * sreal.h (sreal::operator<): New implementation for int64_t as m_sig. * ipa-inline.c (recursive_inlining): LONG_MIN is replaced with sreal::min (). From-SVN: r218579
Diffstat (limited to 'gcc/sreal.h')
-rw-r--r--gcc/sreal.h56
1 files changed, 22 insertions, 34 deletions
diff --git a/gcc/sreal.h b/gcc/sreal.h
index 3938c6e..730f49c 100644
--- a/gcc/sreal.h
+++ b/gcc/sreal.h
@@ -25,8 +25,8 @@ along with GCC; see the file COPYING3. If not see
#define UINT64_BITS 64
-#define SREAL_MIN_SIG ((uint64_t) 1 << (SREAL_PART_BITS - 1))
-#define SREAL_MAX_SIG (((uint64_t) 1 << SREAL_PART_BITS) - 1)
+#define SREAL_MIN_SIG ((int64_t) 1 << (SREAL_PART_BITS - 2))
+#define SREAL_MAX_SIG (((int64_t) 1 << (SREAL_PART_BITS - 1)) - 1)
#define SREAL_MAX_EXP (INT_MAX / 4)
#define SREAL_BITS SREAL_PART_BITS
@@ -36,18 +36,11 @@ class sreal
{
public:
/* Construct an uninitialized sreal. */
- sreal () : m_sig (-1), m_exp (-1), m_negative (0) {}
+ sreal () : m_sig (-1), m_exp (-1) {}
/* Construct a sreal. */
- sreal (int64_t sig, int exp = 0) : m_exp (exp)
+ sreal (int64_t sig, int exp = 0) : m_sig (sig), m_exp (exp)
{
- m_negative = sig < 0;
-
- if (sig < 0)
- sig = -sig;
-
- m_sig = (uint64_t) sig;
-
normalize ();
}
@@ -60,33 +53,30 @@ public:
bool operator< (const sreal &other) const
{
- /* We negate result in case of negative numbers and
- it would return true for equal negative numbers. */
- if (*this == other)
- return false;
-
- if (m_negative != other.m_negative)
- return m_negative > other.m_negative;
-
- bool r = m_exp < other.m_exp
- || (m_exp == other.m_exp && m_sig < other.m_sig);
-
- return m_negative ? !r : r;
+ if (m_exp == other.m_exp)
+ return m_sig < other.m_sig;
+ else
+ {
+ bool negative = m_sig < 0;
+ bool other_negative = other.m_sig < 0;
+
+ if (negative != other_negative)
+ return negative > other_negative;
+
+ bool r = m_exp < other.m_exp;
+ return negative ? !r : r;
+ }
}
bool operator== (const sreal &other) const
{
- return m_exp == other.m_exp && m_sig == other.m_sig
- && m_negative == other.m_negative;
+ return m_exp == other.m_exp && m_sig == other.m_sig;
}
sreal operator- () const
{
- if (m_sig == 0)
- return *this;
-
sreal tmp = *this;
- tmp.m_negative = !tmp.m_negative;
+ tmp.m_sig *= -1;
return tmp;
}
@@ -125,17 +115,15 @@ public:
private:
void normalize ();
void shift_right (int amount);
-
static sreal signedless_plus (const sreal &a, const sreal &b, bool negative);
static sreal signedless_minus (const sreal &a, const sreal &b, bool negative);
- uint64_t m_sig; /* Significant. */
+ int64_t m_sig; /* Significant. */
signed int m_exp; /* Exponent. */
- bool m_negative; /* Negative sign. */
};
-extern void debug (sreal &ref);
-extern void debug (sreal *ptr);
+extern void debug (const sreal &ref);
+extern void debug (const sreal *ptr);
inline sreal &operator+= (sreal &a, const sreal &b)
{