Hi, All !
I have found that GCC does not make a simple, but useful
optimization:
Consider the following code:
void BlankMemoryCh(uint8_t ch)
{
static const struct MemoryCell m={{-1,0,0,0,0},0,""};
EEPROM_Write(&m,MEMORY_START+(ch)*sizeof(m),sizeof(m));
}
And here is GCC's output:
704 * Function `BlankMemoryCh'
705 ***********************/
706 BlankMemoryCh:
128:EEPROM.c ****
129:EEPROM.c **** void BlankMemoryCh(uint8_t ch)
130:EEPROM.c **** {
707 .stabn 68,0,130,.LM32-BlankMemoryCh
708 .LM32:
709 /* prologue: frame size = 0 */
710 .L__FrameSize_BlankMemoryCh=0x0
711 .L__FrameOffset_BlankMemoryCh=0x0
712 /* prologue end (size=0) */
713 .LBB8:
131:EEPROM.c **** static const struct MemoryCell
m={{-1,0,0,0,0},0,"───────"};
132:EEPROM.c ****
EEPROM_Write(&m,MEMORY_START+(ch)*sizeof(m),sizeof(m));
714 .stabn 68,0,132,.LM33-BlankMemoryCh
715 .LM33:
716 03a4 4E4F mov.b r15, r14
717 03a6 0E5E rla r14
718 03a8 0E5E rla r14
719 03aa 0E5E rla r14
720 03ac 0E5E rla r14
721 03ae 7FF3 and.b #-1,r15
722 03b0 0F5F rla r15
723 03b2 0E5F add r15, r14
724 03b4 3E50 0002 add #llo(512), r14
725 03b8 3D40 1200 mov #llo(18), r13
726 03bc 3F40 0000 mov #m.0, r15
727 03c0 B012 0000 call #EEPROM_Write
728 .LBE8:
133:EEPROM.c **** }
729 .stabn 68,0,133,.LM34-BlankMemoryCh
730 .LM34:
731 03c4 3041 ret
732 /* epilogue: not required */
733 /* function BlankMemoryCh size 17 (16) */
We can change
call #EEPROM_Write
ret
to
br #EEPROM_Write
This will save a bit of flash and RAM (stack). The later is aspecially
useful for msp430.
I think this is easy to implement (for example this might be a simple rule
for peephole optimizer, if
GCC have one).
What Dmitry thinks about it?
Bye,
Oleg.