Re: [PATCH v3 next 00/10] Implement mul_u64_u64_div_u64_roundup()
From: Peter Zijlstra
Date: Sat Jun 14 2025 - 06:27:33 EST
On Sat, Jun 14, 2025 at 10:53:36AM +0100, David Laight wrote:
> The pwm-stm32.c code wants a 'rounding up' version of mul_u64_u64_div_u64().
> This can be done simply by adding 'divisor - 1' to the 128bit product.
> Implement mul_u64_add_u64_div_u64(a, b, c, d) = (a * b + c)/d based on the
> existing code.
> Define mul_u64_u64_div_u64(a, b, d) as mul_u64_add_u64_div_u64(a, b, 0, d) and
> mul_u64_u64_div_u64_roundup(a, b, d) as mul_u64_add_u64_div_u64(a, b, d-1, d).
Another way to achieve the same would to to expose the remainder of
mul_u64_64_div_u64(), no?