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, 16, 32, or 64. Wherever possible, intrinsics that act upon vectors are optimized to make use of efficient single instruction, multiple data (SIMD) instructions on the device.

Support for vector data types is enabled by default. You can use the --vectypes=off compiler option if you want to disable the vector data type names that are not prefixed with a double-underscore. For example, the __int4 type is always available, but the --vectypes=off option disables the int4 type. Note that the tables and examples that follow use type names without the double-underscore prefix.

All of the vector data types and related built-in functions that are supported in the C7000 programming model are specified in the "c7x.h" header file.

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 C7000 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 C7000 programming model provides the following built-in vector data types:

Table 5-3 Vector Data Types

Type Description Maximum Elements
charn A vector of n 8-bit signed integer values. 64
ucharn A vector of n 8-bit unsigned integer values. 64
shortn A vector of n 16-bit signed integer values. 32
ushortn A vector of n 16-bit unsigned integer values. 32
intn A vector of n 32-bit signed integer values. 16
uintn A vector of n 32-bit unsigned integer values. 16
longn A vector of n 64-bit signed integer values. 8
ulongn A vector of n 64-bit unsigned integer values. 8
floatn A vector of n 32-bit single-precision floating-point values. 16
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, 16, 32, or 64.

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 long2 has a total size of 128 bits and is aligned on an 8-byte boundary.

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 5-4 Complex Vector Data Types

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

where n can be a vector length of 1, 2, 4, 8, 16, or 32. Note that 64 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 5.14.