This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
SIMD types and aliasing rules
- From: Lorenz Minder <lminder at gmx dot net>
- To: gcc-help at gcc dot gnu dot org
- Date: Mon, 31 Dec 2007 02:27:40 +0100
- Subject: SIMD types and aliasing rules
Hi,
I have a question about SIMD vector types and the gcc aliasing rules.
For simplicity, suppose sizeof(int)==4, and consider the following code:
#include <stdio.h>
typedef int v4si __attribute__ ((vector_size(16)));
int main(void)
{
v4si y = { 1, 1, 1, 1 };
v4si x = { 0, 2, 0, 4 };
((int *)&x)[0] = 1;
((int *)&x)[2] = 3;
x += y;
printf("%d %d %d %d\n", ((int *)&x)[0],
((int *)&x)[1], ((int *)&x)[2], ((int *)&x)[3]);
return 0;
}
Is this code correct? If not, what is the correct portable (within gcc)
way to read or write a member of a vector?
Best,
--Lorenz