linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] m68k: One function call less in cf_tlb_miss()
@ 2019-07-05 15:18 Markus Elfring
  2019-07-05 23:56 ` Finn Thain
  0 siblings, 1 reply; 6+ messages in thread
From: Markus Elfring @ 2019-07-05 15:18 UTC (permalink / raw)
  To: linux-m68k, Andrew Morton, Geert Uytterhoeven, Greg Ungerer,
	Michal Hocko, Mike Rapoport
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 5 Jul 2019 17:11:37 +0200

Avoid an extra function call by using a ternary operator instead of
a conditional statement for a setting selection.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/m68k/mm/mcfmmu.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/arch/m68k/mm/mcfmmu.c b/arch/m68k/mm/mcfmmu.c
index 6cb1e41d58d0..02fc0778028e 100644
--- a/arch/m68k/mm/mcfmmu.c
+++ b/arch/m68k/mm/mcfmmu.c
@@ -146,12 +146,10 @@ int cf_tlb_miss(struct pt_regs *regs, int write, int dtlb, int extension_word)

 	mmu_write(MMUDR, (pte_val(*pte) & PAGE_MASK) |
 		((pte->pte) & CF_PAGE_MMUDR_MASK) | MMUDR_SZ_8KB | MMUDR_X);
-
-	if (dtlb)
-		mmu_write(MMUOR, MMUOR_ACC | MMUOR_UAA);
-	else
-		mmu_write(MMUOR, MMUOR_ITLB | MMUOR_ACC | MMUOR_UAA);
-
+	mmu_write(MMUOR,
+		  dtlb
+		  ? MMUOR_ACC | MMUOR_UAA
+		  : MMUOR_ITLB | MMUOR_ACC | MMUOR_UAA);
 	local_irq_restore(flags);
 	return 0;
 }
--
2.22.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] m68k: One function call less in cf_tlb_miss()
  2019-07-05 15:18 [PATCH] m68k: One function call less in cf_tlb_miss() Markus Elfring
@ 2019-07-05 23:56 ` Finn Thain
  2019-07-14 13:23   ` Geert Uytterhoeven
  0 siblings, 1 reply; 6+ messages in thread
From: Finn Thain @ 2019-07-05 23:56 UTC (permalink / raw)
  To: Markus Elfring
  Cc: linux-m68k, Andrew Morton, Geert Uytterhoeven, Greg Ungerer,
	Michal Hocko, Mike Rapoport, LKML, kernel-janitors


On Fri, 5 Jul 2019, Markus Elfring wrote:

> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Fri, 5 Jul 2019 17:11:37 +0200
> 
> Avoid an extra function call 

Not really. You've avoided an extra statement.

> by using a ternary operator instead of a conditional statement for a 
> setting selection.
> 
> This issue was detected by using the Coccinelle software.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>  arch/m68k/mm/mcfmmu.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/m68k/mm/mcfmmu.c b/arch/m68k/mm/mcfmmu.c
> index 6cb1e41d58d0..02fc0778028e 100644
> --- a/arch/m68k/mm/mcfmmu.c
> +++ b/arch/m68k/mm/mcfmmu.c
> @@ -146,12 +146,10 @@ int cf_tlb_miss(struct pt_regs *regs, int write, int dtlb, int extension_word)
> 
>  	mmu_write(MMUDR, (pte_val(*pte) & PAGE_MASK) |
>  		((pte->pte) & CF_PAGE_MMUDR_MASK) | MMUDR_SZ_8KB | MMUDR_X);
> -
> -	if (dtlb)
> -		mmu_write(MMUOR, MMUOR_ACC | MMUOR_UAA);
> -	else
> -		mmu_write(MMUOR, MMUOR_ITLB | MMUOR_ACC | MMUOR_UAA);
> -
> +	mmu_write(MMUOR,
> +		  dtlb
> +		  ? MMUOR_ACC | MMUOR_UAA
> +		  : MMUOR_ITLB | MMUOR_ACC | MMUOR_UAA);

If you are trying to avoid redundancy, why not finish the job?

+     mmu_write(MMUOR, (dtlb ? 0 : MMUOR_ITLB) | MMUOR_ACC | MMUOR_UAA);

-- 

>  	local_irq_restore(flags);
>  	return 0;
>  }
> --
> 2.22.0
> 
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] m68k: One function call less in cf_tlb_miss()
  2019-07-05 23:56 ` Finn Thain
@ 2019-07-14 13:23   ` Geert Uytterhoeven
  2019-07-14 16:05     ` Markus Elfring
  0 siblings, 1 reply; 6+ messages in thread
From: Geert Uytterhoeven @ 2019-07-14 13:23 UTC (permalink / raw)
  To: Markus Elfring
  Cc: Finn Thain, Andrew Morton, Greg Ungerer, Michal Hocko,
	Mike Rapoport, linux-m68k, LKML, kernel-janitors

Hi Markus,

On Sat, Jul 6, 2019 at 1:57 AM Finn Thain <fthain@telegraphics.com.au> wrote:
> On Fri, 5 Jul 2019, Markus Elfring wrote:
> > From: Markus Elfring <elfring@users.sourceforge.net>
> > Date: Fri, 5 Jul 2019 17:11:37 +0200
> >
> > Avoid an extra function call
> > by using a ternary operator instead of a conditional statement for a
> > setting selection.

