Re: [PATCH v2] iio: frequency: adf4350: replace loop with fls_long()

From: Andy Shevchenko

Date: Mon Mar 16 2026 - 10:15:47 EST


On Mon, Mar 16, 2026 at 01:51:51PM +0000, David Laight wrote:
> On Sat, 14 Mar 2026 13:20:06 -0400
> Neel Bullywon <neelb2403@xxxxxxxxx> wrote:
>
> > Address the TODO in adf4350_set_freq() by replacing the iterative
> > power-of-2 shift loop with a constant-time bitwise calculation.
> >
> > By comparing the highest set bits of the target constant and freq
> > using fls_long(), we can calculate the required RF divider selection
> > in a single step without relying on expensive 64-bit division.
>
> Where is the 64bit division?
> (apart from in v1)
> Indeed where are the 64bit values at all.
> If this code is used on 32bit it has to work with a 32bit long.
> Which makes be think that the 'freq' variable should be u32 (or possibly u64
> if frequencies above 4GHz are likely - which I doubt).

I don't know about _this_ device, but before looking into datasheet I wouldn't
put a low probability on the frequencies higher than 4.3GHz. We have (or going
to have) devices that work with up to 26GHz frequencies in this folder.

> In any case this looks like initialisation code and the existing loop
> has the advantage of being 'obviously correct' and small.

--
With Best Regards,
Andy Shevchenko