summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortejohnson <tejohnson@138bc75d-0d04-0410-961f-82ee72b054a4>2012-12-20 14:31:09 +0000
committertejohnson <tejohnson@138bc75d-0d04-0410-961f-82ee72b054a4>2012-12-20 14:31:09 +0000
commit960a9b56d6ddfdfa9f6ec747b263e8a6dec80bcd (patch)
treee5a6383c98a0438b7479e18dbadac925bec0cc5a
parent91adfb467d1ca86a9b1a9ef6856b27f6f2f8b1ec (diff)
downloadppe42-gcc-960a9b56d6ddfdfa9f6ec747b263e8a6dec80bcd.tar.gz
ppe42-gcc-960a9b56d6ddfdfa9f6ec747b263e8a6dec80bcd.zip
Fix PR gcov-profile/55734 by using methods from hwint.c instead of
builtins, to handle non-GCC and older versions of GCC. When building libgcov.a, however, hwint.c is not available, but we are always using the bootstrapped compiler and can therefore use the builtins. Use __builtin_popcount instead of __builtin_popcountll, since we are operating on an int. Use floor_log2 directly, instead of clz_hwi for the non-libgcov case, and handle situations where the size of the gcov_type is bigger than HOST_WIDE_INT. Verified that the various cases compiled by forcing different HOST_BITS_PER_WIDE_INT values. 2012-12-20 Teresa Johnson <tejohnson@google.com> Jakub Jelinek <jakub@redhat.com> PR gcov-profile/55734 * gcov-io.c (gcov_read_summary): Use __builtin_popcount instead of __builtin_popcountll when building libgcov.a, otherwise use popcount_hwi. (gcov_histo_index): When not building libgcov.a, use floor_log2 instead of __builtin_clzll. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@194634 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog10
-rw-r--r--gcc/gcov-io.c36
2 files changed, 44 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 01ed19b1825..ca9844f4b44 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,13 @@
+2012-12-20 Teresa Johnson <tejohnson@google.com>
+ Jakub Jelinek <jakub@redhat.com>
+
+ PR gcov-profile/55734
+ * gcov-io.c (gcov_read_summary): Use __builtin_popcount instead
+ of __builtin_popcountll when building libgcov.a, otherwise use
+ popcount_hwi.
+ (gcov_histo_index): When not building libgcov.a, use floor_log2
+ instead of __builtin_clzll.
+
2012-12-20 Richard Biener <rguenther@suse.de>
PR middle-end/55740
diff --git a/gcc/gcov-io.c b/gcc/gcov-io.c
index f45c32cc1e5..f4cb0acc1a7 100644
--- a/gcc/gcov-io.c
+++ b/gcc/gcov-io.c
@@ -538,7 +538,15 @@ gcov_read_summary (struct gcov_summary *summary)
for (bv_ix = 0; bv_ix < GCOV_HISTOGRAM_BITVECTOR_SIZE; bv_ix++)
{
histo_bitvector[bv_ix] = gcov_read_unsigned ();
- h_cnt += __builtin_popcountll (histo_bitvector[bv_ix]);
+#if IN_LIBGCOV
+ /* When building libgcov we don't include system.h, which includes
+ hwint.h (where popcount_hwi is declared). However, libgcov.a
+ is built by the bootstrapped compiler and therefore the builtins
+ are always available. */
+ h_cnt += __builtin_popcount (histo_bitvector[bv_ix]);
+#else
+ h_cnt += popcount_hwi (histo_bitvector[bv_ix]);
+#endif
}
bv_ix = 0;
h_ix = 0;
@@ -642,7 +650,31 @@ gcov_histo_index (gcov_type value)
/* Find the place of the most-significant bit set. */
if (v > 0)
- r = 63 - __builtin_clzll (v);
+ {
+#if IN_LIBGCOV
+ /* When building libgcov we don't include system.h, which includes
+ hwint.h (where floor_log2 is declared). However, libgcov.a
+ is built by the bootstrapped compiler and therefore the builtins
+ are always available. */
+ r = sizeof (long long) * __CHAR_BIT__ - 1 - __builtin_clzll (v);
+#else
+ /* We use floor_log2 from hwint.c, which takes a HOST_WIDE_INT
+ that is either 32 or 64 bits, and gcov_type_unsigned may be 64 bits.
+ Need to check for the case where gcov_type_unsigned is 64 bits
+ and HOST_WIDE_INT is 32 bits and handle it specially. */
+#if HOST_BITS_PER_WIDEST_INT == HOST_BITS_PER_WIDE_INT
+ r = floor_log2 (v);
+#elif HOST_BITS_PER_WIDEST_INT == 2 * HOST_BITS_PER_WIDE_INT
+ HOST_WIDE_INT hwi_v = v >> HOST_BITS_PER_WIDE_INT;
+ if (hwi_v)
+ r = floor_log2 (hwi_v) + HOST_BITS_PER_WIDE_INT;
+ else
+ r = floor_log2 ((HOST_WIDE_INT)v);
+#else
+ gcc_unreachable ();
+#endif
+#endif
+ }
/* If at most the 2 least significant bits are set (value is
0 - 3) then that value is our index into the lowest set of
OpenPOWER on IntegriCloud