PowerISA Vector IntrinsicsThe
OpenPOWER ELF V2 application binary interface (ABI): Chapter 6.Vector Programming Interfaces and
Appendix A. Predefined Functions for Vector
Programming document the current and proposed vector built-ins we expect all
C/C++ compilers implement. Some of these operations are endian sensitive and the compiler needs
to make corresponding adjustments as it generates code for endian sensitive
built-ins. There is a good overview for this in the
OpenPOWER ABI Section6.4.
Vector Built-in Functions.Appendix A is organized (sorted) by built-in name, output type, then
parameter types. Most built-ins are generic as the named operation (add,
sub, mul, cmpeq, ...) applies to multiple types. So the vec_add built-in applies to all the signed and unsigned
integer types (char, short, in, and long) plus float and double floating-point
types. The compiler looks at the parameter type to select the vector
instruction (or instruction sequence) that implements the add operation on
that type. The compiler infers the output result type from the operation and
input parameters and will complain if the target variable type is not
compatible. Some examples:
This is one key difference between PowerISA built-ins and Intel
Intrinsics (Intel Intrinsics are not generic and include type information in
the name). This is why it is so important to understand the vector element
types and to add the appropriate type casts to get the correct results.The de facto standard implementation in GCC is defined in the include
file <altivec.h> and documented in the GCC online documentation in
6.59.20 PowerPC
AltiVec Built-in Functions. The header file name and section title
reflect the origin of the Vector Facility, but recent versions of GCC altivec.h
include built-ins for newer PowerISA 2.06 and 2.07 VMX plus VSX extensions.
This is a work in progress where your (older) distro GCC compiler may not
include built-ins for the latest PowerISA 3.0 or ABI edition. So before you use
a built-in you find in the ABI Appendix A, check the specific
GCC online documentation for the
GCC version you are using.