Author: IAR systems

In the development and application of MCU, engineers need to test the ability of MCU. The common practice is to test it with benchmark program. However, in the benchmark test, the optimization ability of the compiler also has a significant impact on the test results. The results may be quite different with the same set of hardware platform, different compilers and different optimization options.

In order to maximize the performance of MCU and obtain the most ideal results in the benchmark test, engineers often need to not only have a better understanding of their own hardware, but also deeply understand the optimization principle of the compiler and apply it flexibly, so as to give full play to the full performance of MCU in the benchmark test. IAR systems, as a world-famous embedded tool manufacturer, its compiler has unique advantages in optimization ability. MCU with IAR compiler can often get better benchmark results.

Taking the IAR embedded workbench development tool suite, which has been widely used in the MCU field, as an example, this paper shares the items that should be paid attention to in MCU software benchmarking and the following skills, so as to help readers generate the most efficient and complete code in the industry. Using the following items and settings, engineers can accurately adjust the optimization level, test and improve the performance of the developed and application code to the greatest extent.

Choose code size or execution speed

Using the development tool suite such as IAR embedded workbench, engineers can set the optimization level and type for the whole project scope or for a single file. In the source code, you can even use #pragma optimize instructions on a single function to do this.

The purpose of optimization is to reduce code size and improve execution speed. If only one of these goals can be met, the compiler takes precedence according to the settings specified by the user. Therefore, in the actual software benchmarking, engineers can try various settings to obtain the best results. For example, because function inlining focuses more on the optimization of execution speed, using function inlining and general code execution speed optimization settings will obtain smaller program code than using general code size optimization settings.

Select a small memory model

In order to give full play to the performance of MCU devices and reduce the problems in application, the memory and other resource constraints of MCU devices must be fully considered in software development. Therefore, it is necessary to select the memory model as small as possible for the target devices and projects. The advantages of the small memory model include:

·Smaller address

·Smaller size instructions

·Smaller pointer

·More efficient

·Less code

Mature development tool Suites such as IAR embedded workbench also integrate relevant evaluation functions, which can evaluate memory models in many aspects, so as to help engineers test the scale and optimize the design of software.

Select the appropriate runtime library

By default, runtime libraries are compiled at the highest level of code size optimization. If you want to optimize the speed, consider recompiling these libraries. You can configure options to set the most appropriate level for certain standard library features, such as locale, file descriptor, and multibyte.

According to specific requirements, select the format of scanf input and printf in the library options. The default option is not the minimum format.

Use the correct data type

Data types are closely related to code size or execution speed, so development tools need to be used to observe and analyze data types in order to find the type suitable for hardware resources. In the IAR embedded workbench development tool suite, developers can test and optimize from the following aspects:

·Choose the data type size that best suits your application

·Try to use unsigned characters so that bit operations can be performed instead of arithmetic operations

Check target specific options

Check the target specific options that can improve performance, which often requires engineers to have considerable experience in daily MCU design and application development, but the necessary performance checks can be completed quickly and perfectly by using mature development tool Suites such as IAR embedded workbench:

·Efficient addressing mode – enables efficient memory access

·Use specific registers to handle constants / variables – Code operates more efficiently on registers than in memory

·Even alignment function entry – even alignment instructions can improve speed

·Byte aligned objects – smaller storage space requirements, but may generate larger code sizes

Use benchmark related codes

All MCU development tools should provide benchmark related code, but the code base of mature general development tools is the enrichment of these providers’ experience in related fields, so it is more comprehensive and efficient. Important experiences include:

·The benchmark of embedded system should be designed according to the characteristics of embedded program.

·Actual applications are usually also suitable for benchmarking, but you need to ensure the executability of the code. Linkers delete unreferenced code and variables, but not all linkers have this function.

·Ensure that the test code is not affected by the test tools (test related functions). The following example is actually a benchmark for printf () (test related functions).

·Compare the code generated after the link. One compiler may use inline code, while another compiler may call the library.

·Fully understand the application code used to perform benchmarking!


By using the mature development tool suite such as IAR embedded workbench and giving full play to its knowledge gathered and iterated in decades of global applications, MCU design and application development engineers can quickly complete these necessary performance tests, and further give full play to the performance of MCU, so as to realize the optimization of target devices The function of integrating software and hardware.

Leave a Reply

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