#11264 - poslundc - Tue Sep 30, 2003 3:12 pm
The biggest things to avoid are division and modulus. Bitshift and mask where you can; multiply by the reciprocal where you can't. If timing is critical and you must divide/modulus, use the SWI dispatch in the bios (documented in various FAQs floating around) instead of gcc's regular divide. Consider using a look-up table if your value is in a known range.
Trigonometric functions obviously are terribly expensive to compute. Use look-up tables instead. The GBA even has a couple built in that you can copy out, if you can get to them (I personally don't bother to, since you end up consuming the memory anyway, but there is information on how to do so floating around).
Don't use floats or doubles, period. These have to be emulated in software and are slow as all heck. Learn how to use fixed-point mathematics. It's easier than it looks, and there's tons of info on the net on how to do it.
Calling functions creates extra overhead, so be smart about it. Small functions that get called repeatedly can often be replaced with macros.
These are the main things I would say to avoid. There's plenty more you can optimize in your code, but premature optimization is never a good idea. Get it working first, then go from there.
Dan.