diff options
author | Trevor Saunders <tsaunders@mozilla.com> | 2014-11-11 02:31:00 +0000 |
---|---|---|
committer | Trevor Saunders <tbsaunde@gcc.gnu.org> | 2014-11-11 02:31:00 +0000 |
commit | 618b7f293745ac92cc4fef113239e84f79c4d4ff (patch) | |
tree | 45432b15918ada70945d621144d6decabaa36832 /gcc/sreal.h | |
parent | 43722f9fa69d4cc9a369b468552d5612674a576f (diff) | |
download | gcc-618b7f293745ac92cc4fef113239e84f79c4d4ff.tar.gz |
c++ify sreal
gcc/ChangeLog:
2014-11-10 Trevor Saunders <tsaunders@mozilla.com>
* ipa-inline.c (edge_badness): Adjust.
(inline_small_functions): Likewise.
* predict.c (propagate_freq): Likewise.
(estimate_bb_frequencies): Likewise.
* sreal.c (sreal::dump): Rename from dump_sreal.
(debug): Adjust.
(copy): Remove function.
(sreal::shift_right): Rename from sreal_sift_right.
(sreal::normalize): Rename from normalize.
(sreal_init): Remove function.
(sreal::to_int): Rename from sreal_to_int.
(sreal_compare): Remove function.
(sreal::operator+): Rename from sreal_add.
(sreal::operator-): Rename from sreal_sub.
(sreal::operator*): Rename from sreal_mul.
(sreal::operator/): Rename from sreal_div.
* sreal.h (class sreal): Adjust.
(inline sreal &operator+=): New operator.
(inline sreal &operator-=): Likewise.
(inline sreal &operator/=): Likewise.
(inline sreal &operator*=): Likewise.
(inline bool operator!=): Likewise.
(inline bool operator>): Likewise.
(inline bool operator<=): Likewise.
(inline bool operator>=): Likewise.
From-SVN: r217332
Diffstat (limited to 'gcc/sreal.h')
-rw-r--r-- | gcc/sreal.h | 106 |
1 files changed, 76 insertions, 30 deletions
diff --git a/gcc/sreal.h b/gcc/sreal.h index 08d577aa218..461e28b3d26 100644 --- a/gcc/sreal.h +++ b/gcc/sreal.h @@ -21,46 +21,92 @@ along with GCC; see the file COPYING3. If not see #define GCC_SREAL_H /* SREAL_PART_BITS has to be an even number. */ -#if (HOST_BITS_PER_WIDE_INT / 2) % 2 == 1 -#define SREAL_PART_BITS (HOST_BITS_PER_WIDE_INT / 2 - 1) -#else -#define SREAL_PART_BITS (HOST_BITS_PER_WIDE_INT / 2) -#endif - -#define uhwi unsigned HOST_WIDE_INT -#define MAX_HOST_WIDE_INT (((uhwi) 1 << (HOST_BITS_PER_WIDE_INT - 1)) - 1) +#define SREAL_PART_BITS 32 -#define SREAL_MIN_SIG ((uhwi) 1 << (SREAL_PART_BITS - 1)) -#define SREAL_MAX_SIG (((uhwi) 1 << SREAL_PART_BITS) - 1) +#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) -#if SREAL_PART_BITS < 32 -#define SREAL_BITS (SREAL_PART_BITS * 2) -#else #define SREAL_BITS SREAL_PART_BITS -#endif /* Structure for holding a simple real number. */ -struct sreal +class sreal { -#if SREAL_PART_BITS < 32 - unsigned HOST_WIDE_INT sig_lo; /* Significant (lower part). */ - unsigned HOST_WIDE_INT sig_hi; /* Significant (higher part). */ -#else - unsigned HOST_WIDE_INT sig; /* Significant. */ -#endif - signed int exp; /* Exponent. */ +public: + /* Construct an uninitialized sreal. */ + sreal () : m_sig (-1), m_exp (-1) {} + + /* Construct a sreal. */ + sreal (uint64_t sig, int exp) : m_sig (sig), m_exp (exp) { 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; + sreal operator/ (const sreal &other) const; + + bool operator< (const sreal &other) const + { + return m_exp < other.m_exp + || (m_exp == other.m_exp && m_sig < other.m_sig); + } + + bool operator== (const sreal &other) const + { + return m_exp == other.m_exp && m_sig == other.m_sig; + } + +private: + void normalize (); + void shift_right (int amount); + + uint64_t m_sig; /* Significant. */ + signed int m_exp; /* Exponent. */ }; -extern void dump_sreal (FILE *, sreal *); extern void debug (sreal &ref); extern void debug (sreal *ptr); -extern sreal *sreal_init (sreal *, unsigned HOST_WIDE_INT, signed int); -extern HOST_WIDE_INT sreal_to_int (sreal *); -extern int sreal_compare (sreal *, sreal *); -extern sreal *sreal_add (sreal *, sreal *, sreal *); -extern sreal *sreal_sub (sreal *, sreal *, sreal *); -extern sreal *sreal_mul (sreal *, sreal *, sreal *); -extern sreal *sreal_div (sreal *, sreal *, sreal *); + +inline sreal &operator+= (sreal &a, const sreal &b) +{ + return a = a + b; +} + +inline sreal &operator-= (sreal &a, const sreal &b) +{ +return a = a - b; +} + +inline sreal &operator/= (sreal &a, const sreal &b) +{ +return a = a / b; +} + +inline sreal &operator*= (sreal &a, const sreal &b) +{ + return a = a * b; +} + +inline bool operator!= (const sreal &a, const sreal &b) +{ + return !(a == b); +} + +inline bool operator> (const sreal &a, const sreal &b) +{ + return !(a == b || a < b); +} + +inline bool operator<= (const sreal &a, const sreal &b) +{ + return a < b || a == b; +} + +inline bool operator>= (const sreal &a, const sreal &b) +{ + return a == b || a > b; +} #endif |