Description

The OpenCL C programming language implements the following additional built-in vector functions. We use the generic type name gentypen (or gentypem) to indicate the built-in data types char{2|4|8|16}, uchar{2|4|8|16}, short{2|4|8|16}, ushort{2|4|8|16}, half{2|4|8|16}49, int{2|4|8|16}, uint{2|4|8|16}, long{2|4|8|16}, ulong{2|4|8|16}, float{2|4|8|16}, or double{2|4|8|16}50 as the type for the arguments unless otherwise stated. We use the generic name ugentypen to indicate the built-in unsigned integer data types.

[49] Only if the cl_khr_fp16 extension is supported and has been enabled.

[50] Only if double precision is supported.

Table 1. Built-in Miscellaneous Vector Functions

Function

Description

int vec_step(gentypen a)
int vec_step(char3 a)
int vec_step(uchar3 a)
int vec_step(short3 a)
int vec_step(ushort3 a)
int vec_step(half3 a)
int vec_step(int3 a)
int vec_step(uint3 a)
int vec_step(long3 a)
int vec_step(ulong3 a)
int vec_step(float3 a)
int vec_step(double3 a)
int vec_step(type)

The vec_step built-in function takes a built-in scalar or vector data type argument and returns an integer value representing the number of elements in the scalar or vector.

For all scalar types, vec_step returns 1.

The vec_step built-in functions that take a 3-component vector return 4.

vec_step may also take a pure type as an argument, e.g. vec_step(float2)

gentypen shuffle(gentypem x, ugentypen mask)
gentypen shuffle2(gentypem x, gentypem y, ugentypen mask)

The shuffle and shuffle2 built-in functions construct a permutation of elements from one or two input vectors respectively that are of the same type, returning a vector with the same element type as the input and length that is the same as the shuffle mask. The size of each element in the mask must match the size of each element in the result. For shuffle, only the ilogb(2m-1) least significant bits of each mask element are considered. For shuffle2, only the ilogb(2m-1)+1 least significant bits of each mask element are considered. Other bits in the mask shall be ignored.

The elements of the input vectors are numbered from left to right across one or both of the vectors. For this purpose, the number of elements in a vector is given by vec_step(gentypem). The shuffle mask operand specifies, for each element of the result vector, which element of the one or two input vectors the result element gets.

Examples:

uint4 mask = (uint4)(3, 2, 1, 0);
float4 a;
float4 r = shuffle(a, mask);

uint8 mask = (uint8)(0, 1, 2, 3, 4, 5, 6, 7);
float4 a, b;
float8 r = shuffle2(a, b, mask);

uint4 mask;
float8 a;
float4 b;

b = shuffle(a, mask);

Examples that are not valid are:

uint8 mask;
short16 a;
short8 b;

b = shuffle(a, mask); //  not valid

See Also

Document Notes

For more information, see the OpenCL C Specification

This page is extracted from the OpenCL C Specification. Fixes and changes should be made to the Specification, not directly.

Copyright (c) 2014-2020 Khronos Group. This work is licensed under a Creative Commons Attribution 4.0 International License.