From nobody Tue Feb 10 20:46:54 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6DDE753E15; Tue, 14 May 2024 09:46:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715680017; cv=none; b=Dg2k+NFUch2BS/ZnAAgyHMRo4Uotdir/PGMgk87I4VPo8wwFI4v8hTe8oL6BLFAoAFRWgtlpfE8UFBB/mvfSb/cTdv4bXWT01EUVsFAgzuKwp/d6IhEJP8UJCfnan6UD2hHmjXZml5Gjy5FhLsXFqX2RMxYpljSJtRcoc7G/Hnk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715680017; c=relaxed/simple; bh=dfYJ4UEi4cz7TvFXBGiFzXx4XErQQccYti1P3UdmCOU=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=ntA8nqIQ284HVuUlgd8vETHqoK+Qa+nxAIisB52jWUfH3qTSsIzu1/+M0kdp0LLk7lgvy47rAnC0OQ7eBvg0l2mGU7v7IlvlrUyuHvH6Vm2vUrB2BNorcrLXNjB2iHYTa4fvE5eEHsMbzBChvQU2MheSdhyOAO3wEYn2DSF1a2Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=L4HGvJ05; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="L4HGvJ05" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 921E4C32786; Tue, 14 May 2024 09:46:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715680016; bh=dfYJ4UEi4cz7TvFXBGiFzXx4XErQQccYti1P3UdmCOU=; h=From:To:Cc:Subject:Date:From; b=L4HGvJ05P1kdy7JsAeGZzTWy5UC5yCDkt7J4izjjNlV+W1yVKpSVB3AtSEcgQn/dm dOpsRZfjdp3lMmQzu5bajEURt5cuBIFXiyE/2Gi7E5myVtrp3WG2pcvJrAcIAfYOMk uCvh68F2oD1Oeot5H0m3JzViCCsqxBMn3rXPkmDSTtFzH4JTu8oH7FmlOutWCqEbL4 xMd2Z6jvh6U9uqYYcma+yR5QPY8qCu8ze5eaubLROkaibqDDwpev+M8tfnIcGm/fUd oIdSDo/05EN2KwpW4RqaFcl0Xam4bNAfNT+GTfv5aWlfX8VJDVMwmXIHTwdphmpoQd TzvCQAAUS2CmQ== From: Puranjay Mohan To: Alan Stern , Andrea Parri , Will Deacon , Peter Zijlstra , Boqun Feng , Nicholas Piggin , David Howells , Jade Alglave , Luc Maranget , "Paul E. McKenney" , Akira Yokosawa , Daniel Lustig , Joel Fernandes , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org Cc: puranjay12@gmail.com Subject: [PATCH] tools/memory-model: Add atomic_andnot() with its variants Date: Tue, 14 May 2024 09:46:33 +0000 Message-Id: <20240514094633.48067-1-puranjay@kernel.org> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Pull-855[1] added the support of atomic_andnot() to the herd tool. Use this to add the implementation in the LKMM. All of the ordering variants are also added. Here is a small litmus-test that uses this operation: C andnot { atomic_t u =3D ATOMIC_INIT(7); } P0(atomic_t *u) { r0 =3D atomic_fetch_andnot(3, u); r1 =3D READ_ONCE(*u); } exists (0:r0=3D7 /\ 0:r1=3D4) Test andnot Allowed States 1 0:r0=3D7; 0:r1=3D4; Ok Witnesses Positive: 1 Negative: 0 Condition exists (0:r0=3D7 /\ 0:r1=3D4) Observation andnot Always 1 0 Time andnot 0.00 Hash=3D78f011a0b5a0c65fa1cf106fcd62c845 [1] https://github.com/herd/herdtools7/pull/855 Signed-off-by: Puranjay Mohan Acked-by: Andrea Parri --- This commit is based on the commit[1] that is adding `&`, `|`, and `^`. Both of these patches should go together when the next version of herd7 is released. I will update the "REQUIREMENTS" section when the new version is released. Later on, I will add some example litmus tests to showcase the usage of these new operations. [1] https://lore.kernel.org/all/20240508143400.36256-1-puranjay@kernel.org/ --- tools/memory-model/linux-kernel.def | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/memory-model/linux-kernel.def b/tools/memory-model/linux= -kernel.def index d1f11930ec51..a12b96c547b7 100644 --- a/tools/memory-model/linux-kernel.def +++ b/tools/memory-model/linux-kernel.def @@ -70,6 +70,7 @@ atomic_or(V,X) { __atomic_op(X,|,V); } atomic_xor(V,X) { __atomic_op(X,^,V); } atomic_inc(X) { __atomic_op(X,+,1); } atomic_dec(X) { __atomic_op(X,-,1); } +atomic_andnot(V,X) { __atomic_op(X,&~,V); } =20 atomic_add_return(V,X) __atomic_op_return{mb}(X,+,V) atomic_add_return_relaxed(V,X) __atomic_op_return{once}(X,+,V) @@ -138,3 +139,8 @@ atomic_add_negative(V,X) __atomic_op_return{mb}(X,+,V) = < 0 atomic_add_negative_relaxed(V,X) __atomic_op_return{once}(X,+,V) < 0 atomic_add_negative_acquire(V,X) __atomic_op_return{acquire}(X,+,V) < 0 atomic_add_negative_release(V,X) __atomic_op_return{release}(X,+,V) < 0 + +atomic_fetch_andnot(V,X) __atomic_fetch_op{mb}(X,&~,V) +atomic_fetch_andnot_acquire(V,X) __atomic_fetch_op{acquire}(X,&~,V) +atomic_fetch_andnot_release(V,X) __atomic_fetch_op{release}(X,&~,V) +atomic_fetch_andnot_relaxed(V,X) __atomic_fetch_op{once}(X,&~,V) --=20 2.40.1