* Re: [PATCH v3 1/5] rust: extract `bitfield!` macro from `register!`
[not found] ` <20260501-bitfield-v3-1-aa1076c3337d@nvidia.com>
@ 2026-05-11 16:34 ` Gary Guo
0 siblings, 0 replies; only message in thread
From: Gary Guo @ 2026-05-11 16:34 UTC (permalink / raw)
To: Alexandre Courbot, Joel Fernandes, Yury Norov, Miguel Ojeda,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
Daniel Almeida, David Airlie, Simona Vetter
Cc: John Hubbard, Alistair Popple, Timur Tabi, Zhi Wang,
Eliot Courtney, linux-kernel, rust-for-linux, nova-gpu,
driver-core, Yury Norov
On Fri May 1, 2026 at 7:03 AM BST, Alexandre Courbot wrote:
> + // Private field accessors working with the exact `Bounded` type for the field.
> + (
> + @private_field_accessors $vis:vis $name:ident $storage:ty : $hi:tt:$lo:tt $field:ident
> + ) => {
> + ::kernel::macros::paste!(
> + $vis const [<$field:upper _RANGE>]: ::core::ops::RangeInclusive<u8> = $lo..=$hi;
> + $vis const [<$field:upper _MASK>]: $storage =
> + ((((1 << $hi) - 1) << 1) + 1) - ((1 << $lo) - 1);
> + $vis const [<$field:upper _SHIFT>]: u32 = $lo;
> + );
> +
> + ::kernel::macros::paste!(
> + fn [<__ $field>](self) ->
This and the __with_ methods are missing inline annotations. I'm witnessing
these functions showing up in the vmlinux uninlined. (To be fair, this is an
existing issue because the `register!` macro generated onces are also showing up).
Best,
Gary
> + ::kernel::num::Bounded<$storage, { $hi + 1 - $lo }> {
> + // Left shift to align the field's MSB with the storage MSB.
> + const ALIGN_TOP: u32 = $storage::BITS - ($hi + 1);
> + // Right shift to move the top-aligned field to bit 0 of the storage.
> + const ALIGN_BOTTOM: u32 = ALIGN_TOP + $lo;
> +
> + // Extract the field using two shifts. `Bounded::shr` produces the correctly-sized
> + // output type.
> + let val = ::kernel::num::Bounded::<$storage, { $storage::BITS }>::from(
> + self.inner << ALIGN_TOP
> + );
> + val.shr::<ALIGN_BOTTOM, { $hi + 1 - $lo } >()
> + }
> +
> + const fn [<__with_ $field>](
> + mut self,
> + value: ::kernel::num::Bounded<$storage, { $hi + 1 - $lo }>,
> + ) -> Self
> + {
> + const MASK: $storage = <$name>::[<$field:upper _MASK>];
> + const SHIFT: u32 = <$name>::[<$field:upper _SHIFT>];
> +
> + let value = value.get() << SHIFT;
> + self.inner = (self.inner & !MASK) | value;
> +
> + self
> + }
> + );
> + };
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-05-11 16:34 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20260501-bitfield-v3-0-aa1076c3337d@nvidia.com>
[not found] ` <20260501-bitfield-v3-1-aa1076c3337d@nvidia.com>
2026-05-11 16:34 ` [PATCH v3 1/5] rust: extract `bitfield!` macro from `register!` Gary Guo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox