ZHCUAQ1F july 2015 – april 2023
编程模型实现方案支持以下“混合”运算符。这些运算符用作变量名的后缀。这些运算符可用于赋值运算符的任意一侧(左侧或右侧)。在赋值的左侧使用时,每个分量必须是唯一可识别的。
char4 my_c4 = (char4)(1, 2, 3, 4);
char tmp = my_c4.y * my_c4.w;
/* ".y" accesses 2nd element ".w" accesses 4th element
* tmp = 2 * 4 = 8; */
uchar16 ucvec16 = (uchar16)(1, 2, 3, 4, 5, 6, 7, 8,
9, 10, 11, 12, 13, 14, 15, 16 );
uchar8 ucvec8 = (uchar8)(2, 4, 6, 8, 10, 12, 14, 16);
int tmp = ucvec16.sa * ucvec8.s7;
/* ".sa" is 11th element of ucvec16
* ".s7" is 8th element of ucvec8
* tmp = 11 * 16 = 176; */
ushort4 usvec4 = (ushort4)(1, 2, 3, 4);
ushort2 usvecodd = usvec4.odd; /* usvecodd = (ushort2)(2, 4); */
ushort2 usveceven = usvec4.even; /* usveceven = (ushort2)(1, 3); */
ushort8 usvec8 = (ushort8)(1, 2, 3, 4, 5, 6, 7, 8);
ushort4 usvechi = usvec8.hi; /* usvechi = (ushort4)(5, 6, 7, 8);*/
ushort4 usveclo = usvec8.lo; /* usveclo = (ushort4)(1, 2, 3, 4); */
cfloat2 cfa = (cfloat2)(1.0, -2.0, 3.0, -4.0);
float2 rfa = cfa.r; /* rfa = (float2)(1.0, 3.0); */
cfloat2 cfa = (cfloat2)(1.0, -2.0, 3.0, -4.0);
float2 ifa = cfa.i; /* ifa = (float2)(-2.0, -4.0); */
可以组合混合运算符来访问元素子集的子集。组合的结果必须明确定义。例如,在以下代码运行后,usvec4 包含(1、2、5、4)。
ushort4 usvec4 = (ushort4)(1, 2, 3, 4);
usvec4.hi.even = 5;