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:32:47 +0200 [thread overview]
Message-ID: <DBDQASMSS32U.FJBYKS3LWEQ6@kernel.org> (raw)
In-Reply-To: <705CD461-60D9-492E-B82F-C88A848A4348@collabora.com>
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.
>>
>> (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. :)
>> (3) OOC, why did you choose u32 as argument type?
>
> No reason. i32 is the default integer type and signed integers don’t make
> sense here, so I chose u32.
>
> Also, we can trivially promote integers to wider types, but the other way
> around is not true. So my reasoning was that if you had u8, or u16s you could
> trivially get u32s using into(), but if you had u32s and e.g. genmask_u16
> required u16s, you'd have to resort to try_into() or `as`, which is annoying.
>
> In any case, feel free to suggest anything else, I think.
I feel like usize would be a better fit, but not a strong opinion.
next prev parent reply other threads:[~2025-07-16 19:32 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 [this message]
2025-07-16 19:44 ` Daniel Almeida
2025-07-16 19:49 ` Danilo Krummrich
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=DBDQASMSS32U.FJBYKS3LWEQ6@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