hippietim
Axe-Master
One of the tricks-of-the-trade when doing embedded programming is to make local copies of member variables. I.e., if you have an object foo with a member bar you would do this:
float bar;
...
bar = foo.bar;
for(i = 0; i < FRAME_SIZE; i++)
{
...
bar = bar * x; // for example
...
}
foo.bar = bar;
The operation on bar is a "Read-Modify-Write (RMW)" and most embedded processors are optimized for this if the memory is L1 cache (or some other tightly-coupled on-chip memory). By making a local copy you force the compiler to use fast, local memory. When you are done with the loop you then save the local variable to the object.
Some compilers will do this automatically if you give them some information about the variable via a pragma. I think it's just easier to manually do it rather than dealing with pragmas which aren't portable.
The danger with doing this is if you forget to initialize bar or save it at the end, which is what I did.
Any modern C/C++ compiler should warn you if you use bar without initializing it but they won't be able to tell you that you forgot to update foo.bar.
BTW, this is not just a trick for embedded programmers. I wish I could get more programmers to write like this with the higher level languages. A lot of guys will write foo.bar = foo.bar * x and if it's javascript, java, etc. you can get some very poor performance characteristics due to unnecessary dereferencing. All the x86/x64 and ARM C/C++ compilers I've used in the last decade or so have no problems optimizing expressions like that though.