From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 03B094284B; Mon, 27 Mar 2023 16:30:41 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 55F7542BC9; Mon, 27 Mar 2023 16:30:27 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 0CF6A410D0 for ; Mon, 27 Mar 2023 16:30:23 +0200 (CEST) Received: by linux.microsoft.com (Postfix, from userid 1086) id 5847620FD8C1; Mon, 27 Mar 2023 07:30:22 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 5847620FD8C1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1679927422; bh=0nJcKkIRDMULe+xr8PDhyshCqH7Bu9Us1x08O+t/IaI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Kiej0t80OVqifkC1JcWPlayBBB4TgflU9w/8AKvzTbOlPqDbuPjLsGfZ5nZXaa2Vh tFtv9BRZY1lPTogjgwbyJbt1Qa3OSLvV7ADFlNLXo6JcCF8Ooj+oqwz83V4WJaqlDW sZ8EIdp1Gq0DUt+a7o9z/rZ7vBBfK1JZG13USHK8= From: Tyler Retzlaff To: dev@dpdk.org Cc: Honnappa.Nagarahalli@arm.com, Ruifeng.Wang@arm.com, thomas@monjalon.net, Tyler Retzlaff Subject: [PATCH 3/3] eal: use C11 memory model GCC builtin atomics Date: Mon, 27 Mar 2023 07:30:20 -0700 Message-Id: <1679927420-26737-4-git-send-email-roretzla@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1679927420-26737-1-git-send-email-roretzla@linux.microsoft.com> References: <1679927420-26737-1-git-send-email-roretzla@linux.microsoft.com> X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Replace use of __sync_fetch_and_add and __sync_fetch_and_sub with __atomic_fetch_add and __atomic_fetch_sub. Signed-off-by: Tyler Retzlaff --- lib/eal/include/generic/rte_atomic.h | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/eal/include/generic/rte_atomic.h b/lib/eal/include/generic/rte_atomic.h index 234b268..58df843 100644 --- a/lib/eal/include/generic/rte_atomic.h +++ b/lib/eal/include/generic/rte_atomic.h @@ -243,7 +243,7 @@ static inline void rte_atomic16_add(rte_atomic16_t *v, int16_t inc) { - __sync_fetch_and_add(&v->cnt, inc); + __atomic_fetch_add(&v->cnt, inc, __ATOMIC_SEQ_CST); } /** @@ -257,7 +257,7 @@ static inline void rte_atomic16_sub(rte_atomic16_t *v, int16_t dec) { - __sync_fetch_and_sub(&v->cnt, dec); + __atomic_fetch_sub(&v->cnt, dec, __ATOMIC_SEQ_CST); } /** @@ -310,7 +310,7 @@ static inline int16_t rte_atomic16_add_return(rte_atomic16_t *v, int16_t inc) { - return __sync_add_and_fetch(&v->cnt, inc); + return __atomic_fetch_add(&v->cnt, inc, __ATOMIC_SEQ_CST) + inc; } /** @@ -330,7 +330,7 @@ static inline int16_t rte_atomic16_sub_return(rte_atomic16_t *v, int16_t dec) { - return __sync_sub_and_fetch(&v->cnt, dec); + return __atomic_fetch_sub(&v->cnt, dec, __ATOMIC_SEQ_CST) - dec; } /** @@ -349,7 +349,7 @@ #ifdef RTE_FORCE_INTRINSICS static inline int rte_atomic16_inc_and_test(rte_atomic16_t *v) { - return __sync_add_and_fetch(&v->cnt, 1) == 0; + return __atomic_fetch_add(&v->cnt, 1, __ATOMIC_SEQ_CST) + 1 == 0; } #endif @@ -369,7 +369,7 @@ static inline int rte_atomic16_inc_and_test(rte_atomic16_t *v) #ifdef RTE_FORCE_INTRINSICS static inline int rte_atomic16_dec_and_test(rte_atomic16_t *v) { - return __sync_sub_and_fetch(&v->cnt, 1) == 0; + return __atomic_fetch_sub(&v->cnt, 1, __ATOMIC_SEQ_CST) - 1 == 0; } #endif @@ -522,7 +522,7 @@ static inline void rte_atomic16_clear(rte_atomic16_t *v) static inline void rte_atomic32_add(rte_atomic32_t *v, int32_t inc) { - __sync_fetch_and_add(&v->cnt, inc); + __atomic_fetch_add(&v->cnt, inc, __ATOMIC_SEQ_CST); } /** @@ -536,7 +536,7 @@ static inline void rte_atomic16_clear(rte_atomic16_t *v) static inline void rte_atomic32_sub(rte_atomic32_t *v, int32_t dec) { - __sync_fetch_and_sub(&v->cnt, dec); + __atomic_fetch_sub(&v->cnt, dec, __ATOMIC_SEQ_CST); } /** @@ -589,7 +589,7 @@ static inline void rte_atomic16_clear(rte_atomic16_t *v) static inline int32_t rte_atomic32_add_return(rte_atomic32_t *v, int32_t inc) { - return __sync_add_and_fetch(&v->cnt, inc); + return __atomic_fetch_add(&v->cnt, inc, __ATOMIC_SEQ_CST) + inc; } /** @@ -609,7 +609,7 @@ static inline void rte_atomic16_clear(rte_atomic16_t *v) static inline int32_t rte_atomic32_sub_return(rte_atomic32_t *v, int32_t dec) { - return __sync_sub_and_fetch(&v->cnt, dec); + return __atomic_fetch_sub(&v->cnt, dec, __ATOMIC_SEQ_CST) - dec; } /** @@ -628,7 +628,7 @@ static inline void rte_atomic16_clear(rte_atomic16_t *v) #ifdef RTE_FORCE_INTRINSICS static inline int rte_atomic32_inc_and_test(rte_atomic32_t *v) { - return __sync_add_and_fetch(&v->cnt, 1) == 0; + return __atomic_fetch_add(&v->cnt, 1, __ATOMIC_SEQ_CST) + 1 == 0; } #endif @@ -648,7 +648,7 @@ static inline int rte_atomic32_inc_and_test(rte_atomic32_t *v) #ifdef RTE_FORCE_INTRINSICS static inline int rte_atomic32_dec_and_test(rte_atomic32_t *v) { - return __sync_sub_and_fetch(&v->cnt, 1) == 0; + return __atomic_fetch_sub(&v->cnt, 1, __ATOMIC_SEQ_CST) - 1 == 0; } #endif @@ -854,7 +854,7 @@ static inline void rte_atomic32_clear(rte_atomic32_t *v) static inline void rte_atomic64_add(rte_atomic64_t *v, int64_t inc) { - __sync_fetch_and_add(&v->cnt, inc); + __atomic_fetch_add(&v->cnt, inc, __ATOMIC_SEQ_CST); } #endif @@ -873,7 +873,7 @@ static inline void rte_atomic32_clear(rte_atomic32_t *v) static inline void rte_atomic64_sub(rte_atomic64_t *v, int64_t dec) { - __sync_fetch_and_sub(&v->cnt, dec); + __atomic_fetch_sub(&v->cnt, dec, __ATOMIC_SEQ_CST); } #endif @@ -931,7 +931,7 @@ static inline void rte_atomic32_clear(rte_atomic32_t *v) static inline int64_t rte_atomic64_add_return(rte_atomic64_t *v, int64_t inc) { - return __sync_add_and_fetch(&v->cnt, inc); + return __atomic_fetch_add(&v->cnt, inc, __ATOMIC_SEQ_CST) + inc; } #endif @@ -955,7 +955,7 @@ static inline void rte_atomic32_clear(rte_atomic32_t *v) static inline int64_t rte_atomic64_sub_return(rte_atomic64_t *v, int64_t dec) { - return __sync_sub_and_fetch(&v->cnt, dec); + return __atomic_fetch_sub(&v->cnt, dec, __ATOMIC_SEQ_CST) - dec; } #endif -- 1.8.3.1