diff options
author | Martin Liska <mliska@suse.cz> | 2014-11-24 11:41:18 +0100 |
---|---|---|
committer | Martin Liska <marxin@gcc.gnu.org> | 2014-11-24 10:41:18 +0000 |
commit | fd27ffab14e3b7c131cc2e454edcd11c9cc53c2e (patch) | |
tree | fc054fc4a4670f251324a07ce04dee2b8dc12fa8 /gcc/sreal.h | |
parent | 6a569cdda92269d42ae8e2cccd8c0f07d39b5d0c (diff) | |
download | gcc-fd27ffab14e3b7c131cc2e454edcd11c9cc53c2e.zip gcc-fd27ffab14e3b7c131cc2e454edcd11c9cc53c2e.tar.gz gcc-fd27ffab14e3b7c131cc2e454edcd11c9cc53c2e.tar.bz2 |
[PATCH 1/2] Negative numbers added for sreal class.
* predict.c (propagate_freq): More elegant sreal API is used.
(estimate_bb_frequencies): Precomputed constants replaced by integer
constants.
* sreal.c (sreal::normalize): New function.
(sreal::to_int): Likewise.
(sreal::operator+): Likewise.
(sreal::operator-): Likewise.
(sreal::signedless_plus): Likewise.
(sreal::signedless_minus): Likewise.
(sreal::operator/): Negative number support is added.
* sreal.h: Definition of new functions added.
(inline sreal operator<<): New function.
(inline sreal operator>>): Likewise.
From-SVN: r218008
Diffstat (limited to 'gcc/sreal.h')
-rw-r--r-- | gcc/sreal.h | 82 |
1 files changed, 73 insertions, 9 deletions
diff --git a/gcc/sreal.h b/gcc/sreal.h index 461e28b..1362bf6 100644 --- a/gcc/sreal.h +++ b/gcc/sreal.h @@ -1,4 +1,4 @@ -/* Definitions for simple data type for positive real numbers. +/* Definitions for simple data type for real numbers. Copyright (C) 2002-2014 Free Software Foundation, Inc. This file is part of GCC. @@ -23,6 +23,8 @@ along with GCC; see the file COPYING3. If not see /* SREAL_PART_BITS has to be an even number. */ #define SREAL_PART_BITS 32 +#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_MAX_EXP (INT_MAX / 4) @@ -34,14 +36,23 @@ class sreal { public: /* Construct an uninitialized sreal. */ - sreal () : m_sig (-1), m_exp (-1) {} + sreal () : m_sig (-1), m_exp (-1), m_negative (0) {} /* Construct a sreal. */ - sreal (uint64_t sig, int exp) : m_sig (sig), m_exp (exp) { normalize (); } + sreal (int64_t sig, int exp = 0) : m_exp (exp) + { + m_negative = sig < 0; + + if (sig < 0) + sig = -sig; + + m_sig = (uint64_t) sig; + + normalize (); + } void dump (FILE *) const; int64_t to_int () const; - sreal operator+ (const sreal &other) const; sreal operator- (const sreal &other) const; sreal operator* (const sreal &other) const; @@ -49,21 +60,64 @@ public: bool operator< (const sreal &other) const { - return m_exp < other.m_exp + 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; } bool operator== (const sreal &other) const { - return m_exp == other.m_exp && m_sig == other.m_sig; + return m_exp == other.m_exp && m_sig == other.m_sig + && m_negative == other.m_negative; + } + + sreal operator- () const + { + if (m_sig == 0) + return *this; + + sreal tmp = *this; + tmp.m_negative = !tmp.m_negative; + + return tmp; + } + + sreal shift (int sig) const + { + sreal tmp = *this; + tmp.m_sig += sig; + + return tmp; + } + + /* Global minimum sreal can hold. */ + inline static sreal min () + { + static sreal min = sreal (-SREAL_MAX_SIG, SREAL_MAX_EXP); + return min; + } + + /* Global minimum sreal can hold. */ + inline static sreal max () + { + static sreal max = sreal (SREAL_MAX_SIG, SREAL_MAX_EXP); + return max; } private: void normalize (); void shift_right (int amount); - uint64_t m_sig; /* Significant. */ + 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. */ signed int m_exp; /* Exponent. */ + bool m_negative; /* Negative sign. */ }; extern void debug (sreal &ref); @@ -76,12 +130,12 @@ inline sreal &operator+= (sreal &a, const sreal &b) inline sreal &operator-= (sreal &a, const sreal &b) { -return a = a - b; + return a = a - b; } inline sreal &operator/= (sreal &a, const sreal &b) { -return a = a / b; + return a = a / b; } inline sreal &operator*= (sreal &a, const sreal &b) @@ -109,4 +163,14 @@ inline bool operator>= (const sreal &a, const sreal &b) return a == b || a > b; } +inline sreal operator<< (const sreal &a, int exp) +{ + return a.shift (exp); +} + +inline sreal operator>> (const sreal &a, int exp) +{ + return a.shift (-exp); +} + #endif |