lm32: optimize irqflags.h for size arch_local_irq_disable and arch_local_irq_save are both not optimal regarding code size. This patch reduces their size by removing unnecessary instructions.
Since those functions are used inline throughout the whole kernel this patch reduces the size of a typical kernel image by 16k. We could eliminate one further instruction in either arch_local_irq_restore or arch_local_irq_save by assuming that only values which are returned by arch_local_irq_save are passed to arch_local_irq_restore. This should be a valid assumption, but the extra instruction is left in for now to be on the save side. Signed-off-by: Lars-Peter Clausen <[email protected]> --- arch/lm32/include/asm/irqflags.h | 31 +++++++++++++++++-------------- 1 files changed, 17 insertions(+), 14 deletions(-) diff --git a/arch/lm32/include/asm/irqflags.h b/arch/lm32/include/asm/irqflags.h index eee1d66..ff7688f 100644 --- a/arch/lm32/include/asm/irqflags.h +++ b/arch/lm32/include/asm/irqflags.h @@ -3,30 +3,33 @@ static inline void arch_local_irq_disable(void) { - unsigned int old_ie, new_ie; + unsigned int ie; asm volatile ( - "mvi %0,0xfffffffe\n" \ - "rcsr %1, IE\n" \ - "and %0, %1, %0\n" \ + "rcsr %0, IE\n" \ + "andi %0, %0, 0xfffe\n" \ "wcsr IE, %0\n" \ - "andi %1, %1, 1\n" \ - : "=r"(new_ie), "=r"(old_ie) \ + : "=r"(ie) \ ); - return; } static inline unsigned long arch_local_save_flags(void) { - unsigned long flags; - asm volatile ("rcsr %0, IE\n" : "=r" (flags)); - return flags; + unsigned long ie; + asm volatile ("rcsr %0, IE\n" : "=r" (ie)); + return ie; } static inline unsigned long arch_local_irq_save(void) { - unsigned long flags = arch_local_save_flags(); - arch_local_irq_disable(); - return flags; + unsigned int old_ie, new_ie; + asm volatile ( + "rcsr %1, IE\n" \ + "andi %0, %1, 0xfffe\n" \ + "wcsr IE, %0\n" \ + "andi %1, %1, 1\n" \ + : "=r"(new_ie), "=r"(old_ie) \ + ); + return old_ie; } static inline void arch_local_irq_enable(void) @@ -43,9 +46,9 @@ static inline void arch_local_irq_restore(unsigned long flags) { unsigned int ie; asm volatile ( \ + "andi %1, %1, 0x0001\n" \ "rcsr %0, IE\n" \ "andi %0, %0, 0xfffe\n" \ - "andi %1, %1, 0x0001\n" \ "or %0, %0, %1\n" \ "wcsr IE, %0\n": \ "=&r" (ie): "r" (flags) ); -- 1.7.2.3 _______________________________________________ http://lists.milkymist.org/listinfo.cgi/devel-milkymist.org IRC: #milkym...@freenode Twitter: www.twitter.com/milkymistvj Ideas? http://milkymist.uservoice.com
