The POWER Bi-Endian Vector Programming Model
To ensure portability of applications optimized to exploit the
SIMD functions of POWER ISA processors, the ELF V2 ABI defines a
set of functions and data types for SIMD programming. ELF
V2-compliant compilers will provide suitable support for these
functions, preferably as built-in functions that translate to one
or more POWER ISA instructions.
Compilers are encouraged, but not required, to provide built-in
functions to access individual instructions in the IBM POWER®
instruction set architecture. In most cases, each such built-in
function should provide direct access to the underlying
instruction.
However, to ease porting between little-endian (LE) and big-endian
(BE) POWER systems, and between POWER and other platforms, it is
preferable that some built-in functions provide the same semantics
on both LE and BE POWER systems, even if this means that the
built-in functions are implemented with different instruction
sequences for LE and BE. To achieve this, vector built-in
functions provide a set of functions derived from the set of
hardware functions provided by the Power vector SIMD
instructions. Unlike traditional “hardware intrinsic” built-in
functions, no fixed mapping exists between these built-in
functions and the generated hardware instruction sequence. Rather,
the compiler is free to generate optimized instruction sequences
that implement the semantics of the program specified by the
programmer using these built-in functions.
This is primarily applicable to the POWER SIMD instructions. As
we've seen, this set of instructions operates on groups of 2, 4,
8, or 16 vector elements at a time in 128-bit registers. On a
big-endian POWER platform, vector elements are loaded from memory
into a register so that the 0th element occupies the high-order
bits of the register, and the (N – 1)th element occupies the
low-order bits of the register. This is referred to as big-endian
element order. On a little-endian POWER platform, vector elements
are loaded from memory such that the 0th element occupies the
low-order bits of the register, and the (N – 1)th element
occupies the high-order bits. This is referred to as little-endian
element order.
Vector Data Types
Languages provide support for the data types in to represent vector data
types stored in vector registers.
For the C and C++ programming languages (and related/derived
languages), these data types may be accessed based on the type
names listed in when
Power ISA SIMD language extensions are enabled using either the
vector
or __vector
keywords. NOTE
THAT THIS IS THE FIRST TIME WE'VE MENTIONED THESE LANGUAGE
EXTENSIONS, NEED TO FIX THAT.
For the Fortran language, OH YET ANOTHER STINKING TABLE gives a
correspondence between Fortran and C/C++ language types.
The assignment operator always performs a byte-by-byte data copy
for vector data types.
Like other C/C++ language types, vector types may be defined to
have const or volatile properties. Vector data types can be
defined as being in static, auto, and register storage.
Pointers to vector types are defined like pointers of other
C/C++ types. Pointers to vector objects may be defined to have
const and volatile properties. Pointers to vector objects must
be divisible by 16, as vector objects are always aligned on
quadword (128-bit) boundaries.
The preferred way to access vectors at an application-defined
address is by using vector pointers and the C/C++ dereference
operator *
. Similar to other C/C++ data types, the
array reference operator []
may be used to access
vector objects with a vector pointer with the usual definition
to access the nth vector element from a
vector pointer. The dereference operator *
may
not be used to access data that is not
aligned at least to a quadword boundary. Built-in functions
such as vec_xl
and vec_xst
are
provided for unaligned data access.
Compilers are expected to recognize and optimize multiple
operations that can be optimized into a single hardware
instruction. For example, a load and splat hardware instruction
might be generated for the following sequence:
double *double_ptr;
register vector double vd = vec_splats(*double_ptr);
Vector Types
Power SIMD C Types
sizeof
Alignment
Description
vector unsigned char
16
Quadword
Vector of 16 unsigned bytes.
vector signed char
16
Quadword
Vector of 16 signed bytes.
vector bool char
16
Quadword
Vector of 16 bytes with a value of either 0 or
28 – 1.
vector unsigned short
16
Quadword
Vector of 8 unsigned halfwords.
vector signed short
16
Quadword
Vector of 8 signed halfwords.
vector bool short
16
Quadword
Vector of 8 halfwords with a value of either 0 or
216 – 1.
vector unsigned int
16
Quadword
Vector of 4 unsigned words.
vector signed int
16
Quadword
Vector of 4 signed words.
vector bool int
16
Quadword
Vector of 4 words with a value of either 0 or
232 – 1.
vector unsigned long
The vector long types are deprecated due to their
ambiguity between 32-bit and 64-bit environments. The use
of the vector long long types is preferred.
vector unsigned long long
16
Quadword
Vector of 2 unsigned doublewords.
vector signed long
vector signed long long
16
Quadword
Vector of 2 signed doublewords.
vector bool long
vector bool long long
16
Quadword
Vector of 2 doublewords with a value of either 0 or
264 – 1.
vector unsigned __int128
16
Quadword
Vector of 1 unsigned quadword.
vector signed __int128
16
Quadword
Vector of 1 signed quadword.
vector _Float16
16
Quadword
Vector of 8 half-precision floats.
vector float
16
Quadword
Vector of 4 single-precision floats.
vector double
16
Quadword
Vector of 2 double-precision floats.
Vector Operators
In addition to the dereference and assignment operators, the
Power SIMD Vector Programming API (REALLY?) provides the usual
operators that are valid on pointers; these operators are also
valid for pointers to vector types.
The traditional C/C++ operators are defined on vector types
with “do all” semantics for unary and binary +
,
unary and binary –, binary *
, binary
%
, and binary /
as well as the unary
and binary shift, logical and comparison operators, and the
ternary ?:
operator.
For unary operators, the specified operation is performed on
the corresponding base element of the single operand to derive
the result value for each vector element of the vector
result. The result type of unary operations is the type of the
single input operand.
For binary operators, the specified operation is performed on
the corresponding base elements of both operands to derive the
result value for each vector element of the vector
result. Both operands of the binary operators must have the
same vector type with the same base element type. The result
of binary operators is the same type as the type of the input
operands.
Further, the array reference operator may be applied to vector
data types, yielding an l-value corresponding to the specified
element in accordance with the vector element numbering rules (see
). An l-value may either
be assigned a new value or accessed for reading its value.
Vector Layout and Element Numbering
filler
Limitations
vec_sld
vec_perm