public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/kubaneko/heads/histogram)] Added histogram params to libgcov
@ 2023-02-26 19:17 Ondrej Kubanek
  0 siblings, 0 replies; only message in thread
From: Ondrej Kubanek @ 2023-02-26 19:17 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:b2ac41c1390c4bf9da1b800d28d33ddf8aca1a61

commit b2ac41c1390c4bf9da1b800d28d33ddf8aca1a61
Author: kubaneko <kubanek0ondrej@gmail.com>
Date:   Sun Feb 26 19:17:42 2023 +0000

    Added histogram params to libgcov

Diff:
---
 gcc/tree-profile.cc       |   2 +-
 libgcc/libgcov-profiler.c | 147 ++++++++++++++++++++++++++++------------------
 libgcc/libgcov.h          |   4 +-
 3 files changed, 92 insertions(+), 61 deletions(-)

diff --git a/gcc/tree-profile.cc b/gcc/tree-profile.cc
index d38ad80ba0f..55289dc765e 100644
--- a/gcc/tree-profile.cc
+++ b/gcc/tree-profile.cc
@@ -365,7 +365,7 @@ gimple_gen_histogram_profiler (histogram_value value, unsigned tag) // , edge_de
   gcc_assert(lp);
   tree ref_ptr = tree_coverage_counter_addr (tag, 0);
   tree hist_size = build_int_cst_type (gcov_type_node,
-				   param_profile_histogram_size_lin + (gcov_type(param_profile_histogram_size)<<32));
+				   param_profile_histogram_size_lin | (gcov_type(param_profile_histogram_size)<<32));
   gcall *call;
   auto_vec<edge> exits = get_loop_exit_edges (lp);
   for ( auto exit : exits ){
diff --git a/libgcc/libgcov-profiler.c b/libgcc/libgcov-profiler.c
index 739a30043c0..9625778d2c7 100644
--- a/libgcc/libgcov-profiler.c
+++ b/libgcc/libgcov-profiler.c
@@ -26,7 +26,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #include "libgcov.h"
 #if !defined(inhibit_libc)
 
-#ifdef L_gcov_histogram_profiler
+#ifndef floor_log2
+
 /*
  * If value is less then 8 we increment corresponding counter
  * otherwise we take its logarithm and increment corresponding counter
@@ -34,90 +35,120 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 /* For convenience, define 0 -> word_size.  */
 static inline int
-clz_hwi (gcov_type x)
+clz_hwi (gcov_type_unsigned x)
 {
   if (x == 0)
-    return 64;
-# if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
-  return __builtin_clzl (x);
-# elif HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONGLONG
-  return __builtin_clzll (x);
-# else
-  return __builtin_clz (x);
-# endif
+    return sizeof(gcov_type_unsigned)*8;
+  if (sizeof(gcov_type_unsigned)==sizeof(long))
+    return __builtin_clzl (x);
+  if (sizeof(gcov_type_unsigned)==sizeof(long long))
+    return __builtin_clzll (x);
+  else
+    return __builtin_clz (x);
 }
 
-static inline int
-floor_log2 (gcov_type x)
+static inline gcov_type_unsigned
+floor_log2 (gcov_type_unsigned x)
 {
-  return 63 - clz_hwi (x);
+  return sizeof(gcov_type_unsigned)*8 - clz_hwi (x)-1;
 }
 
+#endif
+
+#ifdef L_gcov_histogram_profiler
+/*
+ * If value is less then 8 we increment corresponding counter
+ * otherwise we take its logarithm and increment corresponding counter
+ */
+
 void
-__gcov_histogram_profiler (gcov_type *counters, gcov_type value)
+__gcov_histogram_profiler (gcov_type *counters, gcov_type value, gcov_type hist_sizes)
 {
-  if (value>=0 && value<8){
+  fprintf (stderr, "profiling:Skip\n");
+  assert(hist_sizes>=0 && value>=0);
+  gcov_type_unsigned hist_size=hist_sizes;
+  gcov_type_unsigned u_value=value;
+  gcov_type_unsigned tot_size=hist_size>>32;
+  gcov_type_unsigned lin_size=hist_size & ((((gcov_type_unsigned)1)<<32)-1);
+  if (u_value<lin_size){
     counters[value]++;
   }else{
-    gcc_assert(value>0);
-    int pow2=floor_log2(value);
-    counters[pow2+5]++;
+    gcov_type_unsigned pow2=floor_log2(u_value);
+    gcov_type_unsigned lin_pow2=floor_log2(lin_size-1);
+    if ((lin_pow2-lin_size)+tot_size>pow2){
+        counters[pow2+(lin_size-lin_pow2)-1]++;
+    } else {
+        counters[tot_size-1]++;
+    }
   }
 }
 
-//  if (value>=0 && value<param_profile_histogram_size_lin){
-//    counters[value]++;
-//  }else{
-//    gcc_assert(value>0);
-//    int pow2=floor_log2(value);
-//    counters[pow2+(param_profile_histogram_size_lin-floor_log2
-//            (param_profile_histogram_size_lin))]++;
-//  }
+
 
 #endif
 
 
 #if defined(L_gcov_histogram_profiler_atomic) && GCOV_SUPPORTS_ATOMIC
 
-/*
- * If value is less then 8 we increment corresponding counter
- * otherwise we take its logarithm and increment corresponding counter
- */
-
-/* For convenience, define 0 -> word_size.  */
-static inline int
-clz_hwi2 (gcov_type x)
-{
-  if (x == 0)
-    return 64;
-# if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
-  return __builtin_clzl (x);
-# elif HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONGLONG
-  return __builtin_clzll (x);
-# else
-  return __builtin_clz (x);
-# endif
-}
-
-static inline int
-floor_log2_2 (gcov_type x)
-{
-  return 63 - clz_hwi2 (x);
-}
-
-
 void
-__gcov_histogram_profiler_atomic (gcov_type *counters, gcov_type value)
+__gcov_histogram_profiler_atomic (gcov_type *counters, gcov_type value, gcov_type hist_sizes)
 {
-  if (value>=0 && value<8){
+  fprintf (stderr, "profiling:Skip\n");
+  assert(hist_sizes>=0 && value>=0);
+  gcov_type_unsigned hist_size=hist_sizes;
+  gcov_type_unsigned u_value=value;
+  gcov_type_unsigned tot_size=hist_size>>32;
+  gcov_type_unsigned lin_size=hist_size & ((((gcov_type_unsigned)1)<<32)-1);
+  if (u_value<lin_size){
     __atomic_fetch_add (&counters[value], 1, __ATOMIC_RELAXED);
   }else{
-    gcc_assert(value>0);
-    int pow2=floor_log2_2(value);
-    __atomic_fetch_add (&counters[pow2+5], 1, __ATOMIC_RELAXED);
+    gcov_type_unsigned pow2=floor_log2(u_value);
+    gcov_type_unsigned lin_pow2=floor_log2(lin_size-1);
+    if ((lin_pow2-lin_size)+tot_size>pow2){
+        __atomic_fetch_add (&counters[pow2+(lin_size-lin_pow2)-1], 1, __ATOMIC_RELAXED);
+    } else {
+        __atomic_fetch_add (&counters[tot_size-1], 1, __ATOMIC_RELAXED);
+    }
   }
 }
 
+
+
+
+// /* For convenience, define 0 -> word_size.  */
+// static inline int
+// clz_hwi2 (gcov_type x)
+// {
+//   if (x == 0)
+//     return 64;
+// # if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
+//   return __builtin_clzl (x);
+// # elif HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONGLONG
+//   return __builtin_clzll (x);
+// # else
+//   return __builtin_clz (x);
+// # endif
+// }
+// 
+// static inline int
+// floor_log2_2 (gcov_type x)
+// {
+//   return 63 - clz_hwi2 (x);
+// }
+// 
+// 
+// void
+// __gcov_histogram_profiler_atomic (gcov_type *counters, gcov_type value, gcov_type hist_sizes)
+// {
+//   if (value>=0 && value<8){
+//     __atomic_fetch_add (&counters[value], 1, __ATOMIC_RELAXED);
+//   }else{
+//     gcc_assert(value>0);
+//     int pow2=floor_log2_2(value);
+//     __atomic_fetch_add (&counters[pow2+5], 1, __ATOMIC_RELAXED);
+//   }
+// }
+
 #endif
 
 #ifdef L_gcov_interval_profiler
diff --git a/libgcc/libgcov.h b/libgcc/libgcov.h
index cd2f48c4d6d..fa0a95102b0 100644
--- a/libgcc/libgcov.h
+++ b/libgcc/libgcov.h
@@ -317,8 +317,8 @@ extern void __gcov_merge_ior (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
 extern void __gcov_interval_profiler (gcov_type *, gcov_type, int, unsigned);
 extern void __gcov_interval_profiler_atomic (gcov_type *, gcov_type, int,
 					     unsigned);
-extern void __gcov_histogram_profiler (gcov_type *, gcov_type);
-extern void __gcov_histogram_profiler_atomic (gcov_type *, gcov_type);
+extern void __gcov_histogram_profiler (gcov_type *, gcov_type, gcov_type);
+extern void __gcov_histogram_profiler_atomic (gcov_type *, gcov_type, gcov_type);
 extern void __gcov_pow2_profiler (gcov_type *, gcov_type);
 extern void __gcov_pow2_profiler_atomic (gcov_type *, gcov_type);
 extern void __gcov_topn_values_profiler (gcov_type *, gcov_type);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-26 19:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-26 19:17 [gcc(refs/users/kubaneko/heads/histogram)] Added histogram params to libgcov Ondrej Kubanek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).