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 eff
To answer your question about general rules when optimizing C++ code for ARM, here are a few suggestions:
1) As you mentioned, there is no divide instruction. Use logical shifts or multiply by the inverse when possible.
2) Memory is much slower than CPU execution; use logical operations to avoid small lookup tables.
3) Try to write 32-bits at a time to make best use of the write buffer. Writing shorts or chars will slow the code down considerably. In other words, it's faster to logical-OR the smaller bits together and write them as DWORDS.
4) Be aware of your L1/L2 cache size. As a general rule, ARM chips have much smaller caches than Intel.
5) Use SIMD (NEON) when possible. NEON instructions are quite powerful and for "vectorizable" code, can be quite fast. NEON intrinsics are available in most C++ environments and can be nearly as fast as writing hand tuned ASM code.
6) Use the cache prefetch hint (PLD) to speed up looping reads. ARM doesn't have smart precache logic the way that modern Intel chips do.
7) Don't trust the compiler to generate good code. Look at the ASM output and rewrite hotspots in ASM. For bit/byte manipulation, the C language can't specify things as efficiently as they can be accomplished in ASM. ARM has powerful 3-operand instructions, multi-load/store and "free" shifts that can outperform what the compiler is capable of generating.
The best way to optimize an application is to use a good profiler. Its always a good idea to write code thinking about efficiency, but you also want to avoid making changes where you "think" the code may be slow, this could possibly make things worse if you're not 100% sure.
Find out where the bottlenecks are and focus on those.
For me profiling is an iterative process, because usually when you fix one bottleneck, other less important ones manifest themselves.
In addition to profiling the SW, check what sort of HW profiling is available. Check if you can get different HW metrics, like cache misses, memory bus accesses, etc. This is also very helpful to know if your mem bus or cache is a bottleneck.
I recently asked this similar question and got some good answers: Looking for a low impact c++ profiler