What are the main caveats in porting C++ x86 code to an ARM processor?
The ones I know / have heard of (but I don't know if they are really a problem, or even true - please verify):
Any other differences and pitfalls a programmer should be aware of?
Any decent compiler supports 64-bit math on ARM, so it might be not necessary to reduce the range of your variables. However, ARM is natively 32-bit so if you don't need full range then using 32-bit variables will be faster. As well, the 32-bit variables are faster than 8-bit and 16-bit ones, so if you have any char
or short
loop counters, it might be worth updating them to int
s (or, better, unsigned int
s).
Endianness is generally not an issue - most ARM chips either run in little-endian or can switch between big and little endian. What is an issue is alignment. x86 is very forgiving when you access unaligned data. On ARM this either produces an exception or (on later archs) makes your code run slower. This is usually taken care of by the compiler, but you need to watch out if you use assembly or packed structures.
Another thing that might trip you is signed/unsigned variables. Until recently, ARM did not have fast instructions for loading/storing signed char
s, so traditionally char
is unsigned on ARM. If your code relies on char
's signedness, you might have some issues. A quick fix might be to use the compiler switch for signed chars, but take care when using library functions. Also, signed char
will be slower on older chips.
Edit: I just stumbled upon a great page on the Debian Wiki. It deals mostly with porting from old ARM ABI to EABI, but a lot of things mentioned still apply to x86->ARM. It also links to a nice FAQ about structure alignment (although it's not completely correct for ARMv6/v7).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With