public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Ondrej Kubanek <kubaneko@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc(refs/users/kubaneko/heads/histogram)] added atomic counter
Date: Thu, 16 Feb 2023 16:28:01 +0000 (GMT)	[thread overview]
Message-ID: <20230216162801.1B153385B519@sourceware.org> (raw)

https://gcc.gnu.org/g:2ec0ddcc2d8a42904b3b41e67662584e5ae7008c

commit 2ec0ddcc2d8a42904b3b41e67662584e5ae7008c
Author: kubaneko <kubanek0ondrej@gmail.com>
Date:   Tue Nov 1 14:46:59 2022 +0000

    added atomic counter

Diff:
---
 libgcc/Makefile.in        |  3 ++-
 libgcc/libgcov-profiler.c | 32 ++++++++++++++++++++++++++++++++
 libgcc/libgcov.h          |  1 +
 3 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/libgcc/Makefile.in b/libgcc/Makefile.in
index db430e0b6af..52c0c250b0c 100644
--- a/libgcc/Makefile.in
+++ b/libgcc/Makefile.in
@@ -907,7 +907,8 @@ LIBGCOV_PROFILER = _gcov_interval_profiler				\
 	_gcov_ior_profiler_atomic					\
 	_gcov_indirect_call_profiler_v4					\
 	_gcov_time_profiler							\
-	_gcov_histogram_profiler						
+	_gcov_histogram_profiler						\
+	_gcov_histogram_profiler_atomic
 LIBGCOV_INTERFACE = _gcov_dump _gcov_fork				\
 	_gcov_execl _gcov_execlp					\
 	_gcov_execle _gcov_execv _gcov_execvp _gcov_execve _gcov_reset  \
diff --git a/libgcc/libgcov-profiler.c b/libgcc/libgcov-profiler.c
index eb944158a3c..f150d75fee1 100644
--- a/libgcc/libgcov-profiler.c
+++ b/libgcc/libgcov-profiler.c
@@ -56,6 +56,38 @@ __gcov_histogram_profiler (gcov_type *counters, gcov_type value)
 
 #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
+ */
+
+void
+__gcov_histogram_profiler_atomic (gcov_type *counters, gcov_type value)
+{
+  if (value>=0 && value<8){
+    __atomic_fetch_add (&counters[value], 1, __ATOMIC_RELAXED);
+  }else{
+    gcc_assert(value>0);
+    int pow2 = 3;
+    while (1 << pow2 <= value || 1 << pow2 > 1 << (pow2 + 1)){
+      ++pow2;
+    }
+    // pow2 is first bigger power of 2
+    // we increment closer power of 2
+    if ((1<<pow2+1<<(pow2-1))>>1<value){
+      __atomic_fetch_add (&counters[6+(pow2-3)], 1, __ATOMIC_RELAXED);
+    }
+    else{
+      __atomic_fetch_add (&counters[7+(pow2-3)], 1, __ATOMIC_RELAXED);
+    }
+  }
+}
+
+#endif
+
 #ifdef L_gcov_interval_profiler
 /* If VALUE is in interval <START, START + STEPS - 1>, then increases the
    corresponding counter in COUNTERS.  If the VALUE is above or below
diff --git a/libgcc/libgcov.h b/libgcc/libgcov.h
index c01b5afe04b..b32f50ddec3 100644
--- a/libgcc/libgcov.h
+++ b/libgcc/libgcov.h
@@ -318,6 +318,7 @@ 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_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);

             reply	other threads:[~2023-02-16 16:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-16 16:28 Ondrej Kubanek [this message]
  -- strict thread matches above, loose matches on Subject: below --
2023-02-23 23:21 Ondrej Kubanek
2022-11-22 13:13 Ondrej Kubanek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230216162801.1B153385B519@sourceware.org \
    --to=kubaneko@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).