Skip to content

Commit

Permalink
lm32: optimize irqflags.h for size
Browse files Browse the repository at this point in the history
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 <lars@metafoo.de>
  • Loading branch information
larsclausen authored and Takeshi Matsuya committed Jan 16, 2011
1 parent 6ab3223 commit 2754e3b
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions arch/lm32/include/asm/irqflags.h
Expand Up @@ -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)
Expand All @@ -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) );
Expand Down

0 comments on commit 2754e3b

Please sign in to comment.