Thursday, November 4, 2010

Optimizing a package for ARMv7 architecture

This is part of the 0.1 stage of Supporting Architectures above armv5tel project. I need to test an optimized package for BeagleboardXM-ARMv7 architecture and document the results. Packages are needed to be optimized to take advantage of ARMv7 processor features namely:
  • Thumb®-2/ Thumb
  • NEON™
  • VFPv3 Floating Point

I was supposed to test my compile on cdot-beagleboardXM-0-3 yesterday and today, but it’s down because the adapter is loaned out.

Anyway, I’ll just show my compiler optimization options and would appreciate any comments.

Compiling a package using ARM specific optimization option (using GCC 4.4.x):
CFLAGS="-O2 –march=armv7-a –mtune=cortex-a8 –mfpu=neon
–mfloat-abi=hard –fomit-frame-pointer"

*Using -mfloat-abi=hard with VFP coprocessors is not supported. Use -mfloat-abi=softfp with the appropriate -mfpu option to allow the compiler to generate code that makes use of the hardware floating-point capabilities for these CPUs. I would have to use this in any case -mfloat-abi=hard doesn't work

Optimization definition:

-O2
-O2 turns on all -O optimizations and all other optimizations that don't greatly increase binary size or interfere with debugging. -O2 is even better than -O, and usually just as safe. This is the optimization level most commonly used for packages and distributions in the Linux world and for the Linux kernel.

-march=your_arch
-march= tells gcc to optimize for a certain architecture. Basically, you just need to know what your CPU is, and the GCC name for it. This may break compatibility with other architectures!

-mtune=/-mcpu=
-mtune=, or -mcpu in older versions of GCC, is similar to -march and accepts the same options. Unlike -march it doesn't break compatibility with older arches. -march and -mtune/-mcpu options can be mixed to get the desired effect.

-mfpu=name
This specifies what floating point hardware (or hardware emulation) is available on the target.

-mfloat-abi=name
Specifies which floating-point ABI to use. Permissible values are: `soft', `softfp' and `hard'.

Specifying `soft' causes GCC to generate output containing library calls for floating-point operations. `softfp' allows the generation of code using hardware floating-point instructions, but still uses the soft-float calling conventions. `hard' allows generation of floating-point instructions and uses FPU-specific calling conventions.

-fomit-frame-pointer
-fomit-frame-pointer tells gcc to omit frame pointers, freeing up an additional register on the CPU. This is mainly useful on x86 as most other arches, like AMD64, have it on by default at -O2 or greater, though binary size may increase slightly. This flag breaks debugging on x86 and possibly other arches unless you're compiling with gcc 4.x and the -fvar-tracking flag.

Sources:

CFLAGS Definition
GNU Compiler Collection
GCC ARM Options
Armin76's Blog

I would like to extend my thanks to the people on IRC and the community Including Chris Tyler and Paul Whalen for guiding me in this project.

#seneca
#fedora-arm
#ubuntu-arm
#gentoo-embedded


Documentation is still on process, the test results will be posted by next week:

0 comments:

Post a Comment