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

From: Nuno Sá

Date: Mon Mar 23 2026 - 07:23:23 EST


On Mon, 2026-03-16 at 16:07 +0200, Andy Shevchenko wrote:
> 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.

Yes, it goes up to 4.4GHz.

- Nuno Sá

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