m68k: One function call less in cf_tlb_miss()
Subsystems (2)
PATCH 1/1 m68k: One function call less in cf_tlb_miss()
From: Markus Elfring <[email protected]>
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.
--- arch/m68k/mm/mcfmmu.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
arch/m68k/mm/mcfmmu.c +4 -6
@@ -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
Quoted 4 lines · Markus Elfring
From: Markus Elfring <[email protected]>
Date: Fri, 5 Jul 2019 17:11:37 +0200Avoid an extra function call
Not really. You've avoided an extra statement.
Quoted 18 lines
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 <[email protected]>--- arch/m68k/mm/mcfmmu.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)arch/m68k/mm/mcfmmu.c +0
-0@@ -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 );
arch/m68k/mm/mcfmmu.c int cf_tlb_miss(struct pt_regs *regs, int write, int dtlb, int extension_word) · line 152
Quoted 10 lines
arch/m68k/mm/mcfmmu.c +4
-6- -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);
Quoted 7 lines
arch/m68k/mm/mcfmmu.c +0
-1local_irq_restore (flags);return 0 ; } --2.22.0
Geert Uytterhoeven
maintainerHi Markus,
Quoted 7 lines · Finn Thain
Quoted 6 lines · Markus Elfring
From: Markus Elfring <[email protected]>
Date: Fri, 5 Jul 2019 17:11:37 +0200Avoid 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?
Quoted 13 lines
Quoted 13 lines
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- arch/m68k/mm/mcfmmu.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)arch/m68k/mm/mcfmmu.c +0
-0@@ -146,12 +146,10 @@ int cf_tlb_miss(struct pt_regs *regs, int write, int dtlb, int extension_word)
Quoted 12 lines
arch/m68k/mm/mcfmmu.c int cf_tlb_miss(struct pt_regs *regs, int write, int dtlb, int extension_word) · line 152
Quoted 12 lines
arch/m68k/mm/mcfmmu.c +4
-6mmu_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).
Quoted 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
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] 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
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
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
Geert Uytterhoeven
maintainerHi Markus,
Quoted 6 lines · Markus Elfring
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
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!
Quoted 2 lines
* 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
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] 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
Quoted 1 line
You better do,
It can eventually happen again under other circumstances.
Quoted 1 line
it can be a good learning experience!
This can be also possible.
Quoted 4 lines
Quoted 2 lines
* 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