Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Porting low-level x86 optimized code to the ARM Cortex-A8 architecture

Tags:

x86

intel

arm

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):

  • SSE -> NEON
  • 64bit integers become 32bit
  • little endian -> big endian

Any other differences and pitfalls a programmer should be aware of?

like image 859
Fabian Avatar asked Feb 20 '11 22:02

Fabian


1 Answers

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 ints (or, better, unsigned ints).

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 chars, 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).

like image 82
Igor Skochinsky Avatar answered Oct 21 '22 20:10

Igor Skochinsky