I have been developing C++ code for augmented reality on ARM devices and optimization of the code is very important in order to keep a good frame rate. In order to rise efficiency to the maximum level I think it is important to gather general tips that make life easier for compilers and reduce the number of cicles of the program. Any suggestion is welcomed.
1- Avoid high-cost instructions: division, square root, sin, cos
- Use logical shifts to divide or multiply by 2.
- Multiply by the inverse when possible.
2- Optimize inner "for" loops: they are a botleneck so we should avoid making many calculations inside, especially divisions, square roots..
3- Use look-up tables for some mathematical functions (sin, cos, ...)
USEFUL TOOLS
- objdump: gets assembly code of compiled program. This allows to compare two functions and check if it is really optimized.