Improving embedded MCU performance with more efficient incremental C-coding
By Eric Shufro, Department of Computer Science and Engineering Florida Atlantic University
Embedded.com (06/22/10, 05:08:00 PM EDT)
Efficient coding has been an important subject for years especially for resource constrained systems running real-time applications.
Most people take compiler optimizations for granted and do not realize the effect of efficient ‘C’ programming on program execution time. The examples described in this article are intended to serve as a reminder and testament to the fact that program execution speed mainly relies on efficient programming practices
To exemplify the notion consider writing a multiplication subroutine for a processor that does not have a hardware multiplier. Using simple repetitive addition algorithm, the loop will take the multiplicand and adds to itself n times, where n is the multiplier. Think of the run time of 5x1000=5000, versus a 1000x5=5000. A smarter loop would take the smaller number as the multiplier and the larger as the multiplicand.
In this article I have implemented small incremental code improvements to an embedded Ethernet driver, and proved that a performance gain of nearly 17% has been achieved. This figure does not account for the effect of additional compiler optimizations or TCP windowing improvements.
Click here to read more ...