From: "Danilo Krummrich" <dakr@kernel.org>
To: "Daniel Almeida" <daniel.almeida@collabora.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
"Alexandre Courbot" <acourbot@nvidia.com>
Subject: Re: [PATCH v9] rust: kernel: add support for bits/genmask macros
Date: Wed, 16 Jul 2025 21:49:12 +0200 [thread overview]
Message-ID: <DBDQNDJDV41H.I58GXBM55PVG@kernel.org> (raw)
In-Reply-To: <1DCA3EA2-5CBB-4193-B1D3-7E286C344A14@collabora.com>
On Wed Jul 16, 2025 at 9:44 PM CEST, Daniel Almeida wrote:
>
>
>> On 16 Jul 2025, at 16:32, Danilo Krummrich <dakr@kernel.org> wrote:
>>
>> On Wed Jul 16, 2025 at 9:11 PM CEST, Daniel Almeida wrote:
>>> Let’s transfer this discussion to this patch.
>>>
>>>> I also quickly tried genmask and I have a few questions:
>>>>
>>>> (1) Why does genmask not use a const generic? I think this makes it more
>>>> obvious that it's only intended to be used from const context.
>>>
>>> I guess none of us thought about it, since the current version also works.
>>
>> I think using a const generic would be a bit better for the mentioned reason.
>
> Btw, how does monomorphization work here? Would we have to codegen all the
> versions? Also, I don't think that you can take a range as a const generic
> argument, i.e., I don't recall ever seeing this syntax:
>
> genmask_u64::<0..=63>();
Ah, of course, it's RangeInclusive, just scratch the const generic proposal. :)
>>>> (2) Why is there no build_assert() when the range exceeds the number of bits
>>>> of the target type? I would expect genmask_u64(0..100) to fail.
>>>
>>> Doesn’t it?
>>>
>>> There is a build_assert in the underlying bit implementation. It was redundant
>>> to have it both in bit_* and in genmask, because genmask calls bit().
>>>
>>> In your example, bit_u64(100) hits that assert, and so it shouldn't compile.
>>
>> Indeed, and it also works, except from doc-tests for some reason, which is what
>> I tried real quick. :)
>>
>
> Wait, this was a bit confusing :)
> You’re confirming that it doesn’t compile, correct?
Yes, except for in doc-tests for some reason.
>> I feel like usize would be a better fit, but not a strong opinion.
>
> I guess this is the same problem as u64: drivers will usually have either
> i32s/u32s and this would require a cast.
I don't understand this argument? We usualy use usize for such things, no?
>
> — Daniel
next prev parent reply other threads:[~2025-07-16 19:49 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-14 23:29 [PATCH v9] rust: kernel: add support for bits/genmask macros Daniel Almeida
2025-07-16 18:38 ` Danilo Krummrich
2025-07-16 19:11 ` Daniel Almeida
2025-07-16 19:18 ` Daniel Almeida
2025-07-16 19:32 ` Danilo Krummrich
2025-07-16 19:44 ` Daniel Almeida
2025-07-16 19:49 ` Danilo Krummrich [this message]
2025-07-16 20:06 ` Danilo Krummrich
2025-07-16 20:07 ` Danilo Krummrich
2025-07-19 22:17 ` Miguel Ojeda
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DBDQNDJDV41H.I58GXBM55PVG@kernel.org \
--to=dakr@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox