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(3clc)(2m-1) least significant bits of
each mask element are considered. For shuffle2, only the ilogb(3clc)(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(3clc)(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.
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}, int{2|4|8|16}, uint{2|4|8|16}, long{2|4|8|16},
ulong{2|4|8|16}, or float{2|4|8|16} as the type for the arguments unless otherwise stated. We use the
generic name ugentypen to indicate the built-in unsigned integer data types. If the double is supported,
then gentypen (or gentypem) also indicate the built-in data types double{2|4|8|16}.
The generic type name gentypen (or gentypem) may indicate the data type half{2|4|8|16} if the
cl_khr_fp16(3clc) extension is supported.
Example
uint4 mask = (uint4)(3, 2, 1, 0); float4 a; float4 r =
shuffle(a, mask); // r.s0123 = a.wzyx
uint8 mask = (uint8)(0, 1, 2, 3, 4, 5, 6, 7);
float4 a, b; float8 r = shuffle2(a, b, mask); // r.s0123
= a.xyzw // r.s4567 = b.xyzw
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);