diff mbox series

clk: sunxi-ng: mp: Avoid computing the rate twice

Message ID 20220810014024.27568-1-samuel@sholland.org (mailing list archive)
State Awaiting Upstream, archived
Headers show
Series clk: sunxi-ng: mp: Avoid computing the rate twice | expand

Commit Message

Samuel Holland Aug. 10, 2022, 1:40 a.m. UTC
ccu_mp_find_best() already computes a best_rate at the same time as the
best m and p factors. Return it so the caller does not need to duplicate
the division.

Signed-off-by: Samuel Holland <samuel@sholland.org>
---

 drivers/clk/sunxi-ng/ccu_mp.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

Comments

Jernej Škrabec Aug. 14, 2022, 10:02 a.m. UTC | #1
Dne sreda, 10. avgust 2022 ob 03:40:24 CEST je Samuel Holland napisal(a):
> ccu_mp_find_best() already computes a best_rate at the same time as the
> best m and p factors. Return it so the caller does not need to duplicate
> the division.
> 
> Signed-off-by: Samuel Holland <samuel@sholland.org>

Reviewed-by: Jernej Skrabec <jernej.skrabec@gmail.com>

Other ccu_*_find_best() functions would also benefit with similar change.

Best regards,
Jernej
Stephen Boyd Aug. 15, 2022, 5:26 p.m. UTC | #2
Quoting Samuel Holland (2022-08-09 18:40:24)
> ccu_mp_find_best() already computes a best_rate at the same time as the
> best m and p factors. Return it so the caller does not need to duplicate
> the division.

Did the compiler figure this out and thus this patch makes no difference
to the final object code?
Samuel Holland Dec. 31, 2022, 5:21 p.m. UTC | #3
Hi Stephen,

On 8/15/22 12:26, Stephen Boyd wrote:
> Quoting Samuel Holland (2022-08-09 18:40:24)
>> ccu_mp_find_best() already computes a best_rate at the same time as the
>> best m and p factors. Return it so the caller does not need to duplicate
>> the division.
> 
> Did the compiler figure this out and thus this patch makes no difference
> to the final object code?

It makes a difference at least on my gcc version 11.1.0.

Before:
   text    data     bss     dec     hex filename
  18257      12       0   18269    475d drivers/clk/sunxi-ng/sunxi-ccu.o

After:
   text    data     bss     dec     hex filename
  18083      12       0   18095    46af drivers/clk/sunxi-ng/sunxi-ccu.o

I will send a v2 covering all of the CCU clock types.

Regards,
Samuel
diff mbox series

Patch

diff --git a/drivers/clk/sunxi-ng/ccu_mp.c b/drivers/clk/sunxi-ng/ccu_mp.c
index 57cf2d615148..cc94a694cb67 100644
--- a/drivers/clk/sunxi-ng/ccu_mp.c
+++ b/drivers/clk/sunxi-ng/ccu_mp.c
@@ -10,9 +10,9 @@ 
 #include "ccu_gate.h"
 #include "ccu_mp.h"
 
-static void ccu_mp_find_best(unsigned long parent, unsigned long rate,
-			     unsigned int max_m, unsigned int max_p,
-			     unsigned int *m, unsigned int *p)
+static unsigned long ccu_mp_find_best(unsigned long parent, unsigned long rate,
+				      unsigned int max_m, unsigned int max_p,
+				      unsigned int *m, unsigned int *p)
 {
 	unsigned long best_rate = 0;
 	unsigned int best_m = 0, best_p = 0;
@@ -35,6 +35,8 @@  static void ccu_mp_find_best(unsigned long parent, unsigned long rate,
 
 	*m = best_m;
 	*p = best_p;
+
+	return best_rate;
 }
 
 static unsigned long ccu_mp_find_best_with_parent_adj(struct clk_hw *hw,
@@ -109,8 +111,7 @@  static unsigned long ccu_mp_round_rate(struct ccu_mux_internal *mux,
 	max_p = cmp->p.max ?: 1 << ((1 << cmp->p.width) - 1);
 
 	if (!clk_hw_can_set_rate_parent(&cmp->common.hw)) {
-		ccu_mp_find_best(*parent_rate, rate, max_m, max_p, &m, &p);
-		rate = *parent_rate / p / m;
+		rate = ccu_mp_find_best(*parent_rate, rate, max_m, max_p, &m, &p);
 	} else {
 		rate = ccu_mp_find_best_with_parent_adj(hw, parent_rate, rate,
 							max_m, max_p);