From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Christian Marangi <ansuelsmth@gmail.com>
Cc: "Uwe Kleine-König" <ukleinek@kernel.org>,
linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org
Subject: Re: [PATCH v16 1/2] math64.h: provide rounddown_u64 variant for rounddown macro
Date: Wed, 25 Jun 2025 14:39:13 +0300 [thread overview]
Message-ID: <aFvf4c6Jp-cgBssA@smile.fi.intel.com> (raw)
In-Reply-To: <20250625000059.20040-1-ansuelsmth@gmail.com>
On Wed, Jun 25, 2025 at 02:00:38AM +0200, Christian Marangi wrote:
> There is currently a problem with the usage of rounddown() macro with
> u64 dividends. This causes compilation error on specific arch where
> 64-bit division is done on 32-bit system.
>
> To be more specific GCC try to optimize the function and replace it
> with __umoddi3() but this is actually not compiled in the kernel.
>
> Example:
> pwm-airoha.c:(.text+0x8f8): undefined reference to `__umoddi3'
>
> To better handle this, introduce a variant of rounddown() macro,
> rounddown_u64() that can be used exactly for this scenario.
>
> The new rounddown_u64() in math64.h uses do_div() to do the heavy work
> of handling internally all the magic for the 64-bit division on 32-bit
> (and indirectly fix the compilation error).
...
> static inline u64 roundup_u64(u64 x, u32 y)
> {
> return DIV_U64_ROUND_UP(x, y) * y;
> }
...
> +static inline u64 rounddown_u64(u64 x, u32 y)
> +{
> + u64 tmp = x;
> + return x - do_div(tmp, y);
> +}
Can it be implemented as above?
return DIV_U64_ROUND_DOWN(x, y) * y;
(yes, it seems we are missing the DIV_U64_ROUND_DOWN() implementation).
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2025-06-25 11:39 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-25 0:00 Christian Marangi
2025-06-25 0:00 ` [PATCH v16 2/2] pwm: airoha: Add support for EN7581 SoC Christian Marangi
2025-06-25 7:24 ` Uwe Kleine-König
2025-06-25 7:40 ` Christian Marangi
2025-06-25 11:18 ` Andy Shevchenko
2025-06-25 12:01 ` Christian Marangi
2025-06-25 14:05 ` Uwe Kleine-König
2025-06-25 11:39 ` Andy Shevchenko [this message]
2025-06-25 13:16 ` [PATCH v16 1/2] math64.h: provide rounddown_u64 variant for rounddown macro Christian Marangi
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=aFvf4c6Jp-cgBssA@smile.fi.intel.com \
--to=andriy.shevchenko@intel.com \
--cc=ansuelsmth@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=ukleinek@kernel.org \
/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
all inboxes | Powered by JetHome®