Is it possible in GCC to use a struct or class as a vector type for SSE instructions?
something like:
typedef struct vfloat __attribute__((vector_size(16))) {
float x,y,z,w;
} vfloat;
Rather than the canonical:
开发者_Go百科typedef float v4sf __attribute__ ((vector_size(16)));
union vfloat {
v4sf v;
float f[4];
};
Would be very handy, but I can't seem to make it work.
Could you make a union
like the one you posted but with your struct
instead of float f[4];
as the second member? That would give you the behavior you want.
The structure you seem be looking for is
typedef float v4sf __attribute__ ((vector_size(16)));
typedef struct vfloat vfloat;
struct vfloat {
union {
v4sf v;
float f[4];
struct {
float x;
float y;
float z;
float w;
};
};
};
However, the aliasing rules may bite you later on in the future. I recommend using accessor macros or static inline
functions instead.
精彩评论