From nobody Thu Oct 07 03:28:13 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id CEC7312DDF42; Thu, 7 Oct 2021 03:28:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HPxby2M23z4r27; Thu, 7 Oct 2021 03:28:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id EA2464741; Thu, 7 Oct 2021 03:28:13 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1973SDf2060834; Thu, 7 Oct 2021 03:28:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1973SDdI060833; Thu, 7 Oct 2021 03:28:13 GMT (envelope-from git) Date: Thu, 7 Oct 2021 03:28:13 GMT Message-Id: <202110070328.1973SDdI060833@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: e0363a08dc45 - stable/12 - atomic: Add atomic_cmpset_masked to powerpc and use it List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: e0363a08dc453be7b67f38d8a9663ff41dde94ee Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=e0363a08dc453be7b67f38d8a9663ff41dde94ee commit e0363a08dc453be7b67f38d8a9663ff41dde94ee Author: Justin Hibbits AuthorDate: 2019-11-15 04:33:07 +0000 Commit: Kyle Evans CommitDate: 2021-10-07 03:27:27 +0000 atomic: Add atomic_cmpset_masked to powerpc and use it Summary: This is a more optimal way of doing atomic_compset_masked() than the fallback in sys/_atomic_subword.h. There's also an override for _atomic_fcmpset_masked_word(), which may or may not be necessary, and is unused for powerpc. (cherry picked from commit d0bdb11139424b9dcfe3b73cd5a003055382de03) --- sys/powerpc/include/atomic.h | 32 ++++++++++++++++++++++++++++++++ sys/sys/_atomic_subword.h | 4 ++++ 2 files changed, 36 insertions(+) diff --git a/sys/powerpc/include/atomic.h b/sys/powerpc/include/atomic.h index 788e7520d7bc..2510160a402a 100644 --- a/sys/powerpc/include/atomic.h +++ b/sys/powerpc/include/atomic.h @@ -612,6 +612,38 @@ atomic_cmpset_short(volatile u_short *p, u_short cmpval, u_short newval) return (ret); } +#else +static __inline int +atomic_cmpset_masked(uint32_t *p, uint32_t cmpval, uint32_t newval, + uint32_t mask) +{ + int ret; + uint32_t tmp; + + __asm __volatile ( + "1:\tlwarx %2, 0, %2\n\t" /* load old value */ + "and %0, %2, %7\n\t" + "cmplw %4, %0\n\t" /* compare */ + "bne- 2f\n\t" /* exit if not equal */ + "andc %2, %2, %7\n\t" + "or %2, %2, %5\n\t" + "stwcx. %2, 0, %3\n\t" /* attempt to store */ + "bne- 1b\n\t" /* spin if failed */ + "li %0, 1\n\t" /* success - retval = 1 */ + "b 3f\n\t" /* we've succeeded */ + "2:\n\t" + "stwcx. %2, 0, %3\n\t" /* clear reservation (74xx) */ + "li %0, 0\n\t" /* failure - retval = 0 */ + "3:\n\t" + : "=&r" (ret), "=m" (*p), "+&r" (tmp) + : "r" (p), "r" (cmpval), "r" (newval), "m" (*p), + "r" (mask) + : "cr0", "memory"); + + return (ret); +} + +#define _atomic_cmpset_masked_word(a,o,v,m) atomic_cmpset_masked(a, o, v, m) #endif static __inline int diff --git a/sys/sys/_atomic_subword.h b/sys/sys/_atomic_subword.h index fd03ea6a6aed..08e54bf519a9 100644 --- a/sys/sys/_atomic_subword.h +++ b/sys/sys/_atomic_subword.h @@ -63,6 +63,7 @@ ((((__uintptr_t)(p) % 4)) * NBBY) #endif +#ifndef _atomic_cmpset_masked_word /* * Pass these bad boys a couple words and a mask of the bits you care about, * they'll loop until we either succeed or fail because of those bits rather @@ -92,7 +93,9 @@ _atomic_cmpset_masked_word(uint32_t *addr, uint32_t old, uint32_t val, return (ret); } +#endif +#ifndef _atomic_fcmpset_masked_word static __inline int _atomic_fcmpset_masked_word(uint32_t *addr, uint32_t *old, uint32_t val, uint32_t mask) @@ -108,6 +111,7 @@ _atomic_fcmpset_masked_word(uint32_t *addr, uint32_t *old, uint32_t val, *old = (*addr & ~mask) | *old; return (atomic_fcmpset_32(addr, old, (*old & ~mask) | val)); } +#endif static __inline int atomic_cmpset_8(__volatile uint8_t *addr, uint8_t old, uint8_t val)