From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by sourceware.org (Postfix) with ESMTPS id 60AD03857832; Fri, 26 Feb 2021 16:00:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 60AD03857832 IronPort-SDR: k5XvfZmpNuBPc9VAnyvWiaSp1uoLIPP9Y6us7ALRrYMcpYgCri0mRTECpuR4QnWqsfZ6jhlMR3 eysgwX6Q80QQ== X-IronPort-AV: E=McAfee;i="6000,8403,9907"; a="186032773" X-IronPort-AV: E=Sophos;i="5.81,208,1610438400"; d="scan'208";a="186032773" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2021 08:00:36 -0800 IronPort-SDR: 3sLCO2XPqVNPQ4yqqLE7lHNBV1GZNqkgdFhGASL4/hx+BIYuvU4cdFnqWa52dC6JCeUqEw7Aji zGKkUljcgKEA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,208,1610438400"; d="scan'208";a="434413486" Received: from tjmaciei-desk.jf.intel.com (HELO tjmaciei-ctnr.jf.intel.com) ([10.54.75.8]) by fmsmga002.fm.intel.com with ESMTP; 26 Feb 2021 08:00:26 -0800 From: Thiago Macieira To: libstdc++@gcc.gnu.org Cc: gcc-patches@gcc.gnu.org Subject: [PATCH 4/5] barrier: use int instead of unsigned char for the phase state Date: Fri, 26 Feb 2021 07:59:36 -0800 Message-Id: <20210226155937.621324-4-thiago.macieira@intel.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210226155937.621324-1-thiago.macieira@intel.com> References: <1968544.UC5HiB4uFJ@tjmaciei-mobl1> <20210226155937.621324-1-thiago.macieira@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Feb 2021 16:00:41 -0000 ints can be used in futexes. chars can't. --- libstdc++-v3/include/std/barrier | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/libstdc++-v3/include/std/barrier b/libstdc++-v3/include/std/barrier index e09212dfcb9..ae058bd3dc3 100644 --- a/libstdc++-v3/include/std/barrier +++ b/libstdc++-v3/include/std/barrier @@ -70,7 +70,7 @@ It looks different from literature pseudocode for two main reasons: */ - enum class __barrier_phase_t : unsigned char { }; + enum class __barrier_phase_t : int { }; template class __tree_barrier @@ -93,20 +93,24 @@ It looks different from literature pseudocode for two main reasons: alignas(__phase_alignment) __barrier_phase_t _M_phase; + static __barrier_phase_t + _S_add_to_phase(__barrier_phase_t __phase, unsigned char __n) + { + __n += static_cast(__phase); + return static_cast<__barrier_phase_t>(__n); + } + bool _M_arrive(__barrier_phase_t __old_phase) { - const auto __old_phase_val = static_cast(__old_phase); - const auto __half_step = - static_cast<__barrier_phase_t>(__old_phase_val + 1); - const auto __full_step = - static_cast<__barrier_phase_t>(__old_phase_val + 2); - size_t __current_expected = _M_expected; std::hash __hasher; size_t __current = __hasher(std::this_thread::get_id()) % ((_M_expected + 1) >> 1); + const auto __half_step = _S_add_to_phase(__old_phase, 1); + const auto __full_step = _S_add_to_phase(__old_phase, 2); + for (int __round = 0; ; ++__round) { if (__current_expected <= 1) @@ -165,7 +169,6 @@ It looks different from literature pseudocode for two main reasons: { __atomic_phase_ref_t __phase(_M_phase); const auto __old_phase = __phase.load(memory_order_relaxed); - const auto __cur = static_cast(__old_phase); for(; __update; --__update) { if(_M_arrive(__old_phase)) @@ -173,7 +176,7 @@ It looks different from literature pseudocode for two main reasons: _M_completion(); _M_expected += _M_expected_adjustment.load(memory_order_relaxed); _M_expected_adjustment.store(0, memory_order_relaxed); - auto __new_phase = static_cast<__barrier_phase_t>(__cur + 2); + auto __new_phase = _S_add_to_phase(__old_phase, 2); __phase.store(__new_phase, memory_order_release); __phase.notify_all(); } -- 2.30.1