Optimization Breeds Application Efficiency

Sept. 15, 2003
Linker and compiler work on different optimizations to create faster and smaller applications.

To create efficient applications written in a high-level language like C++, developers usually turn to compiler optimizations. Green Hills Software's latest toolchain includes a number of new compiler and linker optimizations. Together they deliver applications that are smaller and faster than the competition. Let's take a peek under the hood to see how two of these optimization techniques operate.

The linker optimization is called CodeFactor. In the simplest terms, it locates common blocks of code with an application, converts them into functions, and replaces the code with calls to the new functions as shown in the figure. Of course, it must submit to a cost/benefit analysis. Replacing a 2-byte instruction with a 4-byte call gives a net loss. Still, relatively small, duplicate blocks of a dozen instructions, depending upon the processor architecture, are very common.

As with most optimizations, CodeFactor is not free. A brute-force algorithm to find duplicate sequences is an N2 problem. Green Hills cuts this down significantly, making CodeFactor computationally practical in large programs.

While CodeFactor's primary task is to minimize code size, it often results in faster code. It may seem counter-intuitive due to the added overhead of a call and return instruction, but keep in mind that the code involved is small.

The factored routines fit easily in a cache. They're likely to be called frequently and will typically be found in the cache. Moving code into common routines makes it more likely that the cache can keep the routines around longer. Ultimately, the level of speed improvement or overhead depends on the processor architecture and cache organization.

Code replacement isn't always easy. Details such as register usage and stack parameters must be addressed. CodeFactor's results may vary, but a 10% code compaction is attainable.

THE MAGIC OF WIZARDS Most compiler optimizations are normally selected statically by the programmer. Green Hills' optimization wizards provide a more interactive approach, using information about the application and feedback from the developer. The Code Balance Wizard is one of a number included in the latest compiler.

Code Balance is well suited for embedded applications. It's designed to selectively optimize applications based on performance profile information. That information is obtained from a prior run of an instrumented version of the program. It allows the wizard to determine which parts of the application should be optimized for speed versus space.

Running this information through the wizard results in a configuration file that specifies the suggested optimization on a "per function" basis. Developers can modify this configuration file. For example, certain functions may be required to quickly respond to events, even though profiling information may not indicate this as an important factor.

This wizard's tradeoff is very important when a developer needs to specify a maximum code size. Hardware and cost limitations are the main reasons for requiring a max code size. It is possible to experiment with different configuration files to get the best setup for a particular application.

All of these new features can be found in Green Hills' latest C and C++ compilers. The compilers are also bundled with the Multi Integrated Development Environment.

GREEN HILLS SOFTWAREwww.ghs.com
About the Author

William G. Wong | Senior Content Director - Electronic Design and Microwaves & RF

I am Editor of Electronic Design focusing on embedded, software, and systems. As Senior Content Director, I also manage Microwaves & RF and I work with a great team of editors to provide engineers, programmers, developers and technical managers with interesting and useful articles and videos on a regular basis. Check out our free newsletters to see the latest content.

You can send press releases for new products for possible coverage on the website. I am also interested in receiving contributed articles for publishing on our website. Use our template and send to me along with a signed release form. 

Check out my blog, AltEmbedded on Electronic Design, as well as his latest articles on this site that are listed below. 

You can visit my social media via these links:

I earned a Bachelor of Electrical Engineering at the Georgia Institute of Technology and a Masters in Computer Science from Rutgers University. I still do a bit of programming using everything from C and C++ to Rust and Ada/SPARK. I do a bit of PHP programming for Drupal websites. I have posted a few Drupal modules.  

I still get a hand on software and electronic hardware. Some of this can be found on our Kit Close-Up video series. You can also see me on many of our TechXchange Talk videos. I am interested in a range of projects from robotics to artificial intelligence. 

Sponsored Recommendations

Comments

To join the conversation, and become an exclusive member of Electronic Design, create an account today!