IBM extension

Vector types

XL C/C++ supports Vector Multimedia Extension (VMX) technology through language extensions. XL C/C++ implements the AltiVec Programming Interface specification with an extended syntax that allows type qualifiers and storage class specifiers to precede the keyword vector (or its alternate spelling, __vector) in a declaration.

The keyword vector is recognized in a declaration context only when used as a type specifier and when VMX support is enabled. The keywords pixel and bool are recognized as valid type specifiers only when preceded by the keyword vector or __vector. To keep your source code maximally portable, avoid using vector, pixel, or bool as keywords or identifiers in your program. Use the underscore versions of the specifiers vector and pixel (__vector and __pixel) in declarations.

Most of the legal forms of the syntax are captured in the following diagram. Some variations have been omitted from the diagram for the sake of clarity: type qualifiers such as const and storage class specifiers such as static can appear in any order within the declaration, as long as neither immediately follows the keyword vector (or __vector).

Read syntax diagramSkip visual syntax diagramVector declaration syntax
   V                             |
   '-__vector-' | +-signed---+  +-short--+-----+-+ |
                | '-unsigned-'  |        '-int-' | |
                |               +-int------------+ |
                |               '-long--+-----+--' |
                |                       '-int-'    |
  1. The long type specifier is deprecated in a vector context.
  2. Duplicate type specifiers are ignored in a vector declaration context. In particular, long long is treated as long.
  3. A long vector type is compatible with the corresponding int vector type (supported in 32-bit mode only).

All vector types are aligned on a 16-byte boundary. An aggregate that contains one or more vector types is aligned on a 16-byte boundary, and padded, if necessary, so that each member of vector type is also 16-byte aligned.

The indirection operator * has been extended to handle pointer to vector types. A vector pointer should point to a memory location that has 16-byte alignment. However, the compiler does not enforce this constraint. Dereferencing a vector pointer maintains the vector type and its 16-byte alignment. If a program dereferences a vector pointer that does not contain a 16-byte aligned address, the behavior is undefined.

Pointer arithmetic is defined for pointer to vector types. Given:

vector unsigned int *v;

the expression v + 1 represents a pointer to the vector following v.

Related information

Vector type casts

Vector types can be cast to other vector types. The cast does not perform a conversion: it preserves the 128-bit pattern, but not necessarily the value. A cast between a vector type and a scalar type is not allowed.

Vector pointers and pointers to non-vector types can be cast back and forth to each other. When a pointer to a non-vector type is cast to a vector pointer, the address should be 16-byte aligned. The referenced object of the pointer to a non-vector type can be aligned on a sixteen-byte boundary by using either the __align specifier or __attribute__((aligned(16))).

Related information

End of IBM extension