From patchwork Fri Feb 26 15:59:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thiago Macieira X-Patchwork-Id: 1444978 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=tgeRXGQL; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DnDsC4JBwz9sTD for ; Sat, 27 Feb 2021 03:00:47 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 35E41398B15C; Fri, 26 Feb 2021 16:00:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 35E41398B15C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1614355243; bh=3X2B0FYQq1snKCPFATDnCnXt4fKFP03bzswhI5MelAQ=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=tgeRXGQLy8V7UhJES2f0AjgYVYySkKcL0JA/UEz4XETBjPuXBkKOWLIXejCNl+7LI DD1xGJ2JZKKiT3chmnb1R9lxg0nDRMfjFRqMxV5pNkTQmRTS7eAjEK1CnQs4kzBoZa x/ROtNvWGhTaID+O7Ngz0rE0MTP8KRSSSCAhLYzk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 To: libstdc++@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 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-Patchwork-Original-From: Thiago Macieira via Gcc-patches From: Thiago Macieira Reply-To: Thiago Macieira Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" 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(); }