Re: [PATCH v5 3/6] math64: New DIV64_U64_ROUND_CLOSEST helper

2019-02-11 Thread Geert Uytterhoeven
On Mon, Feb 11, 2019 at 4:22 PM Sergei Shtylyov
 wrote:
> On 02/11/2019 04:58 PM, Simon Horman wrote:
> > Provide DIV64_U64_ROUND_CLOSEST helper which performs division rounded to
> > the closes integer using an unsigned 64bit dividend and divisor.
>
>Closest?
>
> > This will be used in a follow-up patch to allow calculation of clock
> > divisors with high frequency parents in the R-Car Gen3 CPG MSSR driver
> > where ovefolow occurs if either the dividend or divisor is 32bit.

overflow

> > Signed-off-by: Simon Horman 

With the above fixed:
Reviewed-by: Geert Uytterhoeven 

Note that I can fix the above while applying to my clk-renesas branch.

Andrew: an Acked-by would be appreciated.
Thanks!

Gr{oetje,eeting}s,

Geert


--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds


Re: [PATCH v5 3/6] math64: New DIV64_U64_ROUND_CLOSEST helper

2019-02-11 Thread Sergei Shtylyov
On 02/11/2019 04:58 PM, Simon Horman wrote:

> Provide DIV64_U64_ROUND_CLOSEST helper which performs division rounded to
> the closes integer using an unsigned 64bit dividend and divisor.

   Closest?

> This will be used in a follow-up patch to allow calculation of clock
> divisors with high frequency parents in the R-Car Gen3 CPG MSSR driver
> where ovefolow occurs if either the dividend or divisor is 32bit.
> 
> Signed-off-by: Simon Horman 
[...]

MBR, Sergei


[PATCH v5 3/6] math64: New DIV64_U64_ROUND_CLOSEST helper

2019-02-11 Thread Simon Horman
Provide DIV64_U64_ROUND_CLOSEST helper which performs division rounded to
the closes integer using an unsigned 64bit dividend and divisor.

This will be used in a follow-up patch to allow calculation of clock
divisors with high frequency parents in the R-Car Gen3 CPG MSSR driver
where ovefolow occurs if either the dividend or divisor is 32bit.

Signed-off-by: Simon Horman 
---
v5: New separate patch to add DIV64_U64_ROUND_CLOSEST
---
 include/linux/math64.h | 13 +
 1 file changed, 13 insertions(+)

diff --git a/include/linux/math64.h b/include/linux/math64.h
index bb2c84afb80c..65bef21cdddb 100644
--- a/include/linux/math64.h
+++ b/include/linux/math64.h
@@ -284,4 +284,17 @@ static inline u64 mul_u64_u32_div(u64 a, u32 mul, u32 
divisor)
 #define DIV64_U64_ROUND_UP(ll, d)  \
({ u64 _tmp = (d); div64_u64((ll) + _tmp - 1, _tmp); })
 
+/**
+ * DIV64_U64_ROUND_CLOSEST - unsigned 64bit divide with 64bit divisor rounded 
to nearest integer
+ * @dividend: unsigned 64bit dividend
+ * @divisor: unsigned 64bit divisor
+ *
+ * Divide unsigned 64bit dividend by unsigned 64bit divisor
+ * and round to closest integer.
+ *
+ * Return: dividend / divisor rounded to nearest integer
+ */
+#define DIV64_U64_ROUND_CLOSEST(dividend, divisor) \
+   ({ u64 _tmp = (divisor); div64_u64((dividend) + _tmp / 2, _tmp); })
+
 #endif /* _LINUX_MATH64_H */
-- 
2.11.0