This tutorial will discuss various aspects of code optimisation – (I’m a Brit so we use an ‘s’ not a ‘z’ - let’s just get that out of the way now!).This an enormous, and maybe emotive, subject so be prepared to do a lot of reading !
We will cover items such as:-
* How optimisation works (using a pretend processor and pretend compiler)
* Discuss my 'post-boy' and 'post-boy-supervisor' and 'wash-your-hands' analogies
* The register, volatile and const keywords
* Look at how to change optimisation via your makefile
* Considerations to be given when interrupts or multiple threads are accessing the same data
* How to minimise the amount of code you write by using structures for 'data-driven-programming'. ie like C++ but in C.
Although we will be specifically looking at the AVR microcontrollers and the free avr C compiler, many of these principals apply to other environments, and languages, but you may have to dig around in the documentation for your specific compiler to find the associated equivalent.
Code optimisation covers a myriad of things but can be split down into several basics:-
Also ‘optimisation’ can mean different things to different people, and can also mean something different depending upon what it is that you are trying to do:-
It may appear strange that you have options for both speed and size as you probably think that smaller code will run faster and so small=fast. As a general rule this is normally correct – but not always. More later.