From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f43.google.com (mail-qv1-f43.google.com [209.85.219.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 853E36FC3; Mon, 14 Jul 2025 04:20:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752466856; cv=none; b=YiNyUhoNx5XybRw4uh+t4hCuAgdWC7AI2B6ntWXfJj0UDjtPnoW6kpr5/nG6Urg8qzAdc7PV1ii5dvlKjt/g3bbJ3C7ionepNsHduKeToaCgcdiqKlbJt8mI4DcogVrj4KBHIex7xX602xEgxoBFHXfmhejUaYgKxL5PHS1CefQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752466856; c=relaxed/simple; bh=SuP+qQVi/MxIQB/1CDIRKWnHRBYowFHJSKjU7kuP458=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=M9N8AT/iKTlwsPSigcYOaUCz6XPAG9Ld7vo0s5z36Go+tm7IDOoR0VnmNNFNqrNPToyhZRXB2qhXbvflfTUSE+8SkZrATc7VphA/ZM155MwZShw9AzMIu0O2dhuucpLmtycgETb5fp4N1sDmamjZYH3g/Q+zUx8FihBkr2zPqNw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MT5KAQ2l; arc=none smtp.client-ip=209.85.219.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MT5KAQ2l" Received: by mail-qv1-f43.google.com with SMTP id 6a1803df08f44-6facf4d8ea8so31957986d6.0; Sun, 13 Jul 2025 21:20:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752466853; x=1753071653; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:from:to:cc:subject:date :message-id:reply-to; bh=n7KPUZRfwzKm6vhoXm+OjqDoe1jPCZoU1nC9eh6TlIU=; b=MT5KAQ2lNS6JEgsg4FJl3hGJIBjJqJ+pphzmP3wWObQ2B0IK+DTsYVs1IAkVoWBsQj 5F/b++gy4da9cO5UT8g9UiWTyfEKorlZerk70VmTsDjS/yGBambmmY8vR2OpnNDrmBI3 M0roNcv5Q5zWc4Y3gJmytcQf/99vuZCigsAKV59ON/0c5tuj3/BwYH79uCbcrsDjFTQQ laSzUuZz66v16YcHZPFVE53lo3p4Ndc0avXdk5ZEz5L3UGfa17JK7FOkiKC+AAWd2zLW tXqqUelIL/KGqU6qBAm16cWlwxyin8+SvzjPZ2BxgRSNrxf5yK+MfBnyhRbSbMEgo2UH bYQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752466853; x=1753071653; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=n7KPUZRfwzKm6vhoXm+OjqDoe1jPCZoU1nC9eh6TlIU=; b=MlTo00AjpbYnV3/qMgSdtxqeYce0YfFlijdDs5oqtSCatRa3SVZicz3/dQHmDzeNgJ +IAU0jt3rrjIyu+1uYJ3Hj3mIENZkPGa3xb2t/aiUbdEpgZo090b/duF93XSW/s1czyS nI90HU/4SQQOZNNTC1U/XgMlHfx7XlJvqm6ZJ2YjULP7fHtSd8THj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 2002:ad4:5945:0:b0:704:9618:51d with SMTP id 6a1803df08f44-704a7065aacmr172694506d6.39.1752466853319; Sun, 13 Jul 2025 21:20:53 -0700 (PDT) Received: from fauth-a1-smtp.messagingengine.com (fauth-a1-smtp.messagingengine.com. [103.168.172.200]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-70497d39450sm42915536d6.75.2025.07.13.21.20.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Jul 2025 21:20:52 -0700 (PDT) Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfauth.phl.internal (Postfix) with ESMTP id C2CE5F40068; Mon, 14 Jul 2025 00:20:51 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Mon, 14 Jul 2025 00:20:51 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdehtdelkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpeffhffvvefukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeeuohhquhhnucfh vghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrfgrthhtvg hrnhephedugfduffffteeutddvheeuveelvdfhleelieevtdeguefhgeeuveeiudffiedv necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepsghoqh hunhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedtieegqddu jeejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfhhigihmvg drnhgrmhgvpdhnsggprhgtphhtthhopedvjedpmhhouggvpehsmhhtphhouhhtpdhrtghp thhtoheplhhoshhsihhnsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqd hkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehruhhsthdq fhhorhdqlhhinhhugiesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlkh hmmheslhhishhtshdrlhhinhhugidruggvvhdprhgtphhtthhopehlihhnuhigqdgrrhgt hhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehojhgvuggrsehkvghrnh gvlhdrohhrghdprhgtphhtthhopegrlhgvgidrghgrhihnohhrsehgmhgrihhlrdgtohhm pdhrtghpthhtohepghgrrhihsehgrghrhihguhhordhnvghtpdhrtghpthhtohepsghjoh hrnhefpghghhesphhrohhtohhnmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 14 Jul 2025 00:20:51 -0400 (EDT) Date: Sun, 13 Jul 2025 21:20:50 -0700 From: Boqun Feng To: Benno Lossin Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, lkmm@lists.linux.dev, linux-arch@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Will Deacon , Peter Zijlstra , Mark Rutland , Wedson Almeida Filho , Viresh Kumar , Lyude Paul , Ingo Molnar , Mitchell Levy , "Paul E. McKenney" , Greg Kroah-Hartman , Linus Torvalds , Thomas Gleixner , Alan Stern Subject: Re: [PATCH v6 6/9] rust: sync: atomic: Add the framework of arithmetic operations Message-ID: References: <20250710060052.11955-1-boqun.feng@gmail.com> <20250710060052.11955-7-boqun.feng@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Fri, Jul 11, 2025 at 02:22:13PM -0700, Boqun Feng wrote: [...] > > > pub unsafe trait AtomicAdd: AllowAtomic { > > > type Delta = Self::Repr; > > > fn rhs_into_delta(rhs: Rhs) -> Delta; > > > } > > > > > > Note that I have to provide a `Delta` (or better named as `ReprDelta`?) > > > because of when pointer support is added, atomic addition is between > > > a `*mut ()` and a `isize`, not two `*mut()`. > > > > Makes sense, but we don't have default associated types yet :( > > > > Oops, we are lucky enough to only have a few types to begin with ;-) > Maybe we can use `#[derive(AtomicAdd)] to select the default delta type > later. > Turn out I could give `AtomcImpl` an associate type: pub trait AtomicImpl: Sealed { type Delta; } and then pub unsafe trait AllowAtomicAdd: AllowAtomic { /// Converts `Rhs` into the `Delta` type of the atomic implementation. fn rhs_into_delta(rhs: Rhs) -> ::Delta; } (Yeah, I named it `AllowAtomicAdd` ;-)) and I only need to provide `Delta` for three types (i32, i64 and *mut ()). BTW, since atomic arithmetic is wrapping, do we want things like `impl AllowAtomicAdd for i32`, similar to the concept of `i32::wrapping_add_unsigned()` ;-) Regards, Boqun > Regards, > Boqun