| |||
| Home > Introducing NEON > Developing for NEON > Intrinsics |
Intrinsic functions and data types, or intrinsics, provide similar functionality to inline assembly, and provide additional features like type checking and automatic register allocation. An intrinsic function appears as a function call in C or C++, but is replaced during compilation by a sequence of low-level instructions. This means you can express low-level architectural behavior in a high-level language.
In addition to giving the programmer direct access to instructions that do not normally map well onto high-level language statements, using intrinsics means the compiler can optimize the operation to improve performance. Using intrinsics means the developer does not have to consider register allocation and interlock issues, because the compiler handles these.
GCC and RVCT support the same NEON intrinsic syntax, making
C or C++ code portable between the toolchains. To add support for
NEON intrinsics, include the header file arm_neon.h. Example 1.3 implements the
same functionality as the assembler examples, using intrinsics in
C code instead of assembler instructions.
Example 1.3. NEON intrinsics
#include <arm_neon.h>
uint32x4_t double_elements(uint32x4_t input)
{
return(vaddq_u32(input, input));
}
Although the GNU and RVCT development tools support the same syntax for NEON intrinsics, the command line syntax differs significantly between the two. The methods for compiling this example are described separately in:
To use NEON intrinsics in GCC, you must specify -mfpu=neon on
the compiler command line:
arm-none-linux-gnueabi-gcc -mfpu=neon intrinsic.c
Depending on your toolchain, you might also have to add -mfloat-abi=softfp to indicate to the compiler that NEON variables must be passed in general purpose registers.
A complete list of supported intrinsics can be found at http://gcc.gnu.org/onlinedocs/gcc/ARM-NEON-Intrinsics.html
RVCT accepts NEON instrinsics if you specify, on the compiler command line, a target processor that supports the NEON instructions. For example:
armcc --cpu=Cortex-A9 intrinsic.c
For information about the supported intrinsic functions and
vector data types, see the RealView Compilation Tools
Compiler Reference Guide, available from http://infocenter.arm.com.