The CC-RL provides an attribute among far, near, or saddr to variables or constants, and allocates them to areas with the same names as their attributes; far area, near area, or saddr area.
Since the size of instructions to access variables or constants in these area becomes smaller in this order, the code size can be reduced by specifying the near attribute (or saddr attribute) for variables or constants and then allocating them to the near area (or saddr area).
As the size of the area also becomes smaller in this order, it is necessary to prioritize which area to allocate each variable for a large total size of variables or constants.
The specification method of each attribute, each area, and its allocation method are described in detail in the following.
Options or keywords are used to specify the attribute for variables or constants.
The following four specification methods are available and the priority gets higher in this order.
For details, see each option or keyword and "2.6.6 Relationship with near and far".
The default attribute for variables or constants is always the near attribute.
The default attribute for variables or constants is always the near attribute.
The ROM data has far attribute by default.
A variable has the attribute specified by each keyword.
In general, if variables with higher static reference counts are allocated to an area accessible with a small size of instructions, the code size of the entire program gets smaller.
However, an area accessible with a small size of instructions needs to be used efficiently because the size of the area is also small.
Therefore, it is necessary to maximize the reduction efficiency for one byte of the area, namely, it is preferable to allocate variables whose value obtained by dividing the static reference count of the variable with the variable size is larger to an area accessible with a smaller size of instructions.
Accordingly, the priority is conceived as follows
Here, the static reference count of the variable indicates the reference count in the object code, and this will differ from the reference count in the C source program.
In the RL78, instructions for variable reference have only a 1-byte or 2-byte access width. Thus, for example, two instructions are needed to reference a 4-byte variable.
Therefore, one reference to a 4-byte variable in a C source program corresponds to two references in the object code.
The reference count in the object code can be shown by specifying -show=reference option to linker.
The areas placing variables or constants is divided into three, based on the address range.
The far area is the entire area including the saddr area or near area.
The area from addresses 0xFFE20 to 0xFFF1F is called the saddr area.
Note that some special function registers (SFRs) or general registers, to which variables cannot be allocated, are included in the saddr area.
The saddr-attribute variables located in this address range are accessed by instructions with the smallest size
The area from addresses 0xF0000 to 0xFFE1F is called the near area.
This area includes internal RAM, mirror region, and data flash memory.
Note that extended special function registers (2nd SFRs), to which variables cannot be allocated, are also included in the near area.
The near-attribute variables located in this address range are accessed by instructions with the second smallest size after the saddr area.
The entire area including the saddr area or near area is called the far area.
This area includes RAM other than internal RAM and the constant area in code flash memory other than the mirror region.
The far-attribute variables located in this address range are accessed by instructions with the largest size.
Variables or constants are allocated to each area by using link options to specify the allocation address of the section including each variable or constant.
The default sections allocated to the saddr area are .sbss and .sdata. |
The default sections allocated to the near area are .bss, .data and .const. |
The default sections allocated to the far area are .bssf, .dataf and .constf. |