From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2062) id AB5913858412; Tue, 26 Jul 2022 22:41:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AB5913858412 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Thomas Rodgers To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r11-10177] libstdc++: Minor codegen improvement for atomic wait spinloop X-Act-Checkin: gcc X-Git-Author: Thomas Rodgers X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 2916e857c2941b57cbecf42ee8d5b9ab9d0c8b7d X-Git-Newrev: bd7d57b72d0a18a708e0e5cf32d3381add8ae788 Message-Id: <20220726224108.AB5913858412@sourceware.org> Date: Tue, 26 Jul 2022 22:41:08 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Jul 2022 22:41:08 -0000 https://gcc.gnu.org/g:bd7d57b72d0a18a708e0e5cf32d3381add8ae788 commit r11-10177-gbd7d57b72d0a18a708e0e5cf32d3381add8ae788 Author: Thomas Rodgers 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. (cherry picked from commit e75da2ace6b6f634237259ef62cfb2d3d34adb10) 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 394f666d02e..571a0dd08ef 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())