Code Optimization – Optimized Variable Order

swTry to group order of access to the variables from the same memory bank to the adjacent statements. This will eliminate redundant MOVLB instructions.

Original code

uns8 savedTX;
...
RTHOPS = 0xFF; // @bank5 !=
TX = savedTX;  // @bank11 != @bank5 ==
RTDEF = 2;     // @bank5

Optimized code

uns8 savedTX;
...
TX = savedTX;  // @bank11 != @bank5 ==
RTHOPS = 0xFF; // @bank5 ==
RTDEF = 2;     // @bank5

Original code 2

bank11 uns8 va_11, vb_11;
bank12 uns8 va_12, vb_12;

// @bank11 != @bank12 != @bank11 != @bank12
if ( va_11 == va_12 && vb_11 == vb_12 )
nop();

Optimized code 2

bank11 uns8 va_11, vb_11;
bank12 uns8 va_12, vb_12;

// @bank11 != @bank12 == @bank12 != @bank11
if ( va_11 == va_12 && vb_12 == vb_11 )
nop();

Effects

 ikony_flash ikony_ram  ikony_speed
SAVED NO EFFECT
FASTER

Post sent by Hynek Syrovátka.

Leave a Reply

Your email address will not be published. Required fields are marked *