[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aFvf4c6Jp-cgBssA@smile.fi.intel.com>
Date: Wed, 25 Jun 2025 14:39:13 +0300
From: Andy Shevchenko <andriy.shevchenko@...el.com>
To: Christian Marangi <ansuelsmth@...il.com>
Cc: Uwe Kleine-König <ukleinek@...nel.org>,
linux-kernel@...r.kernel.org, linux-pwm@...r.kernel.org
Subject: Re: [PATCH v16 1/2] math64.h: provide rounddown_u64 variant for
rounddown macro
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
Powered by blists - more mailing lists