diff options
author | Jan Hubicka <hubicka@ucw.cz> | 2017-10-11 19:37:18 +0200 |
---|---|---|
committer | Jan Hubicka <hubicka@gcc.gnu.org> | 2017-10-11 17:37:18 +0000 |
commit | 9588ea78db1d58ab5eb4fccc93e8ef535ce48c66 (patch) | |
tree | e4dda70458567bbf0385750dbbf8f7196369a8d0 /gcc/profile-count.c | |
parent | 278a84349ae1e964dea6bd3bc456e11eb712c9b4 (diff) | |
download | gcc-9588ea78db1d58ab5eb4fccc93e8ef535ce48c66.zip gcc-9588ea78db1d58ab5eb4fccc93e8ef535ce48c66.tar.gz gcc-9588ea78db1d58ab5eb4fccc93e8ef535ce48c66.tar.bz2 |
profile-count.h (slow_safe_scale_64bit): New function.
* profile-count.h (slow_safe_scale_64bit): New function.
(safe_scale_64bit): New inline.
(profile_count::max_safe_multiplier): Remove; use safe_scale_64bit.
* profile-count.c: Include wide-int.h
(slow_safe_scale_64bit): New.
From-SVN: r253652
Diffstat (limited to 'gcc/profile-count.c')
-rw-r--r-- | gcc/profile-count.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/gcc/profile-count.c b/gcc/profile-count.c index 4d22428..02c9ec2 100644 --- a/gcc/profile-count.c +++ b/gcc/profile-count.c @@ -30,6 +30,7 @@ along with GCC; see the file COPYING3. If not see #include "gimple.h" #include "data-streamer.h" #include "cgraph.h" +#include "wide-int.h" /* Dump THIS to F. */ @@ -194,3 +195,21 @@ profile_probability::stream_out (struct lto_output_stream *ob) streamer_write_uhwi_stream (ob, m_val); streamer_write_uhwi_stream (ob, m_quality); } + +/* Compute RES=(a*b + c/2)/c capping and return false if overflow happened. */ + +bool +slow_safe_scale_64bit (uint64_t a, uint64_t b, uint64_t c, uint64_t *res) +{ + FIXED_WIDE_INT (128) tmp = a; + bool overflow; + tmp = wi::udiv_floor (wi::umul (tmp, b, &overflow) + (c / 2), c); + gcc_checking_assert (!overflow); + if (wi::fits_uhwi_p (tmp)) + { + *res = tmp.to_uhwi (); + return true; + } + *res = (uint64_t) -1; + return false; +} |