From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (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 40E0329ACDB for ; Tue, 20 Jan 2026 08:45:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768898702; cv=none; b=eicrPBqZMeKRaL769MZxp+rCwkUBrECHV/9CJMkbcYO1u3lR9Sl15w9JgSYa4+0N/59QzNEbVZ87pJGyX6gSUWvmQij2v3ogIA/6dkBniJ0hnzQbMGSRgI7ybOwVIYKpI+nGGd1RhTLj2isN8KrfiWCkjaGJRjxsvJSIHs6YVSo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768898702; c=relaxed/simple; bh=Qpwd1/M/Rw40FAF33TwG2APzVY3geA2kI8ExRMKWa+w=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=BirGCQkYm3GQVgC5quzjahO7J2fOFTN/mw+vCDAAOtP8wkg1ROCX6SLJkNBb4NUWjHlVsBigkbWQ7+quuIEQ0CtZmdQxjV+F3gRvuVXt184+A8Sz7ItFWXbF6/Bq+/kdCxXxpYBwNt0Czlpa6TdaQi8XZa6Ds1iGwWWAytkQvQI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=UPM+mKCv; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="UPM+mKCv" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-47edfdc6c1aso41761415e9.3 for ; Tue, 20 Jan 2026 00:45:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1768898698; x=1769503498; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=n5ylyY+HwRwF356rLJJuDIeDsrdRt//o2P/JF3RJnGs=; b=UPM+mKCv2ZLguak0Z4my3VQ2x2IgWwIHDxmvu8PVaQFZTK1EClsl3uv9kLAnEQYzjl XCCT4K5JmQPJVyZSz+5g97+d1rJlOMCVNDdJ1KofYa3w4lqaNHxl9zkgnd1fFL0nXJx8 DGhuUh1p/LPNsZ9MHiYmIHJriJjXQec/rLusZoI8q9YlSkXzdKrnwBUZNFOBwgKkckg8 LNMH1P80Jeefz9f5eyEuEtEnGWr7bOcaQT1+v7TD17OqG6Aff5ncC2enLwKSekZ3TepB yjYe9STOd0sT/oqmH/xyKaW/Jn0bsb3HNsIxx7Gox9uvImof4cMANdp7DL6Q7IAhAB5f O0rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768898698; x=1769503498; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=n5ylyY+HwRwF356rLJJuDIeDsrdRt//o2P/JF3RJnGs=; b=GFa0SXsli0ctA3v08Sg4QckJoMvEu/dRP4J+ksqVnrJLUrjpkXcpuk5GnPtHvUF9RO o0ZH25pfk9wvcxQklAcfcXm5ahML888BHJOP55grvpoWa04T1xdO1MIFkUCDR+u/yJAl fDXhOzDTXcMkNp3Q5nv+MXE2yuNzL1IhfcqQEQm4RHqnMfuazVXnnOAZeBYO98Gm7+Ko P47lDKgqmDHf89gyzNsVewedMAu0NFJKHwfR/KVaAvA92TCv1glChQS7nkJtua//wJvF 7s97Vq4K9yovfJCP5W+Heh1m4/iM1x/37xAvwBDefDr+O/5H1bp0iBAqNm/wiYWKqmyy G3cg== X-Forwarded-Encrypted: i=1; AJvYcCWwH+UpdKKMifuDVgoHezd1nmG94RfygKOmGCpHVxGlWKtHkCPgLapvzgEfZnpYMYJyOqcNpNWjHKlotW8=@vger.kernel.org X-Gm-Message-State: AOJu0YxLLEA1Ena1IMz1Uj04baUSo7gzaY562iDINpUUyj25vtGIrn3t MtrguXse3FrJFuQd1/beRLnDyoSdvdlTEazv83vXZMY8LzyBcoj3C0VpGxR2TEcdlbE9j7+qeoQ KD15wsFHHxYMPeCs5Ew== X-Received: from wmco1.prod.google.com ([2002:a05:600c:a301:b0:47a:8f07:f1ab]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1552:b0:47e:e946:3a72 with SMTP id 5b1f17b1804b1-4801eb0e021mr171763595e9.27.1768898698493; Tue, 20 Jan 2026 00:44:58 -0800 (PST) Date: Tue, 20 Jan 2026 08:44:57 +0000 In-Reply-To: <20260120-register-v1-1-723a1743b557@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260120-register-v1-0-723a1743b557@nvidia.com> <20260120-register-v1-1-723a1743b557@nvidia.com> Message-ID: Subject: Re: [PATCH 1/6] rust: num: add `shr` and `shl` methods to `Bounded` From: Alice Ryhl To: Alexandre Courbot Cc: Miguel Ojeda , Boqun Feng , Gary Guo , "=?utf-8?B?QmrDtnJu?= Roy Baron" , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , Yury Norov , John Hubbard , Alistair Popple , Joel Fernandes , Timur Tabi , Edwin Peer , Eliot Courtney , Daniel Almeida , Dirk Behme , Steven Price , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" On Tue, Jan 20, 2026 at 03:17:54PM +0900, Alexandre Courbot wrote: > Shifting a `Bounded` left or right changes the number of bits required > to represent the value. Add methods that perform the shift and return a > `Bounded` with the appropriately adjusted bit width. > > These methods are particularly useful for bitfield extraction. > > Suggested-by: Alice Ryhl > Signed-off-by: Alexandre Courbot Reviewed-by: Alice Ryhl > + /// Right-shifts `self` by `SHIFT` and returns the result as a `Bounded<_, { N - SHIFT }>`. > + /// > + /// # Examples > + /// > + /// ``` > + /// use kernel::num::Bounded; > + /// > + /// let v = Bounded::::new::<0xff00>(); > + /// let v_shifted: Bounded:: = v.shr::<8, _>(); > + /// > + /// assert_eq!(v_shifted.get(), 0xff); > + /// ``` > + pub fn shr(self) -> Bounded { > + const { assert!(RES == N - SHIFT) } In principle this could be const { assert!(RES >= N - SHIFT) } Alice