Rust's `checked_ilog2` is in effect equivalent to the C `fls` operation, with the exception that its result is zero-indexed. This means we don't have a good basis to introduce an equivalent of `fls` on our own.
Convert the relevant Nova code to use `checked_ilog2`, and remove the corresponding TODO item. Signed-off-by: Alexandre Courbot <[email protected]> --- Documentation/gpu/nova/core/todo.rst | 14 -------------- drivers/gpu/nova-core/falcon/hal/ga102.rs | 4 ++-- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/Documentation/gpu/nova/core/todo.rst b/Documentation/gpu/nova/core/todo.rst index 8fdb5bced3460a3971699df79ffa2c69f84b2735..01dfa858d11fe377c345b463742c13c37878e334 100644 --- a/Documentation/gpu/nova/core/todo.rst +++ b/Documentation/gpu/nova/core/todo.rst @@ -141,20 +141,6 @@ Features desired before this happens: | Complexity: Advanced | Contact: Alexandre Courbot -Numerical operations [NUMM] ---------------------------- - -Nova uses integer operations that are not part of the standard library (or not -implemented in an optimized way for the kernel). These include: - -- The "Find Last Set Bit" (`fls` function of the C part of the kernel) - operation. - -A `num` core kernel module is being designed to provide these operations. - -| Complexity: Intermediate -| Contact: Alexandre Courbot - Delay / Sleep abstractions [DLAY] --------------------------------- diff --git a/drivers/gpu/nova-core/falcon/hal/ga102.rs b/drivers/gpu/nova-core/falcon/hal/ga102.rs index 52c33d3f22a8e920742b45940c346c47fdc70e93..430a511aa1f85477690e78cdc1104f0e0097b0e4 100644 --- a/drivers/gpu/nova-core/falcon/hal/ga102.rs +++ b/drivers/gpu/nova-core/falcon/hal/ga102.rs @@ -69,8 +69,8 @@ fn signature_reg_fuse_version_ga102( let reg_fuse_version = bar.read32(reg_fuse_base + ((ucode_id - 1) as usize * core::mem::size_of::<u32>())); - // TODO[NUMM]: replace with `last_set_bit` once it lands. - Ok(u32::BITS - reg_fuse_version.leading_zeros()) + // The original C code performs a `fls`; this is equivalent. + Ok(reg_fuse_version.checked_ilog2().map_or(0, |v| v + 1)) } fn program_brom_ga102<E: FalconEngine>(bar: &Bar0, params: &FalconBromParams) -> Result { -- 2.50.1
