Global Sources
EE Times-India
Stay in touch with EE Times India
 
EE Times-India > Embedded
 
 
Embedded  

Engineering embedded software: Basic C techniques

Posted: 14 Apr 2014     Print Version  Bookmark and Share

Keywords:optimisation  embedded system  programmer  compiler  debuggers 

An essential first step in optimising your embedded system software for performance takes place prior to beginning the optimisation process. It is important to first confirm functional accuracy. In the case of standards-based code (e.g., voice or video coder), there may be reference vectors already available. If not, then at least some basic tests should be written to ensure that a baseline is obtained before optimisation. This enables easy identification that an error has occurred during optimisation—incorrect code changes done by the programmer or any overly aggressive optimisation by a compiler. Once tests in place, optimisation can begin. Figure 1 shows the basic optimisation process.

Figure 1: Basic flow of optimisation process.

It's also important to understand the features of the development tools as they will provide many useful, time-saving features. Modern compilers are increasingly better performing with embedded software and leading to a reduction in the development time required. Linkers, debuggers and other components of the tool chain will have useful code build and debugging features, but in this chapter we will focus only on the compiler.

Compiler optimisation
From the compiler perspective, there are two basic ways of compiling an application: traditional compilation or global (cross-file) compilation. In traditional compilation, each source file is compiled separately and then the generated objects are linked together. In global optimisation, each C file is preprocessed and passed to the optimiser in the same file. This enables greater optimisations (inter-procedural optimisations) to be made as the compiler has complete visibility of the program and doesn't have to make conservative assumptions about the external functions and references.

Global optimisation does have some drawbacks, however. Programs compiled this way will take longer to compile and are harder to debug (as the compiler has taken away function boundaries and moved variables). In the event of a compiler bug, it will be more difficult to isolate and work around when built globally. Global or cross-file optimisations result in full visibility into all the functions, enabling much better optimisations for speed and size. The disadvantage is that since the optimiser can remove function boundaries and eliminate variables, the code becomes difficult to debug. Figure 2 shows the compilation flow for each.

Basic compiler configuration. Before building for the first time, some basic configuration will be necessary. Perhaps the development tools come with project stationery which has the basic options configured, but if not, these items should be checked:

Target architecture: specifying the correct target architecture will allow the best code to be generated.

Endianness: perhaps the vendor sells silicon with only one edianness, perhaps the silicon can be configured. There will likely be a default option.

Memory model: different processors may have options for different memory model configurations.

Initial optimisation level: it's best to disable optimisations initially.

Enabling optimisations. Optimisations may be disabled by default when no optimisation level is specified and either new project stationery is created or code is built on the command line. Such code is designed for debugging only. With optimisations disabled, all variables are written and read back from the stack, enabling the programmer to modify the value of any variable via the debugger when stopped. The code is inefficient and should not be used in production code.

Figure 2: Traditional (on left) versus global (on right) compilation.


1 • 2 • 3 • 4 Next Page Last Page



Comment on "Engineering embedded software: Basic..."
Comments:  
*  You can enter [0] more charecters.
*Verify code:
 
 
Webinars

Seminars

Visit Asia Webinars to learn about the latest in technology and get practical design tips.

 

Go to top             Connect on Facebook      Follow us on Twitter      Follow us on Orkut

 
Back to Top