Linux IIO development
 help / color / mirror / Atom feed
From: "Nuno Sá" <noname.nuno@gmail.com>
To: David Lechner <dlechner@baylibre.com>, nuno.sa@analog.com
Cc: linux-iio@vger.kernel.org, Jonathan Cameron <jic23@kernel.org>,
	 Lars-Peter Clausen <lars@metafoo.de>
Subject: Re: [PATCH] iio: core: make use of DIV_ROUND_CLOSEST_ULL()
Date: Tue, 13 Feb 2024 08:51:23 +0100	[thread overview]
Message-ID: <587e7de71aa8131a9a54a8f6e31762aa8ec1d22e.camel@gmail.com> (raw)
In-Reply-To: <CAMknhBGEKJa_q2MD1q++mTAOP9SrJ_WVJv_CBP+s_8PiBgz2eA@mail.gmail.com>

On Mon, 2024-02-12 at 18:02 -0600, David Lechner wrote:
> On Mon, Feb 12, 2024 at 3:07 AM Nuno Sa via B4 Relay
> <devnull+nuno.sa.analog.com@kernel.org> wrote:
> > 
> > From: Nuno Sa <nuno.sa@analog.com>
> > 
> > Instead of open code DIV_ROUND_CLOSEST_ULL(), let's use it.
> > 
> > Signed-off-by: Nuno Sa <nuno.sa@analog.com>
> > ---
> > 1) For some reason IIO_G_TO_M_S_2() does do not a closest division. Not
> >    sure if there's a reason for it or just something that was forgotten.
> >    Anyways, I left it as it was before.
> > 
> > 2) This conversion could actually be required. In some experiments with
> >    it (in a series I'm working on), I actually realized with
> >    IIO_RAD_TO_DEGREE() that  we could have a 64bit division in 32bits
> >    archs. I'm still not treating it as a fix as no one ever complained.
> >    Jonathan, let me know if you want me to send a follow up email (or v2)
> >    with a proper tag.
> > ---
> >  include/linux/iio/iio.h | 9 +++++----
> >  1 file changed, 5 insertions(+), 4 deletions(-)
> > 
> > diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
> > index e370a7bb3300..3ebf9fe97f0e 100644
> > --- a/include/linux/iio/iio.h
> > +++ b/include/linux/iio/iio.h
> > @@ -10,6 +10,7 @@
> >  #include <linux/device.h>
> >  #include <linux/cdev.h>
> >  #include <linux/cleanup.h>
> > +#include <linux/math.h>
> >  #include <linux/slab.h>
> >  #include <linux/iio/types.h>
> >  /* IIO TODO LIST */
> > @@ -799,8 +800,8 @@ int iio_str_to_fixpoint(const char *str, int fract_mult,
> > int *integer,
> >   *
> >   * Returns the given value converted from degree to rad
> >   */
> > -#define IIO_DEGREE_TO_RAD(deg) (((deg) * 314159ULL + 9000000ULL) /
> > 18000000ULL)
> > -
> > +#define IIO_DEGREE_TO_RAD(deg) \
> > +       DIV_ROUND_CLOSEST_ULL((deg) * 314159ULL, 18000000)
> >  /**
> >   * IIO_RAD_TO_DEGREE() - Convert rad to degree
> >   * @rad: A value in rad
> > @@ -808,7 +809,7 @@ int iio_str_to_fixpoint(const char *str, int fract_mult,
> > int *integer,
> >   * Returns the given value converted from rad to degree
> >   */
> >  #define IIO_RAD_TO_DEGREE(rad) \
> > -       (((rad) * 18000000ULL + 314159ULL / 2) / 314159ULL)
> > +       DIV_ROUND_CLOSEST_ULL((rad) * 18000000ULL + 314159)
> 
> Is this supposed to be "," instead of "+"?

Definitely! Obviously I did some mistake preparing the final patch and out of
confidence didn't even built it... Curious why clangd did not complained.
Anyways, thanks! I'll send a v2

- Nuno Sá
> > 


  reply	other threads:[~2024-02-13  7:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-12  9:07 [PATCH] iio: core: make use of DIV_ROUND_CLOSEST_ULL() Nuno Sa via B4 Relay
2024-02-13  0:02 ` David Lechner
2024-02-13  7:51   ` Nuno Sá [this message]
2024-02-13  9:14     ` Nuno Sá

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=587e7de71aa8131a9a54a8f6e31762aa8ec1d22e.camel@gmail.com \
    --to=noname.nuno@gmail.com \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@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