A.6.6 Specified Order of Section Addresses by Optimizing Linkage Editor at Optimization of External Variable Accesses

In an instruction that accesses memory in the register relative-address format, the instruction size is small when the displacement value is small.

In some cases, the code size can be improved when the order of allocating the sections by the optimizing linkage editor is changed with reference to the following guidelines.

-

Place at the beginning the sections of external variables that are frequently accessed in the function.

-

Place at the beginning the sections of external variables with small type sizes.

Note however that the build time gets longer when external variable accesses are optimized because the compiler runs twice.

[Example]

Source code before improvement

/* Section D_1 */
char d11=0, d12=0, d13=0, d14=0;
/* Section D_2 */
short d21=0, d22=0, d23=0, d24=0, dmy2[12]={0};
/* Section D */
int d41=0, d42=0, d43=0, d44=0, dmy4[60]={0}
 
void func(int a){
     d11 = a;
     d12 = a;
     d13 = a;
     d14 = a;
     d21 = a;
     d22 = a;
     d23 = a;
     d24 = a;
     d41 = a;
     d42 = a;
     d43 = a;
     d44 = a;
}

 

Assembly-language expansion code before improvement

<When the allocation order of sections is "D, D_2, D_1" or D*>
_func:
     MOV.L #d41,R4
     MOV.B R1,0120H[R4]
     MOV.B R1,0121H[R4]
     MOV.B R1,0122H[R4]
     MOV.B R1,0123H[R4]
     MOV.W R1,0100H[R4]
     MOV.W R1,0102H[R4]
     MOV.W R1,0104H[R4]
     MOV.W R1,0106H[R4]
     MOV.L R1,[R4]
     MOV.L R1,04H[R4]
     MOV.L R1,08H[R4]
     MOV.L R1,0CH[R4]
     RTS

 

Source code after improvement

/* Section D_1 */
char d11=0, d12=0, d13=0, d14=0;
/* Section D_2 */
short d21=0, d22=0, d23=0, d24=0, dmy2[12]={0};
/* Section D */
int d41=0, d42=0, d43=0, d44=0, dmy4[60]={0}
 
void func(int a){
     d11 = a;
     d12 = a;
     d13 = a;
     d14 = a;
     d21 = a;
     d22 = a;
     d23 = a;
     d24 = a;
     d41 = a;
     d42 = a;
     d43 = a;
     d44 = a;
}

 

Assembly-language expansion code after improvement

<When the allocation order of sections is "D_1, D_2, D" or D*>
_func:
     MOV.L #d11,R4
     MOV.B R1,[R4]
     MOV.B R1,01H[R4]
     MOV.B R1,02H[R4]
     MOV.B R1,03H[R4]
     MOV.W R1,04H[R4]
     MOV.W R1,06H[R4]
     MOV.W R1,08H[R4]
     MOV.W R1,0AH[R4]
     MOV.L R1,24H[R4]
     MOV.L R1,28H[R4]
     MOV.L R1,2CH[R4]
     MOV.L R1,30H[R4]
     RTS