Alexandre Courbot
2025-Aug-03 13:13 UTC
[PATCH 1/3] rust: add `num` module with `PowerOfTwo` type
On Sat Aug 2, 2025 at 11:18 PM JST, Miguel Ojeda wrote:> On Sat, Aug 2, 2025 at 4:02?PM Alexandre Courbot <acourbot at nvidia.com> wrote: >> >> Belated thanks for the suggestion; I have finally opened an ACP for >> `last_set_bit` (and `first_set_bit` while we are at it): >> https://github.com/rust-lang/libs-team/issues/631 >> >> I am still entangled with how to best leverage `Alignment` for our >> purposes, but think I am getting close to a v2 of this patchset. > > Thanks for filling that one -- linked now from our usual lists :) > > https://github.com/Rust-for-Linux/linux/issues/514We got some interesting feedback on the ACP already. I have been pointed to `checked_ilog2` as an equivalent of `last_set_bit`, and it *does* indeed work well as a replacement - with the caveat that the name is not very natural to me (or anyone familiar with the C interface). Is this something we can live with? If we decide to go with the existing standard library method, how can we make sure that folks looking for an equivalent of `fls` find `checked_ilog2`?
Miguel Ojeda
2025-Aug-03 15:15 UTC
[PATCH 1/3] rust: add `num` module with `PowerOfTwo` type
On Sun, Aug 3, 2025 at 3:13?PM Alexandre Courbot <acourbot at nvidia.com> wrote:> > We got some interesting feedback on the ACP already. I have been pointed > to `checked_ilog2` as an equivalent of `last_set_bit`, and it *does* > indeed work well as a replacement - with the caveat that the name is > not very natural to me (or anyone familiar with the C interface). Is > this something we can live with? If we decide to go with the existing > standard library method, how can we make sure that folks looking for an > equivalent of `fls` find `checked_ilog2`?One option is using the `doc(alias = ...)` attribute, which makes it appear in the search in the rendered docs, and would show easily in greps too. Another option is simply wrapping it in an `inline(always)`, I guess, but I think we can just use the upstream ones, unless we want slightly different semantics. Cheers, Miguel
Alexandre Courbot
2025-Aug-04 07:32 UTC
[PATCH 1/3] rust: add `num` module with `PowerOfTwo` type
On Mon Aug 4, 2025 at 12:15 AM JST, Miguel Ojeda wrote:> On Sun, Aug 3, 2025 at 3:13?PM Alexandre Courbot <acourbot at nvidia.com> wrote: >> >> We got some interesting feedback on the ACP already. I have been pointed >> to `checked_ilog2` as an equivalent of `last_set_bit`, and it *does* >> indeed work well as a replacement - with the caveat that the name is >> not very natural to me (or anyone familiar with the C interface). Is >> this something we can live with? If we decide to go with the existing >> standard library method, how can we make sure that folks looking for an >> equivalent of `fls` find `checked_ilog2`? > > One option is using the `doc(alias = ...)` attribute, which makes it > appear in the search in the rendered docs, and would show easily in > greps too. > > Another option is simply wrapping it in an `inline(always)`, I guess, > but I think we can just use the upstream ones, unless we want slightly > different semantics.That would be useful - let's see what the Rust lib folks say, as you brought up that question on the ACP as well. In any case, since we have reasonable alternatives for both `fls` (`checked_ilog2`) and `ffs` (`NonZero::trailing_zeros`), I guess this means we want to use these directly in the kernel and can drop patch 2 of this series?