Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp2588152lqo; Tue, 14 May 2024 03:28:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXfdfv1cByLxLlnyrGW4ze3c+FO6+tU3QEJ61byLInvd+yMZKveO3HlH5mukXe4sYZ0I5COnHVV1ytNF+KZGRiGMfZxIKXKR2hfzrFwxg== X-Google-Smtp-Source: AGHT+IGkujyTVVxIOw0fuhO7lUBWIJPxbXrZ6El3X7mGSm+m2fuxlTcT2FVRg5zLkED1PtWe7b9L X-Received: by 2002:a17:90a:af90:b0:2b2:cb60:6eb8 with SMTP id 98e67ed59e1d1-2b6ccd6baf8mr10325213a91.32.1715682524977; Tue, 14 May 2024 03:28:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715682524; cv=pass; d=google.com; s=arc-20160816; b=tfS3FszMsG6u+xE96S3YBesvcsEaDZ+7fwooNT5QdjzJEfwM2GZL+lhQKR9gEHY5a9 EDG09WUPCO5G5gxn1Nr34CzyKjCBm9RbVsZgf/SLPmZp9alJUxMoBh1hb/sRKf9RhcK9 IfWmaJVA7L8DBOHI9a9oHWa/Oi9gZpQ8fbvu4GkTS3J67ThDaph5fNutks6buHNvmtIa XCj4ZtEfZOpl0KLuNh9nEk1T+HmwgYubPpLbwqXUNHuQUTwmwYN4+y6GnLN3YbB6G3HM y5I7lE0xxn70svg+6VjDzK9gfSMChTT2XW9XgZJoy6X94JGiQLcw1JohYm3fth3+3GfS HQDQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=gQqnGAbeznu99qnawt48P4UpBGGpdn9Z/4qccwoyE80=; fh=MaZkM021qbfAX3aLJulL8oJ9TBXZh2SjH2oVXl7lSWc=; b=nVN3xbbDA8cLHj3tfVkmKIPHTS9Iv/vP86kJuYnxX1qJxw+tQAI7CG1JLg2G34Fz+Z lrXqRpVkfReWb40lMQ2NWSn47oNy7xPyhODFn17EfxchcWbfcjMvg4CdnERN1Zz7bpj0 2bvF+RN8ZC5/W8L1NpcySyASE5b0zn8mNVIsIcBQeAvf3UsbK7nXkkoAjNa+jlJ0/B/g MBYB72V3b2g+qLfW+EVnjpawZiu6NlGa3xTOprIR+OAtMHxlqp5DizKaNy6CLbhDH4Xr D7O6q2EYduv4XBDxwmU5F9euiuFqnxSeMu6Vu5QOY6XZ/aAlEQzm2oajOb5u5EE3RZQ2 VMJw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=L4HGvJ05; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-178524-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-178524-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2b628ea7a6dsi13417817a91.99.2024.05.14.03.28.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 03:28:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-178524-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=L4HGvJ05; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-178524-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-178524-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 978A2282999 for ; Tue, 14 May 2024 10:28:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 46FD712F36F; Tue, 14 May 2024 09:46:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="L4HGvJ05" 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 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: 8bit 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 = ATOMIC_INIT(7); } P0(atomic_t *u) { r0 = atomic_fetch_andnot(3, u); r1 = READ_ONCE(*u); } exists (0:r0=7 /\ 0:r1=4) Test andnot Allowed States 1 0:r0=7; 0:r1=4; Ok Witnesses Positive: 1 Negative: 0 Condition exists (0:r0=7 /\ 0:r1=4) Observation andnot Always 1 0 Time andnot 0.00 Hash=78f011a0b5a0c65fa1cf106fcd62c845 [1] https://github.com/herd/herdtools7/pull/855 Signed-off-by: Puranjay Mohan --- 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); } 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) -- 2.40.1