From: David Laight <david.laight.linux@gmail.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: "Jonathan Cameron" <Jonathan.Cameron@huawei.com>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
"Jyoti Bhayana" <jbhayana@google.com>,
"Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>
Subject: Re: [PATCH v1 1/1] iio: common: scmi_sensors: Replace const_ilog2() with ilog2()
Date: Fri, 31 Oct 2025 12:45:30 +0000 [thread overview]
Message-ID: <20251031124530.3db7805b@pumpkin> (raw)
In-Reply-To: <aQSHVsWGXzigTEMe@smile.fi.intel.com>
On Fri, 31 Oct 2025 11:54:30 +0200
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> 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@linux.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 :-)
Even without the "i" the division could easily give 8.999999.
So you'd be relying on rounding to get the required integral value.
> But we have intlog10(), I completely forgot about it.
And it isn't the function the code is looking for.
(The result is shifted left 24 and it doesn't have an optimisation
for constants.)
>
> > 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.
Something always crawls out of the woodwork...
David
next prev parent reply other threads:[~2025-10-31 12:45 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-31 7:45 [PATCH v1 1/1] iio: common: scmi_sensors: Replace const_ilog2() with ilog2() Andy Shevchenko
2025-10-31 9:43 ` David Laight
2025-10-31 9:54 ` Andy Shevchenko
2025-10-31 12:45 ` David Laight [this message]
2025-10-31 12:51 ` Andy Shevchenko
2025-10-31 16:13 ` David Laight
2025-11-03 8:30 ` Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251031124530.3db7805b@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jbhayana@google.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox