From nobody Sun Dec 01 04:57:22 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 4Y1F5b0Mwhz5gDGt; Sun, 01 Dec 2024 04:57:23 +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 4Y1F5Z30Jqz49pC; Sun, 1 Dec 2024 04:57:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733029042; 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=7byZhYCq/K6kLbLz9Ke2UgmliBaNOCWDC/udVkC7JRk=; b=uCulsJDCx+/h0nQmcxGfCvCseI9v2jVfldTxhJbrxElKKLlrsyH76SlI9cif+Wck5tznhZ N9ZoR/UHqesY06G85tcZTz2HwSJwOYOhJnWPPEHJ5jyV0NSInNN/Hw4gPxQqxopKjuablD Vz/06PUDtjuB4TzlZD/K2Gcy85IGF80lXPcbVvmuwB5rOIhDVMz8rF+kolSDE1R5/kAcYI tuGbc2W1E1kUd3ie7aXJ1WCgFkmhlxoxq0+lxojzOZ+6bmbG0foM8vpIw93LVynupuGOKS to10JGht87tKwo5e64y2aOH8hcUBJyLSwwjLKgwHuGVderNTakcunsL6pRVJiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733029042; 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=7byZhYCq/K6kLbLz9Ke2UgmliBaNOCWDC/udVkC7JRk=; b=hgYSOKxwKNCtAgP6pG4BNZEbfLsCdmfkUxcxp58QHAVEnRfzVEXmlL56718/9tf+e896VP GihR+4TwQTth0brN5JJiVQdx5ukpYwkYqVhErkApaiwOGyckSUAmlxT3qmFi3NTAeONIAs UgjBujgR7R9QOGaqAR5K6uYBZIoN7ypGZTi75nknBZ72N2USdwHl0sNaqwn0plytIVIl5Q OnWLUhpqXEgBDPoqGVs2a9jS/HYGoBUkGJ097mIpkP6yoFPyNpTiGZZSnA1ylVSqRMQrjn 7gIyalwtwCCW8/GxJhe8jdzW9e2nDIrXi2ACDheUlr7PUUOHGf7MQ9+k/g8yyw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1733029042; a=rsa-sha256; cv=none; b=ZEOw6vvJYVUDd/T9cS6+UFTyXW+A+Oe7KiVzuM5+IXCIIS9NMS90aFiN9kW/4jfKvPtove j1IpfG4wf52hU7APa6jq12aSPim02/RXZwa151sK1i+HwHZ/Bnpyb9OqWQLW//191zxZ/X wpXMgpUw80Tk18N/1LUmJ+amBO1S7ozU9QCMNzxZ8+nePeVc8gkn8PCu+fvdO5Kzak8y7J V4FaQaGrPEfev8OiecsHtp83Wd1V4zefn9+phdySfLB3zgpFSsQld00dqO44PYyg1GjnuR GFD6eVpdz7qhWbbLG2tf+noU/vcZDEBklHtplAUYnA3t0PIoPv9EG8FT1D5YHw== 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 4Y1F5Z2cg2zfLK; Sun, 1 Dec 2024 04:57:22 +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 4B14vMVB095760; Sun, 1 Dec 2024 04:57:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4B14vMWD095757; Sun, 1 Dec 2024 04:57:22 GMT (envelope-from git) Date: Sun, 1 Dec 2024 04:57:22 GMT Message-Id: <202412010457.4B14vMWD095757@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 4380cca46dd9 - stable/14 - 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/stable/14 X-Git-Reftype: branch X-Git-Commit: 4380cca46dd900b96c60b54c2de0315c2f8fa104 Auto-Submitted: auto-generated The branch stable/14 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=4380cca46dd900b96c60b54c2de0315c2f8fa104 commit 4380cca46dd900b96c60b54c2de0315c2f8fa104 Author: John Baldwin AuthorDate: 2024-11-19 15:19:54 +0000 Commit: John Baldwin CommitDate: 2024-12-01 02:46:07 +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 (cherry picked from commit a474e53d03ca8c78696fc222520de7d6876cc530) --- 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 ef9aa5ef057d..be4137cb0df4 100644 --- a/sys/riscv/include/atomic.h +++ b/sys/riscv/include/atomic.h @@ -239,6 +239,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 @@ -410,6 +438,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) { @@ -447,6 +517,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