Using struct as SSE vector type in gcc?

Is it possible in GCC to use a structure or class as a vector type for SSE instructions?

sort of:

typedef struct vfloat __attribute__((vector_size(16))) {
   float x,y,z,w;
} vfloat;

Instead of canonical:

typedef float v4sf __attribute__ ((vector_size(16)));

union vfloat {
    v4sf  v;
    float f[4];
};

It would be very convenient, but I can not get it to work.

+3
source share
2 answers

Could you do unionas the one you published, but with your structinstead float f[4];as the second member? This will give you the behavior you want.

+2
source

The structure you seem to be looking for

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, nickname rules may bite you later in the future. Instead, I recommend using access macros or static inline.

0
source

Source: https://habr.com/ru/post/1790357/


All Articles