[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aQSHVsWGXzigTEMe@smile.fi.intel.com>
Date: Fri, 31 Oct 2025 11:54:30 +0200
From: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To: David Laight <david.laight.linux@...il.com>
Cc: Jonathan Cameron <Jonathan.Cameron@...wei.com>,
linux-iio@...r.kernel.org, linux-kernel@...r.kernel.org,
Jyoti Bhayana <jbhayana@...gle.com>,
Jonathan Cameron <jic23@...nel.org>,
David Lechner <dlechner@...libre.com>,
Nuno Sá <nuno.sa@...log.com>,
Andy Shevchenko <andy@...nel.org>
Subject: Re: [PATCH v1 1/1] iio: common: scmi_sensors: Replace const_ilog2()
with ilog2()
On Fri, Oct 31, 2025 at 09:43:36AM +0000, David Laight wrote:
> On Fri, 31 Oct 2025 08:45:00 +0100
> Andy Shevchenko <andriy.shevchenko@...ux.intel.com> wrote:
...
> > tstamp_scale = sensor->sensor_info->tstamp_scale +
> > - const_ilog2(NSEC_PER_SEC) / const_ilog2(10);
> > + ilog2(NSEC_PER_SEC) / ilog2(10);
>
> Is that just a strange way of writing 9 ?
Why? It's correct way of writing log¹⁰(NSEC_PER_SEC), the problem here is that
"i" people do not think about :-) But we have intlog10(), I completely forgot
about it.
> Mathematically log2(x)/log2(10) is log10(x) - which would be 9.
> The code does seem to be 'in luck' though.
> NSEC_PER_SEC is 10^9 or 0x3b9aca00, so ilog2(NSEC_PER_SEC) is 29.
> ilog2(10) is 3, and 29/3 is 9.
>
> Do the same for 10^10 and you get 11.
That code looks like working by luck entirely, TBH. I just took the scope of
the patch to start dropping const_ilog2() usages.
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists