How do I get the compiler to generate NEON instructions?

Question

How do I get the compiler to generate NEON instructions?

Answer

Use the options -mfpu=neon -mfloat-abi=softfp. The compiler will generate code for NEON.

If you also use the -ftree-vectorize option, the compiler will attempt to automatically vectorize loops. The option -ftree-vectorizer-verbose=1 will display information on the number of vectorized loops and their locations. Using the option -ftree-vectorizer-verbose with a value greater than 1 is not supported.

To enable the automatic vectorizer to use 128-bit vectors you must add -mvectorize-with-neon-quad.

To enable the automatic vectorizer to use NEON instructions in C code that uses floating point values you must add -funsafe-math-optimizations. This is required because certain NEON instructions flush denormals to zero and that does not match the full semantics required by the C language standard. Unless you require exact adherence to IEEE standards you may use -funsafe-math-optimizations. See the compiler manual for more details.

Code compiled with these options is ABI-compatible with soft-float code for processors without NEON, so your program will work fine if part of your code is compiled with software floating point and other parts are compiled with the options given above.

Using -mfloat-abi=hard generates code that is not ABI-compatible with other floating-point options. This is probably not the correct choice unless you must link with third-party libraries using the hard float ABI. In this case, your entire program must use the hard float ABI, and you must link with C libraries that use the hard float ABI. These libraries are available to Sourcery CodeBench Standard and Professional Edition subscribers, but are not included with CodeSourcery's Lite or Personal Edition.


This entry was last updated on 8 March 2013.