From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from fhigh-a3-smtp.messagingengine.com (fhigh-a3-smtp.messagingengine.com [103.168.172.154]) (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 0E79D1FF1C7; Fri, 20 Mar 2026 09:27:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773998831; cv=none; b=Im8zIOEIEoRYNu+QZ9EKeP8KZlR90QSMhCB1K+ctWkTur6RceL3rdD+lWxI5zjESKmdnBDsvTDfQGN7GeE8QXl1U3MABIPC9sqXV83gRnh1tDSRB4pp0G9IN3u1Hr8OqQurbuz+IhovlEveXQWY5C+LweQyyJJ9nzyYdz33Qo2w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773998831; c=relaxed/simple; bh=pPWZDhX+HtdQx3beMQojW008fXJaY1Ts8A4WsG/pNRo=; h=MIME-Version:Date:From:To:Cc:Message-Id:In-Reply-To:References: Subject:Content-Type; b=dMIVZjlMbG71nKE66f7Kj1ro2FbzvjpXjx86vUUM96jZy7DfPlOeJB97M+TqPF3eJSXWeWz7j4hrReEFcjfxgWbY1kFXfrXJmjoJKCcODtn1l3eYKvRM2GFkyYaIfheT+OcBF28Dkeep0jq1PQX0reZklx0N6G+eAewrjPrYb4k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=readahead.eu; spf=pass smtp.mailfrom=readahead.eu; dkim=pass (2048-bit key) header.d=readahead.eu header.i=@readahead.eu header.b=gA+Y+8Qi; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=vo2ar5fD; arc=none smtp.client-ip=103.168.172.154 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=readahead.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=readahead.eu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=readahead.eu header.i=@readahead.eu header.b="gA+Y+8Qi"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="vo2ar5fD" Received: from phl-compute-12.internal (phl-compute-12.internal [10.202.2.52]) by mailfhigh.phl.internal (Postfix) with ESMTP id 44350140018D; Fri, 20 Mar 2026 05:27:09 -0400 (EDT) Received: from phl-imap-18 ([10.202.2.89]) by phl-compute-12.internal (MEProxy); Fri, 20 Mar 2026 05:27:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=readahead.eu; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1773998829; x=1774085229; bh=2qZYXRp93YhiAN3mli/CTXQQYMNSnkZwKPhBCTqz0s0=; b= gA+Y+8Qiocxfz6xEZLsqddjwMbKCbcqovBdg6PM7uIMgqA18dNanN3Z7TtNLWVwY Jh4+/faqZsM+czx/JB7sIfBlPzJKq2SO5WhTYk2aCJzLHdLI7ot1zFuyu8A82+LP 9EM7FZ/JruWj+DhQf4Pat7HbKgX6qosp/xcgDzGb43i66l7Ob3YuKo+EYV4pX+7e iKFrMgONspFfF+3RnCwDpOABr++ZPiOc8sDH3ZT6yzMCa6AFrWB1Xvvp1AU8cC5c /oufHl+xg5noOoa9bPgz2BsKi/ZD1IiC8gIdqs2+1o9sG9jNGxo5H7zOAc22lXq4 m72Lx2s8L5S9gz2qTZiD/g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1773998829; x= 1774085229; bh=2qZYXRp93YhiAN3mli/CTXQQYMNSnkZwKPhBCTqz0s0=; b=v o2ar5fD/oVGLGJx1ZlpLHeZoJHoRnCHDr6TnVLoYyArM3CRRU28s+zGkLVzvfsUJ ga8zT6psKMsJvC/QnJMKY25AbOi5XGMMz4/Wv6zEZ4Qk6y2QOsdYcLhnwMbSB2wV bfcI2FQSW69um+SY622JHTx2UpIg9vSDa2frqdOTWo6zTSnxGR5KZ/PRMTcYCtBZ MgU7VrzUyvMYB2A5zemIDZcoO9Hx58wGsWBhdPxQgMHO7y47ZpM9qONzpF9xur4n Sg6g7wLxoh/DxsfEfdKPBw0s8UyGhr6AehTGX9wjY+hXhzskmd15XmB6v7GxFgXI cIOY79gaAKJum3akB8UnQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdeftdelheefucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepofggfffhvfevkfgjfhfutgfgsehtjeertdertddtnecuhfhrohhmpedfffgrvhhi ugcutfhhvghinhhssggvrhhgfdcuoegurghvihgusehrvggruggrhhgvrggurdgvuheqne cuggftrfgrthhtvghrnheptefhteefhfefteffffffteevueejleeiheetgeehffeileev fefhkeegkeefgeelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomhepuggrvhhiugesrhgvrggurghhvggrugdrvghupdhnsggprhgtphhtthhopedv fedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepshhimhhonhgrsehffhiflhhlrd gthhdprhgtphhtthhopehgrghrhiesghgrrhihghhuohdrnhgvthdprhgtphhtthhopegr ihhrlhhivggusehgmhgrihhlrdgtohhmpdhrtghpthhtoheprghlvgigrdhgrgihnhhorh esghhmrghilhdrtghomhdprhgtphhtthhopegsohhquhhnrdhfvghnghesghhmrghilhdr tghomhdprhgtphhtthhopegrlhhitggvrhihhhhlsehgohhoghhlvgdrtghomhdprhgtph htthhopegshhgvlhhgrggrshesghhoohhglhgvrdgtohhmpdhrtghpthhtoheprgdrhhhi nhgusghorhhgsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghkrheskhgvrhhnvg hlrdhorhhg X-ME-Proxy: Feedback-ID: id2994666:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id ACBC215C0091; Fri, 20 Mar 2026 05:27:08 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ThreadId: AtQVIY85vbR- Date: Fri, 20 Mar 2026 10:26:48 +0100 From: "David Rheinsberg" To: "Alice Ryhl" Cc: "John Hubbard" , "Danilo Krummrich" , "Alexandre Courbot" , "Joel Fernandes" , "Timur Tabi" , "Alistair Popple" , "Eliot Courtney" , "Shashank Sharma" , "Zhi Wang" , "David Airlie" , "Simona Vetter" , "Bjorn Helgaas" , "Miguel Ojeda" , "Alex Gaynor" , "Boqun Feng" , "Gary Guo" , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , "Benno Lossin" , "Andreas Hindborg" , "Trevor Gross" , rust-for-linux@vger.kernel.org, LKML Message-Id: <6163dea3-fa75-4403-929e-8ba9ba22eab5@app.fastmail.com> In-Reply-To: References: <20260317225355.549853-1-jhubbard@nvidia.com> <20260317225355.549853-17-jhubbard@nvidia.com> <125cb5fd-55fe-4c54-bdda-0478f5a8aabd@app.fastmail.com> Subject: Re: [PATCH v7 16/31] rust: ptr: add const_align_up() Content-Type: text/plain Content-Transfer-Encoding: 7bit Hi! On Fri, Mar 20, 2026, at 10:03 AM, Alice Ryhl wrote: > The Alignment type can only hold values that are a power of two. That solves my concern! Kinda off-topic: why doesn't `Alignment` store a u8 that represents the exponent, rather than the power? The left-shift when needing the power should be effectively free, shouldn't it? It would avoid all the unsafety in the impl. >> >> FYI, `core` provides `usize::checked_next_multiple_of()` ((const-)stable since 1.73). So an alternative would be: >> >> >> >> pub const fn const_align_up(value: usize, align: Alignment) -> Option { >> >> value.checked_next_multiple_of(align.as_usize()) >> >> } >> > >> > That would return value+align when value is already aligned, which is wrong. >> >> You sure? (emphasis mine:) >> >> "Calculates the smallest value greater than or **EQUAL TO** self that is a multiple of rhs." >> >> assert_eq!(16_u64.next_multiple_of(8), 16); > > Okay, well, weird naming then. Do you need this helper then at all? I assume it is added because `Alignable` cannot be used in const. But it hard-codes `usize` as type, yet does not reflect that in the name. It comes down to which one is more readable, I guess: const_align_up(value, align) vs value.checked_next_multiple_of(align.as_usize()) Meh, I don't mind too much. Just wanted to point out that the standard library provides this exactly. David