public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/sphinx] libstdc++: Minor codegen improvement for atomic wait spinloop
@ 2022-07-28 12:10 Martin Liska
  0 siblings, 0 replies; only message in thread
From: Martin Liska @ 2022-07-28 12:10 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

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

commit f0b75c239b45d7c48b6b9d76a3efa048ae10118b
Author: Thomas Rodgers <trodgers@redhat.com>
Date:   Tue Jul 5 17:42:42 2022 -0700

    libstdc++: Minor codegen improvement for atomic wait spinloop
    
    This patch merges the spin loops in the atomic wait implementation which is a
    minor codegen improvement.
    
    libstdc++-v3/ChangeLog:
            * include/bits/atomic_wait.h (__atomic_spin): Merge spin loops.

Diff:
---
 libstdc++-v3/include/bits/atomic_wait.h | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/libstdc++-v3/include/bits/atomic_wait.h b/libstdc++-v3/include/bits/atomic_wait.h
index 125b1cad886..a6d55d3af8a 100644
--- a/libstdc++-v3/include/bits/atomic_wait.h
+++ b/libstdc++-v3/include/bits/atomic_wait.h
@@ -142,8 +142,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif
     }
 
-    constexpr auto __atomic_spin_count_1 = 12;
-    constexpr auto __atomic_spin_count_2 = 4;
+    constexpr auto __atomic_spin_count_relax = 12;
+    constexpr auto __atomic_spin_count = 16;
 
     struct __default_spin_policy
     {
@@ -157,18 +157,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       bool
       __atomic_spin(_Pred& __pred, _Spin __spin = _Spin{ }) noexcept
       {
-	for (auto __i = 0; __i < __atomic_spin_count_1; ++__i)
+	for (auto __i = 0; __i < __atomic_spin_count; ++__i)
 	  {
 	    if (__pred())
 	      return true;
-	    __detail::__thread_relax();
-	  }
 
-	for (auto __i = 0; __i < __atomic_spin_count_2; ++__i)
-	  {
-	    if (__pred())
-	      return true;
-	    __detail::__thread_yield();
+	    if (__i < __atomic_spin_count_relax)
+	      __detail::__thread_relax();
+	    else
+	      __detail::__thread_yield();
 	  }
 
 	while (__spin())


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

only message in thread, other threads:[~2022-07-28 12:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-28 12:10 [gcc/devel/sphinx] libstdc++: Minor codegen improvement for atomic wait spinloop Martin Liska

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).