GCC Vector Extensions

Greg Buchholz gcc@sleepingsquirrel.org
Fri Apr 7 20:16:00 GMT 2006

Christian Schoenebeck wrote:
> b) We wondered [2] what the currently best way is to access single elements of
> one vector. Currently the only solution we saw is to use a union trick

/* I don't know if this qualifies as good, but here's some things
   I've used before  */

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

int main()
    v4sf  a,b,c;
    float *z;

    ((float *)&a)[0] = 1.0;
    ((float *)&a)[1] = 2.0;
    ((float *)&a)[2] = 3.0;
    ((float *)&a)[3] = 4.0;
    memcpy((float *)&b,(float[]){0.5,0.6,0.7,0.8},4*sizeof(float));
    c = a + b;

    z = (float *)&c;
    printf("%f, %f, %f, %f\n", *z, *(z+1), z[2], z[3]);
    return 0;

More information about the Gcc-help mailing list