From nobody Tue Nov 19 15:28:41 2024 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 4Xt7gY2nmgz5f7qT; Tue, 19 Nov 2024 15:28:41 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Xt7gY29tDz4CLx; Tue, 19 Nov 2024 15:28:41 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732030121; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TmCaTIck1gUhtR0dcuICUjZOTLO1xNzAa5MzjO+AjVo=; b=i+Lt9airsir9cO6kkUQdwOtpi8awB0RTy9QjmklLlUZyEuVMz1507HPxqk2cx+fEyWPEY5 3UV0K6WQD/ipvadFHisUFxqAg661v58a8FyAon/hIPxFBxGLtH3YwVXlZomgqKkr+kmFyj qdp0nWGGjtJwGADAolic5WYPRntxrCaKoTiVjfHbpgR846ym6W29jhHT3ZVaWZTlZsSEMR yQjP7w4hoFJbZd0UBJ9jj2Wr97qNx0o+0wPAPBdiSSz3QdQLmL54ZMkHtLuRMphpq22STI bme9bupV+rcNMLbYKvnEqCiL+ZjFpP071VL+r2U9os3n1lx3UT7nBN8hLQOb8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732030121; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TmCaTIck1gUhtR0dcuICUjZOTLO1xNzAa5MzjO+AjVo=; b=DUh+TtAa6Kzq4/ieXd/8r13zbFw4/U23bLmVRpd7V1ekPgr4e2+rtE3fdK4BxXZt0inUhn tR8035pMqEfqE2+24D7/cdiWHD7cY5u6J67SpV+TFVYlU9U3lV5ARJPj3utrcq0x50MRBG lPZ+9cHP3FsOUuNvvlO5TizpldpN6BYZveLkHh024IDE4sDyKMnxkR7uq2VquL8fTwTJH3 yUSlC/KhXPjnTQ6xFy78RVNJHqKDUhh6XgAq7JGBUFl3jL+Tt/a533ZC/cR9FgnjZh+um7 aMjfG/2hV6IjSAOO5z4BIihFD7yk5Ig1iWe7A/yWNP5gYfzX2fbsgpB8CvKGCw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1732030121; a=rsa-sha256; cv=none; b=HEjH5I9dlITXK36fWGDey49Yfi2GbU+uMyTRHLXvfNKU02y1vxUoWB7ePqCojFJUsoGSah eqE+j3FrH7WdmZ/jj3gvd3dheWW2pxUW7r2mqtt7v9pEItifgGjJrW5+3D5N+SryG5DlIh 0ZzLVTVFqjjBYRjreqx5rvLnZdmkmvIC0poOaGoEh6HxzzWYV4CcMWG+Hnuur3gC+8Blaf eSgyR0wL6KnznbUydJBh33QaJyfNjLnZ34C7S6Ftn8IQJDGilYDrYfpdvm+ro8xy1zCSu+ SRZKDXK2x/KnXLrjrSEW9dm0cG6NmsbcBt8YJnrBI3p6Xv9m4pWQP0OxQLSl1g== 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 4Xt7gY1nxZzFVQ; Tue, 19 Nov 2024 15:28:41 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4AJFSftD041194; Tue, 19 Nov 2024 15:28:41 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4AJFSfuM041191; Tue, 19 Nov 2024 15:28:41 GMT (envelope-from git) Date: Tue, 19 Nov 2024 15:28:41 GMT Message-Id: <202411191528.4AJFSfuM041191@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: a474e53d03ca - main - riscv: Add implementations of atomic_testand(set|clear)_(32|64|long) 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a474e53d03ca8c78696fc222520de7d6876cc530 Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=a474e53d03ca8c78696fc222520de7d6876cc530 commit a474e53d03ca8c78696fc222520de7d6876cc530 Author: John Baldwin AuthorDate: 2024-11-19 15:19:54 +0000 Commit: John Baldwin CommitDate: 2024-11-19 15:20:32 +0000 riscv: Add implementations of atomic_testand(set|clear)_(32|64|long) These use amoor and amoand rather than a loop. Also define atomic_testandset_acq_(64|long) using amoor.aq. Reviewed by: mhorne, kib Sponsored by: AFRL, DARPA Differential Revision: https://reviews.freebsd.org/D47627 --- sys/riscv/include/atomic.h | 73 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/sys/riscv/include/atomic.h b/sys/riscv/include/atomic.h index 03c1327d74da..38261e95cf31 100644 --- a/sys/riscv/include/atomic.h +++ b/sys/riscv/include/atomic.h @@ -266,6 +266,34 @@ atomic_readandclear_32(volatile uint32_t *p) return (ret); } +static __inline int +atomic_testandclear_32(volatile uint32_t *p, u_int val) +{ + uint32_t mask, old; + + mask = 1u << (val & 31); + __asm __volatile("amoand.w %0, %2, %1" + : "=&r" (old), "+A" (*p) + : "r" (~mask) + : "memory"); + + return ((old & mask) != 0); +} + +static __inline int +atomic_testandset_32(volatile uint32_t *p, u_int val) +{ + uint32_t mask, old; + + mask = 1u << (val & 31); + __asm __volatile("amoor.w %0, %2, %1" + : "=&r" (old), "+A" (*p) + : "r" (mask) + : "memory"); + + return ((old & mask) != 0); +} + #define atomic_add_int atomic_add_32 #define atomic_clear_int atomic_clear_32 #define atomic_cmpset_int atomic_cmpset_32 @@ -437,6 +465,48 @@ atomic_readandclear_64(volatile uint64_t *p) return (ret); } +static __inline int +atomic_testandclear_64(volatile uint64_t *p, u_int val) +{ + uint64_t mask, old; + + mask = 1ul << (val & 63); + __asm __volatile("amoand.d %0, %2, %1" + : "=&r" (old), "+A" (*p) + : "r" (~mask) + : "memory"); + + return ((old & mask) != 0); +} + +static __inline int +atomic_testandset_64(volatile uint64_t *p, u_int val) +{ + uint64_t mask, old; + + mask = 1ul << (val & 63); + __asm __volatile("amoor.d %0, %2, %1" + : "=&r" (old), "+A" (*p) + : "r" (mask) + : "memory"); + + return ((old & mask) != 0); +} + +static __inline int +atomic_testandset_acq_64(volatile uint64_t *p, u_int val) +{ + uint64_t mask, old; + + mask = 1ul << (val & 63); + __asm __volatile("amoor.d.aq %0, %2, %1" + : "=&r" (old), "+A" (*p) + : "r" (mask) + : "memory"); + + return ((old & mask) != 0); +} + static __inline uint32_t atomic_swap_32(volatile uint32_t *p, uint32_t val) { @@ -474,6 +544,9 @@ atomic_swap_64(volatile uint64_t *p, uint64_t val) #define atomic_set_long atomic_set_64 #define atomic_subtract_long atomic_subtract_64 #define atomic_swap_long atomic_swap_64 +#define atomic_testandclear_long atomic_testandclear_64 +#define atomic_testandset_long atomic_testandset_64 +#define atomic_testandset_acq_long atomic_testandset_acq_64 #define atomic_add_ptr atomic_add_64 #define atomic_clear_ptr atomic_clear_64