Vector Data Types

The C/C++ compiler supports the use of native vector data types in C/C++ source files. Vector data types are useful because they can make use of the natural vector width within the processing cores. Vector data types provide a straightforward way to utilize the SIMD instructions that are available on that architecture. Vector data types also provide a more direct mapping from the abstract model of a vector data object to the physical representation of that data object in a register.

Vector data types are similar to an array, in that a vector contains a specified number of elements of a specified type. However, the vector length can only be one of 2, 3, 4, 8, or 16. Wherever possible, intrinsics that act upon vectors are optimized to make use of efficient single instruction, multiple data (SIMD) instructions on the device.

You can enable support for vector data types by using the --vectypes compiler option.

All of the vector data types and related built-in functions that are supported in the C6000 programming model are specified in the "c6x_vec.h" header file in the "include" sub-directory where your C6000 CGT was installed. Any C/C++ source file that uses vector data types or any of the related built-in functions must contain the following in that source file:

#include <c6x_vec.h>

A vector type name concatenates an element type name and a number representing the vector length. The resulting vector consists of the specified number of elements of the specified type.

The C6000 implementation of vector data types and operations follows the OpenCL C language specification closely. For a detailed description of OpenCL vector data types and operations, please see version 1.2 of The OpenCL Specification, which is available from the Khronos OpenCL Working Group. Section 6.1.2 of the version 1.2 specification provides a detailed description of the built-in vector data types supported in the OpenCL C programming language. The C6000 programming model provides the following built-in vector data types:

Table 7-2 Vector Data Types

Type Description Maximum Elements
charn A vector of n 8-bit signed integer values. 16
ucharn A vector of n 8-bit unsigned integer values. 16
shortn A vector of n 16-bit signed integer values. 8
ushortn A vector of n 16-bit unsigned integer values. 8
intn A vector of n 32-bit signed integer values. 4
uintn A vector of n 32-bit unsigned integer values. 4
longlongn A vector of n 64-bit signed integer values. 2
ulonglongn A vector of n 64-bit unsigned integer values. 2
floatn A vector of n 32-bit single-precision floating-point values. 4
doublen A vector of n 64-bit double-precision floating-point values. 8

where n can be a vector length of 2, 3, 4, 8, or 16.

For example, a "uchar8" is a vector of 8 unsigned chars; its length is 8 and its size is 64 bits. A "float4" is a vector of 4 float elements; its length is 4 and its size is 128 bits.

Vectors types are aligned on a boundary equal to the total size of the vector's elements up to 64 bits. Any vector type with a total size of more than 64 bits is aligned to a 64-bit boundary (8 bytes). For example, a short2 has a total size of 32 bits and is aligned on a 4-byte boundary. A longlong2 has a total size of 128 bits and is aligned on an 8-byte boundary.

NOTE

To avoid confusion between C6000's definition of long (32-bits) and 64-bit definitions of long, vector types with a base type of "long" and unsigned long ("ulong") are not provided. If you want to use the standard long and ulong types, you can create a simple preprocessor macro such as: #define long2 longlong2 or #define long2 int2, depending the element type and size you want to use.

The Code Generation Tools also provide an extension for representing vectors of complex types. A prefix of 'c' is used to indicate a complex type name. Each complex type vector element contains a real part and an imaginary part with the real part occupying the lower address in memory. Thus, the complex vector types are as follows:

Table 7-3 Complex Vector Data Types

Type Description Maximum Elements
ccharn A vector of n pairs of 8-bit signed integer values. 8
cshortn A vector of n pairs of 16-bit signed integer values. 4
cintn A vector of n pairs of 32-bit signed integer values. 2
clonglongn A vector of n pairs of 64-bit signed integer values. 1
cfloatn A vector of n pairs of 32-bit floating-point values. 2
cdoublen A vector of n pairs of 64-bit floating-point values. 1

where n can be a vector length of 1, 2, 4, or 8. Note that 16 is not a valid vector length for complex vector types. For example, a "cfloat2" is a vector of 2 complex floats. Its length is 2 and its size is 128 bits. Each "cfloat2" vector element contains a real float and an imaginary float.

For information about operators and built-in functions used with vector data types, see Section 7.15.