Have you looked at the actual assembler output generated by the compiler?

> > This issue was detected by using the Coccinelle software.
> >
> > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> > ---
> >  arch/m68k/mm/mcfmmu.c | 10 ++++------
> >  1 file changed, 4 insertions(+), 6 deletions(-)
> >
> > diff --git a/arch/m68k/mm/mcfmmu.c b/arch/m68k/mm/mcfmmu.c
> > index 6cb1e41d58d0..02fc0778028e 100644
> > --- a/arch/m68k/mm/mcfmmu.c
> > +++ b/arch/m68k/mm/mcfmmu.c
> > @@ -146,12 +146,10 @@ int cf_tlb_miss(struct pt_regs *regs, int write, int dtlb, int extension_word)
> >
> >       mmu_write(MMUDR, (pte_val(*pte) & PAGE_MASK) |
> >               ((pte->pte) & CF_PAGE_MMUDR_MASK) | MMUDR_SZ_8KB | MMUDR_X);
> > -
> > -     if (dtlb)
> > -             mmu_write(MMUOR, MMUOR_ACC | MMUOR_UAA);
> > -     else
> > -             mmu_write(MMUOR, MMUOR_ITLB | MMUOR_ACC | MMUOR_UAA);
> > -
> > +     mmu_write(MMUOR,
> > +               dtlb
> > +               ? MMUOR_ACC | MMUOR_UAA
> > +               : MMUOR_ITLB | MMUOR_ACC | MMUOR_UAA);

While the ternary operator can be useful for short expressions, it can
also lead to hard-to-read code.  IMHO the latter is the case here
(hint: the expression needs 3 lines).

> If you are trying to avoid redundancy, why not finish the job?
>
> +     mmu_write(MMUOR, (dtlb ? 0 : MMUOR_ITLB) | MMUOR_ACC | MMUOR_UAA);

Thanks Finn, much better!

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: m68k: One function call less in cf_tlb_miss()
  2019-07-14 13:23   ` Geert Uytterhoeven
@ 2019-07-14 16:05     ` Markus Elfring
  2019-07-14 21:14       ` Geert Uytterhoeven
  0 siblings, 1 reply; 6+ messages in thread
From: Markus Elfring @ 2019-07-14 16:05 UTC (permalink / raw)
  To: Geert Uytterhoeven, linux-m68k, kernel-janitors
  Cc: Finn Thain, Andrew Morton, Greg Ungerer, Michal Hocko,
	Mike Rapoport, LKML

>>> Avoid an extra function call by using a ternary operator
>>> instead of a conditional statement for a setting selection.
>
> Have you looked at the actual assembler output generated by the compiler?

Not yet.

* Can the suggested small refactoring matter for a specific software combination there?

* Would you like to clarify this change possibility a bit more?

Regards,
Markus

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: m68k: One function call less in cf_tlb_miss()
  2019-07-14 16:05     ` Markus Elfring
@ 2019-07-14 21:14       ` Geert Uytterhoeven
  2019-07-15  6:11         ` Markus Elfring
  0 siblings, 1 reply; 6+ messages in thread
From: Geert Uytterhoeven @ 2019-07-14 21:14 UTC (permalink / raw)
  To: Markus Elfring
  Cc: linux-m68k, kernel-janitors, Finn Thain, Andrew Morton,
	Greg Ungerer, Michal Hocko, Mike Rapoport, LKML

Hi Markus,

On Sun, Jul 14, 2019 at 6:06 PM Markus Elfring <Markus.Elfring@web.de> wrote:
> >>> Avoid an extra function call by using a ternary operator
> >>> instead of a conditional statement for a setting selection.
> >
> > Have you looked at the actual assembler output generated by the compiler?
>
> Not yet.

You better do, it can be a good learning experience!

> * Can the suggested small refactoring matter for a specific software combination there?
> * Would you like to clarify this change possibility a bit more?

-EPARSE

No need to relay my emails through https://en.wikipedia.org/wiki/ELIZA ;-)

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: m68k: One function call less in cf_tlb_miss()
  2019-07-14 21:14       ` Geert Uytterhoeven
@ 2019-07-15  6:11         ` Markus Elfring
  0 siblings, 0 replies; 6+ messages in thread
From: Markus Elfring @ 2019-07-15  6:11 UTC (permalink / raw)
  To: Geert Uytterhoeven, linux-m68k, kernel-janitors
  Cc: Finn Thain, Andrew Morton, Greg Ungerer, Michal Hocko,
	Mike Rapoport, LKML

> You better do,

It can eventually happen again under other circumstances.


> it can be a good learning experience!

This can be also possible.


>> * Can the suggested small refactoring matter for a specific software combination there?
>> * Would you like to clarify this change possibility a bit more?
>
> -EPARSE

I am curious where you got parsing (or more understanding) difficulties
for these questions.

Regards,
Markus

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-07-15  6:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-05 15:18 [PATCH] m68k: One function call less in cf_tlb_miss() Markus Elfring
2019-07-05 23:56 ` Finn Thain
2019-07-14 13:23   ` Geert Uytterhoeven
2019-07-14 16:05     ` Markus Elfring
2019-07-14 21:14       ` Geert Uytterhoeven
2019-07-15  6:11         ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).