Skip to main content

The following page content corresponds to the products marketed in Japan.
If you do not live in Japan, please

System Design Issues:

Proper IDE Usage Can Produce Dramatic Improvements in Embedded System Performance

It's possible and desirable to boost the performance of applications for SuperH microcomputers by properly applying IDE Build options. When using the High-performance Embedded Workshop (HEW) integrated development environment, selecting the best optimization conditions significantly improves the efficiency of the applications that run on these popular RISC chips.

Choosing the right compiler options helps maximize system performance

A good integrated development environment (IDE) gives system developers a common graphical user interface (GUI) for hardware and software development tools such as a text editor, C/C++ compiler, link editor, and emulator. IDEs have many option settings that, when set properly, can have a significant impact on the performance of the resulting system.

To support the SuperH line of microcomputers — and our other device families as well — Renesas supplies our powerful, easy-to-use High-performance Embedded Workshop (HEW) IDE. Seminars and tutorials help customers make the best use of this vitally important development tool, which offers numerous operational options for accommodating the diverse requirements of a broad span of applications.

The following three Build options (compiler options) can be extremely effective for improving processing speeds:

[1] Optimization for Access to External Variables
[2] Optimize for "Speed"
[3] Provides Optimization with Register Save/Restore

Please be aware that Build options [1] and [3] do more than just boost optimize processing speed; they can also reduce memory usage. All of these options are available in HEW versions 9.3 and above.

Selecting Build options [1]: Optimization for Access to External Variables
Select [Inter-module] to apply your settings throughout your system!

The [External Variables] Build option setting relates to access to variables with a wide scope (global variables and external variables). Such variables are defined outside functions that can be referenced by any function in the application program.

We strongly recommend that you select this option when using variables with a wide scope (see Screen 1). For example, if you compile a program containing five external variables and do not select this option, the resulting assembly-language program will contain five separate address load instructions (shown in blue). This is because a separate address is allocated for each external variable (shown in red). However, when you choose the [Optimize External Variable Access] option, the compiler combines the five external variables into a single package (structure) so that only one address load instruction is required. This brings a commensurate improvement in the application's processing speed and memory usage.

An improvement of roughly 10% to 20% in processing speed is possible (see Figure 1). Because selecting this option will never make the program run slower, it's best to think of it as a mandatory option for SuperH microcomputer application development.

Screen 1: Procedure for selecting optimization of external access. Select the [C/C++] tab in the top part of the integrated development environment window to display the compiler settings. Next, select [Optimize] from the [Category] drop-down menu at the top of the window and select [Inter-module] from the list of [External Variables] settings. This causes a [WARNING] message window to open. Click the [OK] button in the window.

Figure 1: Comparison of results of compiling a C language application that defines five external variables (variables with global scope). The figure on the left shows the assembly code produced when the program is compiled without selecting [External Variables]. Because the addressees of each of the five external variables are loaded separately, the code contains five address load instructions. The figure on the right shows how selecting optimization causes the external variables to be treated as a structure and thus results in only one address load instruction being generated.
Selecting Build options [2]: Optimize for "Speed"

It is essential to consider the exact requirements of the application when specifying how you direct the compiler to optimize the object code. Three different optimization methods are available, depending on whether you want to optimize for memory size or processing speed (see Screen 2). Of course, memory size and processing speed are conflicting objectives, so saving memory space results in a slower processing speed, whereas improving speed causes the program to require more memory space.

The default setting is [Optimize for both speed and size], whereby your code is optimized in a way that balances speed and memory size. In contrast, selecting [Optimize for Size] reduces the required memory size at the cost of some loss of processing speed. Alternatively, selecting [Optimize for Speed] improves processing speed but increases the required memory size (see Figure 2).

The generally recommended setting here is [Optimize for Speed]. The reason we recommend this option is that most systems that use the SuperH microcomputer tend to have adequate memory capacity.

Another related option reduces the number of iterations used to execute loop statements by a factor of between 2 and 32 times. The default is 2. To set this option, select the [Optimize] category and then click the [Details] button at the bottom right to open the window for specifying Advanced optimization settings. From this window, select the [Miscellaneous] tab, then select [Custom] in the setting for specifying the maximum number of loop iterations to expand, and next specify the value you want by using the counter field on the right. For example, specifying "4" causes only one-fourth as many loop iterations to be performed.

Screen 2: Procedure for selecting [Optimize for Speed]. Select the [C/C++] tab to open the window for compiler settings. Next, select [Optimize] from the [Category] drop-down menu at the top of the window and select [Optimize for Speed] or another desired setting from the list of [Speed or size] settings.

Figure 2: Example optimization of loop statements. Consider a statement that loops for 100 iterations. The code on the left indicates how this statement is compiled when [Optimize for Size] is selected, whereas the code on the right shows the case when [Optimize for Speed] is selected. Specifying [Optimize for Speed] reduces the number of iterations by half, to 50, but it also increases the number of instructions needed to zero-clear the array in each iteration. Therefore, program size increases accordingly.
Selecting Build options [3]: Reallocate registers
Only the Renesas HEW IDE lets you perform code optimizations using the linker.
Thus, the final option discussed here to be explained is a linker option that is unique to our development environment.

Of the several linker options, the one likely to have the greatest effect is [Reallocate registers] (see Screen 3). Using this option improves processing speed by reducing the number of times the general-purpose registers are saved and restored.

The SuperH microcomputer has 16 general-purpose registers: R0 to R15, with R15 being used as the stack pointer. The compiler determines how these registers are used inside each function. Specifically, R0 to R7 are used without being saved and restored, whereas R8 to R14 are saved and restored before being used. As a result, if it is deemed necessary to use R8 to R14 during the execution of the function, these registers are respectively saved and restored on exiting and entering the function in all circumstances. Note that the compiler must perform those operations because it generates instructions on a function-by-function basis. As a consequence, all systems will end up with some redundant general-purpose register save -and-restore processing.

Despite this inevitability at the compiler level, though, you can do something to rectify the problem because the linker in the HEW IDE is "aware" of the relationship between function calls. The [Reallocate registers] option takes advantage of this fact to offer a solution. When you select this option, for example, if a function backs up and restores a particular register, the associated save and restore instructions can be deleted when linking, provided that the calling function does not use that register.

Again, this linker option is a very effective optimization method, but it is only available in the Renesas development environment. When using HEW, we recommended that you always select the [Generate file for inter-module optimization] checkbox (see Screens 3 and 4).

Screen 3: Procedure for configuring linker optimization. Go to the [C/C++] tab page, select the [Optimize] category, and then select the [Generate file for inter-module optimization] checkbox. This takes you to Screen 4.

Screen 4: Additional steps for linker configuration. Next, change to the [Link/Library] tab page. From the [Optimize] pull-down menu (the third field from the top of the page), select [Custom]. Then select [Reallocate registers] and [Optimize Branches] in the checkboxes underneath this field. This enables the linker to perform a system-wide optimization — a very effective capability that is available only in the Renesas HEW development environment.


End of content

Back To Top