English
Language : 

AN720 Datasheet, PDF (1/28 Pages) Silicon Laboratories – PRECISION32™ OPTIMIZATION CONSIDERATIONS FOR CODE SIZE AND SPEED
AN720
PRECISION32™ OPTIMIZATION CONSIDERATIONS FOR
CODE SIZE AND SPEED
1. Introduction
The code size and execution speed of a 32-bit MCU project can vary greatly depending on the way the code is
written, the toolchain libraries used, and the compiler and linker options. This document addresses how to
determine what portions of code are taking extra space or time and ways to optimize for space or speed for
different tool chains, including GCC redlib and newlib (Precision32 IDE) and Keil.
2. Key Points
The key topics of this document are:
How to determine what portions of the project are taking the most space
Ways to benchmark code execution speed
Common strategies to reduce code size or improve execution speed
Code startup time and ways to reduce it
3. Using CoreMark™ as a Speed Benchmark
CoreMark is a standard code base that can be ported to various processors to provide a speed benchmark. The
CoreMark software provides a score that rates how fast the core and code is, providing a relative comparison
between various toolchain options and settings. The CoreMark software package cannot be modified except for
device-specific information in the portme files. For modes that do not support printf (nohosting libraries), the
results were calculated using the value of the variable in code. See the CoreMark website for more information on
the test and score reporting requirements (www.coremark.org).
4. Non-Toolchain Considerations
The coding style and technique can have a great effect on the overall size of the project.
4.1. Coding Techniques
There are many ways coding technique can affect code size, including library calls, inline code or data, or code
optimizations made for global variables or pointers.
For more information on writing C code for ARM architectures, see the following resources:
EETimes - Energy efficient C code for ARM devices by Chris Shore: http://www.eetimes.com/design/
embedded/4210470/Efficient-C-Code-for-ARM-Devices
Compiler Coding Practices - ARM: http://infocenter.arm.com/help/index.jsp?topic=/
com.arm.doc.dui0472c/CJAFJCFG.html
These guidelines will largely apply regardless of the compiler used for the project.
4.2. Number of Function Parameters
Functions with either Keil or GCC can have as many parameters as desired. In general, the first four parameters
are passed to the function efficiently using registers. Any additional parameters beyond four must be moved on or
off the stack, which results in extra code size for each additional parameter and extra time to execute those
instructions. If possible, keeping functions to no more than four parameters can help reduce code size and
execution time.
Rev. 0.1 9/12
Copyright © 2012 by Silicon Laboratories
AN720