1. overview
This article will show you how to set the Optimization Level for a Nios® V processor (Hereafter as Nios® V ) application.
This article assumes that you are familiar with the procedure for creating a Nios® V project. For the procedure for creating a Nios® V project, please refer to the following article.
Reference: Nios® V Project Development Procedure using Ashling* RiscFree* IDE
2. how to set up
The Optimization Level setting procedure differs from that of NIos® II SBT.
In Nios® V, the Optimization Level can be set with a command used when creating an application project. The Optimization Level can be set at build time by setting -DCMAKE_BUILD_TYPE as an argument to this command.
In this section, we will also introduce the files in which the addition of the argument is reflected.
Figure 1 shows the command for setting the Optimization Level.
Figure 1. Command for setting Optimization Level
If you set "Debug" or "Release" to -DCMAKE_BUILD_TYPE in the red frame of Figure 1, it will be reflected in flags.make stored in the following directory.
<Quartus Project>\software\app\build\Debug\CMakeFiles\sample.elf.dir
It is also possible to set the Optimization Level directly from this file by editing the arguments shown in Figure 2.
Figure 2. Destination of the Optimization Level command
The default Optimization Level is "O0".
Please refer to the documentation in the following directory for more information on the different Optimization Levels.
<Quartus Install Directory>\<Version>\riscfree\toolchain\riscv32-unknown-elf\share\doc\gcc
gcc.pdf 3.11 Options That Control Optimization
Figure 3 shows the logs of projects created and built with different -DCMAKE_BUILD_TYPE values for the same source files.
The logs are created by changing -DCMAKE_BUILD_TYPE=Release for the same source file, and the Optimization Level is set to "O2", which results in a smaller program size.
Figure 3. Execution Log
This is all about how to set the Optimization Level.
Conclusion
For more information on the Nios® V processor, please refer to the following page from the manufacturer.