通过指针、转换和取消引用加载向量?
Loading vectors through pointers, casts and dereferences?
OpenPower Manual | Vector Data Types 声明避免手动加载元素,并使用向量转换:
The preferred way to access vectors at an application-defined address
is by using vector pointers and the C/C++ dereference operator *.
Similar to other C /C++ data types, the array reference operator [ ]
may be used to access vector objects with a vector pointer with the
usual definition to access the n-th vector element from a vector
pointer. The use of vector built-in functions such as vec_xl and
vec_xst is discouraged except for languages where no dereference
operators are available.
vector char vca;
vector char vcb;
vector int via;
int a[4];
void *vp;
via = *(vector int *) &a[0];
vca = (vector char) via;
vcb = vca;
vca = *(vector char *)vp;
*(vector char *)&a[0] = vca;
我正处于测试该技术的早期阶段,但上面的代码似乎可以编译。测试的编译器是 GCC 4.0.1(旧 PowerMac G5)和 GCC 4.8.5(Power 730 服务器)。
我的第一个问题是,该技术是否正确处理未对齐的字节数组?
我的第二个问题是,该技术是否会在小端系统上自动执行大端转换?
我的第三个问题是,我们应该在实践中使用该技术吗?感觉该技术应该产生未定义的行为或双关违规。
My first question is, does the technique handle unaligned byte arrays properly?
不,它不能正确处理未对齐的数组。内存地址和偏移量被 masking-off 4 low-order 位截断为有效地址。
My second question is, does the technique automatically perform big-endian conversions on little-endian systems?
是的。
My third question is, should we use the technique in practice?
不,不要使用它。
OpenPower Manual | Vector Data Types 声明避免手动加载元素,并使用向量转换:
The preferred way to access vectors at an application-defined address is by using vector pointers and the C/C++ dereference operator *. Similar to other C /C++ data types, the array reference operator [ ] may be used to access vector objects with a vector pointer with the usual definition to access the n-th vector element from a vector pointer. The use of vector built-in functions such as vec_xl and vec_xst is discouraged except for languages where no dereference operators are available.
vector char vca;
vector char vcb;
vector int via;
int a[4];
void *vp;
via = *(vector int *) &a[0];
vca = (vector char) via;
vcb = vca;
vca = *(vector char *)vp;
*(vector char *)&a[0] = vca;
我正处于测试该技术的早期阶段,但上面的代码似乎可以编译。测试的编译器是 GCC 4.0.1(旧 PowerMac G5)和 GCC 4.8.5(Power 730 服务器)。
我的第一个问题是,该技术是否正确处理未对齐的字节数组?
我的第二个问题是,该技术是否会在小端系统上自动执行大端转换?
我的第三个问题是,我们应该在实践中使用该技术吗?感觉该技术应该产生未定义的行为或双关违规。
My first question is, does the technique handle unaligned byte arrays properly?
不,它不能正确处理未对齐的数组。内存地址和偏移量被 masking-off 4 low-order 位截断为有效地址。
My second question is, does the technique automatically perform big-endian conversions on little-endian systems?
是的。
My third question is, should we use the technique in practice?
不,不要使用它。